Remove install script, building from source is now opt-in

The vast majority of people don't need this. Package managers
are (correctly) starting to block install scripts by default,
so this change should reduce install-time warnings.
This commit is contained in:
Lovell Fuller
2025-12-21 12:35:18 +00:00
parent 1a2c1c8833
commit e1bad5470e
7 changed files with 17 additions and 45 deletions

2
.gitignore vendored
View File

@@ -1,7 +1,6 @@
src/build src/build
src/node_modules src/node_modules
node_modules node_modules
/coverage
npm/*/* npm/*/*
!npm/*/package.json !npm/*/package.json
test/bench/node_modules test/bench/node_modules
@@ -9,7 +8,6 @@ test/fixtures/output*
test/fixtures/vips-properties.xml test/fixtures/vips-properties.xml
test/leak/libvips.supp test/leak/libvips.supp
.DS_Store .DS_Store
.nyc_output
.vscode/ .vscode/
package-lock.json package-lock.json
.idea .idea

View File

@@ -3,9 +3,12 @@ title: v0.35.0 - TBC
slug: changelog/v0.35.0 slug: changelog/v0.35.0
--- ---
* Upgrade to libvips v8.18.0 for upstream bug fixes. * Breaking: Drop support for Node.js 18, now requires Node.js >= 20.9.0.
* Drop support for Node.js 18, now requires Node.js >= 20.9.0. * Breaking: Remove `install` script from `package.json` file.
Compiling from source is now opt-in via the `build` script.
* Upgrade to libvips v8.18.0 for upstream bug fixes.
* Add `withGainMap` to process HDR JPEG images with embedded gain maps. * Add `withGainMap` to process HDR JPEG images with embedded gain maps.
[#4314](https://github.com/lovell/sharp/issues/4314) [#4314](https://github.com/lovell/sharp/issues/4314)

View File

@@ -20,10 +20,6 @@ npm install sharp
pnpm add sharp pnpm add sharp
``` ```
When using `pnpm`, add `sharp` to
[ignoredBuiltDependencies](https://pnpm.io/settings#ignoredbuiltdependencies)
to silence warnings.
```sh frame="none" ```sh frame="none"
yarn add sharp yarn add sharp
``` ```
@@ -112,13 +108,13 @@ and on macOS when running Node.js under Rosetta.
## Building from source ## Building from source
This module will be compiled from source when: ```sh frame="none"
npm install sharp
npm explore sharp -- npm run build
```
* a globally-installed libvips is detected, or The build process will search for a globally-installed libvips.
* using `npm explore sharp -- npm run build`, or This detection logic can be skipped by setting the
* using the deprecated `npm run --build-from-source` at `npm install` time.
The logic to detect a globally-installed libvips can be skipped by setting the
`SHARP_IGNORE_GLOBAL_LIBVIPS` (never try to use it) or `SHARP_IGNORE_GLOBAL_LIBVIPS` (never try to use it) or
`SHARP_FORCE_GLOBAL_LIBVIPS` (always try to use it, even when missing or outdated) `SHARP_FORCE_GLOBAL_LIBVIPS` (always try to use it, even when missing or outdated)
environment variables. environment variables.
@@ -129,21 +125,12 @@ Building from source requires:
* [node-addon-api](https://www.npmjs.com/package/node-addon-api) version 7+ * [node-addon-api](https://www.npmjs.com/package/node-addon-api) version 7+
* [node-gyp](https://github.com/nodejs/node-gyp#installation) version 9+ and its dependencies * [node-gyp](https://github.com/nodejs/node-gyp#installation) version 9+ and its dependencies
There is an install-time check for these dependencies.
If `node-addon-api` or `node-gyp` cannot be found, try adding them via: If `node-addon-api` or `node-gyp` cannot be found, try adding them via:
```sh frame="none" ```sh frame="none"
npm install --save node-addon-api node-gyp npm install --save node-addon-api node-gyp
``` ```
When using `pnpm`, you may need to add `sharp` to
[onlyBuiltDependencies](https://pnpm.io/settings#onlybuiltdependencies)
to ensure the installation script can be run.
For cross-compiling, the `--platform`, `--arch` and `--libc` npm flags
(or the `npm_config_platform`, `npm_config_arch` and `npm_config_libc` environment variables)
can be used to configure the target environment.
## WebAssembly ## WebAssembly
Experimental support is provided for runtime environments that provide Experimental support is provided for runtime environments that provide
@@ -166,10 +153,8 @@ as well as the additional [building from source](#building-from-source) dependen
```sh frame="none" ```sh frame="none"
pkg install -y pkgconf vips pkg install -y pkgconf vips
``` npm install sharp
npm explore sharp -- npm run build
```sh frame="none"
cd /usr/ports/graphics/vips/ && make install clean
``` ```
## Linux memory allocator ## Linux memory allocator

View File

@@ -10,7 +10,7 @@ const {
spawnRebuild, spawnRebuild,
} = require('../lib/libvips'); } = require('../lib/libvips');
log('Attempting to build from source via node-gyp'); log('Building from source');
log('See https://sharp.pixelplumbing.com/install#building-from-source'); log('See https://sharp.pixelplumbing.com/install#building-from-source');
try { try {
@@ -29,7 +29,7 @@ try {
} }
if (useGlobalLibvips(log)) { if (useGlobalLibvips(log)) {
log(`Detected globally-installed libvips v${globalLibvipsVersion()}`); log(`Found globally-installed libvips v${globalLibvipsVersion()}`);
} }
const status = spawnRebuild(); const status = spawnRebuild();

View File

@@ -1,14 +0,0 @@
/*!
Copyright 2013 Lovell Fuller and others.
SPDX-License-Identifier: Apache-2.0
*/
try {
const { useGlobalLibvips } = require('../lib/libvips');
if (useGlobalLibvips() || process.env.npm_config_build_from_source) {
process.exit(1);
}
} catch (err) {
const summary = err.message.split(/\n/).slice(0, 1);
console.log(`sharp: skipping install check: ${summary}`);
}

View File

@@ -73,6 +73,7 @@ if (sharp) {
} else { } else {
help.push( help.push(
`- Manually install libvips >= ${minimumLibvipsVersion}`, `- Manually install libvips >= ${minimumLibvipsVersion}`,
' See https://sharp.pixelplumbing.com/install#building-from-source',
'- Add experimental WebAssembly-based dependencies:', '- Add experimental WebAssembly-based dependencies:',
' npm install --cpu=wasm32 sharp', ' npm install --cpu=wasm32 sharp',
' npm install @img/sharp-wasm32' ' npm install @img/sharp-wasm32'

View File

@@ -93,8 +93,7 @@
], ],
"scripts": { "scripts": {
"build": "node install/build.js", "build": "node install/build.js",
"install": "node install/check.js || npm run build", "clean": "rm -rf src/build/ test/fixtures/output.*",
"clean": "rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*",
"test": "npm run lint && npm run test-unit", "test": "npm run lint && npm run test-unit",
"lint": "npm run lint-cpp && npm run lint-js && npm run lint-types", "lint": "npm run lint-cpp && npm run lint-js && npm run lint-types",
"lint-cpp": "cpplint --quiet src/*.h src/*.cc", "lint-cpp": "cpplint --quiet src/*.h src/*.cc",