Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devvit create icons uses backslash in asset names on Windows #129

Open
PitchforkAssistant opened this issue Dec 14, 2024 · 0 comments
Open

Comments

@PitchforkAssistant
Copy link
Contributor

When using the devvit create icons command, the name of the asset is its relative path to the assets directory. This results in the generation of assets with an escape sequence in their name in the final TS file.

As an example, consider the following assets folder structure on Windows:

assets/
    subDirectory/
        vectorLogo.svg

Running devvit create icons on Windows will result in this icons.ts file:

// This file is auto-generated by `devvit create icons`. Do not edit it directly.
import {svg} from "@devvit/public-api";

export const Icons = {
  "subDirectory\vectorLogo.svg": svg`<svg/>`
} as const;

This behavior is expected from path.relative used to get the name:

const name = path.relative(assetsPath, asset);

Then backslash is in fact escaped there, but becomes unescaped when writing the SVGs to the icons TS file. I think the best solution would be to replace the backslashes with forward slashes, mimicking the behavior of tinyglob and making sure asset names are the same regardless of which platform you create them on.

TLDR: const name = path.relative(assetsPath, asset); should probably be const name = path.relative(assetsPath, asset).replaceAll(path.sep, '/');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant