Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/installation.md
Original file line number Diff line number Diff line change
@@ -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

---
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/possible-bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ labels: triage
<!-- Please place an [x] in the box to confirm. -->

- [ ] 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.

Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ package-lock.json
.astro
docs/dist
release-notes.md
dist
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ npm install sharp
```

```javascript
// ESM
import sharp from 'sharp';

// CJS
const sharp = require('sharp');
```

Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/api-constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion install/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion install/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/channel.js → lib/channel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SPDX-License-Identifier: Apache-2.0
*/

const is = require('./is');
import is from './is.mjs';

/**
* Boolean operations for bandbool.
Expand Down Expand Up @@ -163,7 +163,7 @@ function bandbool (boolOp) {
* @module Sharp
* @private
*/
module.exports = (Sharp) => {
export default (Sharp) => {
Object.assign(Sharp.prototype, {
// Public instance functions
removeAlpha,
Expand Down
6 changes: 3 additions & 3 deletions lib/colour.js → lib/colour.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -175,7 +175,7 @@ function _setBackgroundColourOption (key, value) {
* @module Sharp
* @private
*/
module.exports = (Sharp) => {
export default (Sharp) => {
Object.assign(Sharp.prototype, {
// Public
tint,
Expand Down
4 changes: 2 additions & 2 deletions lib/composite.js → lib/composite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SPDX-License-Identifier: Apache-2.0
*/

const is = require('./is');
import is from './is.mjs';

/**
* Blend modes.
Expand Down Expand Up @@ -206,7 +206,7 @@ function composite (images) {
* @module Sharp
* @private
*/
module.exports = (Sharp) => {
export default (Sharp) => {
Sharp.prototype.composite = composite;
Sharp.blend = blend;
};
14 changes: 7 additions & 7 deletions lib/constructor.js → lib/constructor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -496,4 +496,4 @@ Object.assign(Sharp.prototype, { clone });
* @module Sharp
* @private
*/
module.exports = Sharp;
export default Sharp;
16 changes: 0 additions & 16 deletions lib/index.js

This file was deleted.

25 changes: 25 additions & 0 deletions lib/index.mjs
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 3 additions & 3 deletions lib/input.js → lib/input.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -792,7 +792,7 @@ function stats (callback) {
* @module Sharp
* @private
*/
module.exports = (Sharp) => {
export default (Sharp) => {
Object.assign(Sharp.prototype, {
// Private
_inputOptionsFromObject,
Expand Down
2 changes: 1 addition & 1 deletion lib/is.js → lib/is.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const nativeError = (native, context) => {
return context;
};

module.exports = {
export default {
defined,
object,
plainObject,
Expand Down
18 changes: 10 additions & 8 deletions lib/libvips.js → lib/libvips.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -189,7 +191,7 @@ const useGlobalLibvips = (logger) => {
return !!globalVipsVersion && semverGreaterThanOrEqualTo(globalVipsVersion, minimumLibvipsVersion);
};

module.exports = {
export default {
minimumLibvipsVersion,
prebuiltPlatforms,
buildPlatformArch,
Expand Down
4 changes: 2 additions & 2 deletions lib/operation.js → lib/operation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -987,7 +987,7 @@ function modulate (options) {
* @module Sharp
* @private
*/
module.exports = (Sharp) => {
export default (Sharp) => {
Object.assign(Sharp.prototype, {
autoOrient,
rotate,
Expand Down
8 changes: 4 additions & 4 deletions lib/output.js → lib/output.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -1630,7 +1630,7 @@ function _pipeline (callback, stack) {
* @module Sharp
* @private
*/
module.exports = (Sharp) => {
export default (Sharp) => {
Object.assign(Sharp.prototype, {
// Public
toFile,
Expand Down
4 changes: 2 additions & 2 deletions lib/resize.js → lib/resize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -579,7 +579,7 @@ function trim (options) {
* @module Sharp
* @private
*/
module.exports = (Sharp) => {
export default (Sharp) => {
Object.assign(Sharp.prototype, {
resize,
extend,
Expand Down
Loading
Loading