diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index b65d48b98..72ffc3793 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -25,7 +25,7 @@ Please select the `main` branch as the destination for your Pull Request so your Please squash your changes into a single commit using a command like `git rebase -i upstream/main`. -To test C++ changes, you can compile the module using `npm run build` and then run the tests using `npm test`. +To test C++ changes, you can compile the module using `npm run build:dist && npm run build` and then run the tests using `npm test`. ## Submit a Pull Request with a new feature diff --git a/.github/ISSUE_TEMPLATE/installation.md b/.github/ISSUE_TEMPLATE/installation.md index b47d10e9a..7ec5f38e7 100644 --- a/.github/ISSUE_TEMPLATE/installation.md +++ b/.github/ISSUE_TEMPLATE/installation.md @@ -1,6 +1,6 @@ --- name: Installation -about: Something went wrong during either 'npm install sharp' or 'require("sharp")' +about: Something went wrong during either 'npm install sharp' or 'import "sharp"' labels: installation --- diff --git a/.github/ISSUE_TEMPLATE/possible-bug.md b/.github/ISSUE_TEMPLATE/possible-bug.md index c7e130e17..6e1fff328 100644 --- a/.github/ISSUE_TEMPLATE/possible-bug.md +++ b/.github/ISSUE_TEMPLATE/possible-bug.md @@ -14,7 +14,7 @@ labels: triage - [ ] Running `npm install sharp` completes without error. -- [ ] Running `node -e "require('sharp')"` completes without error. +- [ ] Running `node -e "import 'sharp'"` completes without error. If you cannot confirm both of these, please open an [installation issue](https://github.com/lovell/sharp/issues/new?labels=installation&template=installation.md) instead. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd6838590..6d45418c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,7 +170,7 @@ jobs: architecture: ${{ matrix.nodejs_arch }} - uses: actions/checkout@v4 - run: npm install - - run: npm run build + - run: npm run build:dist && npm run build - run: npm run test-unit - if: matrix.package run: npm run package-from-local-build @@ -213,7 +213,7 @@ jobs: run: apk add build-base git python3 font-noto --update-cache - uses: actions/checkout@v4 - run: npm install - - run: npm run build + - run: npm run build:dist && npm run build - run: npm run test-unit - if: matrix.package run: npm run package-from-local-build @@ -276,6 +276,7 @@ jobs: curl --silent https://${{ matrix.nodejs_hostname }}/download/release/v${{ matrix.nodejs_version}}/node-v${{ matrix.nodejs_version}}-linux-${{ matrix.nodejs_arch }}.tar.xz | tar xJC /opt/nodejs --strip-components=1 export PATH=$PATH:/opt/nodejs/bin npm install + npm run build:dist npm run build node --test test/unit/io.js npm run package-from-local-build @@ -301,7 +302,7 @@ jobs: with: node-version: "20" - run: npm install - - run: emmake npm run build + - run: npm run build:dist && emmake npm run build - name: Verify emscripten versions match run: | EMSCRIPTEN_VERSION_LIBVIPS=$(node -p "require('@img/sharp-libvips-dev-wasm32/versions').emscripten") diff --git a/.gitignore b/.gitignore index 82f73b3f0..f2ac38d2b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ package-lock.json .astro docs/dist release-notes.md +dist \ No newline at end of file diff --git a/README.md b/README.md index 47da52e8b..d82f7e2d6 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,10 @@ npm install sharp ``` ```javascript +// ESM +import sharp from 'sharp'; + +// CJS const sharp = require('sharp'); ``` diff --git a/biome.json b/biome.json index 7946049c8..b2ba9d0e3 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/2.3.4/schema.json", + "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", "vcs": { "enabled": true, "clientKind": "git", diff --git a/docs/src/content/docs/api-constructor.md b/docs/src/content/docs/api-constructor.md index 3504239dc..b3484701f 100644 --- a/docs/src/content/docs/api-constructor.md +++ b/docs/src/content/docs/api-constructor.md @@ -229,8 +229,8 @@ readableStream.pipe(pipeline); ```js // Create a pipeline that will download an image, resize it and format it to different files // Using Promises to know when the pipeline is complete -const fs = require("fs"); -const got = require("got"); +import fs from "node:fs"; +import got from "got"; const sharpStream = sharp({ failOn: 'none' }); const promises = []; diff --git a/install/build.js b/install/build.js index 2ca224586..82903a055 100644 --- a/install/build.js +++ b/install/build.js @@ -8,7 +8,7 @@ const { globalLibvipsVersion, log, spawnRebuild, -} = require('../lib/libvips'); +} = require('../dist/libvips.cjs'); log('Attempting to build from source via node-gyp'); log('See https://sharp.pixelplumbing.com/install#building-from-source'); diff --git a/install/check.js b/install/check.js index 1cfb7d32e..7d1902ae9 100644 --- a/install/check.js +++ b/install/check.js @@ -4,7 +4,7 @@ */ try { - const { useGlobalLibvips } = require('../lib/libvips'); + const { useGlobalLibvips } = require('../dist/libvips.cjs'); if (useGlobalLibvips() || process.env.npm_config_build_from_source) { process.exit(1); } diff --git a/lib/channel.js b/lib/channel.mjs similarity index 98% rename from lib/channel.js rename to lib/channel.mjs index 3c6c0b439..1fdf0a990 100644 --- a/lib/channel.js +++ b/lib/channel.mjs @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0 */ -const is = require('./is'); +import is from './is.mjs'; /** * Boolean operations for bandbool. @@ -163,7 +163,7 @@ function bandbool (boolOp) { * @module Sharp * @private */ -module.exports = (Sharp) => { +export default (Sharp) => { Object.assign(Sharp.prototype, { // Public instance functions removeAlpha, diff --git a/lib/colour.js b/lib/colour.mjs similarity index 98% rename from lib/colour.js rename to lib/colour.mjs index e61c248a8..718b20a2a 100644 --- a/lib/colour.js +++ b/lib/colour.mjs @@ -3,8 +3,8 @@ SPDX-License-Identifier: Apache-2.0 */ -const color = require('@img/colour'); -const is = require('./is'); +import color from '@img/colour'; +import is from './is.mjs'; /** * Colourspaces. @@ -175,7 +175,7 @@ function _setBackgroundColourOption (key, value) { * @module Sharp * @private */ -module.exports = (Sharp) => { +export default (Sharp) => { Object.assign(Sharp.prototype, { // Public tint, diff --git a/lib/composite.js b/lib/composite.mjs similarity index 99% rename from lib/composite.js rename to lib/composite.mjs index 1c3e5e629..a8f2f2063 100644 --- a/lib/composite.js +++ b/lib/composite.mjs @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0 */ -const is = require('./is'); +import is from './is.mjs'; /** * Blend modes. @@ -206,7 +206,7 @@ function composite (images) { * @module Sharp * @private */ -module.exports = (Sharp) => { +export default (Sharp) => { Sharp.prototype.composite = composite; Sharp.blend = blend; }; diff --git a/lib/constructor.js b/lib/constructor.mjs similarity index 98% rename from lib/constructor.js rename to lib/constructor.mjs index 9aac8105c..480f20fd3 100644 --- a/lib/constructor.js +++ b/lib/constructor.mjs @@ -3,11 +3,11 @@ SPDX-License-Identifier: Apache-2.0 */ -const util = require('node:util'); -const stream = require('node:stream'); -const is = require('./is'); +import util from 'node:util'; +import stream from 'node:stream'; +import is from './is.mjs'; -require('./sharp'); +import './sharp.mjs'; // Use NODE_DEBUG=sharp to enable libvips warnings const debuglog = util.debuglog('sharp'); @@ -426,8 +426,8 @@ Object.setPrototypeOf(Sharp, stream.Duplex); * @example * // Create a pipeline that will download an image, resize it and format it to different files * // Using Promises to know when the pipeline is complete - * const fs = require("fs"); - * const got = require("got"); + * import fs from "node:fs"; + * import got from "got"; * const sharpStream = sharp({ failOn: 'none' }); * * const promises = []; @@ -496,4 +496,4 @@ Object.assign(Sharp.prototype, { clone }); * @module Sharp * @private */ -module.exports = Sharp; +export default Sharp; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index b80191d71..000000000 --- a/lib/index.js +++ /dev/null @@ -1,16 +0,0 @@ -/*! - Copyright 2013 Lovell Fuller and others. - SPDX-License-Identifier: Apache-2.0 -*/ - -const Sharp = require('./constructor'); -require('./input')(Sharp); -require('./resize')(Sharp); -require('./composite')(Sharp); -require('./operation')(Sharp); -require('./colour')(Sharp); -require('./channel')(Sharp); -require('./output')(Sharp); -require('./utility')(Sharp); - -module.exports = Sharp; diff --git a/lib/index.mjs b/lib/index.mjs new file mode 100644 index 000000000..73a5ad2ed --- /dev/null +++ b/lib/index.mjs @@ -0,0 +1,25 @@ +/*! + Copyright 2013 Lovell Fuller and others. + SPDX-License-Identifier: Apache-2.0 +*/ + +import Sharp from './constructor.mjs'; +import input from './input.mjs'; +import resize from './resize.mjs'; +import composite from './composite.mjs'; +import operation from './operation.mjs'; +import colour from './colour.mjs'; +import channel from './channel.mjs'; +import output from './output.mjs'; +import utility from './utility.mjs'; + +input(Sharp); +resize(Sharp); +composite(Sharp); +operation(Sharp); +colour(Sharp); +channel(Sharp); +output(Sharp); +utility(Sharp); + +export default Sharp; diff --git a/lib/input.js b/lib/input.mjs similarity index 99% rename from lib/input.js rename to lib/input.mjs index 48388a1d2..dbffcc7a9 100644 --- a/lib/input.js +++ b/lib/input.mjs @@ -3,8 +3,8 @@ SPDX-License-Identifier: Apache-2.0 */ -const is = require('./is'); -const sharp = require('./sharp'); +import is from './is.mjs'; +import sharp from './sharp.mjs'; /** * Justification alignment @@ -792,7 +792,7 @@ function stats (callback) { * @module Sharp * @private */ -module.exports = (Sharp) => { +export default (Sharp) => { Object.assign(Sharp.prototype, { // Private _inputOptionsFromObject, diff --git a/lib/is.js b/lib/is.mjs similarity index 99% rename from lib/is.js rename to lib/is.mjs index 3ac9a1a35..bfb4188f8 100644 --- a/lib/is.js +++ b/lib/is.mjs @@ -124,7 +124,7 @@ const nativeError = (native, context) => { return context; }; -module.exports = { +export default { defined, object, plainObject, diff --git a/lib/libvips.js b/lib/libvips.mjs similarity index 90% rename from lib/libvips.js rename to lib/libvips.mjs index 881dc5c13..fcf8f1002 100644 --- a/lib/libvips.js +++ b/lib/libvips.mjs @@ -3,14 +3,16 @@ SPDX-License-Identifier: Apache-2.0 */ -const { spawnSync } = require('node:child_process'); -const { createHash } = require('node:crypto'); -const semverCoerce = require('semver/functions/coerce'); -const semverGreaterThanOrEqualTo = require('semver/functions/gte'); -const semverSatisfies = require('semver/functions/satisfies'); -const detectLibc = require('detect-libc'); +import { spawnSync } from 'node:child_process'; +import { createHash } from 'node:crypto'; +import fs from 'node:fs'; +import semverCoerce from 'semver/functions/coerce'; +import semverGreaterThanOrEqualTo from 'semver/functions/gte'; +import semverSatisfies from 'semver/functions/satisfies'; +import detectLibc from 'detect-libc'; -const { config, engines, optionalDependencies } = require('../package.json'); +// Cannot use an import because sometimes it can need the attr or with keyword +const { config, engines, optionalDependencies } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')); /* node:coverage ignore next */ const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || config.libvips; @@ -189,7 +191,7 @@ const useGlobalLibvips = (logger) => { return !!globalVipsVersion && semverGreaterThanOrEqualTo(globalVipsVersion, minimumLibvipsVersion); }; -module.exports = { +export default { minimumLibvipsVersion, prebuiltPlatforms, buildPlatformArch, diff --git a/lib/operation.js b/lib/operation.mjs similarity index 99% rename from lib/operation.js rename to lib/operation.mjs index ebbf54e9c..d4d1ac777 100644 --- a/lib/operation.js +++ b/lib/operation.mjs @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0 */ -const is = require('./is'); +import is from './is.mjs'; /** * How accurate an operation should be. @@ -987,7 +987,7 @@ function modulate (options) { * @module Sharp * @private */ -module.exports = (Sharp) => { +export default (Sharp) => { Object.assign(Sharp.prototype, { autoOrient, rotate, diff --git a/lib/output.js b/lib/output.mjs similarity index 99% rename from lib/output.js rename to lib/output.mjs index 27a6ac470..75346cd1a 100644 --- a/lib/output.js +++ b/lib/output.mjs @@ -3,9 +3,9 @@ SPDX-License-Identifier: Apache-2.0 */ -const path = require('node:path'); -const is = require('./is'); -const sharp = require('./sharp'); +import path from 'node:path'; +import is from './is.mjs'; +import sharp from './sharp.mjs'; const formats = new Map([ ['heic', 'heif'], @@ -1630,7 +1630,7 @@ function _pipeline (callback, stack) { * @module Sharp * @private */ -module.exports = (Sharp) => { +export default (Sharp) => { Object.assign(Sharp.prototype, { // Public toFile, diff --git a/lib/resize.js b/lib/resize.mjs similarity index 99% rename from lib/resize.js rename to lib/resize.mjs index 544fbba3a..d4da00eb3 100644 --- a/lib/resize.js +++ b/lib/resize.mjs @@ -3,7 +3,7 @@ SPDX-License-Identifier: Apache-2.0 */ -const is = require('./is'); +import is from './is.mjs'; /** * Weighting to apply when using contain/cover fit. @@ -579,7 +579,7 @@ function trim (options) { * @module Sharp * @private */ -module.exports = (Sharp) => { +export default (Sharp) => { Object.assign(Sharp.prototype, { resize, extend, diff --git a/lib/sharp.js b/lib/sharp.mjs similarity index 91% rename from lib/sharp.js rename to lib/sharp.mjs index 1081c9314..3a3de0288 100644 --- a/lib/sharp.js +++ b/lib/sharp.mjs @@ -5,9 +5,9 @@ // Inspects the runtime environment and exports the relevant sharp.node binary -const { familySync, versionSync } = require('detect-libc'); +import { familySync, versionSync } from 'detect-libc'; -const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips'); +import { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } from './libvips.mjs'; const runtimePlatform = runtimePlatformArch(); const paths = [ @@ -23,7 +23,7 @@ let path, sharp; const errors = []; for (path of paths) { try { - sharp = require(path); + sharp = await import(path); break; } catch (err) { errors.push(err); @@ -37,9 +37,7 @@ if (sharp && path.startsWith('@img/sharp-linux-x64') && !sharp._isUsingX64V2()) sharp = null; } -if (sharp) { - module.exports = sharp; -} else { +if (!sharp) { const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os)); const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`]; @@ -79,7 +77,7 @@ if (sharp) { } if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) { try { - const { config } = require(`@img/sharp-libvips-${runtimePlatform}/package`); + const { config } = await import(`@img/sharp-libvips-${runtimePlatform}/package`); const libcFound = `${familySync()} ${versionSync()}`; const libcRequires = `${config.musl ? 'musl' : 'glibc'} ${config.musl || config.glibc}`; help.push( @@ -119,3 +117,5 @@ if (sharp) { ); throw new Error(help.join('\n')); } + +export default sharp \ No newline at end of file diff --git a/lib/utility.js b/lib/utility.mjs similarity index 92% rename from lib/utility.js rename to lib/utility.mjs index c0ad39f86..065d38acf 100644 --- a/lib/utility.js +++ b/lib/utility.mjs @@ -3,12 +3,13 @@ SPDX-License-Identifier: Apache-2.0 */ -const events = require('node:events'); -const detectLibc = require('detect-libc'); +import events from 'node:events'; +import fs from 'node:fs'; +import detectLibc from 'detect-libc'; -const is = require('./is'); -const { runtimePlatformArch } = require('./libvips'); -const sharp = require('./sharp'); +import is from './is.mjs'; +import { runtimePlatformArch } from './libvips.mjs'; +import sharp from './sharp.mjs'; const runtimePlatform = runtimePlatformArch(); const libvipsVersion = sharp.libvipsVersion(); @@ -61,19 +62,20 @@ let versions = { if (!libvipsVersion.isGlobal) { if (!libvipsVersion.isWasm) { try { - versions = require(`@img/sharp-${runtimePlatform}/versions`); + versions = await import(`@img/sharp-${runtimePlatform}/versions`); } catch (_) { try { - versions = require(`@img/sharp-libvips-${runtimePlatform}/versions`); + versions = await import(`@img/sharp-libvips-${runtimePlatform}/versions`); } catch (_) {} } } else { try { - versions = require('@img/sharp-wasm32/versions'); + versions = await import('@img/sharp-wasm32/versions'); } catch (_) {} } } -versions.sharp = require('../package.json').version; +// Cannot use an import because sometimes it can need the attr or with keyword +versions.sharp = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8')).version; /* node:coverage ignore next 5 */ if (versions.heif && format.heif) { @@ -156,7 +158,8 @@ if (detectLibc.familySync() === detectLibc.GLIBC && !sharp._isUsingJemalloc()) { sharp.concurrency(1); } else if (detectLibc.familySync() === detectLibc.MUSL && sharp.concurrency() === 1024) { // Reduce default concurrency when musl thread over-subscription detected - sharp.concurrency(require('node:os').availableParallelism()); + const { availableParallelism } = await import('node:os') + sharp.concurrency(availableParallelism()); } /** @@ -277,7 +280,7 @@ function unblock (options) { * @module Sharp * @private */ -module.exports = (Sharp) => { +export default (Sharp) => { Sharp.cache = cache; Sharp.concurrency = concurrency; Sharp.counters = counters; diff --git a/npm/from-local-build.js b/npm/from-local-build.js index fc35bd2ed..d1f0f76c9 100644 --- a/npm/from-local-build.js +++ b/npm/from-local-build.js @@ -8,7 +8,7 @@ const { copyFileSync, cpSync, readFileSync, writeFileSync, appendFileSync } = require('node:fs'); const { basename, join } = require('node:path'); -const { buildPlatformArch } = require('../lib/libvips'); +const { buildPlatformArch } = require('../dist/libvips.cjs'); const licensing = ` ## Licensing diff --git a/package.json b/package.json index 0c0d00988..74ff4cad7 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ ], "scripts": { "build": "node install/build.js", + "build:dist": "node scripts/build.mjs", "install": "node install/check.js || npm run build", "clean": "rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*", "test": "npm run lint && npm run test-unit", @@ -109,13 +110,21 @@ "docs-publish": "cd docs && npm run build && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp" }, "type": "commonjs", - "main": "lib/index.js", - "types": "lib/index.d.ts", "files": [ + "dist", "install", - "lib", + "lib/index.d.ts", "src/*.{cc,h,gyp}" ], + "main": "./dist/index.cjs", + "module": "./dist/index.mjs", + "types": "./lib/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.cjs" + } + }, "repository": { "type": "git", "url": "git://github.com/lovell/sharp.git" @@ -199,4 +208,4 @@ "funding": { "url": "https://opencollective.com/libvips" } -} +} \ No newline at end of file diff --git a/scripts/build.mjs b/scripts/build.mjs new file mode 100644 index 000000000..eda355d64 --- /dev/null +++ b/scripts/build.mjs @@ -0,0 +1,36 @@ +// @ts-check +import * as fs from "node:fs/promises"; + +const distDir = new URL("../dist/", import.meta.url); + +await fs.rm(distDir, { force: true, recursive: true }); +await fs.mkdir(new URL("../dist/", import.meta.url), { recursive: true }); + +const libDir = new URL("../lib/", import.meta.url); + +/** + * @param {string} input + * @returns {string} + */ +function cjsToEsm(input) { + return input + // Turn import into require() and .mjs into .cjs + .replace( + /import\s+(.+)\s+from\s+('[^']+'|"[^"]+");?/g, + (_, bindings, path) => `const ${bindings} = require(${path.replace(".mjs", ".cjs")});`, + ) + .replace(/import\s+('[^']+'|"[^"]+");?/g, (_, path) => `require(${path.replace(".mjs", ".cjs")});`) + // Transforms TLA + .replaceAll("await import(", "require(") + .replaceAll("export default", "module.exports =") + // import.meta.url doesn't exist in cjs + .replaceAll("import.meta.url", "require('node:url').pathToFileURL(__filename)"); +} + +const entries = (await fs.readdir(libDir, { recursive: true })).filter(e => e.endsWith('.mjs')); + +for (const entry of entries) { + await fs.cp(new URL(entry, libDir), new URL(entry, distDir)); + const contents = await fs.readFile(new URL(entry, libDir), "utf-8"); + await fs.writeFile(new URL(entry.replace(".mjs", ".cjs"), distDir), cjsToEsm(contents)); +} diff --git a/src/binding.gyp b/src/binding.gyp index 2040cde5b..7b4c34a33 100644 --- a/src/binding.gyp +++ b/src/binding.gyp @@ -3,13 +3,13 @@ { 'variables': { - 'vips_version': ' path.join(__dirname, filename); diff --git a/test/unit/clahe.js b/test/unit/clahe.js index f3d68ebbb..ed00a5411 100644 --- a/test/unit/clahe.js +++ b/test/unit/clahe.js @@ -6,7 +6,7 @@ const { describe, it } = require('node:test'); const assert = require('node:assert'); -const sharp = require('../../lib'); +const sharp = require('../../dist/index.cjs'); const fixtures = require('../fixtures'); describe('Clahe', () => { diff --git a/test/unit/failOn.js b/test/unit/failOn.js index c4d44e892..bd9ea1521 100644 --- a/test/unit/failOn.js +++ b/test/unit/failOn.js @@ -7,7 +7,7 @@ const { describe, it } = require('node:test'); const assert = require('node:assert'); const fs = require('node:fs'); -const sharp = require('../../lib'); +const sharp = require('../../dist/index.cjs'); const fixtures = require('../fixtures'); describe('failOn', () => { diff --git a/test/unit/libvips.js b/test/unit/libvips.js index 8ed822458..1b5349a6a 100644 --- a/test/unit/libvips.js +++ b/test/unit/libvips.js @@ -7,7 +7,7 @@ const { after, before, describe, it } = require('node:test'); const assert = require('node:assert'); const fs = require('node:fs'); const semver = require('semver'); -const libvips = require('../../lib/libvips'); +const libvips = require('../../dist/libvips.cjs'); const originalPlatform = process.platform; diff --git a/test/unit/text.js b/test/unit/text.js index 029b45f1f..4c36e8f20 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -8,7 +8,7 @@ const assert = require('node:assert'); const sharp = require('../../'); const fixtures = require('../fixtures'); -const { inRange } = require('../../lib/is'); +const { inRange } = require('../../dist/is.cjs'); describe('Text to image', () => { it('text with default values', async (t) => { diff --git a/test/unit/trim.js b/test/unit/trim.js index 99b14a8d9..fd193b1ec 100644 --- a/test/unit/trim.js +++ b/test/unit/trim.js @@ -7,7 +7,7 @@ const { describe, it } = require('node:test'); const assert = require('node:assert'); const sharp = require('../../'); -const inRange = require('../../lib/is').inRange; +const inRange = require('../../dist/is.cjs').inRange; const fixtures = require('../fixtures'); describe('Trim borders', () => {