From e1bad5470e43ea1f8895ed4694d0be7ae1cbe8e7 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sun, 21 Dec 2025 12:35:18 +0000 Subject: [PATCH] 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. --- .gitignore | 2 -- docs/src/content/docs/changelog/v0.35.0.md | 7 +++-- docs/src/content/docs/install.md | 31 ++++++---------------- install/build.js | 4 +-- install/check.js | 14 ---------- lib/sharp.js | 1 + package.json | 3 +-- 7 files changed, 17 insertions(+), 45 deletions(-) delete mode 100644 install/check.js diff --git a/.gitignore b/.gitignore index 82f73b3f..56114cd4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ src/build src/node_modules node_modules -/coverage npm/*/* !npm/*/package.json test/bench/node_modules @@ -9,7 +8,6 @@ test/fixtures/output* test/fixtures/vips-properties.xml test/leak/libvips.supp .DS_Store -.nyc_output .vscode/ package-lock.json .idea diff --git a/docs/src/content/docs/changelog/v0.35.0.md b/docs/src/content/docs/changelog/v0.35.0.md index a7719d84..03fb139b 100644 --- a/docs/src/content/docs/changelog/v0.35.0.md +++ b/docs/src/content/docs/changelog/v0.35.0.md @@ -3,9 +3,12 @@ title: v0.35.0 - TBC 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. [#4314](https://github.com/lovell/sharp/issues/4314) diff --git a/docs/src/content/docs/install.md b/docs/src/content/docs/install.md index 9611b4f4..e5a3c182 100644 --- a/docs/src/content/docs/install.md +++ b/docs/src/content/docs/install.md @@ -20,10 +20,6 @@ npm install sharp pnpm add sharp ``` -When using `pnpm`, add `sharp` to -[ignoredBuiltDependencies](https://pnpm.io/settings#ignoredbuiltdependencies) -to silence warnings. - ```sh frame="none" yarn add sharp ``` @@ -112,13 +108,13 @@ and on macOS when running Node.js under Rosetta. ## 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 -* using `npm explore sharp -- npm run build`, or -* 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 +The build process will search for a globally-installed libvips. +This detection logic can be skipped by setting the `SHARP_IGNORE_GLOBAL_LIBVIPS` (never try to use it) or `SHARP_FORCE_GLOBAL_LIBVIPS` (always try to use it, even when missing or outdated) environment variables. @@ -129,21 +125,12 @@ Building from source requires: * [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 -There is an install-time check for these dependencies. If `node-addon-api` or `node-gyp` cannot be found, try adding them via: ```sh frame="none" 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 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" pkg install -y pkgconf vips -``` - -```sh frame="none" -cd /usr/ports/graphics/vips/ && make install clean +npm install sharp +npm explore sharp -- npm run build ``` ## Linux memory allocator diff --git a/install/build.js b/install/build.js index 2ca22458..579e11ad 100644 --- a/install/build.js +++ b/install/build.js @@ -10,7 +10,7 @@ const { spawnRebuild, } = 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'); try { @@ -29,7 +29,7 @@ try { } if (useGlobalLibvips(log)) { - log(`Detected globally-installed libvips v${globalLibvipsVersion()}`); + log(`Found globally-installed libvips v${globalLibvipsVersion()}`); } const status = spawnRebuild(); diff --git a/install/check.js b/install/check.js deleted file mode 100644 index 1cfb7d32..00000000 --- a/install/check.js +++ /dev/null @@ -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}`); -} diff --git a/lib/sharp.js b/lib/sharp.js index ce6548ff..6bf79d02 100644 --- a/lib/sharp.js +++ b/lib/sharp.js @@ -73,6 +73,7 @@ if (sharp) { } else { help.push( `- Manually install libvips >= ${minimumLibvipsVersion}`, + ' See https://sharp.pixelplumbing.com/install#building-from-source', '- Add experimental WebAssembly-based dependencies:', ' npm install --cpu=wasm32 sharp', ' npm install @img/sharp-wasm32' diff --git a/package.json b/package.json index 79f4eefb..6d2f0e98 100644 --- a/package.json +++ b/package.json @@ -93,8 +93,7 @@ ], "scripts": { "build": "node install/build.js", - "install": "node install/check.js || npm run build", - "clean": "rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*", + "clean": "rm -rf src/build/ test/fixtures/output.*", "test": "npm run lint && npm run test-unit", "lint": "npm run lint-cpp && npm run lint-js && npm run lint-types", "lint-cpp": "cpplint --quiet src/*.h src/*.cc",