-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Enhancement: Major overhaul of installation #3750
Comments
- Remove all custom download logic for prebuilt binaries - Add scripts to populate package contents - Specify minimum versions of common package managers - Remove sharp.vendor runtime API as no-longer relevant - Update installation docs and issue templates
Please don't drop support for |
@falkenhawk It might work with older versions of yarn, but evanw/esbuild#2949 provides a good example of the sort of problems you're going to run into. |
🎉 There is now a v0.33.0-rc.2 release candidate of sharp available that has no custom install scripts and relies entirely on the npm registry. I've tested it locally on Linux and via a new packaging test CI job - see https://github.com/lovell/sharp/actions/runs/6957160711
...both with and without the If you would like to test this locally then you can install this via:
When installed on Linux, Package Phobia suggests this has a disk space requirement of 16.4MB with yarn v3 and 32.4MB with npm 10 (the latter is still ignoring the There is also an experimental WebAssembly version. You'll need to use an up-to-date version of npm 10 with support for the
👍 If it works, brilliant, add a thumbs up please (no need to comment). 😭 I expect there will be a few problems, so if it doesn't work and no-one else has already mentioned it, please add a minimal comment that includes the output of |
I often have painful fights with electron when it comes to native libraries, so I am giving this a try in a project now. First problem is that the latest electron release is based on nodejs The second problem is the binding.gyp confuses electron-builder. It ends up failing to build with:
Yarn3 does recommend explicitly declaring I did have to make a change to my I also had to change some paths in my electron-builder config to point to the new location of libvips, but that is expected and simple. Simpler than before actually, as the path no longer includes a version number which changes for each release. With that, electron-builder is able to produce builds and it will bundle every installed version of the sharp native components. It would be nice for it to only include the relevant one, but thats an electron-builder issue. I was concerned going into this, but I am pleasantly surprised with how it went. I did also have to change the project to be yarn3 based, but I am fine with that. It was the kick needed to make it happen. I expect you will get pushback on this, but yarn1 has been EOL for over 2 years now, so I think it reasonable to 'force' users to change. |
@Julusian Thank you very much, this is really useful feedback. I've been considering moving the sharp C++ source code, gyp config etc. into a separate opt-in package and you've provided a good reason for doing so, namely that lots of the current tooling makes assumptions about the presence of a The use of |
@Julusian There's a new |
Trying to use the alpha.6 with Next.js serverless function on Vercel leading to the following error on invocation. Build is successful though. Command:- bun install v1.0.3 (25e69c71) Env Info:-
|
…d from `yarn` to `npm` (gated behind feature flag) (#11131) This PR changes the default package manager from `yarn` to `npm` in the case that no lockfile is present. Many years ago when `yarn` was first released, it was much faster than `npm` so we used it by default. That is no longer the case today and `yarn@1` is no longer receiving new features. For example, `sharp` and `esbuild` no longer works with `yarn@1`: ### Related - lovell/sharp#3750 - evanw/esbuild#2949 Note that this change will not impact most projects because most used a lockfile.
…ependency (#63321) ## History Previously, we added support for `squoosh` because it was a wasm implementation that "just worked" on all platforms when running `next dev` for the first time. However, it was slow so we always recommended manually installing `sharp` for production use cases running `next build` and `next start`. Now that [`sharp` supports webassembly](https://sharp.pixelplumbing.com/install#webassembly), we no longer need to maintain `squoosh`, so it can be removed. We also don't need to make the user install sharp manually because it can be installed under `optionalDependencies`. I left it optional in case there was some platform that still needed to manually install the wasm variant with `npm install --cpu=wasm32 sharp` such as codesandbox/stackblitz (I don't believe sharp has any fallback built in yet). Since we can guarantee `sharp`, we can also remove `get-orientation` dep and upgrade `image-size` dep. I also moved an [existing `sharp` test](#56674) into its own fixture since it was unrelated to image optimization. ## Related Issues - Fixes #41417 - Related #54670 - Related #54708 - Related #44804 - Related #48820 - Related #61810 - Related #61696 - Related #44685 - Closes #64362 ## Breaking Change This is a breaking change because newer versions of `sharp` no longer support `yarn@1`. - lovell/sharp#3750 The workaround is to install with `yarn --ignore-engines` flag. Also note that Vercel no longer defaults to yarn when no lockfile is found - vercel/vercel#11131 - vercel/vercel#11242 Closes NEXT-2823
…ependency (#63321) ## History Previously, we added support for `squoosh` because it was a wasm implementation that "just worked" on all platforms when running `next dev` for the first time. However, it was slow so we always recommended manually installing `sharp` for production use cases running `next build` and `next start`. Now that [`sharp` supports webassembly](https://sharp.pixelplumbing.com/install#webassembly), we no longer need to maintain `squoosh`, so it can be removed. We also don't need to make the user install sharp manually because it can be installed under `optionalDependencies`. I left it optional in case there was some platform that still needed to manually install the wasm variant with `npm install --cpu=wasm32 sharp` such as codesandbox/stackblitz (I don't believe sharp has any fallback built in yet). Since we can guarantee `sharp`, we can also remove `get-orientation` dep and upgrade `image-size` dep. I also moved an [existing `sharp` test](#56674) into its own fixture since it was unrelated to image optimization. ## Related Issues - Fixes #41417 - Related #54670 - Related #54708 - Related #44804 - Related #48820 - Related #61810 - Related #61696 - Related #44685 - Closes #64362 ## Breaking Change This is a breaking change because newer versions of `sharp` no longer support `yarn@1`. - lovell/sharp#3750 The workaround is to install with `yarn --ignore-engines` flag. Also note that Vercel no longer defaults to yarn when no lockfile is found - vercel/vercel#11131 - vercel/vercel#11242 Closes NEXT-2823
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
optionalDependencies
and platform-basedcpu
/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 thenpm
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.
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-arch
e.g.@img/sharp-libvips-linuxmusl-x64
Publish per-platform prebuilt binaries of sharp:
@sharpen/sharp-platform-arch
e.g.@img/sharp-linuxmusl-x64
rpath
values for Linux and macOS that match the various package manager filesystem layouts.Example: if
sharp.node
is located atnode_modules/@img/sharp-platform-arch/lib/sharp.node
then itsrpath
needs to contain:$$ORIGIN/../../sharp-libvips-platform-arch/lib
$$ORIGIN/../node_modules/@img/sharp-libvips-platform-arch/lib
arm_version
.Support multi-platform within same installation tree:
dependencies
to include a list of specific@img/sharp-platform-arch
packages.supportedArchitectures
- see https://yarnpkg.com/configuration/yarnrc#supportedArchitecturesSupport building from source:
@img/sharp-libvips-dev
package and add to sharp'sdevDependencies
node-addon-api
(and for yarn v3node-gyp
) to theirpackage.json
file.Windows will be a bit different, natch:
@img/sharp-libvips-win32-x64
.Support Wasm fallback:
process.platform
andprocess.arch
?--no-addons
at runtime? Yes, catchERR_DLOPEN_DISABLED
error 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-optional
flag.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#4533postpack
script to runadvdef --recompress --shrink-insane
over tarballs before uploading?Other breaking changes:
^18.17.0 || ^20.3.0 || >=21.0.0
yarn v3 PNP (Plug'n'Play) is unsupported, all the otherPNP support works.nodeLinker
settings should work.--ignore-engines
flag.sharp.vendor
runtime API as this logic will now be "owned" by the package manager.The text was updated successfully, but these errors were encountered: