You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 2015 sharp first started providing prebuilt libvips binaries and in 2018 started providing prebuilt binaries of itself.
The primary aim of this meta-improvement is to attempt to use only package manager mechanics at install time, without custom scripts, and without downloading binaries from hosts other than those controlled by a package manager.
(What appears below is a bit of a brain-dump and will evolve over time.)
What will this change allow/support?
Non-exhaustive list:
Reproducible builds
Offline installation
Secure/sandbox environments where npm scripts cannot be run at install time
Environments (countries, organisations) where access to GitHub is limited
Vulnerability reporting via package manager for upstream dependencies
The approach taken by esbuild has now proven that this is possible with its use of optionalDependencies and platform-based cpu/os/libc filters.
A small but important piece of the puzzle fell into place with libc filtering via npm/npm-install-checks#54, which is part of npm v9.6.5 and therefore included with the latest Node.js 18 and 20. but sadly it's not quite available in the npm CLI yet - see npm/rfcs#438 (comment)
This should remove an entire class of install and runtime error, whilst no doubt introducing a new class of error, but a change is as good as a rest.
Many thanks to the team at npm for transferring ownership.
Publish per-platform prebuilt binaries of libvips and its dependencies specifically for use by sharp:
These will tale the form @img/sharp-libvips-platform-arch e.g. @img/sharp-libvips-linuxmusl-x64
Publish per-platform prebuilt binaries of sharp:
These will take the form @sharpen/sharp-platform-arch e.g. @img/sharp-linuxmusl-x64
Set rpath values for Linux and macOS that match the various package manager filesystem layouts.
Example: if sharp.node is located at node_modules/@img/sharp-platform-arch/lib/sharp.node then its rpath needs to contain:
Can we declare an optional package that does not support a list of otherwise-natively-supported os/cpu/libc combos, e.g. not linux-x64 and not darwin-x64 and not ...?
What values do "sandbox" or "web container" platforms provide for process.platform and process.arch?
Can we detect when Node.js is run with --no-addons at runtime? Yes, catch ERR_DLOPEN_DISABLED error code.
Must display helpful error message for unsupported environments e.g. browsers and Wasm runtimes without threads/workers.
How is this going to be tested?
Need to be able to run sharp's unit tests against:
sharp built from source against prebuilt libvips binaries.
Prebuilt binaries of both sharp and libvips.
Using non-Node.js runtimes too e.g. Deno, Bun.
What are the possible problems?
Impossible to please everyone all the time:
Approach will fail when a package manager is configured to skip optional dependencies e.g. via npm's --no-optional flag.
Filesize increase as Brotli-ball option for libvips binaries no longer an option = ~10% increased download size:
TL;DR - see #3750 (comment)
In 2015 sharp first started providing prebuilt libvips binaries and in 2018 started providing prebuilt binaries of itself.
The primary aim of this meta-improvement is to attempt to use only package manager mechanics at install time, without custom scripts, and without downloading binaries from hosts other than those controlled by a package manager.
(What appears below is a bit of a brain-dump and will evolve over time.)
What will this change allow/support?
Non-exhaustive list:
The approach taken by esbuild has now proven that this is possible with its use of
optionalDependenciesand platform-basedcpu/os/libcfilters.A small but important piece of the puzzle fell into place with
libcfiltering via npm/npm-install-checks#54,which is part of npm v9.6.5 and therefore included with the latest Node.js 18 and 20.but sadly it's not quite available in thenpmCLI yet - see npm/rfcs#438 (comment)This should remove an entire class of install and runtime error, whilst no doubt introducing a new class of error, but a change is as good as a rest.
What needs to happen?
Register a suitable npm org for the namespace:
@img- see https://www.npmjs.com/org/imgPublish per-platform prebuilt binaries of libvips and its dependencies specifically for use by sharp:
@img/sharp-libvips-platform-arche.g.@img/sharp-libvips-linuxmusl-x64Publish per-platform prebuilt binaries of sharp:
@sharpen/sharp-platform-arche.g.@img/sharp-linuxmusl-x64rpathvalues for Linux and macOS that match the various package manager filesystem layouts.Example: if
sharp.nodeis located atnode_modules/@img/sharp-platform-arch/lib/sharp.nodethen itsrpathneeds to contain:$$ORIGIN/../../sharp-libvips-platform-arch/lib$$ORIGIN/../node_modules/@img/sharp-libvips-platform-arch/libarm_version.Support multi-platform within same installation tree:
dependenciesto include a list of specific@img/sharp-platform-archpackages.supportedArchitectures- see https://yarnpkg.com/configuration/yarnrc#supportedArchitecturesSupport building from source:
@img/sharp-libvips-devpackage and add to sharp'sdevDependenciesnode-addon-api(and for yarn v3node-gyp) to theirpackage.jsonfile.Windows will be a bit different, natch:
@img/sharp-libvips-win32-x64.Support Wasm fallback:
process.platformandprocess.arch?--no-addonsat runtime? Yes, catchERR_DLOPEN_DISABLEDerror code.How is this going to be tested?
Need to be able to run sharp's unit tests against:
What are the possible problems?
Impossible to please everyone all the time:
--no-optionalflag.Can we use an npmNo we cannot, as postpack is broken in slightly different ways in different versions of npm e.g. [BUG] npm publish with <tarball> parameter recreates tarball npm/cli#4533postpackscript to runadvdef --recompress --shrink-insaneover tarballs before uploading?Other breaking changes:
^18.17.0 || ^20.3.0 || >=21.0.0yarn v3 PNP (Plug'n'Play) is unsupported, all the otherPNP support works.nodeLinkersettings should work.--ignore-enginesflag.sharp.vendorruntime API as this logic will now be "owned" by the package manager.