akabekobeko / npm-icon-gen

Icon file generator for Windows, macOS, Web
MIT License
157 stars 29 forks source link

Failed, if I want covnert only to PNG #155

Open panther7 opened 1 year ago

panther7 commented 1 year ago

version: 3.0.1

const icongen = require('icon-gen');

 // FAIL, i want only 256 png
icongen('./sample.svg', './icons', {
   favicon: {
      name: 'favicon-',
      pngSizes: [256],
   },
});
// FAIL, i want only 256 png
icongen('./sample.svg', './icons', {
   favicon: {
      name: 'favicon-',
      pngSizes: [256],
      icoSizes: [],
   },
});
// FAIL, i want only 256 png
icongen('./sample.svg', './icons', {
   favicon: {
      name: 'favicon-',
      pngSizes: [256],
      icoSizes: [16],
   },
});

Error:

Error: ENOENT: no such file or directory, unlink 'C:\Users\filip\git\electron-analysis\app-build-bZGKMS\favicon.ico'
    at Object.unlinkSync (node:fs:1808:3)
    at generateICO (C:\Users\filip\git\electron-analysis\node_modules\icon-gen\dist\lib\ico.js:205:22)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at generateFavicon (C:\Users\filip\git\electron-analysis\node_modules\icon-gen\dist\lib\favicon.js:87:18)
    at generate (C:\Users\filip\git\electron-analysis\node_modules\icon-gen\dist\lib\index.js:112:23)
    at generateIconFromSVG (C:\Users\filip\git\electron-analysis\node_modules\icon-gen\dist\lib\index.js:176:25)
    at getIcon (C:\Users\filip\git\electron-analysis\scripts\app-build.js:132:5)
    at C:\Users\filip\git\electron-analysis\scripts\app-build.js:197:23 {
  errno: -4058,
  syscall: 'unlink',
  code: 'ENOENT',
  path: 'C:\\Users\\filip\\git\\electron-analysis\\app-build-bZGKMS\\favicon.ico'
}
// It's OK ¯\_(ツ)_/¯
icongen('./sample.svg', './icons', {
   favicon: {
      name: 'favicon-',
      pngSizes: [256],
      icoSizes: [256],
   },
});
eagerestwolf commented 1 year ago

I actually found the bug causing this. In favicon.ts#L105, the generateFavicon function checks if the array is "truthy". That in and of itself isn't an issue, since a non-empty array is "truthy". However, if the array is "falsy", the function ignores the options and just generates the default ICO sizes. Put another way, for anything that calls generateFavicon, generating BOTH PNG and ICO files will always happen, regardless of the options. The only control the user has is what size/sizes are generated. If no sizes are specified or the option is omitted, the defaults will ALWAYS be used.

eagerestwolf commented 1 year ago

UPDATE: I have added a proof of concept here. Also, sorry for commenting on such an old issue, just found the bug and thought it would be good to share the info.