scriptex / svg-symbol-sprite

A script to generate a symbol sprite from SVG files
https://atanas.info/portfolio/open-source/svg-symbol-sprite
MIT License
17 stars 2 forks source link

svg-symbol-sprite not getting/finding the config file when using pnpm #61

Open irv-armenta-g opened 2 weeks ago

irv-armenta-g commented 2 weeks ago

I am trying to use a custom config file (svgo.config.js) but it seems svg-symbol-sprite is unable to find it's location, even though it is in the same level as the script.

I have another project where I am using yarn and in that project it does seem to be working correctly.

In this current project I am using pnpm as the package manager and script runner, I am using tsx to run a specific file in root called generate-svg-icons.ts

 "scripts": {
    "generate:icons": "tsx generate-svg-icons.ts",
  },

This file uses execSync to call the inline CLI script, it's inside a fs.readDir call with other async functions in order to follow an order in execution.

  fs.readdir(iconsDirectory, (error, files) => {
      fs.writeFile(distributionFilePath, tsFileContents, async (error) => {

       // async logic....

       execSync(
        `pnpm svg-symbol-sprite -i public/icons -o public/${svgSymbolsFileName} -c ./svgo.config.js`,
        { stdio: 'inherit' }
      );
    });
});

edit: I also have tried withouth ./ as it is stated should be "absolute" but I get the same result"

I have tried so many ways, even using path.resolve() also tried adding the inline script in a separate script key and still I keep getting the same message:

SVG Symbol Sprite: SVGO configuration file not found. Using default SVGO configuration.

is this related to pnpm being the package manager? Information about my environment:

OS: windows 
NODE: v20.17.0
package manager: pnpm
script runner: tsx 

generate-svg-icons.ts and svgo.config.js both are in the same level at root ./

scriptex commented 2 weeks ago

Thanks for opening this and sorry for the troubles which you have. I haven't tried this with pnpm but it looks like this might be the issue here as it works correctly with yarn or npm. I also haven't used the module programatically as you do.

One thing which comes into my mind is adding a new script under scripts of your package.json like this:

{
  "scripts": {
    "svg-sprite": "svg-symbol-sprite -i public/icons -c ./svgo.config.js"
  }
}

and then execute it inside your script file like this

execSync(`pnpm run svg-sprite -o public/${svgSymbolsFileName}`, { stdio: 'inherit' });

Disclaimer: I haven't used pnpm and have no idea how it plays with stdio: 'inherit'.

If this doesn't work maybe you can verify that actually pnpm is causing the issues by temporarily switching to npm or yarn?

Let me know how this goes.