josephden16 / pic-shrink

pic-shrink is an easy-to-use CLI tool for compressing images in JPG, PNG, and WEBP.
4 stars 0 forks source link

Installable binary #1

Closed a11rew closed 1 year ago

a11rew commented 1 year ago

Would be great to get this in a single binary downloadable from NPM or Github releases we could use without having to ensure Node is present in the environment (or a specific version of Node for that matter).

josephden16 commented 1 year ago

Great suggestion. I'll add a downloadable binary preferably with GitHub releases this week. Thanks, bro 🙌

josephden16 commented 1 year ago

You can now download a packaged binary of this project for your platform/os of choice @a11rew
Please check it out and share feedback if there are any concerns. Thanks.

a11rew commented 1 year ago

Binary fails for me with the following output:

$ chmod +x ./image-compressor-macos-x64 && ./image-compressor-macos-x64 --imagesPath office.jpeg

pkg/prelude/bootstrap.js:1872
      throw error;
      ^

Error:
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-darwin-x64.node'
Require stack:
- /snapshot/image-compressor/node_modules/sharp/lib/sharp.js
- /snapshot/image-compressor/node_modules/sharp/lib/constructor.js
- /snapshot/image-compressor/node_modules/sharp/lib/index.js
- /snapshot/image-compressor/dist/app.js
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.

Possible solutions:
- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
- Install for the current darwin-x64 runtime: "npm install --platform=darwin --arch=x64 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (/snapshot/image-compressor/node_modules/sharp/lib/sharp.js:37:9)
    at Module._compile (pkg/prelude/bootstrap.js:1926:22)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (/snapshot/image-compressor/node_modules/sharp/lib/constructor.js:11:1)
    at Module._compile (pkg/prelude/bootstrap.js:1926:22)

Local Env Details:

OS: MacOS Ventura - 13.4.1 Platform: M Series ARM Chip

josephden16 commented 1 year ago

Thanks for the feedback. I'll look into the error and find ways to reproduce it and possibly work out a fix.

josephden16 commented 1 year ago

@a11rew I've made some changes to the CI workflow that might provide a possible fix for the issue. Please try it out and send feedback if there are still errors. Thanks.

a11rew commented 1 year ago

Still the same error.

chmod +x ./image-compressor-mac && ./image-compressor-mac --imagesPath office.jpeg
pkg/prelude/bootstrap.js:1872
      throw error;
      ^

Error:
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-darwin-x64.node'
Require stack:
- /snapshot/image-compressor/node_modules/sharp/lib/sharp.js
- /snapshot/image-compressor/node_modules/sharp/lib/constructor.js
- /snapshot/image-compressor/node_modules/sharp/lib/index.js
- /snapshot/image-compressor/dist/app.js
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.

Possible solutions:
- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
- Install for the current darwin-x64 runtime: "npm install --platform=darwin --arch=x64 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (/snapshot/image-compressor/node_modules/sharp/lib/sharp.js:37:9)
    at Module._compile (pkg/prelude/bootstrap.js:1926:22)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at Module.require (pkg/prelude/bootstrap.js:1851:31)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/snapshot/image-compressor/node_modules/sharp/lib/constructor.js:11:1)
    at Module._compile (pkg/prelude/bootstrap.js:1926:22)

The Sharp binary this depends on isn't added to the executable, take a look at the output of the build action: https://github.com/josephden16/image-compressor/actions/runs/5588385852/jobs/10215102199#step:6:9

A single executable would be best case scenario for me but a zip with the Sharp binary included would work too.

josephden16 commented 1 year ago

This makes a lot of sense. I'll look into it and work out a fix. Thanks bro.

josephden16 commented 1 year ago

@a11rew I've tried bundling the sharp binary with the executable and zipped it for the specific os/platform. Please try it out and send feedback if there are still errors. Thanks bro.

a11rew commented 1 year ago

Works great now, thanks for taking this up 🚀

image