From 92f8e96f96193cf05b8570c7a9d9eebcd9af6bc0 Mon Sep 17 00:00:00 2001 From: Mark van Seventer Date: Thu, 13 Aug 2026 18:21:01 -0700 Subject: [PATCH 1/6] Remove lodash.pick. --- cmd/operations/affine.js | 3 +- cmd/operations/convolve.js | 3 +- cmd/operations/modulate.js | 3 +- cmd/operations/normalise.js | 3 +- cmd/operations/sharpen.js | 3 +- cmd/output.js | 3 +- cmd/resizing/extend.js | 3 +- cmd/resizing/extract.js | 3 +- cmd/resizing/resize.js | 3 +- lib/cli.js | 2 +- lib/index.js | 3 +- lib/utils.js | 35 +++++++++++++++ package-lock.json | 87 ++----------------------------------- package.json | 5 +-- test/utils.js | 46 ++++++++++++++++++++ 15 files changed, 97 insertions(+), 108 deletions(-) create mode 100644 lib/utils.js create mode 100644 test/utils.js diff --git a/cmd/operations/affine.js b/cmd/operations/affine.js index b6d6da3..d73b7e3 100644 --- a/cmd/operations/affine.js +++ b/cmd/operations/affine.js @@ -27,11 +27,10 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const constants = require("../../lib/constants"); const queue = require("../../lib/queue"); +const { pick } = require("../../lib/utils"); // Configure. const placeholders = { diff --git a/cmd/operations/convolve.js b/cmd/operations/convolve.js index 4472bc8..f872686 100644 --- a/cmd/operations/convolve.js +++ b/cmd/operations/convolve.js @@ -27,10 +27,9 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const queue = require("../../lib/queue"); +const { pick } = require("../../lib/utils"); // Configure. const positionals = { diff --git a/cmd/operations/modulate.js b/cmd/operations/modulate.js index 9a4802a..b4c7a7c 100644 --- a/cmd/operations/modulate.js +++ b/cmd/operations/modulate.js @@ -27,10 +27,9 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const queue = require("../../lib/queue"); +const { pick } = require("../../lib/utils"); // Configure. const options = { diff --git a/cmd/operations/normalise.js b/cmd/operations/normalise.js index f781b78..7525fdb 100644 --- a/cmd/operations/normalise.js +++ b/cmd/operations/normalise.js @@ -27,10 +27,9 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const queue = require("../../lib/queue"); +const { pick } = require("../../lib/utils"); const options = { lower: { diff --git a/cmd/operations/sharpen.js b/cmd/operations/sharpen.js index c3da810..75b560a 100644 --- a/cmd/operations/sharpen.js +++ b/cmd/operations/sharpen.js @@ -27,10 +27,9 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const queue = require("../../lib/queue"); +const { pick } = require("../../lib/utils"); // Configure. const positionals = { diff --git a/cmd/output.js b/cmd/output.js index b3e363f..63d2932 100644 --- a/cmd/output.js +++ b/cmd/output.js @@ -27,11 +27,10 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const constants = require("../lib/constants"); const queue = require("../lib/queue"); +const { pick } = require("../lib/utils"); // Configure. const positionals = { diff --git a/cmd/resizing/extend.js b/cmd/resizing/extend.js index 50b6c26..905a148 100644 --- a/cmd/resizing/extend.js +++ b/cmd/resizing/extend.js @@ -27,11 +27,10 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const constants = require("../../lib/constants"); const queue = require("../../lib/queue"); +const { pick } = require("../../lib/utils"); // Configure. const positionals = { diff --git a/cmd/resizing/extract.js b/cmd/resizing/extract.js index 586fbf6..14a159a 100644 --- a/cmd/resizing/extract.js +++ b/cmd/resizing/extract.js @@ -27,10 +27,9 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const queue = require("../../lib/queue"); +const { pick } = require("../../lib/utils"); // Configure. const positionals = { diff --git a/cmd/resizing/resize.js b/cmd/resizing/resize.js index ab887f3..00edbaf 100644 --- a/cmd/resizing/resize.js +++ b/cmd/resizing/resize.js @@ -27,11 +27,10 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const constants = require("../../lib/constants"); const queue = require("../../lib/queue"); +const { pick } = require("../../lib/utils"); // Configure. const positionals = { diff --git a/lib/cli.js b/lib/cli.js index 87990b2..b91db2d 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -25,7 +25,6 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); const sharp = require("sharp"); const yargs = require("yargs"); @@ -33,6 +32,7 @@ const yargs = require("yargs"); const constants = require("./constants"); const pkg = require("../package.json"); const queue = require("./queue"); +const { pick } = require("./utils"); // Configure. const IS_TEXT_TERMINAL = process.stdin.isTTY; diff --git a/lib/index.js b/lib/index.js index 5dccdea..81a880c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -25,11 +25,10 @@ "use strict"; // Package modules. -const pick = require("lodash.pick"); - // Local modules. const cli = require("./cli"); const convert = require("./convert"); +const { pick } = require("./utils"); // Exports. module.exports = (args, options = {}) => { diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 0000000..01903c5 --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,35 @@ +/*! + * The MIT License (MIT) + * + * Copyright (c) 2019 Mark van Seventer + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +// Strict mode. +"use strict"; + +// Exports. +module.exports = { + pick: (object, keys) => { + return keys.reduce((result, key) => { + if (Object.hasOwn(object, key)) result[key] = object[key]; + return result; + }, {}); + }, +}; diff --git a/package-lock.json b/package-lock.json index 94630fb..05ad4a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,16 @@ { "name": "sharp-cli", - "version": "5.3.0", + "version": "6.0.0-dev", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sharp-cli", - "version": "5.3.0", + "version": "6.0.0-dev", "license": "MIT", "dependencies": { "glob": "10.5.x", "is-directory": "0.3.x", - "lodash.pick": "3.1.0", "sharp": "0.34.5", "yargs": "^17.6.2" }, @@ -28,7 +27,7 @@ "tempy": "1.0.x" }, "engines": { - "node": ">=18.17" + "node": ">=20.9" } }, "node_modules/@ampproject/remapping": { @@ -2418,28 +2417,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash._baseflatten": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/lodash._baseflatten/-/lodash._baseflatten-3.1.4.tgz", - "integrity": "sha512-fESngZd+X4k+GbTxdMutf8ohQa0s3sJEHIcwtu4/LsIQ2JTDzdRxDCMQjW+ezzwRitLmHnacVVmosCbxifefbw==", - "license": "MIT", - "dependencies": { - "lodash.isarguments": "^3.0.0", - "lodash.isarray": "^3.0.0" - } - }, - "node_modules/lodash._basefor": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/lodash._basefor/-/lodash._basefor-3.0.3.tgz", - "integrity": "sha512-6bc3b8grkpMgDcVJv9JYZAk/mHgcqMljzm7OsbmcE2FGUMmmLQTPHlh/dFqR8LA0GQ7z4K67JSotVKu5058v1A==", - "license": "MIT" - }, - "node_modules/lodash._bindcallback": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz", - "integrity": "sha512-2wlI0JRAGX8WEf4Gm1p/mv/SZ+jLijpj0jyaE/AXeuQphzCgD8ZQW4oSpoN8JAopujOFGU3KMuq7qfHBWlGpjQ==", - "license": "MIT" - }, "node_modules/lodash._createwrapper": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/lodash._createwrapper/-/lodash._createwrapper-3.2.0.tgz", @@ -2449,22 +2426,6 @@ "lodash._root": "^3.0.0" } }, - "node_modules/lodash._pickbyarray": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/lodash._pickbyarray/-/lodash._pickbyarray-3.0.2.tgz", - "integrity": "sha512-tHzBIfgugzI7HV0y8MJS1z/ryWDh8NyD6AV+so9vlplRnhD4qBuwoyDt7g241ad3F43YDFghCN+R3iaFd4Azvw==", - "license": "MIT" - }, - "node_modules/lodash._pickbycallback": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/lodash._pickbycallback/-/lodash._pickbycallback-3.0.0.tgz", - "integrity": "sha512-DVP27YmN0lB+j/Tgd/+gtxfmW/XihgWpQpHptBuwyp2fD9zEBRwwcnw6Qej16LUV8LRFuTqyoc0i6ON97d/C5w==", - "license": "MIT", - "dependencies": { - "lodash._basefor": "^3.0.0", - "lodash.keysin": "^3.0.0" - } - }, "node_modules/lodash._root": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/lodash._root/-/lodash._root-3.0.1.tgz", @@ -2485,48 +2446,6 @@ "dev": true, "license": "MIT" }, - "node_modules/lodash.isarguments": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz", - "integrity": "sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg==", - "license": "MIT" - }, - "node_modules/lodash.isarray": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz", - "integrity": "sha512-JwObCrNJuT0Nnbuecmqr5DgtuBppuCvGD9lxjFpAzwnVtdGoDQ1zig+5W8k5/6Gcn0gZ3936HDAlGd28i7sOGQ==", - "license": "MIT" - }, - "node_modules/lodash.keysin": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/lodash.keysin/-/lodash.keysin-3.0.8.tgz", - "integrity": "sha512-YDB/5xkL3fBKFMDaC+cfGV00pbiJ6XoJIfRmBhv7aR6wWtbCW6IzkiWnTfkiHTF6ALD7ff83dAtB3OEaSoyQPg==", - "license": "MIT", - "dependencies": { - "lodash.isarguments": "^3.0.0", - "lodash.isarray": "^3.0.0" - } - }, - "node_modules/lodash.pick": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-3.1.0.tgz", - "integrity": "sha512-Y04wnFghB7l1dkYINfjdMLpeAGM1IYEjlsGFxvjeewCbVQUlD9jw3M20ThuNrsf6yGmuPLwj60PKP+D6gZ+o2w==", - "deprecated": "This package is deprecated. Use destructuring assignment syntax instead.", - "license": "MIT", - "dependencies": { - "lodash._baseflatten": "^3.0.0", - "lodash._bindcallback": "^3.0.0", - "lodash._pickbyarray": "^3.0.0", - "lodash._pickbycallback": "^3.0.0", - "lodash.restparam": "^3.0.0" - } - }, - "node_modules/lodash.restparam": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/lodash.restparam/-/lodash.restparam-3.6.1.tgz", - "integrity": "sha512-L4/arjjuq4noiUJpt3yS6KIKDtJwNe2fIYgMqyYYKoeIfV1iEqvPwhCx23o+R9dzouGihDAPN1dTIRWa7zk8tw==", - "license": "MIT" - }, "node_modules/lodash.wrap": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/lodash.wrap/-/lodash.wrap-3.0.1.tgz", diff --git a/package.json b/package.json index d17a1c0..c921e11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sharp-cli", - "version": "5.3.0", + "version": "6.0.0-dev", "description": "CLI for sharp.", "keywords": [ "cli", @@ -29,7 +29,6 @@ "dependencies": { "glob": "10.5.x", "is-directory": "0.3.x", - "lodash.pick": "3.1.0", "sharp": "0.34.5", "yargs": "^17.6.2" }, @@ -43,6 +42,6 @@ "tempy": "1.0.x" }, "engines": { - "node": ">=18.17" + "node": ">=20.9" } } diff --git a/test/utils.js b/test/utils.js new file mode 100644 index 0000000..1154162 --- /dev/null +++ b/test/utils.js @@ -0,0 +1,46 @@ +/* global describe, it */ +/*! + * The MIT License (MIT) + * + * Copyright (c) 2019 Mark van Seventer + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +// Strict mode. +"use strict"; + +// Package modules. +const expect = require("must"); + +// Local modules. +const { pick } = require("../lib/utils"); + +// Test suite. +describe("utils", () => { + describe("pick", () => { + it("must pick own properties, including falsy values", () => { + const input = { falseValue: false, nullValue: null, zero: 0 }; + expect(pick(input, ["falseValue", "nullValue", "zero"])).to.eql(input); + }); + + it("must omit missing properties", () => { + expect(pick({ value: 1 }, ["missing"])).to.eql({}); + }); + }); +}); From 227b93ffb30dadf889dc7697c33e82633e7bbf9a Mon Sep 17 00:00:00 2001 From: Mark van Seventer Date: Thu, 13 Aug 2026 18:22:32 -0700 Subject: [PATCH 2/6] Remove is-directory. --- lib/convert.js | 4 ++-- lib/utils.js | 12 ++++++++++++ package-lock.json | 9 --------- package.json | 1 - test/utils.js | 12 +++++++++++- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/convert.js b/lib/convert.js index 9f1369e..427c43e 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -31,11 +31,11 @@ const { pipeline } = require("stream/promises"); // Package modules. const { globSync } = require("glob"); -const isDirectory = require("is-directory"); const sharp = require("sharp"); // Local modules. const queue = require("./queue"); +const { isDirectory } = require("./utils"); // Configure. const EXTENSIONS = { @@ -82,7 +82,7 @@ module.exports = { // If output was not a template, assume dest is a directory when using // batch processing. const outputAssumeDir = dest === path.resolve(output) && isBatch; - if (outputAssumeDir || isDirectory.sync(dest)) { + if (outputAssumeDir || isDirectory(dest)) { const defaultExt = path.extname(src); const desiredExt = transformer.options.formatOut; dest = path.format({ diff --git a/lib/utils.js b/lib/utils.js index 01903c5..e2ca338 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -24,8 +24,20 @@ // Strict mode. "use strict"; +// Standard lib. +const fs = require("fs"); + // Exports. module.exports = { + isDirectory: (path) => { + try { + return fs.statSync(path).isDirectory(); + } catch (err) { + if (err.code === "ENOENT") return false; + throw err; + } + }, + pick: (object, keys) => { return keys.reduce((result, key) => { if (Object.hasOwn(object, key)) result[key] = object[key]; diff --git a/package-lock.json b/package-lock.json index 05ad4a4..18a3d9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "MIT", "dependencies": { "glob": "10.5.x", - "is-directory": "0.3.x", "sharp": "0.34.5", "yargs": "^17.6.2" }, @@ -2082,14 +2081,6 @@ "node": ">=8" } }, - "node_modules/is-directory": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz", - "integrity": "sha512-yVChGzahRFvbkscn2MlwGismPO12i9+znNruC5gVEntG3qu0xQMzsGg/JFbrsqDOHtHFPci+V5aP5T9I+yeKqw==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", diff --git a/package.json b/package.json index c921e11..ceb6832 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ }, "dependencies": { "glob": "10.5.x", - "is-directory": "0.3.x", "sharp": "0.34.5", "yargs": "^17.6.2" }, diff --git a/test/utils.js b/test/utils.js index 1154162..805a06c 100644 --- a/test/utils.js +++ b/test/utils.js @@ -29,10 +29,20 @@ const expect = require("must"); // Local modules. -const { pick } = require("../lib/utils"); +const { isDirectory, pick } = require("../lib/utils"); // Test suite. describe("utils", () => { + describe("isDirectory", () => { + it("must identify directories", () => { + expect(isDirectory(__dirname)).to.be.true(); + }); + + it("must return false for missing paths", () => { + expect(isDirectory(`${__dirname}/missing`)).to.be.false(); + }); + }); + describe("pick", () => { it("must pick own properties, including falsy values", () => { const input = { falseValue: false, nullValue: null, zero: 0 }; From 75588fe3632af27538f26da2a8d6d47afb78642c Mon Sep 17 00:00:00 2001 From: Mark van Seventer Date: Thu, 13 Aug 2026 20:32:43 -0700 Subject: [PATCH 3/6] Add ESLint. --- cmd/channel-manipulation/remove-alpha.js | 2 +- cmd/colour-manipulation/greyscale.js | 3 +- cmd/operations/flip.js | 2 +- cmd/operations/flop.js | 2 +- cmd/operations/unflatten.js | 3 +- eslint.config.mjs | 25 + package-lock.json | 823 +++++++++++++++++- package.json | 6 +- test/cli.js | 5 +- test/cmd.js | 1 - test/cmd/channel-manipulation.js | 1 - test/cmd/channel-manipulation/bandbool.js | 1 - test/cmd/channel-manipulation/ensure-alpha.js | 1 - .../channel-manipulation/extract-channel.js | 1 - test/cmd/channel-manipulation/join-channel.js | 3 +- test/cmd/channel-manipulation/remove-alpha.js | 1 - test/cmd/colour-manipulation.js | 1 - test/cmd/colour-manipulation/greyscale.js | 1 - .../pipeline-colourspace.js | 1 - test/cmd/colour-manipulation/tint.js | 1 - test/cmd/colour-manipulation/tocolourspace.js | 1 - test/cmd/compositing.js | 1 - test/cmd/compositing/composite.js | 3 +- test/cmd/operations.js | 1 - test/cmd/operations/affine.js | 1 - test/cmd/operations/blur.js | 1 - test/cmd/operations/boolean.js | 3 +- test/cmd/operations/clahe.js | 1 - test/cmd/operations/convolve.js | 1 - test/cmd/operations/dilate.js | 1 - test/cmd/operations/erode.js | 1 - test/cmd/operations/flatten.js | 1 - test/cmd/operations/flip.js | 1 - test/cmd/operations/flop.js | 1 - test/cmd/operations/gamma.js | 1 - test/cmd/operations/linear.js | 1 - test/cmd/operations/median.js | 1 - test/cmd/operations/modulate.js | 1 - test/cmd/operations/negate.js | 1 - test/cmd/operations/normalise.js | 1 - test/cmd/operations/recomb.js | 1 - test/cmd/operations/rotate.js | 1 - test/cmd/operations/sharpen.js | 1 - test/cmd/operations/threshold.js | 1 - test/cmd/operations/unflatten.js | 1 - test/cmd/output.js | 1 - test/cmd/resizing.js | 1 - test/cmd/resizing/extend.js | 1 - test/cmd/resizing/extract.js | 1 - test/cmd/resizing/resize.js | 1 - test/cmd/resizing/trim.js | 1 - test/convert.js | 1 - test/index.js | 1 - test/utils.js | 1 - 54 files changed, 843 insertions(+), 79 deletions(-) create mode 100644 eslint.config.mjs diff --git a/cmd/channel-manipulation/remove-alpha.js b/cmd/channel-manipulation/remove-alpha.js index 5f24888..2a0faf0 100644 --- a/cmd/channel-manipulation/remove-alpha.js +++ b/cmd/channel-manipulation/remove-alpha.js @@ -40,7 +40,7 @@ const builder = (yargs) => { }; // Command handler. -const handler = (args) => +const handler = () => queue.push(["removeAlpha", (sharp) => sharp.removeAlpha()]); // Exports. diff --git a/cmd/colour-manipulation/greyscale.js b/cmd/colour-manipulation/greyscale.js index 44163b1..ac4bd04 100644 --- a/cmd/colour-manipulation/greyscale.js +++ b/cmd/colour-manipulation/greyscale.js @@ -43,8 +43,7 @@ const builder = (yargs) => { }; // Command handler. -const handler = (args) => - queue.push(["greyscale", (sharp) => sharp.greyscale()]); +const handler = () => queue.push(["greyscale", (sharp) => sharp.greyscale()]); // Exports. module.exports = { diff --git a/cmd/operations/flip.js b/cmd/operations/flip.js index 90c88e1..4b79148 100644 --- a/cmd/operations/flip.js +++ b/cmd/operations/flip.js @@ -40,7 +40,7 @@ const builder = (yargs) => { }; // Command handler. -const handler = (args) => queue.push(["flip", (sharp) => sharp.flip()]); +const handler = () => queue.push(["flip", (sharp) => sharp.flip()]); // Exports. module.exports = { diff --git a/cmd/operations/flop.js b/cmd/operations/flop.js index fab9b60..2f5dace 100644 --- a/cmd/operations/flop.js +++ b/cmd/operations/flop.js @@ -40,7 +40,7 @@ const builder = (yargs) => { }; // Command handler. -const handler = (args) => queue.push(["flop", (sharp) => sharp.flop()]); +const handler = () => queue.push(["flop", (sharp) => sharp.flop()]); // Exports. module.exports = { diff --git a/cmd/operations/unflatten.js b/cmd/operations/unflatten.js index f4ec6c6..5512782 100644 --- a/cmd/operations/unflatten.js +++ b/cmd/operations/unflatten.js @@ -40,8 +40,7 @@ const builder = (yargs) => { }; // Command handler. -const handler = (args) => - queue.push(["unflatten", (sharp) => sharp.unflatten()]); +const handler = () => queue.push(["unflatten", (sharp) => sharp.unflatten()]); // Exports. module.exports = { diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..c9976f0 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,25 @@ +// Package modules. +import js from "@eslint/js"; +import globals from "globals"; +import { defineConfig, globalIgnores } from "eslint/config"; + +// Exports. +export default defineConfig([ + globalIgnores(["coverage/**", ".nyc_output/**"]), + js.configs.recommended, + + { + files: ["**/*.{js,mjs,cjs}"], + languageOptions: { globals: globals.node }, + }, + + { + files: ["test/**/*.js"], + languageOptions: { + globals: { + ...globals.node, + ...globals.mocha, + }, + }, + }, +]); diff --git a/package-lock.json b/package-lock.json index 18a3d9d..99bc576 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,10 @@ "sharp": "bin/cli.js" }, "devDependencies": { + "@eslint/js": "9.39.x", + "eslint": "^9.39.5", "fs-extra": "11.3.x", + "globals": "17.11.x", "mocha": "10.8.x", "must": "0.13.x", "nyc": "17.1.x", @@ -340,6 +343,15 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/traverse/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/types": { "version": "7.27.6", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.27.6.tgz", @@ -364,6 +376,277 @@ "tslib": "^2.4.0" } }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.10.1", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.10.1.tgz", + "integrity": "sha512-cuadcxVFE8sDK6iWJbs8Sn0av2Nrh2QSGQhVlBW9AaAHqHwjWsZHT8LJ4hFGPh7ASBV2deFdM7H/DPjulmh8rg==", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.12.2", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.2.tgz", + "integrity": "sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, + "node_modules/@eslint/config-array": { + "version": "0.21.2", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.21.2.tgz", + "integrity": "sha512-nJl2KGTlrf9GjLimgIru+V/mzgSK0ABCDQRvxw5BjURL7WfH5uoWmizbH7QB6MmnMBd8cIC9uceWnezL1VZWWw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@eslint/object-schema": "^2.1.7", + "debug": "^4.3.1", + "minimatch": "^3.1.5" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/config-array/node_modules/brace-expansion": { + "version": "1.1.18", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz", + "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@eslint/config-array/node_modules/minimatch": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", + "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@eslint/config-helpers": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.4.2.tgz", + "integrity": "sha512-gBrxN88gOIf3R7ja5K9slwNayVcZgK6SOUORm2uBzTeIEfeVaIhOpCtTox3P6R7o2jLFwLFTLnC7kU/RGcYEgw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@eslint/core": "^0.17.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/core": { + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.17.0.tgz", + "integrity": "sha512-yL/sLrpmtDaFEiUj1osRP4TI2MDz1AddJL+jZ7KSqvBuliN4xqYY54IfdN8qD8Toa6g1iloph1fxQNkjOxrrpQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/eslintrc": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.3.6.tgz", + "integrity": "sha512-l2Ul9PrHsPCKcEY/ac7VgFj9D80C7S68sOKc618SyHDPK36s1XcFebXY0iTzUVn4Yq+YbwvSnDmCz9yxjX+QrA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^6.14.0", + "debug": "^4.3.2", + "espree": "^10.0.1", + "globals": "^14.0.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.3.0", + "minimatch": "^3.1.5", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint/eslintrc/node_modules/brace-expansion": { + "version": "1.1.18", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz", + "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@eslint/eslintrc/node_modules/minimatch": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", + "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@eslint/js": { + "version": "9.39.5", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.39.5.tgz", + "integrity": "sha512-QywQuszQh77pIXCsq998c8hbhSTI/azTty1Z6N53dmAudKHhy573j3yvRLsX2BSp8YpLtoCEG8E9DJe+8zUh4A==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://eslint.org/donate" + } + }, + "node_modules/@eslint/object-schema": { + "version": "2.1.7", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.7.tgz", + "integrity": "sha512-VtAOaymWVfZcmZbp6E2mympDIHvyjXs/12LqWYjVw6qjrfF+VK+fyG33kChz3nnK+SU5/NeHOqrTEHS8sXO3OA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/plugin-kit": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.4.1.tgz", + "integrity": "sha512-43/qtrDUokr7LJqoF2c3+RInu/t4zfrpYdoSDfYyhg52rwLV6TnOvdG4fXm7IkSB3wErkcmJS9iEhjVtOSEjjA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@eslint/core": "^0.17.0", + "levn": "^0.4.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@humanfs/core": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.2.tgz", + "integrity": "sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/types": "^0.15.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node": { + "version": "0.16.8", + "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.8.tgz", + "integrity": "sha512-gE1eQNZ3R++kTzFUpdGlpmy8kDZD/MLyHqDwqjkVQI0JMdI1D51sy1H958PNXYkM2rAac7e5/CnIKZrHtPh3BQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.2", + "@humanfs/types": "^0.15.0", + "@humanwhocodes/retry": "^0.4.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/types": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/@humanfs/types/-/types-0.15.0.tgz", + "integrity": "sha512-ZZ1w0aoQkwuUuC7Yf+7sdeaNfqQiiLcSRbfI08oAxqLtpXQr9AIVX7Ay7HLDuiLYAaFPu8oBYNq/QIi9URHJ3Q==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanwhocodes/module-importer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", + "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/retry": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.3.tgz", + "integrity": "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, "node_modules/@img/colour": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz", @@ -1168,6 +1451,43 @@ "node": ">=4" } }, + "node_modules/@types/estree": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", + "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true, + "license": "MIT" + }, + "node_modules/acorn": { + "version": "8.18.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.18.0.tgz", + "integrity": "sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, "node_modules/aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -1181,6 +1501,23 @@ "node": ">=8" } }, + "node_modules/ajv": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.15.0.tgz", + "integrity": "sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, "node_modules/ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", @@ -1352,6 +1689,16 @@ "node": ">=8" } }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/camelcase": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", @@ -1551,6 +1898,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true, + "license": "MIT" + }, "node_modules/default-require-extensions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-3.0.1.tgz", @@ -1686,6 +2040,151 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/eslint": { + "version": "9.39.5", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.39.5.tgz", + "integrity": "sha512-DgZS62aPLXKlnxILS/AYCoRvHaZeXceIzlXPkkGGzJWSow1aEk0lbTlxUSlyjC8jcaKxAdOnTDz+o1JFSBsyjw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.8.0", + "@eslint-community/regexpp": "^4.12.1", + "@eslint/config-array": "^0.21.2", + "@eslint/config-helpers": "^0.4.2", + "@eslint/core": "^0.17.0", + "@eslint/eslintrc": "^3.3.6", + "@eslint/js": "9.39.5", + "@eslint/plugin-kit": "^0.4.1", + "@humanfs/node": "^0.16.6", + "@humanwhocodes/module-importer": "^1.0.1", + "@humanwhocodes/retry": "^0.4.2", + "@types/estree": "^1.0.6", + "ajv": "^6.14.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.6", + "debug": "^4.3.2", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^8.4.0", + "eslint-visitor-keys": "^4.2.1", + "espree": "^10.4.0", + "esquery": "^1.5.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^8.0.0", + "find-up": "^5.0.0", + "glob-parent": "^6.0.2", + "ignore": "^5.2.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.5", + "natural-compare": "^1.4.0", + "optionator": "^0.9.3" + }, + "bin": { + "eslint": "bin/eslint.js" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "jiti": "*" + }, + "peerDependenciesMeta": { + "jiti": { + "optional": true + } + } + }, + "node_modules/eslint-scope": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.4.0.tgz", + "integrity": "sha512-sNXOfKCn74rt8RICKMvJS7XKV/Xk9kA7DyJr8mJik3S7Cwgy3qlkkmyS2uQB3jiJg6VNdZd/pDBJu0nvG2NlTg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.1.tgz", + "integrity": "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint/node_modules/brace-expansion": { + "version": "1.1.18", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz", + "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/eslint/node_modules/glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/eslint/node_modules/minimatch": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", + "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/espree": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.4.0.tgz", + "integrity": "sha512-j6PAQ2uUr79PZhBjP5C5fhl8e39FmRnOjsD5lGnWrFU8i2G776tBK7+nP8KuQUTTyAZUwfQqXAgrVH5MbH9CYQ==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "acorn": "^8.15.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^4.2.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, "node_modules/esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", @@ -1699,6 +2198,59 @@ "node": ">=4" } }, + "node_modules/esquery": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.7.0.tgz", + "integrity": "sha512-Ap6G0WQwcU/LHsvLwON1fAQX9Zp0A2Y6Y/cJBl9r/JbW90Zyg4/zbG6zzKa2OTALELarYHmKu0GhpM5EO+7T0g==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true, + "license": "MIT" + }, "node_modules/fast-glob": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", @@ -1715,6 +2267,20 @@ "node": ">=8.6.0" } }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true, + "license": "MIT" + }, "node_modules/fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -1724,6 +2290,19 @@ "reusify": "^1.0.4" } }, + "node_modules/file-entry-cache": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", + "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "flat-cache": "^4.0.0" + }, + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/fill-range": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", @@ -1778,6 +2357,27 @@ "flat": "cli.js" } }, + "node_modules/flat-cache": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", + "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", + "dev": true, + "license": "MIT", + "dependencies": { + "flatted": "^3.2.9", + "keyv": "^4.5.4" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/flatted": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.4.tgz", + "integrity": "sha512-5+ybhBZANEJxaH3X5evAFatUxLfEHSr7n6kYJ+1Qd0mUqr4eu9gIf6GDbWHf8RJijHrjjO8G+la14SlL2SeS1Q==", + "dev": true, + "license": "ISC" + }, "node_modules/foreground-child": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", @@ -1950,12 +2550,15 @@ } }, "node_modules/globals": { - "version": "11.12.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", - "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "version": "17.11.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-17.11.0.tgz", + "integrity": "sha512-Z2I8hM+PbJDXQDq3Icgpzv+mPdwr68iZUU9d5WW4FuXfDUQfkZaZuvjMv42/5crNyw154+9+VWXbYrUgDXbxNw==", "dev": true, "engines": { - "node": ">=4" + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/globby": { @@ -2033,6 +2636,33 @@ "node": ">= 4" } }, + "node_modules/import-fresh": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", + "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/import-fresh/node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", @@ -2334,10 +2964,21 @@ "dev": true }, "node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz", + "integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==", "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], + "license": "MIT", "dependencies": { "argparse": "^2.0.1" }, @@ -2357,6 +2998,27 @@ "node": ">=4" } }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "license": "MIT" + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true, + "license": "MIT" + }, "node_modules/json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", @@ -2387,12 +3049,36 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "dev": true, + "license": "MIT", + "dependencies": { + "json-buffer": "3.0.1" + } + }, "node_modules/kindof": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/kindof/-/kindof-2.0.0.tgz", "integrity": "sha512-ZjkyNRo87FUdtxtpx/MLmePxaLoAhipw0CSTNgX50S1BQhPnsjkgZ/Vso0tR9pbfrzzQiAn+MSFooZAr/GfUNw==", "dev": true }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -2437,6 +3123,13 @@ "dev": true, "license": "MIT" }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true, + "license": "MIT" + }, "node_modules/lodash.wrap": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/lodash.wrap/-/lodash.wrap-3.0.1.tgz", @@ -2619,18 +3312,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/mocha/node_modules/strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/mocha/node_modules/yargs": { "version": "16.2.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", @@ -2679,6 +3360,13 @@ "oolong": ">= 1.11.0 < 2" } }, + "node_modules/natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true, + "license": "MIT" + }, "node_modules/node-preload": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", @@ -2974,6 +3662,24 @@ "integrity": "sha512-I2XTx2/q8CsAXrAnoczmX0uSP5jIh7wQmLnVRcRLynYepaBPQ/p0nGLloO2Q5Lek6T5Gglnkb/SaEYLQrAWR3g==", "dev": true }, + "node_modules/optionator": { + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", + "dev": true, + "license": "MIT", + "dependencies": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -3045,6 +3751,19 @@ "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.0.tgz", "integrity": "sha512-dATvCeZN/8wQsGywez1mzHtTlP22H8OEfPrVMLNr4/eGa+ijtLn/6M5f0dY8UKNrC2O9UCU6SSoG3qRKnt7STw==" }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "license": "MIT", + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -3185,6 +3904,16 @@ "node": ">=8" } }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/prettier": { "version": "3.9.6", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.6.tgz", @@ -3213,6 +3942,16 @@ "node": ">=8" } }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -3631,6 +4370,19 @@ "node": ">=8" } }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/supports-color": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", @@ -3763,6 +4515,19 @@ "license": "0BSD", "optional": true }, + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "license": "MIT", + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", @@ -3842,6 +4607,16 @@ "browserslist": ">= 4.21.0" } }, + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "punycode": "^2.1.0" + } + }, "node_modules/uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", @@ -3871,6 +4646,16 @@ "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==", "dev": true }, + "node_modules/word-wrap": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/workerpool": { "version": "6.5.1", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.5.1.tgz", diff --git a/package.json b/package.json index ceb6832..74a9bae 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "main": "lib/", "scripts": { "format": "prettier . --write", - "pretest": "prettier . --check", + "lint": "eslint", + "pretest": "npm run lint && prettier . --check", "test": "nyc mocha", "posttest": "nyc report --reporter=lcov" }, @@ -32,7 +33,10 @@ "yargs": "^17.6.2" }, "devDependencies": { + "@eslint/js": "9.39.x", + "eslint": "^9.39.5", "fs-extra": "11.3.x", + "globals": "17.11.x", "mocha": "10.8.x", "must": "0.13.x", "nyc": "17.1.x", diff --git a/test/cli.js b/test/cli.js index 88c9d6f..ae2a7c5 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * @@ -38,10 +37,8 @@ const sharp = require("./mocks/sharp"); // Test suite. describe(`${pkg.name} [command..]`, () => { // Defaults (avoid path.join` to test for input normalizing). - /* eslint-disable n/no-path-concat */ const input = `${__dirname}/../test/fixtures/input.jpg`; const output = `${__dirname}/../test/`; - /* eslint-enable n/no-path-concat */ const ioFlags = ["-i", input, "-o", output]; // Reset. @@ -1222,7 +1219,7 @@ describe(`${pkg.name} [command..]`, () => { ["v", "version"].forEach((alias) => { describe(`--${alias}`, () => { it("must set the version flag", (done) => { - cli.parse([`--${alias}`], (err, args, output) => { + cli.parse([`--${alias}`], (err, args) => { expect(args).to.have.property("version", true); done(err); }); diff --git a/test/cmd.js b/test/cmd.js index fc13a06..66c82af 100644 --- a/test/cmd.js +++ b/test/cmd.js @@ -1,4 +1,3 @@ -/* global describe */ /*! * The MIT License (MIT) * diff --git a/test/cmd/channel-manipulation.js b/test/cmd/channel-manipulation.js index 34c8ba6..1413fdc 100644 --- a/test/cmd/channel-manipulation.js +++ b/test/cmd/channel-manipulation.js @@ -1,4 +1,3 @@ -/* global describe */ /*! * The MIT License (MIT) * diff --git a/test/cmd/channel-manipulation/bandbool.js b/test/cmd/channel-manipulation/bandbool.js index e6c5e43..2b7d503 100644 --- a/test/cmd/channel-manipulation/bandbool.js +++ b/test/cmd/channel-manipulation/bandbool.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/channel-manipulation/ensure-alpha.js b/test/cmd/channel-manipulation/ensure-alpha.js index 8912e7f..978de93 100644 --- a/test/cmd/channel-manipulation/ensure-alpha.js +++ b/test/cmd/channel-manipulation/ensure-alpha.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/channel-manipulation/extract-channel.js b/test/cmd/channel-manipulation/extract-channel.js index 2ad5ae7..dfa4aec 100644 --- a/test/cmd/channel-manipulation/extract-channel.js +++ b/test/cmd/channel-manipulation/extract-channel.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/channel-manipulation/join-channel.js b/test/cmd/channel-manipulation/join-channel.js index d556dca..96b427b 100644 --- a/test/cmd/channel-manipulation/join-channel.js +++ b/test/cmd/channel-manipulation/join-channel.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * @@ -45,7 +44,7 @@ describe("joinChannel ", () => { const cli = new Yargs().command(joinChannel); // Default input (avoid `path.join` to test for input normalizing). - const input = `${__dirname}/../../fixtures/input.jpg`; // eslint-disable-line n/no-path-concat + const input = `${__dirname}/../../fixtures/input.jpg`; // Reset. afterEach("queue", () => queue.splice(0)); diff --git a/test/cmd/channel-manipulation/remove-alpha.js b/test/cmd/channel-manipulation/remove-alpha.js index d77e140..26da70d 100644 --- a/test/cmd/channel-manipulation/remove-alpha.js +++ b/test/cmd/channel-manipulation/remove-alpha.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/colour-manipulation.js b/test/cmd/colour-manipulation.js index 937e7fe..4a6c878 100644 --- a/test/cmd/colour-manipulation.js +++ b/test/cmd/colour-manipulation.js @@ -1,4 +1,3 @@ -/* global describe */ /*! * The MIT License (MIT) * diff --git a/test/cmd/colour-manipulation/greyscale.js b/test/cmd/colour-manipulation/greyscale.js index d223d95..e576e8b 100644 --- a/test/cmd/colour-manipulation/greyscale.js +++ b/test/cmd/colour-manipulation/greyscale.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/colour-manipulation/pipeline-colourspace.js b/test/cmd/colour-manipulation/pipeline-colourspace.js index c7ab548..8969f86 100644 --- a/test/cmd/colour-manipulation/pipeline-colourspace.js +++ b/test/cmd/colour-manipulation/pipeline-colourspace.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/colour-manipulation/tint.js b/test/cmd/colour-manipulation/tint.js index d2c404f..5f62051 100644 --- a/test/cmd/colour-manipulation/tint.js +++ b/test/cmd/colour-manipulation/tint.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/colour-manipulation/tocolourspace.js b/test/cmd/colour-manipulation/tocolourspace.js index 3f60195..285ec7d 100644 --- a/test/cmd/colour-manipulation/tocolourspace.js +++ b/test/cmd/colour-manipulation/tocolourspace.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/compositing.js b/test/cmd/compositing.js index 8422493..b635c6f 100644 --- a/test/cmd/compositing.js +++ b/test/cmd/compositing.js @@ -1,4 +1,3 @@ -/* global describe */ /*! * The MIT License (MIT) * diff --git a/test/cmd/compositing/composite.js b/test/cmd/compositing/composite.js index 7622bd4..04e4702 100644 --- a/test/cmd/compositing/composite.js +++ b/test/cmd/compositing/composite.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * @@ -45,7 +44,7 @@ describe("composite", () => { const cli = new Yargs().command(composite); // Default input (avoid `path.join` to test for input normalizing). - const input = `${__dirname}/../fixtures/input.jpg`; // eslint-disable-line n/no-path-concat + const input = `${__dirname}/../fixtures/input.jpg`; // Reset. afterEach("queue", () => queue.splice(0)); diff --git a/test/cmd/operations.js b/test/cmd/operations.js index 0f6028d..63f296c 100644 --- a/test/cmd/operations.js +++ b/test/cmd/operations.js @@ -1,4 +1,3 @@ -/* global describe */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/affine.js b/test/cmd/operations/affine.js index 126dc8e..01e8e86 100644 --- a/test/cmd/operations/affine.js +++ b/test/cmd/operations/affine.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/blur.js b/test/cmd/operations/blur.js index 80f0f56..79da087 100644 --- a/test/cmd/operations/blur.js +++ b/test/cmd/operations/blur.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/boolean.js b/test/cmd/operations/boolean.js index e82ced2..2863542 100644 --- a/test/cmd/operations/boolean.js +++ b/test/cmd/operations/boolean.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * @@ -45,7 +44,7 @@ describe("boolean", () => { const cli = new Yargs().command(boolean); // Default input (avoid `path.join` to test for input normalizing). - const input = `${__dirname}/../../fixtures/input.jpg`; // eslint-disable-line n/no-path-concat + const input = `${__dirname}/../../fixtures/input.jpg`; // Reset. afterEach("queue", () => queue.splice(0)); diff --git a/test/cmd/operations/clahe.js b/test/cmd/operations/clahe.js index ff56bf6..a781c87 100644 --- a/test/cmd/operations/clahe.js +++ b/test/cmd/operations/clahe.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/convolve.js b/test/cmd/operations/convolve.js index 41c0d68..713ecd1 100644 --- a/test/cmd/operations/convolve.js +++ b/test/cmd/operations/convolve.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/dilate.js b/test/cmd/operations/dilate.js index fee7465..1d88621 100644 --- a/test/cmd/operations/dilate.js +++ b/test/cmd/operations/dilate.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/erode.js b/test/cmd/operations/erode.js index 2886aa1..06ed21c 100644 --- a/test/cmd/operations/erode.js +++ b/test/cmd/operations/erode.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/flatten.js b/test/cmd/operations/flatten.js index 34de8c4..569df9d 100644 --- a/test/cmd/operations/flatten.js +++ b/test/cmd/operations/flatten.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/flip.js b/test/cmd/operations/flip.js index 21461b5..4e4e581 100644 --- a/test/cmd/operations/flip.js +++ b/test/cmd/operations/flip.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/flop.js b/test/cmd/operations/flop.js index 81f0ee1..b003dfb 100644 --- a/test/cmd/operations/flop.js +++ b/test/cmd/operations/flop.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/gamma.js b/test/cmd/operations/gamma.js index aa0ef76..22878e1 100644 --- a/test/cmd/operations/gamma.js +++ b/test/cmd/operations/gamma.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/linear.js b/test/cmd/operations/linear.js index 5b1a205..fea2c74 100644 --- a/test/cmd/operations/linear.js +++ b/test/cmd/operations/linear.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/median.js b/test/cmd/operations/median.js index f6829e1..073f0b1 100644 --- a/test/cmd/operations/median.js +++ b/test/cmd/operations/median.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/modulate.js b/test/cmd/operations/modulate.js index 497aae0..cc63a61 100644 --- a/test/cmd/operations/modulate.js +++ b/test/cmd/operations/modulate.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/negate.js b/test/cmd/operations/negate.js index d1cfb57..9935d55 100644 --- a/test/cmd/operations/negate.js +++ b/test/cmd/operations/negate.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/normalise.js b/test/cmd/operations/normalise.js index 12c77ea..cafd29c 100644 --- a/test/cmd/operations/normalise.js +++ b/test/cmd/operations/normalise.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/recomb.js b/test/cmd/operations/recomb.js index f784522..8837589 100644 --- a/test/cmd/operations/recomb.js +++ b/test/cmd/operations/recomb.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/rotate.js b/test/cmd/operations/rotate.js index 0ef8f24..48ab1ba 100644 --- a/test/cmd/operations/rotate.js +++ b/test/cmd/operations/rotate.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/sharpen.js b/test/cmd/operations/sharpen.js index 1e37fac..27974cd 100644 --- a/test/cmd/operations/sharpen.js +++ b/test/cmd/operations/sharpen.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/threshold.js b/test/cmd/operations/threshold.js index 5ce6980..faf7a83 100644 --- a/test/cmd/operations/threshold.js +++ b/test/cmd/operations/threshold.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/operations/unflatten.js b/test/cmd/operations/unflatten.js index 9ca8464..bfae656 100644 --- a/test/cmd/operations/unflatten.js +++ b/test/cmd/operations/unflatten.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/output.js b/test/cmd/output.js index 6b2618a..bb888dd 100644 --- a/test/cmd/output.js +++ b/test/cmd/output.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/resizing.js b/test/cmd/resizing.js index 559607a..55df230 100644 --- a/test/cmd/resizing.js +++ b/test/cmd/resizing.js @@ -1,4 +1,3 @@ -/* global describe */ /*! * The MIT License (MIT) * diff --git a/test/cmd/resizing/extend.js b/test/cmd/resizing/extend.js index 8e8b499..491fc1a 100644 --- a/test/cmd/resizing/extend.js +++ b/test/cmd/resizing/extend.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/resizing/extract.js b/test/cmd/resizing/extract.js index 5d914df..62e50af 100644 --- a/test/cmd/resizing/extract.js +++ b/test/cmd/resizing/extract.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/resizing/resize.js b/test/cmd/resizing/resize.js index ba7d95e..225fcaa 100644 --- a/test/cmd/resizing/resize.js +++ b/test/cmd/resizing/resize.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/cmd/resizing/trim.js b/test/cmd/resizing/trim.js index ca5197a..581c4df 100644 --- a/test/cmd/resizing/trim.js +++ b/test/cmd/resizing/trim.js @@ -1,4 +1,3 @@ -/* global describe, it, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/convert.js b/test/convert.js index 05771af..5940f91 100644 --- a/test/convert.js +++ b/test/convert.js @@ -1,4 +1,3 @@ -/* global describe, it, before, after, beforeEach, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/index.js b/test/index.js index 33d2728..a152dff 100644 --- a/test/index.js +++ b/test/index.js @@ -1,4 +1,3 @@ -/* global describe, it, before, after, afterEach */ /*! * The MIT License (MIT) * diff --git a/test/utils.js b/test/utils.js index 805a06c..9bc46a7 100644 --- a/test/utils.js +++ b/test/utils.js @@ -1,4 +1,3 @@ -/* global describe, it */ /*! * The MIT License (MIT) * From aa6d091dc4c02b01e12ac27828d489f5d2d6d23e Mon Sep 17 00:00:00 2001 From: Mark van Seventer Date: Thu, 13 Aug 2026 22:49:08 -0700 Subject: [PATCH 4/6] Refactor to ESM. --- bin/cli.js | 10 +- cmd/channel-manipulation/bandbool.js | 9 +- cmd/channel-manipulation/ensure-alpha.js | 7 +- cmd/channel-manipulation/extract-channel.js | 9 +- cmd/channel-manipulation/join-channel.js | 7 +- cmd/channel-manipulation/remove-alpha.js | 7 +- cmd/colour-manipulation/greyscale.js | 7 +- .../pipeline-colourspace.js | 9 +- cmd/colour-manipulation/tint.js | 7 +- cmd/colour-manipulation/tocolourspace.js | 9 +- cmd/compositing/composite.js | 9 +- cmd/operations/affine.js | 12 +- cmd/operations/blur.js | 7 +- cmd/operations/boolean.js | 9 +- cmd/operations/clahe.js | 7 +- cmd/operations/convolve.js | 10 +- cmd/operations/dilate.js | 7 +- cmd/operations/erode.js | 7 +- cmd/operations/flatten.js | 7 +- cmd/operations/flip.js | 7 +- cmd/operations/flop.js | 7 +- cmd/operations/gamma.js | 7 +- cmd/operations/linear.js | 7 +- cmd/operations/median.js | 7 +- cmd/operations/modulate.js | 10 +- cmd/operations/negate.js | 7 +- cmd/operations/normalise.js | 10 +- cmd/operations/recomb.js | 7 +- cmd/operations/rotate.js | 7 +- cmd/operations/sharpen.js | 10 +- cmd/operations/threshold.js | 7 +- cmd/operations/unflatten.js | 7 +- cmd/output.js | 12 +- cmd/resizing/extend.js | 12 +- cmd/resizing/extract.js | 10 +- cmd/resizing/resize.js | 12 +- cmd/resizing/trim.js | 7 +- lib/cli.js | 133 ++-- lib/constants.js | 7 +- lib/convert.js | 19 +- lib/index.js | 12 +- lib/queue.js | 5 +- lib/utils.js | 37 +- package-lock.json | 457 ++++++++++---- package.json | 8 +- test/cli.js | 81 +-- test/cmd.js | 21 +- test/cmd/channel-manipulation.js | 24 +- test/cmd/channel-manipulation/bandbool.js | 61 +- test/cmd/channel-manipulation/ensure-alpha.js | 79 ++- .../channel-manipulation/extract-channel.js | 61 +- test/cmd/channel-manipulation/join-channel.js | 82 +-- test/cmd/channel-manipulation/remove-alpha.js | 55 +- test/cmd/colour-manipulation.js | 21 +- test/cmd/colour-manipulation/greyscale.js | 57 +- .../pipeline-colourspace.js | 63 +- test/cmd/colour-manipulation/tint.js | 59 +- test/cmd/colour-manipulation/tocolourspace.js | 63 +- test/cmd/compositing.js | 12 +- test/cmd/compositing/composite.js | 569 +++++++++--------- test/cmd/operations.js | 72 ++- test/cmd/operations/affine.js | 159 +++-- test/cmd/operations/blur.js | 197 +++--- test/cmd/operations/boolean.js | 70 +-- test/cmd/operations/clahe.js | 87 ++- test/cmd/operations/convolve.js | 149 +++-- test/cmd/operations/dilate.js | 75 ++- test/cmd/operations/erode.js | 75 ++- test/cmd/operations/flatten.js | 85 ++- test/cmd/operations/flip.js | 55 +- test/cmd/operations/flop.js | 55 +- test/cmd/operations/gamma.js | 119 ++-- test/cmd/operations/linear.js | 123 ++-- test/cmd/operations/median.js | 85 ++- test/cmd/operations/modulate.js | 87 ++- test/cmd/operations/negate.js | 73 ++- test/cmd/operations/normalise.js | 111 ++-- test/cmd/operations/recomb.js | 75 ++- test/cmd/operations/rotate.js | 113 ++-- test/cmd/operations/sharpen.js | 219 ++++--- test/cmd/operations/threshold.js | 117 ++-- test/cmd/operations/unflatten.js | 55 +- test/cmd/output.js | 383 ++++++------ test/cmd/resizing.js | 21 +- test/cmd/resizing/extend.js | 163 ++--- test/cmd/resizing/extract.js | 75 ++- test/cmd/resizing/resize.js | 421 +++++++------ test/cmd/resizing/trim.js | 133 ++-- test/convert.js | 34 +- test/index.js | 28 +- test/mocks/logger.js | 7 +- test/mocks/sharp.js | 9 +- test/utils.js | 11 +- 93 files changed, 2969 insertions(+), 2867 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index e41c9a1..9b66731 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -22,11 +22,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Package modules. -const { hideBin } = require("yargs/helpers"); +import { hideBin } from "yargs/helpers"; + +// Local modules. +import sharp from "../lib/index.js"; // Run. -require("../lib")(hideBin(process.argv)); +sharp(hideBin(process.argv)); diff --git a/cmd/channel-manipulation/bandbool.js b/cmd/channel-manipulation/bandbool.js index 0cc3abc..b1b6fae 100644 --- a/cmd/channel-manipulation/bandbool.js +++ b/cmd/channel-manipulation/bandbool.js @@ -23,12 +23,9 @@ // @see https://sharp.pixelplumbing.com/api-channel#bandbool -// Strict mode. -"use strict"; - // Local modules. -const constants = require("../../lib/constants"); -const queue = require("../../lib/queue"); +import constants from "../../lib/constants.js"; +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -58,7 +55,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "bandbool ", describe: "Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image", diff --git a/cmd/channel-manipulation/ensure-alpha.js b/cmd/channel-manipulation/ensure-alpha.js index ce584f4..6cd482e 100644 --- a/cmd/channel-manipulation/ensure-alpha.js +++ b/cmd/channel-manipulation/ensure-alpha.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-channel#ensurealpha -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -62,7 +59,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "ensureAlpha [alpha]", describe: "Ensure the output image has an alpha transparency channel", builder, diff --git a/cmd/channel-manipulation/extract-channel.js b/cmd/channel-manipulation/extract-channel.js index 2b4eb78..3b8eb99 100644 --- a/cmd/channel-manipulation/extract-channel.js +++ b/cmd/channel-manipulation/extract-channel.js @@ -23,12 +23,9 @@ // @see https://sharp.pixelplumbing.com/api-channel#extractchannel -// Strict mode. -"use strict"; - // Local modules. -const constants = require("../../lib/constants"); -const queue = require("../../lib/queue"); +import constants from "../../lib/constants.js"; +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -61,7 +58,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "extractChannel ", describe: "Extract a single channel from a multi-channel image", builder, diff --git a/cmd/channel-manipulation/join-channel.js b/cmd/channel-manipulation/join-channel.js index 7104d4b..bf00d87 100644 --- a/cmd/channel-manipulation/join-channel.js +++ b/cmd/channel-manipulation/join-channel.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-channel#joinchannel -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -54,7 +51,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "joinChannel ", describe: "Join one or more channels to the image", builder, diff --git a/cmd/channel-manipulation/remove-alpha.js b/cmd/channel-manipulation/remove-alpha.js index 2a0faf0..c54f4f2 100644 --- a/cmd/channel-manipulation/remove-alpha.js +++ b/cmd/channel-manipulation/remove-alpha.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-channel#removealpha -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Command builder. const builder = (yargs) => { @@ -44,7 +41,7 @@ const handler = () => queue.push(["removeAlpha", (sharp) => sharp.removeAlpha()]); // Exports. -module.exports = { +export default { command: "removeAlpha", describe: "Remove alpha channel, if any", builder, diff --git a/cmd/colour-manipulation/greyscale.js b/cmd/colour-manipulation/greyscale.js index ac4bd04..c04ab9a 100644 --- a/cmd/colour-manipulation/greyscale.js +++ b/cmd/colour-manipulation/greyscale.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-colour#greyscale -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Command builder. const builder = (yargs) => { @@ -46,7 +43,7 @@ const builder = (yargs) => { const handler = () => queue.push(["greyscale", (sharp) => sharp.greyscale()]); // Exports. -module.exports = { +export default { command: "greyscale", aliases: "grayscale", describe: "Convert to 8-bit greyscale; 256 shades of grey", diff --git a/cmd/colour-manipulation/pipeline-colourspace.js b/cmd/colour-manipulation/pipeline-colourspace.js index 2f05915..319e7b3 100644 --- a/cmd/colour-manipulation/pipeline-colourspace.js +++ b/cmd/colour-manipulation/pipeline-colourspace.js @@ -23,12 +23,9 @@ // @see https://sharp.pixelplumbing.com/api-colour#tocolourspace -// Strict mode. -"use strict"; - // Local modules. -const constants = require("../../lib/constants"); -const queue = require("../../lib/queue"); +import constants from "../../lib/constants.js"; +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -62,7 +59,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "pipelineColourspace ", aliases: "pipelineColorspace", describe: "Set the pipeline colourspace", diff --git a/cmd/colour-manipulation/tint.js b/cmd/colour-manipulation/tint.js index 72c036e..1d61fe7 100644 --- a/cmd/colour-manipulation/tint.js +++ b/cmd/colour-manipulation/tint.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-colour#tint -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -52,7 +49,7 @@ const builder = (yargs) => { const handler = (args) => queue.push(["tint", (sharp) => sharp.tint(args.rgb)]); // Exports. -module.exports = { +export default { command: "tint ", describe: "Tint the image using the provided chroma while preserving the image luminance", diff --git a/cmd/colour-manipulation/tocolourspace.js b/cmd/colour-manipulation/tocolourspace.js index bc9626b..769a412 100644 --- a/cmd/colour-manipulation/tocolourspace.js +++ b/cmd/colour-manipulation/tocolourspace.js @@ -23,12 +23,9 @@ // @see https://sharp.pixelplumbing.com/api-colour#tocolourspace -// Strict mode. -"use strict"; - // Local modules. -const constants = require("../../lib/constants"); -const queue = require("../../lib/queue"); +import constants from "../../lib/constants.js"; +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -59,7 +56,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "toColourspace ", aliases: "toColorspace", describe: "Set the output colourspace", diff --git a/cmd/compositing/composite.js b/cmd/compositing/composite.js index 95a0076..739ac95 100644 --- a/cmd/compositing/composite.js +++ b/cmd/compositing/composite.js @@ -23,12 +23,9 @@ // @see http://sharp.pixelplumbing.com/api-composite#composite -// Strict mode. -"use strict"; - // Local modules. -const constants = require("../../lib/constants"); -const queue = require("../../lib/queue"); +import constants from "../../lib/constants.js"; +import queue from "../../lib/queue.js"; // Helpers. function getValueAt(arrayLike, index) { @@ -206,7 +203,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "composite [images..]", describe: "Composite image(s) over the processed (resized, extracted etc.) image", diff --git a/cmd/operations/affine.js b/cmd/operations/affine.js index d73b7e3..cc4b24c 100644 --- a/cmd/operations/affine.js +++ b/cmd/operations/affine.js @@ -23,14 +23,10 @@ // @see https://sharp.pixelplumbing.com/api-operation#affine -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const constants = require("../../lib/constants"); -const queue = require("../../lib/queue"); -const { pick } = require("../../lib/utils"); +import constants from "../../lib/constants.js"; +import queue from "../../lib/queue.js"; +import { pick } from "../../lib/utils.js"; // Configure. const placeholders = { @@ -109,7 +105,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "affine ", describe: "Perform an affine transform on an image", builder, diff --git a/cmd/operations/blur.js b/cmd/operations/blur.js index 119ff4a..c37aaa5 100644 --- a/cmd/operations/blur.js +++ b/cmd/operations/blur.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#blur -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -87,7 +84,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "blur [sigma]", describe: "Blur the image", builder, diff --git a/cmd/operations/boolean.js b/cmd/operations/boolean.js index 3df6cbd..8d5c864 100644 --- a/cmd/operations/boolean.js +++ b/cmd/operations/boolean.js @@ -23,12 +23,9 @@ // @see https://sharp.pixelplumbing.com/api-operation#boolean -// Strict mode. -"use strict"; - // Local modules. -const constants = require("../../lib/constants"); -const queue = require("../../lib/queue"); +import constants from "../../lib/constants.js"; +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -63,7 +60,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "boolean ", describe: "Perform a bitwise boolean operation with operand image", builder, diff --git a/cmd/operations/clahe.js b/cmd/operations/clahe.js index 269cea7..af22bf1 100644 --- a/cmd/operations/clahe.js +++ b/cmd/operations/clahe.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#clahe -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -79,7 +76,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "clahe ", describe: "Perform contrast limiting adaptive histogram equalization CLAHE", builder, diff --git a/cmd/operations/convolve.js b/cmd/operations/convolve.js index f872686..698174a 100644 --- a/cmd/operations/convolve.js +++ b/cmd/operations/convolve.js @@ -23,13 +23,9 @@ // @see https://sharp.pixelplumbing.com/api-operation#convolve -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const queue = require("../../lib/queue"); -const { pick } = require("../../lib/utils"); +import queue from "../../lib/queue.js"; +import { pick } from "../../lib/utils.js"; // Configure. const positionals = { @@ -102,7 +98,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "convolve ", describe: "Convolve the image with the specified kernel", builder, diff --git a/cmd/operations/dilate.js b/cmd/operations/dilate.js index cefdbbf..39277c9 100644 --- a/cmd/operations/dilate.js +++ b/cmd/operations/dilate.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#dilate -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -56,7 +53,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "dilate [width]", describe: "Expand foreground objects using the dilate morphological operator", builder, diff --git a/cmd/operations/erode.js b/cmd/operations/erode.js index 7ced864..b1a2dbb 100644 --- a/cmd/operations/erode.js +++ b/cmd/operations/erode.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#erode -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -56,7 +53,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "erode [width]", describe: "Shrink foreground objects using the erode morphological operator", builder, diff --git a/cmd/operations/flatten.js b/cmd/operations/flatten.js index 62784b6..8d2a87f 100644 --- a/cmd/operations/flatten.js +++ b/cmd/operations/flatten.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#flatten -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -60,7 +57,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "flatten [background]", describe: "Merge alpha transparency channel, if any, with a background", builder, diff --git a/cmd/operations/flip.js b/cmd/operations/flip.js index 4b79148..179f5ad 100644 --- a/cmd/operations/flip.js +++ b/cmd/operations/flip.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#flip -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Command builder. const builder = (yargs) => { @@ -43,7 +40,7 @@ const builder = (yargs) => { const handler = () => queue.push(["flip", (sharp) => sharp.flip()]); // Exports. -module.exports = { +export default { command: "flip", describe: "Flip the image about the vertical Y axis", builder, diff --git a/cmd/operations/flop.js b/cmd/operations/flop.js index 2f5dace..0902683 100644 --- a/cmd/operations/flop.js +++ b/cmd/operations/flop.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#flop -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Command builder. const builder = (yargs) => { @@ -43,7 +40,7 @@ const builder = (yargs) => { const handler = () => queue.push(["flop", (sharp) => sharp.flop()]); // Exports. -module.exports = { +export default { command: "flop", describe: "Flop the image about the horizontal X axis", builder, diff --git a/cmd/operations/gamma.js b/cmd/operations/gamma.js index 48595e4..b65dd0b 100644 --- a/cmd/operations/gamma.js +++ b/cmd/operations/gamma.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#gamma -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -64,7 +61,7 @@ const handler = (args) => ]); // Exports. -module.exports = { +export default { command: "gamma [gamma] [gammaOut]", describe: "Apply a gamma correction by reducing the encoding (darken) pre-resize then increasing the encoding (brighten) post-resize", diff --git a/cmd/operations/linear.js b/cmd/operations/linear.js index 99af74e..955169d 100644 --- a/cmd/operations/linear.js +++ b/cmd/operations/linear.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#linear -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -71,7 +68,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "linear [multiplier..]", describe: "Apply the linear formula a × input + b to the image to adjust image levels", diff --git a/cmd/operations/median.js b/cmd/operations/median.js index 31b8fb5..0650b5f 100644 --- a/cmd/operations/median.js +++ b/cmd/operations/median.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#median -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -56,7 +53,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "median [size]", describe: "Apply median filter", builder, diff --git a/cmd/operations/modulate.js b/cmd/operations/modulate.js index b4c7a7c..8e06e31 100644 --- a/cmd/operations/modulate.js +++ b/cmd/operations/modulate.js @@ -23,13 +23,9 @@ // @see http://sharp.pixelplumbing.com/api-operation#modulate -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const queue = require("../../lib/queue"); -const { pick } = require("../../lib/utils"); +import queue from "../../lib/queue.js"; +import { pick } from "../../lib/utils.js"; // Configure. const options = { @@ -78,7 +74,7 @@ const handler = (args) => queue.push(["modulate", (sharp) => sharp.modulate(pick(args, optionNames))]); // Exports. -module.exports = { +export default { command: "modulate", describe: "Transforms the image using brightness, saturation, hue rotation, and lightness", diff --git a/cmd/operations/negate.js b/cmd/operations/negate.js index 5466b47..7a26328 100644 --- a/cmd/operations/negate.js +++ b/cmd/operations/negate.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#negate -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const options = { @@ -55,7 +52,7 @@ const handler = (args) => queue.push(["negate", (sharp) => sharp.negate(args.alpha)]); // Exports. -module.exports = { +export default { command: "negate", describe: 'Produce the "negative" of the image', builder, diff --git a/cmd/operations/normalise.js b/cmd/operations/normalise.js index 7525fdb..0523ed9 100644 --- a/cmd/operations/normalise.js +++ b/cmd/operations/normalise.js @@ -23,13 +23,9 @@ // @see https://sharp.pixelplumbing.com/api-operation#normalise -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const queue = require("../../lib/queue"); -const { pick } = require("../../lib/utils"); +import queue from "../../lib/queue.js"; +import { pick } from "../../lib/utils.js"; const options = { lower: { @@ -65,7 +61,7 @@ const handler = (args) => ]); // Exports. -module.exports = { +export default { command: "normalise", aliases: "normalize", describe: diff --git a/cmd/operations/recomb.js b/cmd/operations/recomb.js index 5268889..6657a5a 100644 --- a/cmd/operations/recomb.js +++ b/cmd/operations/recomb.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#recomb -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const placeholders = { @@ -74,7 +71,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "recomb ", describe: "Recomb the image with the specified matrix", builder, diff --git a/cmd/operations/rotate.js b/cmd/operations/rotate.js index 0740f96..dcd2055 100644 --- a/cmd/operations/rotate.js +++ b/cmd/operations/rotate.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#rotate -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -72,7 +69,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "rotate [angle]", describe: "Rotate the output image", builder, diff --git a/cmd/operations/sharpen.js b/cmd/operations/sharpen.js index 75b560a..92ce3ab 100644 --- a/cmd/operations/sharpen.js +++ b/cmd/operations/sharpen.js @@ -23,13 +23,9 @@ // @see https://sharp.pixelplumbing.com/api-operation#sharpen -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const queue = require("../../lib/queue"); -const { pick } = require("../../lib/utils"); +import queue from "../../lib/queue.js"; +import { pick } from "../../lib/utils.js"; // Configure. const positionals = { @@ -105,7 +101,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "sharpen [sigma]", describe: "Sharpen the image", builder, diff --git a/cmd/operations/threshold.js b/cmd/operations/threshold.js index c46a656..f9510ba 100644 --- a/cmd/operations/threshold.js +++ b/cmd/operations/threshold.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#threshold -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -70,7 +67,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "threshold [value]", describe: "Any pixel value greater than or equal to the threshold value will be set to 255, otherwise it will be set to 0", diff --git a/cmd/operations/unflatten.js b/cmd/operations/unflatten.js index 5512782..1b63bba 100644 --- a/cmd/operations/unflatten.js +++ b/cmd/operations/unflatten.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-operation#unflatten -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Command builder. const builder = (yargs) => { @@ -43,7 +40,7 @@ const builder = (yargs) => { const handler = () => queue.push(["unflatten", (sharp) => sharp.unflatten()]); // Exports. -module.exports = { +export default { command: "unflatten", describe: "Ensure the image has an alpha channel with all white pixel values made fully transparent", diff --git a/cmd/output.js b/cmd/output.js index 63d2932..041598c 100644 --- a/cmd/output.js +++ b/cmd/output.js @@ -23,14 +23,10 @@ // @see https://sharp.pixelplumbing.com/api-output#tile -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const constants = require("../lib/constants"); -const queue = require("../lib/queue"); -const { pick } = require("../lib/utils"); +import constants from "../lib/constants.js"; +import queue from "../lib/queue.js"; +import { pick } from "../lib/utils.js"; // Configure. const positionals = { @@ -124,7 +120,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "tile [size]", describe: "Use tile-based deep zoom (image pyramid) output", builder, diff --git a/cmd/resizing/extend.js b/cmd/resizing/extend.js index 905a148..71c5025 100644 --- a/cmd/resizing/extend.js +++ b/cmd/resizing/extend.js @@ -23,14 +23,10 @@ // @see https://sharp.pixelplumbing.com/api-resize#extend -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const constants = require("../../lib/constants"); -const queue = require("../../lib/queue"); -const { pick } = require("../../lib/utils"); +import constants from "../../lib/constants.js"; +import queue from "../../lib/queue.js"; +import { pick } from "../../lib/utils.js"; // Configure. const positionals = { @@ -104,7 +100,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "extend ", describe: "Extends/pads the edges of the image with the provided background colour", diff --git a/cmd/resizing/extract.js b/cmd/resizing/extract.js index 14a159a..a61378b 100644 --- a/cmd/resizing/extract.js +++ b/cmd/resizing/extract.js @@ -23,13 +23,9 @@ // @see https://sharp.pixelplumbing.com/api-resize#extract -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const queue = require("../../lib/queue"); -const { pick } = require("../../lib/utils"); +import queue from "../../lib/queue.js"; +import { pick } from "../../lib/utils.js"; // Configure. const positionals = { @@ -75,7 +71,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "extract ", describe: "Extract a region of the image", builder, diff --git a/cmd/resizing/resize.js b/cmd/resizing/resize.js index 00edbaf..fcaf239 100644 --- a/cmd/resizing/resize.js +++ b/cmd/resizing/resize.js @@ -23,14 +23,10 @@ // @see https://sharp.pixelplumbing.com/api-resize/ -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const constants = require("../../lib/constants"); -const queue = require("../../lib/queue"); -const { pick } = require("../../lib/utils"); +import constants from "../../lib/constants.js"; +import queue from "../../lib/queue.js"; +import { pick } from "../../lib/utils.js"; // Configure. const positionals = { @@ -144,7 +140,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "resize [width] [height]", describe: "Resize image to width, height, or width × height", builder, diff --git a/cmd/resizing/trim.js b/cmd/resizing/trim.js index 4046497..628df41 100644 --- a/cmd/resizing/trim.js +++ b/cmd/resizing/trim.js @@ -23,11 +23,8 @@ // @see https://sharp.pixelplumbing.com/api-resize#trim -// Strict mode. -"use strict"; - // Local modules. -const queue = require("../../lib/queue"); +import queue from "../../lib/queue.js"; // Configure. const positionals = { @@ -92,7 +89,7 @@ const handler = (args) => { }; // Exports. -module.exports = { +export default { command: "trim [threshold]", describe: "Trim pixels from all edges that contain values similar to the given background color, which defaults to that of the top-left pixel", diff --git a/lib/cli.js b/lib/cli.js index b91db2d..ddb27d9 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -21,18 +21,57 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; +// Standard lib. +import { createRequire } from "node:module"; // Package modules. -const sharp = require("sharp"); -const yargs = require("yargs"); +import sharp from "sharp"; +import yargsFactory from "yargs"; // Local modules. -const constants = require("./constants"); -const pkg = require("../package.json"); -const queue = require("./queue"); -const { pick } = require("./utils"); +import affine from "../cmd/operations/affine.js"; +import bandbool from "../cmd/channel-manipulation/bandbool.js"; +import blur from "../cmd/operations/blur.js"; +import boolean from "../cmd/operations/boolean.js"; +import clahe from "../cmd/operations/clahe.js"; +import composite from "../cmd/compositing/composite.js"; +import convolve from "../cmd/operations/convolve.js"; +import dilate from "../cmd/operations/dilate.js"; +import ensureAlpha from "../cmd/channel-manipulation/ensure-alpha.js"; +import erode from "../cmd/operations/erode.js"; +import extend from "../cmd/resizing/extend.js"; +import extract from "../cmd/resizing/extract.js"; +import extractChannel from "../cmd/channel-manipulation/extract-channel.js"; +import flatten from "../cmd/operations/flatten.js"; +import flip from "../cmd/operations/flip.js"; +import flop from "../cmd/operations/flop.js"; +import gamma from "../cmd/operations/gamma.js"; +import greyscale from "../cmd/colour-manipulation/greyscale.js"; +import joinChannel from "../cmd/channel-manipulation/join-channel.js"; +import linear from "../cmd/operations/linear.js"; +import median from "../cmd/operations/median.js"; +import modulate from "../cmd/operations/modulate.js"; +import negate from "../cmd/operations/negate.js"; +import normalise from "../cmd/operations/normalise.js"; +import pipelineColourspace from "../cmd/colour-manipulation/pipeline-colourspace.js"; +import recomb from "../cmd/operations/recomb.js"; +import removeAlpha from "../cmd/channel-manipulation/remove-alpha.js"; +import resize from "../cmd/resizing/resize.js"; +import rotate from "../cmd/operations/rotate.js"; +import sharpen from "../cmd/operations/sharpen.js"; +import threshold from "../cmd/operations/threshold.js"; +import tint from "../cmd/colour-manipulation/tint.js"; +import tile from "../cmd/output.js"; +import toColourspace from "../cmd/colour-manipulation/tocolourspace.js"; +import trim from "../cmd/resizing/trim.js"; +import unflatten from "../cmd/operations/unflatten.js"; +import constants from "./constants.js"; +import queue from "./queue.js"; +import { pick } from "./utils.js"; + +// Assets. +const pkg = createRequire(import.meta.url)("../package.json"); +const yargs = yargsFactory(); // Configure. const IS_TEXT_TERMINAL = process.stdin.isTTY; @@ -592,42 +631,42 @@ const cli = yargs // Commands. // Avoid `yargs.commandDir()` as it uses insertion order, not alphabetical. - .command(require("../cmd/operations/affine")) - .command(require("../cmd/channel-manipulation/bandbool")) - .command(require("../cmd/operations/blur")) - .command(require("../cmd/operations/boolean")) - .command(require("../cmd/operations/clahe")) - .command(require("../cmd/compositing/composite")) - .command(require("../cmd/operations/convolve")) - .command(require("../cmd/operations/dilate")) - .command(require("../cmd/channel-manipulation/ensure-alpha")) - .command(require("../cmd/operations/erode")) - .command(require("../cmd/resizing/extend")) - .command(require("../cmd/resizing/extract")) - .command(require("../cmd/channel-manipulation/extract-channel")) - .command(require("../cmd/operations/flatten")) - .command(require("../cmd/operations/flip")) - .command(require("../cmd/operations/flop")) - .command(require("../cmd/operations/gamma")) - .command(require("../cmd/colour-manipulation/greyscale")) - .command(require("../cmd/channel-manipulation/join-channel")) - .command(require("../cmd/operations/linear")) - .command(require("../cmd/operations/median")) - .command(require("../cmd/operations/modulate")) - .command(require("../cmd/operations/negate")) - .command(require("../cmd/operations/normalise")) - .command(require("../cmd/colour-manipulation/pipeline-colourspace")) - .command(require("../cmd/operations/recomb")) - .command(require("../cmd/channel-manipulation/remove-alpha")) - .command(require("../cmd/resizing/resize")) - .command(require("../cmd/operations/rotate")) - .command(require("../cmd/operations/sharpen")) - .command(require("../cmd/operations/threshold")) - .command(require("../cmd/colour-manipulation/tint")) - .command(require("../cmd/output")) - .command(require("../cmd/colour-manipulation/tocolourspace")) - .command(require("../cmd/resizing/trim")) - .command(require("../cmd/operations/unflatten")); + .command(affine) + .command(bandbool) + .command(blur) + .command(boolean) + .command(clahe) + .command(composite) + .command(convolve) + .command(dilate) + .command(ensureAlpha) + .command(erode) + .command(extend) + .command(extract) + .command(extractChannel) + .command(flatten) + .command(flip) + .command(flop) + .command(gamma) + .command(greyscale) + .command(joinChannel) + .command(linear) + .command(median) + .command(modulate) + .command(negate) + .command(normalise) + .command(pipelineColourspace) + .command(recomb) + .command(removeAlpha) + .command(resize) + .command(rotate) + .command(sharpen) + .command(threshold) + .command(tint) + .command(tile) + .command(toColourspace) + .command(trim) + .command(unflatten); // Helpers. const originalParse = cli.parse.bind(cli); @@ -646,9 +685,9 @@ const promisifiedParse = (...args) => { }; // Exports. -module.exports = cli; -module.exports.inputOptions = Object.keys(inputOptions); -module.exports.parse = function recursiveParse(args, context = {}) { +export default cli; +cli.inputOptions = Object.keys(inputOptions); +cli.parse = function recursiveParse(args, context = {}) { return promisifiedParse(args, context).then((argv) => { // Handle arguments. // NOTE Use queue.unshift to apply global options first. diff --git a/lib/constants.js b/lib/constants.js index 9e87bdc..a498c98 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -21,14 +21,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Package modules. -const sharp = require("sharp"); +import sharp from "sharp"; // Exports. -module.exports = { +export default { BLEND: Object.keys(sharp.blend), BOOL: Object.keys(sharp.bool), CHANNEL: ["red", "green", "blue", "alpha"], diff --git a/lib/convert.js b/lib/convert.js index 427c43e..10c6ade 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -21,21 +21,18 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Standard lib. -const fs = require("fs"); -const path = require("path"); -const { pipeline } = require("stream/promises"); +import fs from "node:fs"; +import path from "node:path"; +import { pipeline } from "node:stream/promises"; // Package modules. -const { globSync } = require("glob"); -const sharp = require("sharp"); +import { globSync } from "glob"; +import sharp from "sharp"; // Local modules. -const queue = require("./queue"); -const { isDirectory } = require("./utils"); +import queue from "./queue.js"; +import { isDirectory } from "./utils.js"; // Configure. const EXTENSIONS = { @@ -50,7 +47,7 @@ const EXTENSIONS = { }; // Exports. -module.exports = { +export default { // Convert a list of files. files: (input, output, options) => { // Resolve files. diff --git a/lib/index.js b/lib/index.js index 81a880c..10ae1f6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -21,17 +21,13 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - -// Package modules. // Local modules. -const cli = require("./cli"); -const convert = require("./convert"); -const { pick } = require("./utils"); +import cli from "./cli.js"; +import convert from "./convert.js"; +import { pick } from "./utils.js"; // Exports. -module.exports = (args, options = {}) => { +export default (args, options = {}) => { const logger = options.logger || console; // Cast. // Parse arguments and handle i/o. diff --git a/lib/queue.js b/lib/queue.js index e4eecbb..5f2ccf7 100644 --- a/lib/queue.js +++ b/lib/queue.js @@ -21,9 +21,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Configure. const queue = []; @@ -42,4 +39,4 @@ Object.defineProperties(queue, { }); // Exports. -module.exports = queue; +export default queue; diff --git a/lib/utils.js b/lib/utils.js index e2ca338..fc5932f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -21,27 +21,24 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Standard lib. -const fs = require("fs"); +import fs from "node:fs"; -// Exports. -module.exports = { - isDirectory: (path) => { - try { - return fs.statSync(path).isDirectory(); - } catch (err) { - if (err.code === "ENOENT") return false; - throw err; - } - }, +const isDirectory = (path) => { + try { + return fs.statSync(path).isDirectory(); + } catch (err) { + if (err.code === "ENOENT") return false; + throw err; + } +}; - pick: (object, keys) => { - return keys.reduce((result, key) => { - if (Object.hasOwn(object, key)) result[key] = object[key]; - return result; - }, {}); - }, +const pick = (object, keys) => { + return keys.reduce((result, key) => { + if (Object.hasOwn(object, key)) result[key] = object[key]; + return result; + }, {}); }; + +// Exports. +export { isDirectory, pick }; diff --git a/package-lock.json b/package-lock.json index 99bc576..9ef44be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,8 @@ }, "devDependencies": { "@eslint/js": "9.39.x", - "eslint": "^9.39.5", + "@istanbuljs/esm-loader-hook": "0.3.x", + "eslint": "9.39.x", "fs-extra": "11.3.x", "globals": "17.11.x", "mocha": "10.8.x", @@ -46,13 +47,13 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz", - "integrity": "sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==", + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", + "integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==", "dev": true, "license": "MIT", "dependencies": { - "@babel/helper-validator-identifier": "^7.27.1", + "@babel/helper-validator-identifier": "^7.29.7", "js-tokens": "^4.0.0", "picocolors": "^1.1.1" }, @@ -115,15 +116,30 @@ } }, "node_modules/@babel/generator": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.8.tgz", - "integrity": "sha512-47DG+6F5SzOi0uEvK4wMShmn5yY0mVjVJoWTphdY2B4Rx9wHgjK7Yhtr0ru6nE+sn0v38mzrWOlah0p/YlHHOQ==", + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.8.tgz", + "integrity": "sha512-gZbepsdh3WDtgZKWL+vTPh71LSBrm/Y4/QDZBVCcYfmeTEEuoOYwlSy+G1StfJg+/Zy550u/3TATbm7qDbbMtg==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/types": "^7.24.8", - "@jridgewell/gen-mapping": "^0.3.5", - "@jridgewell/trace-mapping": "^0.3.25", - "jsesc": "^2.5.1" + "@babel/parser": "^7.29.8", + "@babel/types": "^7.29.8", + "@jridgewell/gen-mapping": "^0.3.12", + "@jridgewell/trace-mapping": "^0.3.28", + "jsesc": "^3.0.2" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-annotate-as-pure": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.29.7.tgz", + "integrity": "sha512-OoK6239jHPuSQOoS0kfTVKn0b/rVTk0seKq4Gd2UMLtmOVLjDC0ki3e+c90Trqv2gMfvJFqkiljrr568+qddiw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/types": "^7.29.7" }, "engines": { "node": ">=6.9.0" @@ -154,67 +170,86 @@ "semver": "bin/semver.js" } }, - "node_modules/@babel/helper-environment-visitor": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.24.7.tgz", - "integrity": "sha512-DoiN84+4Gnd0ncbBOM9AZENV4a5ZiL39HYMyZJGZ/AZEykHYdJw0wW3kdcsh9/Kn+BRXHLkkklZ51ecPKmI1CQ==", + "node_modules/@babel/helper-create-class-features-plugin": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.29.7.tgz", + "integrity": "sha512-IY3ZD9Tmooqr3TUhc3DUWxiuo8xx1DWLhd5M7hQ+ZWJamqM2BbalrBJb2MisSLoYorOj75U03qULCxQTY9r3hg==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/types": "^7.24.7" + "@babel/helper-annotate-as-pure": "^7.29.7", + "@babel/helper-member-expression-to-functions": "^7.29.7", + "@babel/helper-optimise-call-expression": "^7.29.7", + "@babel/helper-replace-supers": "^7.29.7", + "@babel/helper-skip-transparent-expression-wrappers": "^7.29.7", + "@babel/traverse": "^7.29.7", + "semver": "^6.3.1" }, "engines": { "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@babel/helper-function-name": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.24.7.tgz", - "integrity": "sha512-FyoJTsj/PEUWu1/TYRiXTIHc8lbw+TDYkZuoE43opPS5TrI7MyONBE1oNvfguEXAD9yhQRrVBnXdXzSLQl9XnA==", + "node_modules/@babel/helper-create-class-features-plugin/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, - "dependencies": { - "@babel/template": "^7.24.7", - "@babel/types": "^7.24.7" - }, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/@babel/helper-globals": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.29.7.tgz", + "integrity": "sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==", + "dev": true, + "license": "MIT", "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/helper-hoist-variables": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.24.7.tgz", - "integrity": "sha512-MJJwhkoGy5c4ehfoRyrJ/owKeMl19U54h27YYftT0o2teQ3FJ3nQUf/I3LlJsX4l3qlw7WRXUmiyajvHXoTubQ==", + "node_modules/@babel/helper-member-expression-to-functions": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.29.7.tgz", + "integrity": "sha512-j+7JYmk1JYDtACIGj0QJqqWZjoUpMoEikQGADMaHgCMCSDqd2+P32rfcibUNrGOMWrlzK1WJBdxrB3JJQZwWtg==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/types": "^7.24.7" + "@babel/traverse": "^7.29.7", + "@babel/types": "^7.29.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-imports": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.7.tgz", - "integrity": "sha512-8AyH3C+74cgCVVXow/myrynrAGv+nTVg5vKu2nZph9x7RcRwzmh0VFallJuFTZ9mx6u4eSdXZfcOzSqTUm0HCA==", + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.29.7.tgz", + "integrity": "sha512-ejHwrQQYcm9xnTivShn2IDOlIzInN34AXskvq9QicvCtEzq1Vzclu/tKF8Jq1Cg8JG2GL6/EmjgsCT7lXepE3g==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/traverse": "^7.24.7", - "@babel/types": "^7.24.7" + "@babel/traverse": "^7.29.7", + "@babel/types": "^7.29.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.24.8.tgz", - "integrity": "sha512-m4vWKVqvkVAWLXfHCCfff2luJj86U+J0/x+0N3ArG/tP0Fq7zky2dYwMbtPmkc/oulkkbjdL3uWzuoBwQ8R00Q==", + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.29.7.tgz", + "integrity": "sha512-UPUVSyXbOh627KiCIGQSgwWzGeBKLkaJ9PJEdrngIwMSzxLR4jS4+f1f1jb7VzBbg8nFLaYotvVPFCTqdrmTAg==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/helper-environment-visitor": "^7.24.7", - "@babel/helper-module-imports": "^7.24.7", - "@babel/helper-simple-access": "^7.24.7", - "@babel/helper-split-export-declaration": "^7.24.7", - "@babel/helper-validator-identifier": "^7.24.7" + "@babel/helper-module-imports": "^7.29.7", + "@babel/helper-validator-identifier": "^7.29.7", + "@babel/traverse": "^7.29.7" }, "engines": { "node": ">=6.9.0" @@ -223,35 +258,65 @@ "@babel/core": "^7.0.0" } }, - "node_modules/@babel/helper-simple-access": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.7.tgz", - "integrity": "sha512-zBAIvbCMh5Ts+b86r/CjU+4XGYIs+R1j951gxI3KmmxBMhCg4oQMsv6ZXQ64XOm/cvzfU1FmoCyt6+owc5QMYg==", + "node_modules/@babel/helper-optimise-call-expression": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.29.7.tgz", + "integrity": "sha512-+kmGVjcT9RGYzoDwdwEqEvGgKe3BYq+O1iGzjFubaNgZHwYHP6lsF2Yghf4kEuv9BV7tYDZ913aBW9am6YKong==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/traverse": "^7.24.7", - "@babel/types": "^7.24.7" + "@babel/types": "^7.29.7" }, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/helper-split-export-declaration": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.24.7.tgz", - "integrity": "sha512-oy5V7pD+UvfkEATUKvIjvIAH/xCzfsFVw7ygW2SI6NClZzquT+mwdTfgfdbUiceh6iQO0CHtCPsyze/MZ2YbAA==", + "node_modules/@babel/helper-plugin-utils": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.29.7.tgz", + "integrity": "sha512-G7sHYigPY17oO5SYWnfD/0MTBwVR781S/JI643e/JhUYgVgWE/61SoW3NH9KWUKyKq5LVh3npif99Wkt6j86Jw==", "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-replace-supers": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.29.7.tgz", + "integrity": "sha512-atfGXWSeCiF4DnKZIfmJfQRkSw9b9gNNXR1kqKjbhG4pGYCOnkp8OcTB8E3NXjBu8NpheSnOeNKz8KT7UNFTmQ==", + "dev": true, + "license": "MIT", "dependencies": { - "@babel/types": "^7.24.7" + "@babel/helper-member-expression-to-functions": "^7.29.7", + "@babel/helper-optimise-call-expression": "^7.29.7", + "@babel/traverse": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } + }, + "node_modules/@babel/helper-skip-transparent-expression-wrappers": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-skip-transparent-expression-wrappers/-/helper-skip-transparent-expression-wrappers-7.29.7.tgz", + "integrity": "sha512-brcMGQaVzIeUb+6/bs1Av0f8YuNNjKY2JyvfRCsFuFsdKccEQ5Ges2y74D74NZ1Rz8lKJ9ksJkfqwQFJ/iNEyQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/traverse": "^7.29.7", + "@babel/types": "^7.29.7" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz", - "integrity": "sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==", + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz", + "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==", "dev": true, "license": "MIT", "engines": { @@ -259,9 +324,9 @@ } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.27.1.tgz", - "integrity": "sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow==", + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", + "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", "dev": true, "license": "MIT", "engines": { @@ -269,10 +334,11 @@ } }, "node_modules/@babel/helper-validator-option": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.24.8.tgz", - "integrity": "sha512-xb8t9tD1MHLungh/AIoWYN+gVHaB9kwlu8gffXGSt3FFEIT7RjS+xWbc2vUD1UTZdIpKj/ab3rdqJ7ufngyi2Q==", + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.29.7.tgz", + "integrity": "sha512-N9ZErrD+yW5geCDtBqnOoxmR8+tNKiGuxKlDpuJxfsqpa2dFcexaziGAE/qoHLiDDreVNMupxGmSoNlyvsA3gw==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -292,13 +358,13 @@ } }, "node_modules/@babel/parser": { - "version": "7.27.5", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.5.tgz", - "integrity": "sha512-OsQd175SxWkGlzbny8J3K8TnnDD0N3lrIUtB92xwyRpzaenGZhxDvxN/JgU00U3CDZNj9tPuDJ5H0WS4Nt3vKg==", + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.8.tgz", + "integrity": "sha512-E8lTAYNB1KW+FH+VGJuZM1ioAx2E6oVlvQFRrf5P8ZZmsiJXYAD9vTFV7yyEURNzgh1dFqMZuO6tUwcARbqFCA==", "dev": true, "license": "MIT", "dependencies": { - "@babel/types": "^7.27.3" + "@babel/types": "^7.29.8" }, "bin": { "parser": "bin/babel-parser.js" @@ -307,60 +373,154 @@ "node": ">=6.0.0" } }, - "node_modules/@babel/template": { - "version": "7.27.2", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.2.tgz", - "integrity": "sha512-LPDZ85aEJyYSd18/DkjNh4/y1ntkE5KwUHWTiqgRxruuZL2F1yuHligVHLvcHY2vMHXttKFpJn6LwfI7cw7ODw==", + "node_modules/@babel/plugin-syntax-decorators": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-decorators/-/plugin-syntax-decorators-7.29.7.tgz", + "integrity": "sha512-9MTTLbF39X6sqM92JPEsoI7++26hjZvzkxKZy64aMhWLH2mPkJ/Q3AV4QLmls3R14FpSpkOwQQfUh962JGQxxg==", "dev": true, "license": "MIT", "dependencies": { - "@babel/code-frame": "^7.27.1", - "@babel/parser": "^7.27.2", - "@babel/types": "^7.27.1" + "@babel/helper-plugin-utils": "^7.29.7" }, "engines": { "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/traverse": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.8.tgz", - "integrity": "sha512-t0P1xxAPzEDcEPmjprAQq19NWum4K0EQPjMwZQZbHt+GiZqvjCHjj755Weq1YRPVzBI+3zSfvScfpnuIecVFJQ==", + "node_modules/@babel/plugin-syntax-jsx": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.29.7.tgz", + "integrity": "sha512-TSu8+mHCoEaaCDEZ0I3+6mvTBYR4PCxQwf2z9/r5Tbztv6NaLR3B9thGTTxX2WGuGHJqRiAbKPeGTJ5XWXVg6A==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/code-frame": "^7.24.7", - "@babel/generator": "^7.24.8", - "@babel/helper-environment-visitor": "^7.24.7", - "@babel/helper-function-name": "^7.24.7", - "@babel/helper-hoist-variables": "^7.24.7", - "@babel/helper-split-export-declaration": "^7.24.7", - "@babel/parser": "^7.24.8", - "@babel/types": "^7.24.8", - "debug": "^4.3.1", - "globals": "^11.1.0" + "@babel/helper-plugin-utils": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-syntax-typescript": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.29.7.tgz", + "integrity": "sha512-ngr+82Sh0xMz25TPCZi+nC2iTzjfCdWS2ONXTp/PtSCHCgaCNBpdMqgvJ2ccdLlClVZ7sisIgB914j/JFe+RZA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-plugin-utils": "^7.29.7" }, "engines": { "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/traverse/node_modules/globals": { - "version": "11.12.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", - "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "node_modules/@babel/plugin-transform-modules-commonjs": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.29.7.tgz", + "integrity": "sha512-j0vCldybPC5b5dwCQOJ21uKtHzt7hxLygJTg9eF1ScfaikEDNfzn94XoW5Fi+seBR0nCyL23xaBFFkq7dTM8XQ==", "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-module-transforms": "^7.29.7", + "@babel/helper-plugin-utils": "^7.29.7" + }, "engines": { - "node": ">=4" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-typescript": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.29.7.tgz", + "integrity": "sha512-jK52h8LaLc7JarhQV2ofeFMts4H7vnOXnqZNA6fYglBTZewRBE51KWt3BUltW1P+KoPsYkHoJeXePuz4zo2LMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.29.7", + "@babel/helper-create-class-features-plugin": "^7.29.7", + "@babel/helper-plugin-utils": "^7.29.7", + "@babel/helper-skip-transparent-expression-wrappers": "^7.29.7", + "@babel/plugin-syntax-typescript": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/preset-typescript": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.29.7.tgz", + "integrity": "sha512-/Foi8vKY2EVbed/1eZx0gJEEwHAIxogrySI7rULcRIvhZzbvoE/b5qG5Ghc0WKAFKOHA9SD1x7RsFlOYdutIiQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-plugin-utils": "^7.29.7", + "@babel/helper-validator-option": "^7.29.7", + "@babel/plugin-syntax-jsx": "^7.29.7", + "@babel/plugin-transform-modules-commonjs": "^7.29.7", + "@babel/plugin-transform-typescript": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/template": { + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.29.7.tgz", + "integrity": "sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/parser": "^7.29.7", + "@babel/types": "^7.29.7" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/traverse": { + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.8.tgz", + "integrity": "sha512-I5z7H3bf/41ktsNVLtpN0wAa336HkqIHQ5BuPLEhTkt1jVSyZpeNKIzTgEWmlxjdg81R0IgUCcaE+Ok3NvrfZg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.29.7", + "@babel/generator": "^7.29.8", + "@babel/helper-globals": "^7.29.7", + "@babel/parser": "^7.29.8", + "@babel/template": "^7.29.7", + "@babel/types": "^7.29.8", + "debug": "^4.3.1" + }, + "engines": { + "node": ">=6.9.0" } }, "node_modules/@babel/types": { - "version": "7.27.6", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.27.6.tgz", - "integrity": "sha512-ETyHEk2VHHvl9b9jZP5IHPavHYk57EhanlRRuae9XCpb/j5bDCbPPMOBfCWhnl/7EDJz0jEMCi/RhccCE8r1+Q==", + "version": "7.29.8", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.8.tgz", + "integrity": "sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==", "dev": true, "license": "MIT", "dependencies": { - "@babel/helper-string-parser": "^7.27.1", - "@babel/helper-validator-identifier": "^7.27.1" + "@babel/helper-string-parser": "^7.29.7", + "@babel/helper-validator-identifier": "^7.29.7" }, "engines": { "node": ">=6.9.0" @@ -1208,6 +1368,25 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/@istanbuljs/esm-loader-hook": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@istanbuljs/esm-loader-hook/-/esm-loader-hook-0.3.0.tgz", + "integrity": "sha512-lEnYroBUYfNQuJDYrPvre8TSwPZnyIQv9qUT3gACvhr3igZr+BbrdyIcz4+2RnEXZzi12GqkUW600+QQPpIbVg==", + "dev": true, + "license": "ISC", + "dependencies": { + "@babel/core": "^7.8.7", + "@babel/plugin-syntax-decorators": "^7.25.9", + "@babel/preset-typescript": "^7.26.0", + "@istanbuljs/load-nyc-config": "^1.1.0", + "@istanbuljs/schema": "^0.1.3", + "babel-plugin-istanbul": "^6.0.0", + "test-exclude": "^6.0.0" + }, + "engines": { + "node": ">=16.12.0" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -1317,17 +1496,14 @@ } }, "node_modules/@jridgewell/gen-mapping": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", - "integrity": "sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==", + "version": "0.3.13", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", + "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", "dev": true, + "license": "MIT", "dependencies": { - "@jridgewell/set-array": "^1.2.1", - "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/sourcemap-codec": "^1.5.0", "@jridgewell/trace-mapping": "^0.3.24" - }, - "engines": { - "node": ">=6.0.0" } }, "node_modules/@jridgewell/resolve-uri": { @@ -1339,15 +1515,6 @@ "node": ">=6.0.0" } }, - "node_modules/@jridgewell/set-array": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz", - "integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==", - "dev": true, - "engines": { - "node": ">=6.0.0" - } - }, "node_modules/@jridgewell/sourcemap-codec": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", @@ -1355,10 +1522,11 @@ "dev": true }, "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.25", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", - "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", "dev": true, + "license": "MIT", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" @@ -1597,6 +1765,50 @@ "node": ">=8" } }, + "node_modules/babel-plugin-istanbul": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-6.1.1.tgz", + "integrity": "sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@babel/helper-plugin-utils": "^7.0.0", + "@istanbuljs/load-nyc-config": "^1.0.0", + "@istanbuljs/schema": "^0.1.2", + "istanbul-lib-instrument": "^5.0.4", + "test-exclude": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/babel-plugin-istanbul/node_modules/istanbul-lib-instrument": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-5.2.1.tgz", + "integrity": "sha512-pzqtp31nLv/XFOzXGuvhCb8qhjmTVo5vjVk19XE4CRlSWz0KoeJ3bw9XsA7nOp9YBf4qHjwBxkDzKcME/J29Yg==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@babel/core": "^7.12.3", + "@babel/parser": "^7.14.7", + "@istanbuljs/schema": "^0.1.2", + "istanbul-lib-coverage": "^3.2.0", + "semver": "^6.3.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/babel-plugin-istanbul/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -2987,15 +3199,16 @@ } }, "node_modules/jsesc": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", - "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", + "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", "dev": true, + "license": "MIT", "bin": { "jsesc": "bin/jsesc" }, "engines": { - "node": ">=4" + "node": ">=6" } }, "node_modules/json-buffer": { diff --git a/package.json b/package.json index 74a9bae..f2e82c6 100644 --- a/package.json +++ b/package.json @@ -14,17 +14,18 @@ "homepage": "https://github.com/vseventer/sharp-cli", "bugs": "https://github.com/vseventer/sharp-cli/issues", "license": "MIT", + "type": "module", "author": "Mark van Seventer ", "repository": "vseventer/sharp-cli", "bin": { "sharp": "bin/cli.js" }, - "main": "lib/", + "main": "lib/index.js", "scripts": { "format": "prettier . --write", "lint": "eslint", "pretest": "npm run lint && prettier . --check", - "test": "nyc mocha", + "test": "NODE_OPTIONS=--experimental-loader=@istanbuljs/esm-loader-hook nyc mocha", "posttest": "nyc report --reporter=lcov" }, "dependencies": { @@ -34,7 +35,8 @@ }, "devDependencies": { "@eslint/js": "9.39.x", - "eslint": "^9.39.5", + "@istanbuljs/esm-loader-hook": "0.3.x", + "eslint": "9.39.x", "fs-extra": "11.3.x", "globals": "17.11.x", "mocha": "10.8.x", diff --git a/test/cli.js b/test/cli.js index ae2a7c5..b17728e 100644 --- a/test/cli.js +++ b/test/cli.js @@ -21,25 +21,34 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; +// Standard lib. +import { createRequire } from "node:module"; +import { fileURLToPath } from "node:url"; // Package modules. -const expect = require("must"); -const sinon = require("sinon"); +import expect from "must"; +import sinon from "sinon"; // Local modules. -const cli = require("../lib/cli"); -const pkg = require("../package.json"); -const queue = require("../lib/queue"); -const sharp = require("./mocks/sharp"); +import cli from "../lib/cli.js"; +import queue from "../lib/queue.js"; +import sharp from "./mocks/sharp.js"; + +// Assets. +const pkg = createRequire(import.meta.url)("../package.json"); // Test suite. describe(`${pkg.name} [command..]`, () => { // Defaults (avoid path.join` to test for input normalizing). - const input = `${__dirname}/../test/fixtures/input.jpg`; - const output = `${__dirname}/../test/`; + const input = fileURLToPath(new URL("./fixtures/input.jpg", import.meta.url)); + const output = fileURLToPath(new URL("./", import.meta.url)); const ioFlags = ["-i", input, "-o", output]; + const parse = (args) => + new Promise((resolve) => + cli.parse(args, (error, argv, output) => + resolve({ error, argv, output }), + ), + ); // Reset. afterEach("queue", () => queue.splice(0)); @@ -86,8 +95,8 @@ describe(`${pkg.name} [command..]`, () => { }); describe("--animated", () => { - beforeEach((done) => - cli.parse(["--animated", "composite", input, ...ioFlags], done), + beforeEach(() => + cli.parse(["--animated", "composite", input, ...ioFlags]), ); it("must set the animated flag", () => { @@ -104,8 +113,8 @@ describe(`${pkg.name} [command..]`, () => { }); describe("--autoOrient", () => { - beforeEach((done) => - cli.parse(["--autoOrient", "composite", input, ...ioFlags], done), + beforeEach(() => + cli.parse(["--autoOrient", "composite", input, ...ioFlags]), ); it("must set the autoOrient flag", () => { @@ -343,8 +352,8 @@ describe(`${pkg.name} [command..]`, () => { // Default failOn. const failOn = "error"; - beforeEach((done) => - cli.parse(["--failOn", failOn, "composite", input, ...ioFlags], done), + beforeEach(() => + cli.parse(["--failOn", failOn, "composite", input, ...ioFlags]), ); it("must set the failOn flag", () => { @@ -452,8 +461,8 @@ describe(`${pkg.name} [command..]`, () => { }); describe("--ignoreIcc", () => { - beforeEach((done) => - cli.parse(["--ignoreIcc", "composite", input, ...ioFlags], done), + beforeEach(() => + cli.parse(["--ignoreIcc", "composite", input, ...ioFlags]), ); // Tests. @@ -550,11 +559,14 @@ describe(`${pkg.name} [command..]`, () => { // Default value. const value = 10; - beforeEach((done) => - cli.parse( - ["--limitInputPixels", value, "composite", input, ...ioFlags], - done, - ), + beforeEach(() => + cli.parse([ + "--limitInputPixels", + value, + "composite", + input, + ...ioFlags, + ]), ); it("must set the limitInputPixels flag", () => { @@ -846,11 +858,8 @@ describe(`${pkg.name} [command..]`, () => { // Default value. const value = "rgb(255, 255, 255)"; - beforeEach((done) => - cli.parse( - ["--pdfBackground", value, "composite", input, ...ioFlags], - done, - ), + beforeEach(() => + cli.parse(["--pdfBackground", value, "composite", input, ...ioFlags]), ); it("must set the pdfBackground flag", () => { @@ -1218,17 +1227,13 @@ describe(`${pkg.name} [command..]`, () => { }); ["v", "version"].forEach((alias) => { describe(`--${alias}`, () => { - it("must set the version flag", (done) => { - cli.parse([`--${alias}`], (err, args) => { - expect(args).to.have.property("version", true); - done(err); - }); + it("must set the version flag", async () => { + const { argv } = await parse([`--${alias}`]); + expect(argv).to.have.property("version", true); }); - it("must display the version number", (done) => { - cli.parse([`--${alias}`], (err, args, output) => { - expect(output).to.equal(pkg.version); - done(err); - }); + it("must display the version number", async () => { + const { output } = await parse([`--${alias}`]); + expect(output).to.equal(pkg.version); }); }); }); diff --git a/test/cmd.js b/test/cmd.js index 66c82af..8416977 100644 --- a/test/cmd.js +++ b/test/cmd.js @@ -21,15 +21,20 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; +// Local modules. +import registerChannelManipulation from "./cmd/channel-manipulation.js"; +import registerColourManipulation from "./cmd/colour-manipulation.js"; +import registerOperations from "./cmd/operations.js"; +import registerCompositing from "./cmd/compositing.js"; +import registerOutput from "./cmd/output.js"; +import registerResizing from "./cmd/resizing.js"; // Test suite. describe("Commands", () => { - require("./cmd/channel-manipulation"); - require("./cmd/colour-manipulation"); - require("./cmd/operations"); - require("./cmd/compositing"); - require("./cmd/output"); - require("./cmd/resizing"); + registerChannelManipulation(); + registerColourManipulation(); + registerOperations(); + registerCompositing(); + registerOutput(); + registerResizing(); }); diff --git a/test/cmd/channel-manipulation.js b/test/cmd/channel-manipulation.js index 1413fdc..a294b91 100644 --- a/test/cmd/channel-manipulation.js +++ b/test/cmd/channel-manipulation.js @@ -21,14 +21,20 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; +// Local modules. +import registerBandbool from "./channel-manipulation/bandbool.js"; +import registerEnsureAlpha from "./channel-manipulation/ensure-alpha.js"; +import registerExtractChannel from "./channel-manipulation/extract-channel.js"; +import registerJoinChannel from "./channel-manipulation/join-channel.js"; +import registerRemoveAlpha from "./channel-manipulation/remove-alpha.js"; // Test suite. -describe("Channel Manipulation", () => { - require("./channel-manipulation/bandbool"); - require("./channel-manipulation/ensure-alpha"); - require("./channel-manipulation/extract-channel"); - require("./channel-manipulation/join-channel"); - require("./channel-manipulation/remove-alpha"); -}); +export default function register() { + describe("Channel Manipulation", () => { + registerBandbool(); + registerEnsureAlpha(); + registerExtractChannel(); + registerJoinChannel(); + registerRemoveAlpha(); + }); +} diff --git a/test/cmd/channel-manipulation/bandbool.js b/test/cmd/channel-manipulation/bandbool.js index 2b7d503..12d9db8 100644 --- a/test/cmd/channel-manipulation/bandbool.js +++ b/test/cmd/channel-manipulation/bandbool.js @@ -23,40 +23,39 @@ // @see https://sharp.pixelplumbing.com/api-channel#bandbool -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const bandbool = require("../../../cmd/channel-manipulation/bandbool"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import bandbool from "../../../cmd/channel-manipulation/bandbool.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("bandbool ", () => { - const cli = new Yargs().command(bandbool); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - // Run. - beforeEach((done) => cli.parse(["bandbool", "and"], done)); - - // Tests. - it("must set the operator flag", () => { - expect(cli.parsed.argv).to.have.property("operator", "and"); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("bandbool"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.bandbool, "and"); +export default function register() { + describe("bandbool ", () => { + const cli = yargsFactory().command(bandbool); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + // Run. + beforeEach(() => cli.parse(["bandbool", "and"])); + + // Tests. + it("must set the operator flag", () => { + expect(cli.parsed.argv).to.have.property("operator", "and"); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("bandbool"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.bandbool, "and"); + }); }); -}); +} diff --git a/test/cmd/channel-manipulation/ensure-alpha.js b/test/cmd/channel-manipulation/ensure-alpha.js index 978de93..99f8d4c 100644 --- a/test/cmd/channel-manipulation/ensure-alpha.js +++ b/test/cmd/channel-manipulation/ensure-alpha.js @@ -23,62 +23,61 @@ // @see https://sharp.pixelplumbing.com/api-channel#ensurealpha -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const ensureAlpha = require("../../../cmd/channel-manipulation/ensure-alpha"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import ensureAlpha from "../../../cmd/channel-manipulation/ensure-alpha.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("ensureAlpha", () => { - const cli = new Yargs().command(ensureAlpha); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["ensureAlpha"], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("ensureAlpha"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.ensureAlpha); - }); - }); +export default function register() { + describe("ensureAlpha", () => { + const cli = yargsFactory().command(ensureAlpha); - describe("[options]", () => { - describe("--alpha", () => { - // Default alpha. - const alpha = 0; + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + describe("..", () => { // Run. - beforeEach((done) => cli.parse(["ensureAlpha", "--alpha", alpha], done)); + beforeEach(() => cli.parse(["ensureAlpha"])); // Tests. - it("must set the alpha flag", () => { - expect(cli.parsed.argv).to.have.property("alpha", alpha); - }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); expect(queue.pipeline).to.include("ensureAlpha"); }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.ensureAlpha, alpha); + sinon.assert.called(pipeline.ensureAlpha); + }); + }); + + describe("[options]", () => { + describe("--alpha", () => { + // Default alpha. + const alpha = 0; + + // Run. + beforeEach(() => cli.parse(["ensureAlpha", "--alpha", alpha])); + + // Tests. + it("must set the alpha flag", () => { + expect(cli.parsed.argv).to.have.property("alpha", alpha); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("ensureAlpha"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.ensureAlpha, alpha); + }); }); }); }); -}); +} diff --git a/test/cmd/channel-manipulation/extract-channel.js b/test/cmd/channel-manipulation/extract-channel.js index dfa4aec..d79c415 100644 --- a/test/cmd/channel-manipulation/extract-channel.js +++ b/test/cmd/channel-manipulation/extract-channel.js @@ -23,40 +23,39 @@ // @see https://sharp.pixelplumbing.com/api-channel#extractchannel -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const extractChannel = require("../../../cmd/channel-manipulation/extract-channel"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import extractChannel from "../../../cmd/channel-manipulation/extract-channel.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("extractChannel ", () => { - const cli = new Yargs().command(extractChannel); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - // Run. - beforeEach((done) => cli.parse(["extractChannel", "red"], done)); - - // Tests. - it("must set the operator flag", () => { - expect(cli.parsed.argv).to.have.property("channel", "red"); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("extractChannel"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.extractChannel, "red"); +export default function register() { + describe("extractChannel ", () => { + const cli = yargsFactory().command(extractChannel); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + // Run. + beforeEach(() => cli.parse(["extractChannel", "red"])); + + // Tests. + it("must set the operator flag", () => { + expect(cli.parsed.argv).to.have.property("channel", "red"); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("extractChannel"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.extractChannel, "red"); + }); }); -}); +} diff --git a/test/cmd/channel-manipulation/join-channel.js b/test/cmd/channel-manipulation/join-channel.js index 96b427b..b2db4b8 100644 --- a/test/cmd/channel-manipulation/join-channel.js +++ b/test/cmd/channel-manipulation/join-channel.js @@ -23,56 +23,58 @@ // @see https://sharp.pixelplumbing.com/api-channel#bandbool -// Strict mode. -"use strict"; - // Standard lib. -const path = require("path"); +import path from "node:path"; +import { fileURLToPath } from "node:url"; // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const joinChannel = require("../../../cmd/channel-manipulation/join-channel"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import joinChannel from "../../../cmd/channel-manipulation/join-channel.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("joinChannel ", () => { - const cli = new Yargs().command(joinChannel); +export default function register() { + describe("joinChannel ", () => { + const cli = yargsFactory().command(joinChannel); - // Default input (avoid `path.join` to test for input normalizing). - const input = `${__dirname}/../../fixtures/input.jpg`; + // Default input (avoid `path.join` to test for input normalizing). + const input = fileURLToPath( + new URL("../../fixtures/input.jpg", import.meta.url), + ); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("", () => { - // Run. - beforeEach((done) => cli.parse(["joinChannel", input, input], done)); + describe("", () => { + // Run. + beforeEach(() => cli.parse(["joinChannel", input, input])); - // Tests. - it("must set the operator flag", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("images"); - expect(args.images).to.eql([ - path.normalize(input), - path.normalize(input), - ]); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("joinChannel"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.joinChannel, [ - path.normalize(input), - path.normalize(input), - ]); + // Tests. + it("must set the operator flag", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("images"); + expect(args.images).to.eql([ + path.normalize(input), + path.normalize(input), + ]); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("joinChannel"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.joinChannel, [ + path.normalize(input), + path.normalize(input), + ]); + }); }); }); -}); +} diff --git a/test/cmd/channel-manipulation/remove-alpha.js b/test/cmd/channel-manipulation/remove-alpha.js index 26da70d..9379ddb 100644 --- a/test/cmd/channel-manipulation/remove-alpha.js +++ b/test/cmd/channel-manipulation/remove-alpha.js @@ -23,37 +23,36 @@ // @see https://sharp.pixelplumbing.com/api-channel#removealpha -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const removeAlpha = require("../../../cmd/channel-manipulation/remove-alpha"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import removeAlpha from "../../../cmd/channel-manipulation/remove-alpha.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("removeAlpha", () => { - const cli = new Yargs().command(removeAlpha); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - // Run. - beforeEach((done) => cli.parse(["removeAlpha"], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("removeAlpha"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.removeAlpha); +export default function register() { + describe("removeAlpha", () => { + const cli = yargsFactory().command(removeAlpha); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + // Run. + beforeEach(() => cli.parse(["removeAlpha"])); + + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("removeAlpha"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.removeAlpha); + }); }); -}); +} diff --git a/test/cmd/colour-manipulation.js b/test/cmd/colour-manipulation.js index 4a6c878..5bc0b85 100644 --- a/test/cmd/colour-manipulation.js +++ b/test/cmd/colour-manipulation.js @@ -21,13 +21,18 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; +// Local modules. +import registerGreyscale from "./colour-manipulation/greyscale.js"; +import registerPipelineColourspace from "./colour-manipulation/pipeline-colourspace.js"; +import registerTint from "./colour-manipulation/tint.js"; +import registerToColourspace from "./colour-manipulation/tocolourspace.js"; // Test suite. -describe("Colour Manipulation", () => { - require("./colour-manipulation/greyscale"); - require("./colour-manipulation/pipeline-colourspace"); - require("./colour-manipulation/tint"); - require("./colour-manipulation/tocolourspace"); -}); +export default function register() { + describe("Colour Manipulation", () => { + registerGreyscale(); + registerPipelineColourspace(); + registerTint(); + registerToColourspace(); + }); +} diff --git a/test/cmd/colour-manipulation/greyscale.js b/test/cmd/colour-manipulation/greyscale.js index e576e8b..e37b125 100644 --- a/test/cmd/colour-manipulation/greyscale.js +++ b/test/cmd/colour-manipulation/greyscale.js @@ -23,39 +23,38 @@ // @see https://sharp.pixelplumbing.com/api-channel#greyscale -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const greyscale = require("../../../cmd/colour-manipulation/greyscale"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import greyscale from "../../../cmd/colour-manipulation/greyscale.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -["grayscale", "greyscale"].forEach((alias) => { - describe(alias, () => { - const cli = new Yargs().command(greyscale); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - // Run. - beforeEach((done) => cli.parse([alias], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("greyscale"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.greyscale); +export default function register() { + ["grayscale", "greyscale"].forEach((alias) => { + describe(alias, () => { + const cli = yargsFactory().command(greyscale); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + // Run. + beforeEach(() => cli.parse([alias])); + + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("greyscale"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.greyscale); + }); }); }); -}); +} diff --git a/test/cmd/colour-manipulation/pipeline-colourspace.js b/test/cmd/colour-manipulation/pipeline-colourspace.js index 8969f86..b4d5dda 100644 --- a/test/cmd/colour-manipulation/pipeline-colourspace.js +++ b/test/cmd/colour-manipulation/pipeline-colourspace.js @@ -23,42 +23,41 @@ // @see https://sharp.pixelplumbing.com/api-colour#pipelinecolorspace -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); -const pipelineColourspace = require("../../../cmd/colour-manipulation/pipeline-colourspace"); +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; +import pipelineColourspace from "../../../cmd/colour-manipulation/pipeline-colourspace.js"; // Test suite. -["pipelineColourspace", "pipelineColorspace"].forEach((alias) => { - describe(`${alias} `, () => { - const cli = new Yargs().command(pipelineColourspace); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - // Run. - beforeEach((done) => cli.parse([alias, "srgb"], done)); - - // Tests. - it("must set the colourspace flag", () => { - expect(cli.parsed.argv).to.have.property("colourspace", "srgb"); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("pipelineColourspace"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.pipelineColourspace); +export default function register() { + ["pipelineColourspace", "pipelineColorspace"].forEach((alias) => { + describe(`${alias} `, () => { + const cli = yargsFactory().command(pipelineColourspace); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + // Run. + beforeEach(() => cli.parse([alias, "srgb"])); + + // Tests. + it("must set the colourspace flag", () => { + expect(cli.parsed.argv).to.have.property("colourspace", "srgb"); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("pipelineColourspace"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.pipelineColourspace); + }); }); }); -}); +} diff --git a/test/cmd/colour-manipulation/tint.js b/test/cmd/colour-manipulation/tint.js index 5f62051..c36ec5e 100644 --- a/test/cmd/colour-manipulation/tint.js +++ b/test/cmd/colour-manipulation/tint.js @@ -23,43 +23,42 @@ // @see https://sharp.pixelplumbing.com/api-colour#tint -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); -const tint = require("../../../cmd/colour-manipulation/tint"); +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; +import tint from "../../../cmd/colour-manipulation/tint.js"; // Test suite. -describe("tint ", () => { - const cli = new Yargs().command(tint); +export default function register() { + describe("tint ", () => { + const cli = yargsFactory().command(tint); - // Default rgb. - const rgb = "rgba(0,0,0)"; + // Default rgb. + const rgb = "rgba(0,0,0)"; - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - // Run. - beforeEach((done) => cli.parse(["tint", rgb], done)); + // Run. + beforeEach(() => cli.parse(["tint", rgb])); - // Tests. - it("must set the colourspace flag", () => { - expect(cli.parsed.argv).to.have.property("rgb", rgb); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tint"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.tint); + // Tests. + it("must set the colourspace flag", () => { + expect(cli.parsed.argv).to.have.property("rgb", rgb); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tint"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.tint); + }); }); -}); +} diff --git a/test/cmd/colour-manipulation/tocolourspace.js b/test/cmd/colour-manipulation/tocolourspace.js index 285ec7d..0e0eafe 100644 --- a/test/cmd/colour-manipulation/tocolourspace.js +++ b/test/cmd/colour-manipulation/tocolourspace.js @@ -23,42 +23,41 @@ // @see https://sharp.pixelplumbing.com/api-channel#tocolourspace -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); -const toColourspace = require("../../../cmd/colour-manipulation/tocolourspace"); +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; +import toColourspace from "../../../cmd/colour-manipulation/tocolourspace.js"; // Test suite. -["toColorspace", "toColourspace"].forEach((alias) => { - describe(`${alias} `, () => { - const cli = new Yargs().command(toColourspace); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - // Run. - beforeEach((done) => cli.parse([alias, "srgb"], done)); - - // Tests. - it("must set the colourspace flag", () => { - expect(cli.parsed.argv).to.have.property("colourspace", "srgb"); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("toColourspace"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.toColourspace); +export default function register() { + ["toColorspace", "toColourspace"].forEach((alias) => { + describe(`${alias} `, () => { + const cli = yargsFactory().command(toColourspace); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + // Run. + beforeEach(() => cli.parse([alias, "srgb"])); + + // Tests. + it("must set the colourspace flag", () => { + expect(cli.parsed.argv).to.have.property("colourspace", "srgb"); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("toColourspace"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.toColourspace); + }); }); }); -}); +} diff --git a/test/cmd/compositing.js b/test/cmd/compositing.js index b635c6f..6f21114 100644 --- a/test/cmd/compositing.js +++ b/test/cmd/compositing.js @@ -21,10 +21,12 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; +// Local modules. +import registerComposite from "./compositing/composite.js"; // Test suite. -describe("Compositing", () => { - require("./compositing/composite"); -}); +export default function register() { + describe("Compositing", () => { + registerComposite(); + }); +} diff --git a/test/cmd/compositing/composite.js b/test/cmd/compositing/composite.js index 04e4702..0088701 100644 --- a/test/cmd/compositing/composite.js +++ b/test/cmd/compositing/composite.js @@ -23,59 +23,59 @@ // @see http://sharp.pixelplumbing.com/api-composite#composite -// Strict mode. -"use strict"; - // Standard lib. -const path = require("path"); +import path from "node:path"; +import { fileURLToPath } from "node:url"; // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const composite = require("../../../cmd/compositing/composite"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import composite from "../../../cmd/compositing/composite.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("composite", () => { - const cli = new Yargs().command(composite); - - // Default input (avoid `path.join` to test for input normalizing). - const input = `${__dirname}/../fixtures/input.jpg`; - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("[images..]", () => { - // Run. - beforeEach((done) => cli.parse(["composite", input], done)); - - // Tests. - it("must set the images flag", () => { - expect(cli.parsed.argv).to.have.property("images"); - expect(cli.parsed.argv.images[0]).to.equal(path.normalize(input)); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("composite"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].input", path.normalize(input)), - ); +export default function register() { + describe("composite", () => { + const cli = yargsFactory().command(composite); + + // Default input (avoid `path.join` to test for input normalizing). + const input = fileURLToPath( + new URL("../fixtures/input.jpg", import.meta.url), + ); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + describe("[images..]", () => { + // Run. + beforeEach(() => cli.parse(["composite", input])); + + // Tests. + it("must set the images flag", () => { + expect(cli.parsed.argv).to.have.property("images"); + expect(cli.parsed.argv.images[0]).to.equal(path.normalize(input)); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("composite"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].input", path.normalize(input)), + ); + }); }); - }); - describe("[options]", () => { - it("should roll over when using multiple inputs", (done) => { - cli.parse( - [ + describe("[options]", () => { + it("should roll over when using multiple inputs", async () => { + await cli.parse([ "composite", "--create.width", 20, @@ -93,108 +93,98 @@ describe("composite", () => { input, "--blend", "out", - ], - (err) => { - if (err) { - return done(err); - } + ]); - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].input.create.width", 20), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].input.create.height", 40), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].blend", "in"), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].gravity", "southeast"), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[1].input.create.width", 30), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[1].input.create.height", 40), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[1].blend", "out"), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[1].gravity", "southeast"), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[2].input", path.normalize(input)), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[2].blend", "out"), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[2].gravity", "southeast"), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[3].input", path.normalize(input)), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[3].blend", "out"), - ); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[3].gravity", "southeast"), - ); - done(); - }, - ); - }); - - describe("--blend", () => { - // Default blend. - const blend = "add"; - - beforeEach((done) => - cli.parse(["composite", input, "--blend", blend], done), - ); - - it("must set the blend flag", () => { - expect(cli.parsed.argv).to.have.property("blend", blend); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("composite"); - }); - it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); sinon.assert.calledWithMatch( pipeline.composite, - sinon.match.hasNested("[0].blend", blend), + sinon.match.hasNested("[0].input.create.width", 20), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].input.create.height", 40), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].blend", "in"), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].gravity", "southeast"), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[1].input.create.width", 30), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[1].input.create.height", 40), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[1].blend", "out"), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[1].gravity", "southeast"), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[2].input", path.normalize(input)), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[2].blend", "out"), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[2].gravity", "southeast"), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[3].input", path.normalize(input)), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[3].blend", "out"), + ); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[3].gravity", "southeast"), ); }); - }); - describe("--create", () => { - // Default configuration. - const width = 10; - const height = 20; - const channels = 3; - const background = "rgba(0,0,0,0)"; + describe("--blend", () => { + // Default blend. + const blend = "add"; + + beforeEach(() => cli.parse(["composite", input, "--blend", blend])); + + it("must set the blend flag", () => { + expect(cli.parsed.argv).to.have.property("blend", blend); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("composite"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].blend", blend), + ); + }); + }); + + describe("--create", () => { + // Default configuration. + const width = 10; + const height = 20; + const channels = 3; + const background = "rgba(0,0,0,0)"; - beforeEach((done) => { - return cli.parse( - [ + beforeEach(() => { + return cli.parse([ "composite", "--create.width", width, @@ -204,16 +194,94 @@ describe("composite", () => { channels, "--create.background", background, - ], - done, - ); + ]); + }); + + describe("--create.width", () => { + it("must set the create.width flag", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("create"); + expect(args.create).to.have.property("width", width); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("composite"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].input.create.width", width), + ); + }); + }); + + describe("--create.height", () => { + it("must set the create.height flag", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("create"); + expect(args.create).to.have.property("height", height); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("composite"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].input.create.height", height), + ); + }); + }); + + describe("--create.channels", () => { + it("must set the create.channels flag", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("create"); + expect(args.create).to.have.property("channels", channels); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("composite"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].input.create.channels", channels), + ); + }); + }); + + describe("--create.background", () => { + it("must set the create.background flag", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("create"); + expect(args.create).to.have.property("background", background); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("composite"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].input.create.background", background), + ); + }); + }); }); - describe("--create.width", () => { - it("must set the create.width flag", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("create"); - expect(args.create).to.have.property("width", width); + describe("--density", () => { + // Default density. + const density = 72.1; + + beforeEach(() => cli.parse(["composite", input, "--density", density])); + + it("must set the density flag", () => { + expect(cli.parsed.argv).to.have.property("density", density); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -223,16 +291,18 @@ describe("composite", () => { const pipeline = queue.drain(sharp()); sinon.assert.calledWithMatch( pipeline.composite, - sinon.match.hasNested("[0].input.create.width", width), + sinon.match.hasNested("[0].density", density), ); }); }); - describe("--create.height", () => { - it("must set the create.height flag", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("create"); - expect(args.create).to.have.property("height", height); + describe("--gravity", () => { + beforeEach(() => + cli.parse(["composite", input, "--gravity", "centre"]), + ); + + it("must set the gravity flag", () => { + expect(cli.parsed.argv).to.have.property("gravity", "centre"); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -242,16 +312,22 @@ describe("composite", () => { const pipeline = queue.drain(sharp()); sinon.assert.calledWithMatch( pipeline.composite, - sinon.match.hasNested("[0].input.create.height", height), + sinon.match.hasNested("[0].gravity", "centre"), ); }); }); - describe("--create.channels", () => { - it("must set the create.channels flag", () => { + describe("--left", () => { + // Default left. + const left = 20; + + beforeEach(() => + cli.parse(["composite", input, "--left", left, "--top", 10]), + ); + + it("must set the left flag", () => { const args = cli.parsed.argv; - expect(args).to.have.property("create"); - expect(args.create).to.have.property("channels", channels); + expect(args).to.have.property("left", left); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -261,16 +337,16 @@ describe("composite", () => { const pipeline = queue.drain(sharp()); sinon.assert.calledWithMatch( pipeline.composite, - sinon.match.hasNested("[0].input.create.channels", channels), + sinon.match.hasNested("[0].left", left), ); }); }); - describe("--create.background", () => { - it("must set the create.background flag", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("create"); - expect(args.create).to.have.property("background", background); + describe("--premultiplied", () => { + beforeEach(() => cli.parse(["composite", input, "--premultiplied"])); + + it("must set the premultiplied flag", () => { + expect(cli.parsed.argv).to.have.property("premultiplied", true); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -280,145 +356,54 @@ describe("composite", () => { const pipeline = queue.drain(sharp()); sinon.assert.calledWithMatch( pipeline.composite, - sinon.match.hasNested("[0].input.create.background", background), + sinon.match.hasNested("[0].premultiplied", true), ); }); }); - }); - describe("--density", () => { - // Default density. - const density = 72.1; + describe("--tile", () => { + beforeEach(() => cli.parse(["composite", input, "--tile"])); - beforeEach((done) => - cli.parse(["composite", input, "--density", density], done), - ); - - it("must set the density flag", () => { - expect(cli.parsed.argv).to.have.property("density", density); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("composite"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].density", density), - ); - }); - }); - - describe("--gravity", () => { - beforeEach((done) => - cli.parse(["composite", input, "--gravity", "centre"], done), - ); - - it("must set the gravity flag", () => { - expect(cli.parsed.argv).to.have.property("gravity", "centre"); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("composite"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].gravity", "centre"), - ); - }); - }); - - describe("--left", () => { - // Default left. - const left = 20; - - beforeEach((done) => - cli.parse(["composite", input, "--left", left, "--top", 10], done), - ); - - it("must set the left flag", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("left", left); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("composite"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].left", left), - ); - }); - }); - - describe("--premultiplied", () => { - beforeEach((done) => - cli.parse(["composite", input, "--premultiplied"], done), - ); - - it("must set the premultiplied flag", () => { - expect(cli.parsed.argv).to.have.property("premultiplied", true); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("composite"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].premultiplied", true), - ); + it("must set the tile flag", () => { + expect(cli.parsed.argv).to.have.property("tile", true); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("composite"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].tile", true), + ); + }); }); - }); - describe("--tile", () => { - beforeEach((done) => cli.parse(["composite", input, "--tile"], done)); + describe("--top", () => { + // Default top. + const top = 20; - it("must set the tile flag", () => { - expect(cli.parsed.argv).to.have.property("tile", true); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("composite"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].tile", true), + beforeEach(() => + cli.parse(["composite", input, "--left", 10, "--top", top]), ); - }); - }); - - describe("--top", () => { - // Default top. - const top = 20; - beforeEach((done) => - cli.parse(["composite", input, "--left", 10, "--top", top], done), - ); - - it("must set the top flag", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("top", top); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("composite"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.composite, - sinon.match.hasNested("[0].top", top), - ); + it("must set the top flag", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("top", top); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("composite"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.composite, + sinon.match.hasNested("[0].top", top), + ); + }); }); }); }); -}); +} diff --git a/test/cmd/operations.js b/test/cmd/operations.js index 63f296c..e8266a5 100644 --- a/test/cmd/operations.js +++ b/test/cmd/operations.js @@ -21,30 +21,52 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; +// Local modules. +import registerAffine from "./operations/affine.js"; +import registerBlur from "./operations/blur.js"; +import registerBoolean from "./operations/boolean.js"; +import registerClahe from "./operations/clahe.js"; +import registerConvolve from "./operations/convolve.js"; +import registerDilate from "./operations/dilate.js"; +import registerErode from "./operations/erode.js"; +import registerFlatten from "./operations/flatten.js"; +import registerFlip from "./operations/flip.js"; +import registerFlop from "./operations/flop.js"; +import registerGamma from "./operations/gamma.js"; +import registerLinear from "./operations/linear.js"; +import registerMedian from "./operations/median.js"; +import registerModulate from "./operations/modulate.js"; +import registerNegate from "./operations/negate.js"; +import registerNormalise from "./operations/normalise.js"; +import registerRecomb from "./operations/recomb.js"; +import registerRotate from "./operations/rotate.js"; +import registerSharpen from "./operations/sharpen.js"; +import registerThreshold from "./operations/threshold.js"; +import registerUnflatten from "./operations/unflatten.js"; // Test suite. -describe("Operations", () => { - require("./operations/affine"); - require("./operations/blur"); - require("./operations/boolean"); - require("./operations/clahe"); - require("./operations/convolve"); - require("./operations/dilate"); - require("./operations/erode"); - require("./operations/flatten"); - require("./operations/flip"); - require("./operations/flop"); - require("./operations/gamma"); - require("./operations/linear"); - require("./operations/median"); - require("./operations/modulate"); - require("./operations/negate"); - require("./operations/normalise"); - require("./operations/recomb"); - require("./operations/rotate"); - require("./operations/sharpen"); - require("./operations/threshold"); - require("./operations/unflatten"); -}); +export default function register() { + describe("Operations", () => { + registerAffine(); + registerBlur(); + registerBoolean(); + registerClahe(); + registerConvolve(); + registerDilate(); + registerErode(); + registerFlatten(); + registerFlip(); + registerFlop(); + registerGamma(); + registerLinear(); + registerMedian(); + registerModulate(); + registerNegate(); + registerNormalise(); + registerRecomb(); + registerRotate(); + registerSharpen(); + registerThreshold(); + registerUnflatten(); + }); +} diff --git a/test/cmd/operations/affine.js b/test/cmd/operations/affine.js index 01e8e86..50a3776 100644 --- a/test/cmd/operations/affine.js +++ b/test/cmd/operations/affine.js @@ -23,65 +23,36 @@ // @see https://sharp.pixelplumbing.com/api-operation#affine -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const affine = require("../../../cmd/operations/affine"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import affine from "../../../cmd/operations/affine.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("affine", () => { - const cli = new Yargs().command(affine); - - // Default matrix. - const matrix = [1, 0.3, 0.1, 0.7]; - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); +export default function register() { + describe("affine", () => { + const cli = yargsFactory().command(affine); - describe("", () => { - // Run. - beforeEach((done) => cli.parse(["affine", ...matrix], done)); - - // Tests. - it("must set the matrix flag", () => { - expect(cli.parsed.argv).to.have.property("matrix"); - expect(cli.parsed.argv.matrix).to.eql(matrix); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("affine"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.affine, [ - matrix.slice(0, 2), - matrix.slice(2, 4), - ]); - }); - }); + // Default matrix. + const matrix = [1, 0.3, 0.1, 0.7]; - describe("[options]", () => { - describe("--background", () => { - // Default background. - const background = "rgba(0,0,0,.5)"; + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + describe("", () => { // Run. - beforeEach((done) => - cli.parse(["affine", ...matrix, "--background", background], done), - ); + beforeEach(() => cli.parse(["affine", ...matrix])); // Tests. - it("must set the background flag", () => { - expect(cli.parsed.argv).to.have.property("background", background); + it("must set the matrix flag", () => { + expect(cli.parsed.argv).to.have.property("matrix"); + expect(cli.parsed.argv.matrix).to.eql(matrix); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -89,25 +60,26 @@ describe("affine", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.affine, sinon.match.any, { - background, - }); + sinon.assert.calledWithMatch(pipeline.affine, [ + matrix.slice(0, 2), + matrix.slice(2, 4), + ]); }); }); - ["idx", "idy", "odx", "ody"].forEach((alias) => { - describe(`--${alias}`, () => { - // Default value. - const value = 10; + describe("[options]", () => { + describe("--background", () => { + // Default background. + const background = "rgba(0,0,0,.5)"; // Run. - beforeEach((done) => - cli.parse(["affine", ...matrix, `--${alias}`, value], done), + beforeEach(() => + cli.parse(["affine", ...matrix, "--background", background]), ); // Tests. - it("must set the flat flag", () => { - expect(cli.parsed.argv).to.have.property(alias, value); + it("must set the background flag", () => { + expect(cli.parsed.argv).to.have.property("background", background); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -116,35 +88,62 @@ describe("affine", () => { it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); sinon.assert.calledWithMatch(pipeline.affine, sinon.match.any, { - [alias]: value, + background, }); }); }); - }); - describe("--interpolate", () => { - // Default interpolator. - const interpolator = "nohalo"; + ["idx", "idy", "odx", "ody"].forEach((alias) => { + describe(`--${alias}`, () => { + // Default value. + const value = 10; - // Run. - beforeEach((done) => - cli.parse(["affine", ...matrix, "--interpolate", interpolator], done), - ); + // Run. + beforeEach(() => + cli.parse(["affine", ...matrix, `--${alias}`, value]), + ); - // Tests. - it("must set the background flag", () => { - expect(cli.parsed.argv).to.have.property("interpolate", interpolator); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("affine"); + // Tests. + it("must set the flat flag", () => { + expect(cli.parsed.argv).to.have.property(alias, value); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("affine"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.affine, sinon.match.any, { + [alias]: value, + }); + }); + }); }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.affine, sinon.match.any, { - interpolate: interpolator, + + describe("--interpolate", () => { + // Default interpolator. + const interpolator = "nohalo"; + + // Run. + beforeEach(() => + cli.parse(["affine", ...matrix, "--interpolate", interpolator]), + ); + + // Tests. + it("must set the background flag", () => { + expect(cli.parsed.argv).to.have.property("interpolate", interpolator); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("affine"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.affine, sinon.match.any, { + interpolate: interpolator, + }); }); }); }); }); -}); +} diff --git a/test/cmd/operations/blur.js b/test/cmd/operations/blur.js index 79da087..45ed036 100644 --- a/test/cmd/operations/blur.js +++ b/test/cmd/operations/blur.js @@ -23,110 +23,119 @@ // @see https://sharp.pixelplumbing.com/api-operation#blur -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const blur = require("../../../cmd/operations/blur"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import blur from "../../../cmd/operations/blur.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("blur", () => { - const cli = new Yargs().command(blur); - - // Default amplitude and precision. - const amplitude = 0.5; - const precision = "approximate"; - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["blur"], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("blur"); +export default function register() { + describe("blur", () => { + const cli = yargsFactory().command(blur); + + // Default amplitude and precision. + const amplitude = 0.5; + const precision = "approximate"; + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + describe("..", () => { + // Run. + beforeEach(() => cli.parse(["blur"])); + + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("blur"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.blur); + }); }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.blur); - }); - }); - - describe("[sigma]", () => { - // Default sigma. - const sigma = 1.1; - // Run. - beforeEach((done) => cli.parse(["blur", sigma], done)); - - // Tests. - it("must set the sigma flag", () => { - expect(cli.parsed.argv).to.have.property("sigma", sigma); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("blur"); + describe("[sigma]", () => { + // Default sigma. + const sigma = 1.1; + + // Run. + beforeEach(() => cli.parse(["blur", sigma])); + + // Tests. + it("must set the sigma flag", () => { + expect(cli.parsed.argv).to.have.property("sigma", sigma); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("blur"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.blur, sigma); + }); }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.blur, sigma); - }); - }); - - describe("[minAmplitude]", () => { - // Run. - beforeEach((done) => - cli.parse( - ["blur", 5, "--minAmplitude", amplitude, "--precision", precision], - done, - ), - ); - // Tests. - it("must set the minAmplitude flag", () => { - expect(cli.parsed.argv).to.have.property("minAmplitude"); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("blur"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.blur, { minAmplitude: amplitude }); + describe("[minAmplitude]", () => { + // Run. + beforeEach(() => + cli.parse([ + "blur", + 5, + "--minAmplitude", + amplitude, + "--precision", + precision, + ]), + ); + + // Tests. + it("must set the minAmplitude flag", () => { + expect(cli.parsed.argv).to.have.property("minAmplitude"); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("blur"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.blur, { + minAmplitude: amplitude, + }); + }); }); - }); - - describe("[precision]", () => { - // Run. - beforeEach((done) => - cli.parse( - ["blur", 5, "--minAmplitude", amplitude, "--precision", precision], - done, - ), - ); - // Tests. - it("must set the offset flag", () => { - expect(cli.parsed.argv).to.have.property("precision"); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("blur"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.blur, { precision }); + describe("[precision]", () => { + // Run. + beforeEach(() => + cli.parse([ + "blur", + 5, + "--minAmplitude", + amplitude, + "--precision", + precision, + ]), + ); + + // Tests. + it("must set the offset flag", () => { + expect(cli.parsed.argv).to.have.property("precision"); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("blur"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.blur, { precision }); + }); }); }); -}); +} diff --git a/test/cmd/operations/boolean.js b/test/cmd/operations/boolean.js index 2863542..49f97e7 100644 --- a/test/cmd/operations/boolean.js +++ b/test/cmd/operations/boolean.js @@ -23,50 +23,52 @@ // @see https://sharp.pixelplumbing.com/api-operation#boolean -// Strict mode. -"use strict"; - // Standard lib. -const path = require("path"); +import path from "node:path"; +import { fileURLToPath } from "node:url"; // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const boolean = require("../../../cmd/operations/boolean"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import boolean from "../../../cmd/operations/boolean.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("boolean", () => { - const cli = new Yargs().command(boolean); +export default function register() { + describe("boolean", () => { + const cli = yargsFactory().command(boolean); - // Default input (avoid `path.join` to test for input normalizing). - const input = `${__dirname}/../../fixtures/input.jpg`; + // Default input (avoid `path.join` to test for input normalizing). + const input = fileURLToPath( + new URL("../../fixtures/input.jpg", import.meta.url), + ); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe(" ", () => { - // Run. - beforeEach((done) => cli.parse(["boolean", input, "and"], done)); + describe(" ", () => { + // Run. + beforeEach(() => cli.parse(["boolean", input, "and"])); - // Tests. - it("must set the operand and operator flags", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("operand", path.normalize(input)); - expect(args).to.have.property("operator", "and"); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("boolean"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.boolean, path.normalize(input), "and"); + // Tests. + it("must set the operand and operator flags", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("operand", path.normalize(input)); + expect(args).to.have.property("operator", "and"); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("boolean"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.boolean, path.normalize(input), "and"); + }); }); }); -}); +} diff --git a/test/cmd/operations/clahe.js b/test/cmd/operations/clahe.js index a781c87..b2ee56b 100644 --- a/test/cmd/operations/clahe.js +++ b/test/cmd/operations/clahe.js @@ -23,67 +23,66 @@ // @see https://sharp.pixelplumbing.com/api-operation#recomb -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const clahe = require("../../../cmd/operations/clahe"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import clahe from "../../../cmd/operations/clahe.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("clahe", () => { - const cli = new Yargs().command(clahe); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - const width = 20; - const height = 10; - - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["clahe", width, height], done)); +export default function register() { + describe("clahe", () => { + const cli = yargsFactory().command(clahe); - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("clahe"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.clahe, { width, height }); - }); - }); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("[options]", () => { - describe("--maxSlope", () => { - // Default slope. - const slope = 10; + const width = 20; + const height = 10; + describe("..", () => { // Run. - beforeEach((done) => - cli.parse(["clahe", width, height, "--maxSlope", slope], done), - ); + beforeEach(() => cli.parse(["clahe", width, height])); // Tests. - it("must set the maxSlope flag", () => { - expect(cli.parsed.argv).to.have.property("maxSlope", slope); - }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); expect(queue.pipeline).to.include("clahe"); }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.clahe, { maxSlope: slope }); + sinon.assert.calledWithMatch(pipeline.clahe, { width, height }); + }); + }); + + describe("[options]", () => { + describe("--maxSlope", () => { + // Default slope. + const slope = 10; + + // Run. + beforeEach(() => + cli.parse(["clahe", width, height, "--maxSlope", slope]), + ); + + // Tests. + it("must set the maxSlope flag", () => { + expect(cli.parsed.argv).to.have.property("maxSlope", slope); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("clahe"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.clahe, { maxSlope: slope }); + }); }); }); }); -}); +} diff --git a/test/cmd/operations/convolve.js b/test/cmd/operations/convolve.js index 713ecd1..c1bc399 100644 --- a/test/cmd/operations/convolve.js +++ b/test/cmd/operations/convolve.js @@ -23,74 +23,41 @@ // @see https://sharp.pixelplumbing.com/api-operation#convolve -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const convolve = require("../../../cmd/operations/convolve"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import convolve from "../../../cmd/operations/convolve.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("convolve", () => { - const cli = new Yargs().command(convolve); - - // Default width, height, and kernel. - const width = 3; - const height = 3; - const kernel = [-1, 0, 1, -2, 0, 2, -1, 0, 1]; - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); +export default function register() { + describe("convolve", () => { + const cli = yargsFactory().command(convolve); - describe(" ", () => { - // Run. - beforeEach((done) => - cli.parse(["convolve", width, height, ...kernel], done), - ); - - // Tests. - it("must set the width, height, and kernel flags", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("width", width); - expect(args).to.have.property("height", height); - expect(args).to.have.property("kernel"); - expect(args.kernel).to.eql(kernel); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("convolve"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.convolve, { - width, - height, - kernel, - }); - }); - }); + // Default width, height, and kernel. + const width = 3; + const height = 3; + const kernel = [-1, 0, 1, -2, 0, 2, -1, 0, 1]; - describe("[options]", () => { - describe("--offset", () => { - // Default offset. - const offset = 10; + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - beforeEach((done) => - cli.parse( - ["convolve", width, height, ...kernel, "--offset", offset], - done, - ), - ); + describe(" ", () => { + // Run. + beforeEach(() => cli.parse(["convolve", width, height, ...kernel])); - it("must set the offset flag", () => { - expect(cli.parsed.argv).to.have.property("offset", offset); + // Tests. + it("must set the width, height, and kernel flags", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("width", width); + expect(args).to.have.property("height", height); + expect(args).to.have.property("kernel"); + expect(args.kernel).to.eql(kernel); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -98,31 +65,55 @@ describe("convolve", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.convolve, { offset }); + sinon.assert.calledWithMatch(pipeline.convolve, { + width, + height, + kernel, + }); }); }); - describe("--scale", () => { - // Default scale. - const scale = 10; - beforeEach((done) => - cli.parse( - ["convolve", width, height, ...kernel, "--scale", scale], - done, - ), - ); + describe("[options]", () => { + describe("--offset", () => { + // Default offset. + const offset = 10; - it("must set the scale flag", () => { - expect(cli.parsed.argv).to.have.property("scale", scale); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("convolve"); + beforeEach(() => + cli.parse(["convolve", width, height, ...kernel, "--offset", offset]), + ); + + it("must set the offset flag", () => { + expect(cli.parsed.argv).to.have.property("offset", offset); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("convolve"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.convolve, { offset }); + }); }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.convolve, { scale }); + describe("--scale", () => { + // Default scale. + const scale = 10; + + beforeEach(() => + cli.parse(["convolve", width, height, ...kernel, "--scale", scale]), + ); + + it("must set the scale flag", () => { + expect(cli.parsed.argv).to.have.property("scale", scale); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("convolve"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.convolve, { scale }); + }); }); }); }); -}); +} diff --git a/test/cmd/operations/dilate.js b/test/cmd/operations/dilate.js index 1d88621..5a7c7c8 100644 --- a/test/cmd/operations/dilate.js +++ b/test/cmd/operations/dilate.js @@ -23,55 +23,54 @@ // @see https://sharp.pixelplumbing.com/api-operation#dilate -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const dilate = require("../../../cmd/operations/dilate"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import dilate from "../../../cmd/operations/dilate.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("dilate", () => { - const cli = new Yargs().command(dilate); +export default function register() { + describe("dilate", () => { + const cli = yargsFactory().command(dilate); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("..", () => { - beforeEach((done) => cli.parse(["dilate"], done)); + describe("..", () => { + beforeEach(() => cli.parse(["dilate"])); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("dilate"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.dilate, undefined); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("dilate"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.dilate, undefined); + }); }); - }); - describe("[width]", () => { - const width = 3; + describe("[width]", () => { + const width = 3; - beforeEach((done) => cli.parse(["dilate", width], done)); + beforeEach(() => cli.parse(["dilate", width])); - it("must set the width flag", () => { - expect(cli.parsed.argv).to.have.property("width", width); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("dilate"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.dilate, width); + it("must set the width flag", () => { + expect(cli.parsed.argv).to.have.property("width", width); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("dilate"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.dilate, width); + }); }); }); -}); +} diff --git a/test/cmd/operations/erode.js b/test/cmd/operations/erode.js index 06ed21c..36a2027 100644 --- a/test/cmd/operations/erode.js +++ b/test/cmd/operations/erode.js @@ -23,55 +23,54 @@ // @see https://sharp.pixelplumbing.com/api-operation#erode -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const erode = require("../../../cmd/operations/erode"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import erode from "../../../cmd/operations/erode.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("erode", () => { - const cli = new Yargs().command(erode); +export default function register() { + describe("erode", () => { + const cli = yargsFactory().command(erode); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("..", () => { - beforeEach((done) => cli.parse(["erode"], done)); + describe("..", () => { + beforeEach(() => cli.parse(["erode"])); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("erode"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.erode, undefined); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("erode"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.erode, undefined); + }); }); - }); - describe("[width]", () => { - const width = 3; + describe("[width]", () => { + const width = 3; - beforeEach((done) => cli.parse(["erode", width], done)); + beforeEach(() => cli.parse(["erode", width])); - it("must set the width flag", () => { - expect(cli.parsed.argv).to.have.property("width", width); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("erode"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.erode, width); + it("must set the width flag", () => { + expect(cli.parsed.argv).to.have.property("width", width); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("erode"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.erode, width); + }); }); }); -}); +} diff --git a/test/cmd/operations/flatten.js b/test/cmd/operations/flatten.js index 569df9d..0169ad1 100644 --- a/test/cmd/operations/flatten.js +++ b/test/cmd/operations/flatten.js @@ -23,60 +23,59 @@ // @see https://sharp.pixelplumbing.com/api-operation#flatten -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const flatten = require("../../../cmd/operations/flatten"); -const sharp = require("../../mocks/sharp"); +import queue from "../../../lib/queue.js"; +import flatten from "../../../cmd/operations/flatten.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("flatten", () => { - const cli = new Yargs().command(flatten); +export default function register() { + describe("flatten", () => { + const cli = yargsFactory().command(flatten); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["flatten"], done)); + describe("..", () => { + // Run. + beforeEach(() => cli.parse(["flatten"])); - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("flatten"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.flatten); + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("flatten"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.flatten); + }); }); - }); - describe("[background]", () => { - // Default background. - const background = "rgb(0, 0, 0)"; + describe("[background]", () => { + // Default background. + const background = "rgb(0, 0, 0)"; - // Run. - beforeEach((done) => cli.parse(["flatten", background], done)); + // Run. + beforeEach(() => cli.parse(["flatten", background])); - // Tests. - it("must set the factor flag", () => { - expect(cli.parsed.argv).to.have.property("background", background); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("flatten"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.flatten, { background }); + // Tests. + it("must set the factor flag", () => { + expect(cli.parsed.argv).to.have.property("background", background); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("flatten"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.flatten, { background }); + }); }); }); -}); +} diff --git a/test/cmd/operations/flip.js b/test/cmd/operations/flip.js index 4e4e581..d04b255 100644 --- a/test/cmd/operations/flip.js +++ b/test/cmd/operations/flip.js @@ -23,37 +23,36 @@ // @see https://sharp.pixelplumbing.com/api-operation#flip -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const flip = require("../../../cmd/operations/flip"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import flip from "../../../cmd/operations/flip.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("flip", () => { - const cli = new Yargs().command(flip); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - // Run. - beforeEach((done) => cli.parse(["flip"], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("flip"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.flip); +export default function register() { + describe("flip", () => { + const cli = yargsFactory().command(flip); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + // Run. + beforeEach(() => cli.parse(["flip"])); + + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("flip"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.flip); + }); }); -}); +} diff --git a/test/cmd/operations/flop.js b/test/cmd/operations/flop.js index b003dfb..9ec66a2 100644 --- a/test/cmd/operations/flop.js +++ b/test/cmd/operations/flop.js @@ -23,37 +23,36 @@ // @see https://sharp.pixelplumbing.com/api-operation#flop -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const flop = require("../../../cmd/operations/flop"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import flop from "../../../cmd/operations/flop.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("flop", () => { - const cli = new Yargs().command(flop); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - // Run. - beforeEach((done) => cli.parse(["flop"], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("flop"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.flop); +export default function register() { + describe("flop", () => { + const cli = yargsFactory().command(flop); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + // Run. + beforeEach(() => cli.parse(["flop"])); + + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("flop"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.flop); + }); }); -}); +} diff --git a/test/cmd/operations/gamma.js b/test/cmd/operations/gamma.js index 22878e1..791a078 100644 --- a/test/cmd/operations/gamma.js +++ b/test/cmd/operations/gamma.js @@ -23,81 +23,80 @@ // @see https://sharp.pixelplumbing.com/api-operation#gamma -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const gamma = require("../../../cmd/operations/gamma"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import gamma from "../../../cmd/operations/gamma.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("gamma", () => { - const cli = new Yargs().command(gamma); +export default function register() { + describe("gamma", () => { + const cli = yargsFactory().command(gamma); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["gamma"], done)); + describe("..", () => { + // Run. + beforeEach(() => cli.parse(["gamma"])); - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("gamma"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.gamma); + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("gamma"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.gamma); + }); }); - }); - describe("[gamma]", () => { - // Default gamma. - const gamma = 1.1; + describe("[gamma]", () => { + // Default gamma. + const gamma = 1.1; - // Run. - beforeEach((done) => cli.parse(["gamma", gamma], done)); + // Run. + beforeEach(() => cli.parse(["gamma", gamma])); - // Tests. - it("must set the gamma flag", () => { - expect(cli.parsed.argv).to.have.property("gamma", gamma); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("gamma"); + // Tests. + it("must set the gamma flag", () => { + expect(cli.parsed.argv).to.have.property("gamma", gamma); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("gamma"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.gamma, gamma); + }); }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.gamma, gamma); - }); - }); - describe("[gammaOut]", () => { - // Default gammaOut. - const gammaOut = 1.1; + describe("[gammaOut]", () => { + // Default gammaOut. + const gammaOut = 1.1; - // Run. - beforeEach((done) => cli.parse(["gamma", 2.2, gammaOut], done)); + // Run. + beforeEach(() => cli.parse(["gamma", 2.2, gammaOut])); - // Tests. - it("must set the gammaOut flag", () => { - expect(cli.parsed.argv).to.have.property("gammaOut", gammaOut); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("gamma"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.gamma, sinon.match.any, gammaOut); + // Tests. + it("must set the gammaOut flag", () => { + expect(cli.parsed.argv).to.have.property("gammaOut", gammaOut); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("gamma"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.gamma, sinon.match.any, gammaOut); + }); }); }); -}); +} diff --git a/test/cmd/operations/linear.js b/test/cmd/operations/linear.js index fea2c74..e27b032 100644 --- a/test/cmd/operations/linear.js +++ b/test/cmd/operations/linear.js @@ -23,83 +23,82 @@ // @see https://sharp.pixelplumbing.com/api-operation#rotate -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const linear = require("../../../cmd/operations/linear"); -const sharp = require("../../mocks/sharp"); +import queue from "../../../lib/queue.js"; +import linear from "../../../cmd/operations/linear.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("linear", () => { - const cli = new Yargs().command(linear); +export default function register() { + describe("linear", () => { + const cli = yargsFactory().command(linear); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["linear"], done)); + describe("..", () => { + // Run. + beforeEach(() => cli.parse(["linear"])); - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("linear"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.linear); + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("linear"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.linear); + }); }); - }); - describe("[multiplier..]", () => { - // Default multiplier. - const multiplier = 1.5; + describe("[multiplier..]", () => { + // Default multiplier. + const multiplier = 1.5; - // Run. - beforeEach((done) => cli.parse(["linear", multiplier], done)); + // Run. + beforeEach(() => cli.parse(["linear", multiplier])); - // Tests. - it("must set the multiplier flag", () => { - expect(cli.parsed.argv).to.have.property("multiplier"); - expect(cli.parsed.argv.multiplier[0]).to.equal(multiplier); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("linear"); + // Tests. + it("must set the multiplier flag", () => { + expect(cli.parsed.argv).to.have.property("multiplier"); + expect(cli.parsed.argv.multiplier[0]).to.equal(multiplier); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("linear"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.linear, multiplier); + }); }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.linear, multiplier); - }); - }); - describe("[offset]", () => { - // Default offset. - const offset = 0.5; + describe("[offset]", () => { + // Default offset. + const offset = 0.5; - // Run. - beforeEach((done) => cli.parse(["linear", 1.5, "--offset", offset], done)); + // Run. + beforeEach(() => cli.parse(["linear", 1.5, "--offset", offset])); - // Tests. - it("must set the offset flag", () => { - expect(cli.parsed.argv).to.have.property("offset"); - expect(cli.parsed.argv.offset[0]).to.equal(offset); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("linear"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.linear, sinon.match.any, [offset]); + // Tests. + it("must set the offset flag", () => { + expect(cli.parsed.argv).to.have.property("offset"); + expect(cli.parsed.argv.offset[0]).to.equal(offset); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("linear"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.linear, sinon.match.any, [offset]); + }); }); }); -}); +} diff --git a/test/cmd/operations/median.js b/test/cmd/operations/median.js index 073f0b1..833bd6f 100644 --- a/test/cmd/operations/median.js +++ b/test/cmd/operations/median.js @@ -23,60 +23,59 @@ // @see https://sharp.pixelplumbing.com/api-operation#median -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const median = require("../../../cmd/operations/median"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import median from "../../../cmd/operations/median.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("median", () => { - const cli = new Yargs().command(median); +export default function register() { + describe("median", () => { + const cli = yargsFactory().command(median); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["median"], done)); + describe("..", () => { + // Run. + beforeEach(() => cli.parse(["median"])); - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("median"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.median); + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("median"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.median); + }); }); - }); - describe("[size]", () => { - // Default size. - const size = 4; + describe("[size]", () => { + // Default size. + const size = 4; - // Run. - beforeEach((done) => cli.parse(["median", size], done)); + // Run. + beforeEach(() => cli.parse(["median", size])); - // Tests. - it("must set the size flag", () => { - expect(cli.parsed.argv).to.have.property("size", size); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("median"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.median, size); + // Tests. + it("must set the size flag", () => { + expect(cli.parsed.argv).to.have.property("size", size); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("median"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.median, size); + }); }); }); -}); +} diff --git a/test/cmd/operations/modulate.js b/test/cmd/operations/modulate.js index cc63a61..d51e6a5 100644 --- a/test/cmd/operations/modulate.js +++ b/test/cmd/operations/modulate.js @@ -23,64 +23,61 @@ // @see http://sharp.pixelplumbing.com/api-operation#modulate -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); -const modulate = require("../../../cmd/operations/modulate"); +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; +import modulate from "../../../cmd/operations/modulate.js"; // Test suite. -describe("modulate", () => { - const cli = new Yargs().command(modulate); +export default function register() { + describe("modulate", () => { + const cli = yargsFactory().command(modulate); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["modulate"], done)); + describe("..", () => { + // Run. + beforeEach(() => cli.parse(["modulate"])); - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("modulate"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.modulate); + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("modulate"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.modulate); + }); }); - }); - describe("[options]", () => { - ["brightness", "saturation", "hue", "lightness"].forEach((option) => { - describe(`--${option}`, () => { - // Default value. - const value = 10; + describe("[options]", () => { + ["brightness", "saturation", "hue", "lightness"].forEach((option) => { + describe(`--${option}`, () => { + // Default value. + const value = 10; - beforeEach((done) => - cli.parse(["modulate", `--${option}`, value], done), - ); + beforeEach(() => cli.parse(["modulate", `--${option}`, value])); - it(`must set the ${option} flag`, () => { - expect(cli.parsed.argv).to.have.property(option, value); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("modulate"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.modulate, { [[option]]: value }); + it(`must set the ${option} flag`, () => { + expect(cli.parsed.argv).to.have.property(option, value); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("modulate"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.modulate, { [[option]]: value }); + }); }); }); }); }); -}); +} diff --git a/test/cmd/operations/negate.js b/test/cmd/operations/negate.js index 9935d55..16370bf 100644 --- a/test/cmd/operations/negate.js +++ b/test/cmd/operations/negate.js @@ -23,59 +23,58 @@ // @see https://sharp.pixelplumbing.com/api-operation#negate -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const negate = require("../../../cmd/operations/negate"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import negate from "../../../cmd/operations/negate.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("negate", () => { - const cli = new Yargs().command(negate); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["negate"], done)); +export default function register() { + describe("negate", () => { + const cli = yargsFactory().command(negate); - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("negate"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.negate); - }); - }); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("[options]", () => { - describe("--alpha", () => { + describe("..", () => { // Run. - beforeEach((done) => cli.parse(["negate", "--no-alpha"], done)); + beforeEach(() => cli.parse(["negate"])); // Tests. - it("must set the alpha flag", () => { - expect(cli.parsed.argv).to.have.property("alpha", false); - }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); expect(queue.pipeline).to.include("negate"); }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.negate, false); + sinon.assert.called(pipeline.negate); + }); + }); + + describe("[options]", () => { + describe("--alpha", () => { + // Run. + beforeEach(() => cli.parse(["negate", "--no-alpha"])); + + // Tests. + it("must set the alpha flag", () => { + expect(cli.parsed.argv).to.have.property("alpha", false); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("negate"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.negate, false); + }); }); }); }); -}); +} diff --git a/test/cmd/operations/normalise.js b/test/cmd/operations/normalise.js index cafd29c..2126ca3 100644 --- a/test/cmd/operations/normalise.js +++ b/test/cmd/operations/normalise.js @@ -23,85 +23,84 @@ // @see https://sharp.pixelplumbing.com/api-operation#normalise -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const normalise = require("../../../cmd/operations/normalise"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import normalise from "../../../cmd/operations/normalise.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -["normalise", "normalize"].forEach((alias) => { - describe(alias, () => { - const cli = new Yargs().command(normalise); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("..", () => { - // Run. - beforeEach((done) => cli.parse([alias], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("normalise"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.normalise); - }); - }); +export default function register() { + ["normalise", "normalize"].forEach((alias) => { + describe(alias, () => { + const cli = yargsFactory().command(normalise); - describe("[options]", () => { - describe("--lower", () => { - // Default lower. - const lower = 25; + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + describe("..", () => { // Run. - beforeEach((done) => cli.parse([alias, "--lower", lower], done)); + beforeEach(() => cli.parse([alias])); // Tests. - it("must set the lower flag", () => { - expect(cli.parsed.argv).to.have.property("lower", lower); - }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); expect(queue.pipeline).to.include("normalise"); }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.normalise, { lower }); + sinon.assert.called(pipeline.normalise); }); }); - describe("--upper", () => { - // Default upper. - const upper = 25; + describe("[options]", () => { + describe("--lower", () => { + // Default lower. + const lower = 25; - // Run. - beforeEach((done) => cli.parse([alias, "--upper", upper], done)); + // Run. + beforeEach(() => cli.parse([alias, "--lower", lower])); - // Tests. - it("must set the upper flag", () => { - expect(cli.parsed.argv).to.have.property("upper", upper); + // Tests. + it("must set the lower flag", () => { + expect(cli.parsed.argv).to.have.property("lower", lower); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("normalise"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.normalise, { lower }); + }); }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("normalise"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.normalise, { upper }); + + describe("--upper", () => { + // Default upper. + const upper = 25; + + // Run. + beforeEach(() => cli.parse([alias, "--upper", upper])); + + // Tests. + it("must set the upper flag", () => { + expect(cli.parsed.argv).to.have.property("upper", upper); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("normalise"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.normalise, { upper }); + }); }); }); }); }); -}); +} diff --git a/test/cmd/operations/recomb.js b/test/cmd/operations/recomb.js index 8837589..2d0b973 100644 --- a/test/cmd/operations/recomb.js +++ b/test/cmd/operations/recomb.js @@ -23,52 +23,51 @@ // @see https://sharp.pixelplumbing.com/api-operation#recomb -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const recomb = require("../../../cmd/operations/recomb"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import recomb from "../../../cmd/operations/recomb.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("recomb", () => { - const cli = new Yargs().command(recomb); +export default function register() { + describe("recomb", () => { + const cli = yargsFactory().command(recomb); - // Default matrix. - const matrix = [ - 0.3588, 0.7044, 0.1368, 0.299, 0.587, 0.114, 0.2392, 0.4696, 0.0912, - ]; + // Default matrix. + const matrix = [ + 0.3588, 0.7044, 0.1368, 0.299, 0.587, 0.114, 0.2392, 0.4696, 0.0912, + ]; - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("", () => { - // Run. - beforeEach((done) => cli.parse(["recomb", ...matrix], done)); + describe("", () => { + // Run. + beforeEach(() => cli.parse(["recomb", ...matrix])); - // Tests. - it("must set the matrix flag", () => { - expect(cli.parsed.argv).to.have.property("matrix"); - expect(cli.parsed.argv.matrix).to.eql(matrix); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("recomb"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.recomb, [ - matrix.slice(0, 3), - matrix.slice(3, 6), - matrix.slice(6, 9), - ]); + // Tests. + it("must set the matrix flag", () => { + expect(cli.parsed.argv).to.have.property("matrix"); + expect(cli.parsed.argv.matrix).to.eql(matrix); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("recomb"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.recomb, [ + matrix.slice(0, 3), + matrix.slice(3, 6), + matrix.slice(6, 9), + ]); + }); }); }); -}); +} diff --git a/test/cmd/operations/rotate.js b/test/cmd/operations/rotate.js index 48ab1ba..57d4955 100644 --- a/test/cmd/operations/rotate.js +++ b/test/cmd/operations/rotate.js @@ -23,76 +23,50 @@ // @see https://sharp.pixelplumbing.com/api-operation#rotate -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const rotate = require("../../../cmd/operations/rotate"); -const sharp = require("../../mocks/sharp"); +import queue from "../../../lib/queue.js"; +import rotate from "../../../cmd/operations/rotate.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("rotate", () => { - const cli = new Yargs().command(rotate); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["rotate"], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("rotate"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.rotate); - }); - }); +export default function register() { + describe("rotate", () => { + const cli = yargsFactory().command(rotate); - describe("[angle]", () => { - // Default angle. - const angle = 90; + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - // Run. - beforeEach((done) => cli.parse(["rotate", angle], done)); + describe("..", () => { + // Run. + beforeEach(() => cli.parse(["rotate"])); - // Tests. - it("must set the factor flag", () => { - expect(cli.parsed.argv).to.have.property("angle", angle); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("rotate"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.rotate, angle); + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("rotate"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.rotate); + }); }); - }); - describe("[options]", () => { - describe("--background", () => { - // Default background. - const background = "rgba(0,0,0,.5)"; + describe("[angle]", () => { + // Default angle. + const angle = 90; // Run. - beforeEach((done) => - cli.parse(["rotate", "--background", background], done), - ); + beforeEach(() => cli.parse(["rotate", angle])); // Tests. - it("must set the background flag", () => { - expect(cli.parsed.argv).to.have.property("background", background); + it("must set the factor flag", () => { + expect(cli.parsed.argv).to.have.property("angle", angle); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -100,8 +74,31 @@ describe("rotate", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.rotate, undefined, { background }); + sinon.assert.calledWith(pipeline.rotate, angle); + }); + }); + + describe("[options]", () => { + describe("--background", () => { + // Default background. + const background = "rgba(0,0,0,.5)"; + + // Run. + beforeEach(() => cli.parse(["rotate", "--background", background])); + + // Tests. + it("must set the background flag", () => { + expect(cli.parsed.argv).to.have.property("background", background); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("rotate"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.rotate, undefined, { background }); + }); }); }); }); -}); +} diff --git a/test/cmd/operations/sharpen.js b/test/cmd/operations/sharpen.js index 27974cd..6527689 100644 --- a/test/cmd/operations/sharpen.js +++ b/test/cmd/operations/sharpen.js @@ -23,137 +23,130 @@ // @see https://sharp.pixelplumbing.com/api-operation#sharpen -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); -const sharpen = require("../../../cmd/operations/sharpen"); +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; +import sharpen from "../../../cmd/operations/sharpen.js"; // Test suite. -describe("sharpen", () => { - const cli = new Yargs().command(sharpen); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["sharpen"], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("sharpen"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.sharpen); +export default function register() { + describe("sharpen", () => { + const cli = yargsFactory().command(sharpen); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + describe("..", () => { + // Run. + beforeEach(() => cli.parse(["sharpen"])); + + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("sharpen"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.sharpen); + }); }); - }); - describe("[sigma]", () => { - // Default sigma. - const sigma = 1.1; + describe("[sigma]", () => { + // Default sigma. + const sigma = 1.1; - // Run. - beforeEach((done) => cli.parse(["sharpen", sigma], done)); + // Run. + beforeEach(() => cli.parse(["sharpen", sigma])); - // Tests. - it("must set the sigma flag", () => { - expect(cli.parsed.argv).to.have.property("sigma", sigma); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("sharpen"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.sharpen, { sigma }); + // Tests. + it("must set the sigma flag", () => { + expect(cli.parsed.argv).to.have.property("sigma", sigma); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("sharpen"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.sharpen, { sigma }); + }); }); - }); - describe("[options]", () => { - ["m1", "flat"].forEach((alias) => { - describe(`--${alias}`, () => { - // Default flat. - const flat = 1.1; - - // Run. - beforeEach((done) => - cli.parse(["sharpen", 2, `--${alias}`, flat], done), - ); - - // Tests. - it("must set the flat flag", () => { - expect(cli.parsed.argv).to.have.property("m1", flat); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("sharpen"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.sharpen, { m1: flat }); + describe("[options]", () => { + ["m1", "flat"].forEach((alias) => { + describe(`--${alias}`, () => { + // Default flat. + const flat = 1.1; + + // Run. + beforeEach(() => cli.parse(["sharpen", 2, `--${alias}`, flat])); + + // Tests. + it("must set the flat flag", () => { + expect(cli.parsed.argv).to.have.property("m1", flat); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("sharpen"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.sharpen, { m1: flat }); + }); }); }); - }); - - ["m2", "jagged"].forEach((alias) => { - describe(`--${alias}`, () => { - // Default jagged. - const jagged = 1.1; - - // Run. - beforeEach((done) => - cli.parse(["sharpen", 2, `--${alias}`, jagged], done), - ); - // Tests. - it("must set the jagged flag", () => { - expect(cli.parsed.argv).to.have.property("jagged", jagged); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("sharpen"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.sharpen, { m2: jagged }); + ["m2", "jagged"].forEach((alias) => { + describe(`--${alias}`, () => { + // Default jagged. + const jagged = 1.1; + + // Run. + beforeEach(() => cli.parse(["sharpen", 2, `--${alias}`, jagged])); + + // Tests. + it("must set the jagged flag", () => { + expect(cli.parsed.argv).to.have.property("jagged", jagged); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("sharpen"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.sharpen, { m2: jagged }); + }); }); }); - }); - - ["x1", "y2", "y3"].forEach((alias) => { - describe(`--${alias}`, () => { - // Default value. - const value = 1.1; - // Run. - beforeEach((done) => - cli.parse(["sharpen", 2, `--${alias}`, value], done), - ); - - // Tests. - it("must set the flat flag", () => { - expect(cli.parsed.argv).to.have.property(alias, value); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("sharpen"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.sharpen, { [alias]: value }); + ["x1", "y2", "y3"].forEach((alias) => { + describe(`--${alias}`, () => { + // Default value. + const value = 1.1; + + // Run. + beforeEach(() => cli.parse(["sharpen", 2, `--${alias}`, value])); + + // Tests. + it("must set the flat flag", () => { + expect(cli.parsed.argv).to.have.property(alias, value); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("sharpen"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.sharpen, { [alias]: value }); + }); }); }); }); }); -}); +} diff --git a/test/cmd/operations/threshold.js b/test/cmd/operations/threshold.js index faf7a83..f1afeeb 100644 --- a/test/cmd/operations/threshold.js +++ b/test/cmd/operations/threshold.js @@ -23,82 +23,81 @@ // @see https://sharp.pixelplumbing.com/api-operation#threshold -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); -const threshold = require("../../../cmd/operations/threshold"); +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; +import threshold from "../../../cmd/operations/threshold.js"; // Test suite. -describe("threshold", () => { - const cli = new Yargs().command(threshold); +export default function register() { + describe("threshold", () => { + const cli = yargsFactory().command(threshold); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["threshold"], done)); + describe("..", () => { + // Run. + beforeEach(() => cli.parse(["threshold"])); - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("threshold"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.threshold); + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("threshold"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.threshold); + }); }); - }); - describe("[value]", () => { - // Default value. - const value = 128; + describe("[value]", () => { + // Default value. + const value = 128; - // Run. - beforeEach((done) => cli.parse(["threshold", value], done)); + // Run. + beforeEach(() => cli.parse(["threshold", value])); - // Tests. - it("must set the factor flag", () => { - expect(cli.parsed.argv).to.have.property("value", value); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("threshold"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.threshold, value); + // Tests. + it("must set the factor flag", () => { + expect(cli.parsed.argv).to.have.property("value", value); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("threshold"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.threshold, value); + }); }); - }); - describe("[options]", () => { - ["grayscale", "greyscale"].forEach((alias) => { - describe(`--${alias}`, () => { - beforeEach((done) => cli.parse(["threshold", `--${alias}`], done)); + describe("[options]", () => { + ["grayscale", "greyscale"].forEach((alias) => { + describe(`--${alias}`, () => { + beforeEach(() => cli.parse(["threshold", `--${alias}`])); - it("must set the greyscale flag", () => { - expect(cli.parsed.argv).to.have.property("greyscale", true); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("threshold"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.threshold, sinon.match.any, { - greyscale: true, + it("must set the greyscale flag", () => { + expect(cli.parsed.argv).to.have.property("greyscale", true); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("threshold"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.threshold, sinon.match.any, { + greyscale: true, + }); }); }); }); }); }); -}); +} diff --git a/test/cmd/operations/unflatten.js b/test/cmd/operations/unflatten.js index bfae656..3f60c88 100644 --- a/test/cmd/operations/unflatten.js +++ b/test/cmd/operations/unflatten.js @@ -23,37 +23,36 @@ // @see https://sharp.pixelplumbing.com/api-operation#unflatten -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const unflatten = require("../../../cmd/operations/unflatten"); -const sharp = require("../../mocks/sharp"); +import queue from "../../../lib/queue.js"; +import unflatten from "../../../cmd/operations/unflatten.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("unflatten", () => { - const cli = new Yargs().command(unflatten); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - // Run. - beforeEach((done) => cli.parse(["unflatten"], done)); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("unflatten"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.unflatten); +export default function register() { + describe("unflatten", () => { + const cli = yargsFactory().command(unflatten); + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + // Run. + beforeEach(() => cli.parse(["unflatten"])); + + // Tests. + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("unflatten"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.called(pipeline.unflatten); + }); }); -}); +} diff --git a/test/cmd/output.js b/test/cmd/output.js index bb888dd..c8a0d28 100644 --- a/test/cmd/output.js +++ b/test/cmd/output.js @@ -23,97 +23,50 @@ // @see https://sharp.pixelplumbing.com/api-output#tile -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../lib/queue"); -const sharp = require("../mocks/sharp"); -const tile = require("../../cmd/output"); +import queue from "../../lib/queue.js"; +import sharp from "../mocks/sharp.js"; +import tile from "../../cmd/output.js"; // Test suite. -describe("tile", () => { - const cli = new Yargs().command(tile); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("..", () => { - // Run. - beforeEach(() => cli.parse(["tile"])); - - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tile"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.tile); - }); - }); - - describe("[size]", () => { - // Default size. - const size = 512; - - // Run. - beforeEach(() => cli.parse(["tile", size])); - - // Tests. - it("must set the size flag", () => { - expect(cli.parsed.argv).to.have.property("size", size); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tile"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { size }); - }); - }); +export default function register() { + describe("tile", () => { + const cli = yargsFactory().command(tile); - describe("[options]", () => { - describe("--angle", () => { - // Default angle. - const angle = 90; + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + describe("..", () => { // Run. - beforeEach(() => cli.parse(["tile", "--angle", angle])); + beforeEach(() => cli.parse(["tile"])); // Tests. - it("must set the angle flag", () => { - expect(cli.parsed.argv).to.have.property("angle", angle); - }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); expect(queue.pipeline).to.include("tile"); }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { angle }); + sinon.assert.called(pipeline.tile); }); }); - describe("--background", () => { - // Default background. - const background = "rgba(0,0,0,.5)"; + describe("[size]", () => { + // Default size. + const size = 512; // Run. - beforeEach((done) => - cli.parse(["tile", "--background", background], done), - ); + beforeEach(() => cli.parse(["tile", size])); // Tests. - it("must set the background flag", () => { - expect(cli.parsed.argv).to.have.property("background", background); + it("must set the size flag", () => { + expect(cli.parsed.argv).to.have.property("size", size); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -121,37 +74,42 @@ describe("tile", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { background }); + sinon.assert.calledWithMatch(pipeline.tile, { size }); }); }); - describe("--basename", () => { - // Default basename. - const basename = "tiles"; + describe("[options]", () => { + describe("--angle", () => { + // Default angle. + const angle = 90; - // Run. - beforeEach(() => cli.parse(["tile", "--basename", basename])); + // Run. + beforeEach(() => cli.parse(["tile", "--angle", angle])); - // Tests. - it("must set the id flag", () => { - expect(cli.parsed.argv).to.have.property("basename", basename); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tile"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { basename }); + // Tests. + it("must set the angle flag", () => { + expect(cli.parsed.argv).to.have.property("angle", angle); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tile"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.tile, { angle }); + }); }); - }); - ["center", "centre"].forEach((alias) => { - describe(`--${alias}`, () => { - beforeEach(() => cli.parse(["tile", `--${alias}`])); + describe("--background", () => { + // Default background. + const background = "rgba(0,0,0,.5)"; - it("must set the center flag", () => { - expect(cli.parsed.argv).to.have.property("center", true); + // Run. + beforeEach(() => cli.parse(["tile", "--background", background])); + + // Tests. + it("must set the background flag", () => { + expect(cli.parsed.argv).to.have.property("background", background); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -159,135 +117,174 @@ describe("tile", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { center: true }); + sinon.assert.calledWithMatch(pipeline.tile, { background }); }); }); - }); - describe("--container", () => { - // Default container. - const container = "fs"; + describe("--basename", () => { + // Default basename. + const basename = "tiles"; - // Run. - beforeEach(() => cli.parse(["tile", "--container", container])); + // Run. + beforeEach(() => cli.parse(["tile", "--basename", basename])); - // Tests. - it("must set the container flag", () => { - expect(cli.parsed.argv).to.have.property("container", container); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tile"); + // Tests. + it("must set the id flag", () => { + expect(cli.parsed.argv).to.have.property("basename", basename); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tile"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.tile, { basename }); + }); }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { container }); + + ["center", "centre"].forEach((alias) => { + describe(`--${alias}`, () => { + beforeEach(() => cli.parse(["tile", `--${alias}`])); + + it("must set the center flag", () => { + expect(cli.parsed.argv).to.have.property("center", true); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tile"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.tile, { center: true }); + }); + }); }); - }); - describe("--depth", () => { - // Default depth. - const depth = "onepixel"; + describe("--container", () => { + // Default container. + const container = "fs"; - // Run. - beforeEach(() => cli.parse(["tile", "--depth", depth])); + // Run. + beforeEach(() => cli.parse(["tile", "--container", container])); - // Tests. - it("must set the depth flag", () => { - expect(cli.parsed.argv).to.have.property("depth", depth); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tile"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { depth }); + // Tests. + it("must set the container flag", () => { + expect(cli.parsed.argv).to.have.property("container", container); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tile"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.tile, { container }); + }); }); - }); - describe("--id", () => { - // Default id. - const id = "http://www.example.com"; + describe("--depth", () => { + // Default depth. + const depth = "onepixel"; - // Run. - beforeEach(() => cli.parse(["tile", "--id", id])); + // Run. + beforeEach(() => cli.parse(["tile", "--depth", depth])); - // Tests. - it("must set the id flag", () => { - expect(cli.parsed.argv).to.have.property("id", id); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tile"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { id }); + // Tests. + it("must set the depth flag", () => { + expect(cli.parsed.argv).to.have.property("depth", depth); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tile"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.tile, { depth }); + }); }); - }); - describe("--layout", () => { - // Default layout. - const layout = "dz"; + describe("--id", () => { + // Default id. + const id = "http://www.example.com"; - // Run. - beforeEach(() => cli.parse(["tile", "--layout", layout])); + // Run. + beforeEach(() => cli.parse(["tile", "--id", id])); - // Tests. - it("must set the layout flag", () => { - expect(cli.parsed.argv).to.have.property("layout", layout); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tile"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { layout }); + // Tests. + it("must set the id flag", () => { + expect(cli.parsed.argv).to.have.property("id", id); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tile"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.tile, { id }); + }); }); - }); - describe("--overlap", () => { - // Default overlap. - const overlap = 10; + describe("--layout", () => { + // Default layout. + const layout = "dz"; - // Run. - beforeEach(() => cli.parse(["tile", "--overlap", overlap])); + // Run. + beforeEach(() => cli.parse(["tile", "--layout", layout])); - // Tests. - it("must set the overlap flag", () => { - expect(cli.parsed.argv).to.have.property("overlap", overlap); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tile"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { overlap }); + // Tests. + it("must set the layout flag", () => { + expect(cli.parsed.argv).to.have.property("layout", layout); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tile"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.tile, { layout }); + }); }); - }); - describe("--skipBlanks", () => { - // Default skip. - const skip = 10; + describe("--overlap", () => { + // Default overlap. + const overlap = 10; - // Run. - beforeEach(() => cli.parse(["tile", "--skipBlanks", skip])); + // Run. + beforeEach(() => cli.parse(["tile", "--overlap", overlap])); - // Tests. - it("must set the overlap flag", () => { - expect(cli.parsed.argv).to.have.property("skipBlanks", skip); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("tile"); + // Tests. + it("must set the overlap flag", () => { + expect(cli.parsed.argv).to.have.property("overlap", overlap); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tile"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.tile, { overlap }); + }); }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.tile, { skipBlanks: skip }); + + describe("--skipBlanks", () => { + // Default skip. + const skip = 10; + + // Run. + beforeEach(() => cli.parse(["tile", "--skipBlanks", skip])); + + // Tests. + it("must set the overlap flag", () => { + expect(cli.parsed.argv).to.have.property("skipBlanks", skip); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("tile"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.tile, { skipBlanks: skip }); + }); }); }); }); -}); +} diff --git a/test/cmd/resizing.js b/test/cmd/resizing.js index 55df230..07cccd1 100644 --- a/test/cmd/resizing.js +++ b/test/cmd/resizing.js @@ -21,13 +21,18 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; +// Local modules. +import registerExtend from "./resizing/extend.js"; +import registerExtract from "./resizing/extract.js"; +import registerResize from "./resizing/resize.js"; +import registerTrim from "./resizing/trim.js"; // Test suite. -describe("Resizing", () => { - require("./resizing/extend"); - require("./resizing/extract"); - require("./resizing/resize"); - require("./resizing/trim"); -}); +export default function register() { + describe("Resizing", () => { + registerExtend(); + registerExtract(); + registerResize(); + registerTrim(); + }); +} diff --git a/test/cmd/resizing/extend.js b/test/cmd/resizing/extend.js index 491fc1a..c699918 100644 --- a/test/cmd/resizing/extend.js +++ b/test/cmd/resizing/extend.js @@ -23,76 +23,42 @@ // @see https://sharp.pixelplumbing.com/api-resize#extend -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const extend = require("../../../cmd/resizing/extend"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import extend from "../../../cmd/resizing/extend.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("extend", () => { - const cli = new Yargs().command(extend); - - // Default offsets. - const top = 10; - const bottom = 20; - const left = 10; - const right = 10; - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); +export default function register() { + describe("extend", () => { + const cli = yargsFactory().command(extend); - describe(" ", () => { - // Run. - beforeEach((done) => cli.parse(["extend", top, bottom, left, right], done)); - - // Tests. - it("must set the top, bottom, left, and right flags", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("top", args.top); - expect(args).to.have.property("bottom", args.bottom); - expect(args).to.have.property("left", args.left); - expect(args).to.have.property("right", args.right); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("extend"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.extend, { - top, - bottom, - left, - right, - }); - }); - }); + // Default offsets. + const top = 10; + const bottom = 20; + const left = 10; + const right = 10; - describe("[options]", () => { - describe("--background", () => { - // Default background. - const background = "rgba(0,0,0,.5)"; + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + describe(" ", () => { // Run. - beforeEach((done) => - cli.parse( - ["extend", top, bottom, left, right, "--background", background], - done, - ), - ); + beforeEach(() => cli.parse(["extend", top, bottom, left, right])); // Tests. - it("must set the background flag", () => { - expect(cli.parsed.argv).to.have.property("background", background); + it("must set the top, bottom, left, and right flags", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("top", args.top); + expect(args).to.have.property("bottom", args.bottom); + expect(args).to.have.property("left", args.left); + expect(args).to.have.property("right", args.right); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -100,34 +66,69 @@ describe("extend", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.extend, { background }); + sinon.assert.calledWithMatch(pipeline.extend, { + top, + bottom, + left, + right, + }); }); }); - describe("--extendWith", () => { - // Default mode. - const mode = "copy"; + describe("[options]", () => { + describe("--background", () => { + // Default background. + const background = "rgba(0,0,0,.5)"; - // Run. - beforeEach((done) => - cli.parse( - ["extend", top, bottom, left, right, "--extendWith", mode], - done, - ), - ); + // Run. + beforeEach(() => + cli.parse([ + "extend", + top, + bottom, + left, + right, + "--background", + background, + ]), + ); - // Tests. - it("must set the background flag", () => { - expect(cli.parsed.argv).to.have.property("extendWith", mode); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("extend"); + // Tests. + it("must set the background flag", () => { + expect(cli.parsed.argv).to.have.property("background", background); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("extend"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.extend, { background }); + }); }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.extend, { extendWith: mode }); + + describe("--extendWith", () => { + // Default mode. + const mode = "copy"; + + // Run. + beforeEach(() => + cli.parse(["extend", top, bottom, left, right, "--extendWith", mode]), + ); + + // Tests. + it("must set the background flag", () => { + expect(cli.parsed.argv).to.have.property("extendWith", mode); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("extend"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.extend, { extendWith: mode }); + }); }); }); }); -}); +} diff --git a/test/cmd/resizing/extract.js b/test/cmd/resizing/extract.js index 62e50af..bbdf3c2 100644 --- a/test/cmd/resizing/extract.js +++ b/test/cmd/resizing/extract.js @@ -23,52 +23,51 @@ // @see https://sharp.pixelplumbing.com/api-operation#extract -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const extract = require("../../../cmd/resizing/extract"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import extract from "../../../cmd/resizing/extract.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("extract", () => { - const cli = new Yargs().command(extract); +export default function register() { + describe("extract", () => { + const cli = yargsFactory().command(extract); - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); - describe(" ", () => { - // Default offset and dimensions. - const top = 10; - const left = 20; - const width = 30; - const height = 40; + describe(" ", () => { + // Default offset and dimensions. + const top = 10; + const left = 20; + const width = 30; + const height = 40; - // Run. - beforeEach(() => cli.parse(["extract", top, left, width, height])); + // Run. + beforeEach(() => cli.parse(["extract", top, left, width, height])); - // Tests. - it("must set the top, left, width, and height flags", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("top", top); - expect(args).to.have.property("left", left); - expect(args).to.have.property("width", width); - expect(args).to.have.property("height", height); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("extract"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWith(pipeline.extract, { top, left, width, height }); + // Tests. + it("must set the top, left, width, and height flags", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("top", top); + expect(args).to.have.property("left", left); + expect(args).to.have.property("width", width); + expect(args).to.have.property("height", height); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("extract"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWith(pipeline.extract, { top, left, width, height }); + }); }); }); -}); +} diff --git a/test/cmd/resizing/resize.js b/test/cmd/resizing/resize.js index 225fcaa..096543b 100644 --- a/test/cmd/resizing/resize.js +++ b/test/cmd/resizing/resize.js @@ -23,110 +23,46 @@ // @see https://sharp.pixelplumbing.com/api-resize/ -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const resize = require("../../../cmd/resizing/resize"); -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); +import resize from "../../../cmd/resizing/resize.js"; +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; // Test suite. -describe("resize", () => { - const cli = new Yargs().command(resize); - - // Default width × height. - const width = 100; - const height = 200; - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("..", () => { - it("must prompt an error", (done) => { - cli.parse(["resize"], (err) => { - expect(err).to.exist(); - expect(err).to.have.property("message"); - expect(err.message).to.contain("one of width and height"); - done(); +export default function register() { + describe("resize", () => { + const cli = yargsFactory().command(resize); + + // Default width × height. + const width = 100; + const height = 200; + + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + + describe("..", () => { + it("must prompt an error", async () => { + const error = await new Promise((resolve) => + cli.parse(["resize"], (err) => resolve(err)), + ); + expect(error).to.exist(); + expect(error).to.have.property("message"); + expect(error.message).to.contain("one of width and height"); }); }); - }); - - describe("[width]", () => { - beforeEach((done) => cli.parse(["resize", width], done)); - - it("must set the width flag", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("width", width); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("resize"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.resize, width, null); - }); - }); - - describe("[height]", () => { - beforeEach((done) => cli.parse(["resize", "--height", height], done)); - - it("must set the height flag", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("height", height); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("resize"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.resize, null, height); - }); - }); - - describe("[width] [height]", () => { - // Run. - beforeEach((done) => cli.parse(["resize", width, height], done)); - - // Tests. - it("must set the width and height flags", () => { - const args = cli.parsed.argv; - expect(args).to.have.property("width", width); - expect(args).to.have.property("height", height); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("resize"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.resize, width, height); - }); - }); - - describe("[options]", () => { - // @see https://sharp.pixelplumbing.com/api-resize#resize - describe("--background", () => { - // Default background. - const background = "rgba(0,0,0,.5)"; - // Run. - beforeEach((done) => - cli.parse(["resize", width, height, "--background", background], done), - ); + describe("[width]", () => { + beforeEach(() => cli.parse(["resize", width])); - // Tests. - it("must set the background flag", () => { - expect(cli.parsed.argv).to.have.property("background", background); + it("must set the width flag", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("width", width); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -134,23 +70,16 @@ describe("resize", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.resize, - sinon.match.any, - sinon.match.any, - { background }, - ); + sinon.assert.calledWithMatch(pipeline.resize, width, null); }); }); - // @see https://sharp.pixelplumbing.com/api-resize#resize - describe("--fastShrinkOnLoad", () => { - beforeEach((done) => - cli.parse(["resize", width, height, "--no-fastShrinkOnLoad"], done), - ); + describe("[height]", () => { + beforeEach(() => cli.parse(["resize", "--height", height])); - it("must set the fastShrinkOnLoad flag", () => { - expect(cli.parsed.argv).to.have.property("fastShrinkOnLoad", false); + it("must set the height flag", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("height", height); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -158,26 +87,19 @@ describe("resize", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.resize, - sinon.match.any, - sinon.match.any, - { fastShrinkOnLoad: false }, - ); + sinon.assert.calledWithMatch(pipeline.resize, null, height); }); }); - // @see https://sharp.pixelplumbing.com/api-resize#resize - describe("--fit", () => { - // Default fit. - const fit = "fill"; - - beforeEach((done) => - cli.parse(["resize", width, height, "--fit", fit], done), - ); + describe("[width] [height]", () => { + // Run. + beforeEach(() => cli.parse(["resize", width, height])); - it("must set the fit flag", () => { - expect(cli.parsed.argv).to.have.property("fit", fit); + // Tests. + it("must set the width and height flags", () => { + const args = cli.parsed.argv; + expect(args).to.have.property("width", width); + expect(args).to.have.property("height", height); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -185,115 +107,190 @@ describe("resize", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.resize, - sinon.match.any, - sinon.match.any, - { fit }, - ); + sinon.assert.calledWithMatch(pipeline.resize, width, height); }); }); - // @see https://sharp.pixelplumbing.com/api-resize#resize - describe("--kernel", () => { - // Default kernel. - const kernel = "lanczos3"; + describe("[options]", () => { + // @see https://sharp.pixelplumbing.com/api-resize#resize + describe("--background", () => { + // Default background. + const background = "rgba(0,0,0,.5)"; - beforeEach((done) => - cli.parse(["resize", width, height, "--kernel", kernel], done), - ); + // Run. + beforeEach(() => + cli.parse(["resize", width, height, "--background", background]), + ); - it("must set the kernel flag", () => { - expect(cli.parsed.argv).to.have.property("kernel", kernel); + // Tests. + it("must set the background flag", () => { + expect(cli.parsed.argv).to.have.property("background", background); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("resize"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.resize, + sinon.match.any, + sinon.match.any, + { background }, + ); + }); }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("resize"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.resize, - sinon.match.any, - sinon.match.any, - { kernel }, + + // @see https://sharp.pixelplumbing.com/api-resize#resize + describe("--fastShrinkOnLoad", () => { + beforeEach(() => + cli.parse(["resize", width, height, "--no-fastShrinkOnLoad"]), ); + + it("must set the fastShrinkOnLoad flag", () => { + expect(cli.parsed.argv).to.have.property("fastShrinkOnLoad", false); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("resize"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.resize, + sinon.match.any, + sinon.match.any, + { fastShrinkOnLoad: false }, + ); + }); }); - }); - // @see https://sharp.pixelplumbing.com/api-resize#resize - describe("--position", () => { - // Default position. - const position = "centre"; + // @see https://sharp.pixelplumbing.com/api-resize#resize + describe("--fit", () => { + // Default fit. + const fit = "fill"; + + beforeEach(() => cli.parse(["resize", width, height, "--fit", fit])); + + it("must set the fit flag", () => { + expect(cli.parsed.argv).to.have.property("fit", fit); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("resize"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.resize, + sinon.match.any, + sinon.match.any, + { fit }, + ); + }); + }); - beforeEach((done) => - cli.parse(["resize", width, height, "--position", position], done), - ); + // @see https://sharp.pixelplumbing.com/api-resize#resize + describe("--kernel", () => { + // Default kernel. + const kernel = "lanczos3"; - it("must set the position flag", () => { - expect(cli.parsed.argv).to.have.property("position", position); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("resize"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.resize, - sinon.match.any, - sinon.match.any, - { position }, + beforeEach(() => + cli.parse(["resize", width, height, "--kernel", kernel]), ); + + it("must set the kernel flag", () => { + expect(cli.parsed.argv).to.have.property("kernel", kernel); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("resize"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.resize, + sinon.match.any, + sinon.match.any, + { kernel }, + ); + }); }); - }); - // @see https://sharp.pixelplumbing.com/api-resize#withoutenlargement - describe("--withoutEnlargement", () => { - beforeEach((done) => - cli.parse(["resize", width, height, "--withoutEnlargement"], done), - ); + // @see https://sharp.pixelplumbing.com/api-resize#resize + describe("--position", () => { + // Default position. + const position = "centre"; - it("must set the withoutEnlargement flag", () => { - expect(cli.parsed.argv).to.have.property("withoutEnlargement", true); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("resize"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.resize, - sinon.match.any, - sinon.match.any, - { withoutEnlargement: true }, + beforeEach(() => + cli.parse(["resize", width, height, "--position", position]), ); + + it("must set the position flag", () => { + expect(cli.parsed.argv).to.have.property("position", position); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("resize"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.resize, + sinon.match.any, + sinon.match.any, + { position }, + ); + }); }); - }); - // @see https://sharp.pixelplumbing.com/api-resize#resize - describe("--withoutReduction", () => { - beforeEach((done) => - cli.parse(["resize", width, height, "--withoutReduction"], done), - ); + // @see https://sharp.pixelplumbing.com/api-resize#withoutenlargement + describe("--withoutEnlargement", () => { + beforeEach(() => + cli.parse(["resize", width, height, "--withoutEnlargement"]), + ); - it("must set the withoutReduction flag", () => { - expect(cli.parsed.argv).to.have.property("withoutReduction", true); + it("must set the withoutEnlargement flag", () => { + expect(cli.parsed.argv).to.have.property("withoutEnlargement", true); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("resize"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.resize, + sinon.match.any, + sinon.match.any, + { withoutEnlargement: true }, + ); + }); }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("resize"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch( - pipeline.resize, - sinon.match.any, - sinon.match.any, - { withoutReduction: true }, + + // @see https://sharp.pixelplumbing.com/api-resize#resize + describe("--withoutReduction", () => { + beforeEach(() => + cli.parse(["resize", width, height, "--withoutReduction"]), ); + + it("must set the withoutReduction flag", () => { + expect(cli.parsed.argv).to.have.property("withoutReduction", true); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("resize"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch( + pipeline.resize, + sinon.match.any, + sinon.match.any, + { withoutReduction: true }, + ); + }); }); }); }); -}); +} diff --git a/test/cmd/resizing/trim.js b/test/cmd/resizing/trim.js index 581c4df..59c3a52 100644 --- a/test/cmd/resizing/trim.js +++ b/test/cmd/resizing/trim.js @@ -23,94 +23,50 @@ // @see https://sharp.pixelplumbing.com/api-resize#trim -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); -const sinon = require("sinon"); -const Yargs = require("yargs"); +import expect from "must"; +import sinon from "sinon"; +import yargsFactory from "yargs"; // Local modules. -const queue = require("../../../lib/queue"); -const sharp = require("../../mocks/sharp"); -const trim = require("../../../cmd/resizing/trim"); +import queue from "../../../lib/queue.js"; +import sharp from "../../mocks/sharp.js"; +import trim from "../../../cmd/resizing/trim.js"; // Test suite. -describe("trim", () => { - const cli = new Yargs().command(trim); - - // Reset. - afterEach("queue", () => queue.splice(0)); - afterEach("sharp", sharp.prototype.reset); - - describe("..", () => { - // Run. - beforeEach((done) => cli.parse(["trim"], done)); +export default function register() { + describe("trim", () => { + const cli = yargsFactory().command(trim); - // Tests. - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("trim"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.called(pipeline.trim); - }); - }); - - describe("[threshold]", () => { - // Default threshold. - const threshold = 10; - - // Run. - beforeEach((done) => cli.parse(["trim", threshold], done)); - - // Tests. - it("must set the threshold flag", () => { - expect(cli.parsed.argv).to.have.property("threshold", threshold); - }); - it("must update the pipeline", () => { - expect(queue.pipeline).to.have.length(1); - expect(queue.pipeline).to.include("trim"); - }); - it("must execute the pipeline", () => { - const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.trim, { threshold }); - }); - }); - - describe("[options]", () => { - describe("--background", () => { - // Default background. - const background = "rgb(0, 0, 0)"; + // Reset. + afterEach("queue", () => queue.splice(0)); + afterEach("sharp", sharp.prototype.reset); + describe("..", () => { // Run. - beforeEach((done) => - cli.parse(["trim", "--background", background], done), - ); + beforeEach(() => cli.parse(["trim"])); // Tests. - it("must set the factor flag", () => { - expect(cli.parsed.argv).to.have.property("background", background); - }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); expect(queue.pipeline).to.include("trim"); }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.trim, { background }); + sinon.assert.called(pipeline.trim); }); }); - describe("--lineArt", () => { + describe("[threshold]", () => { + // Default threshold. + const threshold = 10; + // Run. - beforeEach((done) => cli.parse(["trim", "--lineArt"], done)); + beforeEach(() => cli.parse(["trim", threshold])); // Tests. - it("must set the factor flag", () => { - expect(cli.parsed.argv).to.have.property("lineArt", true); + it("must set the threshold flag", () => { + expect(cli.parsed.argv).to.have.property("threshold", threshold); }); it("must update the pipeline", () => { expect(queue.pipeline).to.have.length(1); @@ -118,8 +74,49 @@ describe("trim", () => { }); it("must execute the pipeline", () => { const pipeline = queue.drain(sharp()); - sinon.assert.calledWithMatch(pipeline.trim, { lineArt: true }); + sinon.assert.calledWithMatch(pipeline.trim, { threshold }); + }); + }); + + describe("[options]", () => { + describe("--background", () => { + // Default background. + const background = "rgb(0, 0, 0)"; + + // Run. + beforeEach(() => cli.parse(["trim", "--background", background])); + + // Tests. + it("must set the factor flag", () => { + expect(cli.parsed.argv).to.have.property("background", background); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("trim"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.trim, { background }); + }); + }); + + describe("--lineArt", () => { + // Run. + beforeEach(() => cli.parse(["trim", "--lineArt"])); + + // Tests. + it("must set the factor flag", () => { + expect(cli.parsed.argv).to.have.property("lineArt", true); + }); + it("must update the pipeline", () => { + expect(queue.pipeline).to.have.length(1); + expect(queue.pipeline).to.include("trim"); + }); + it("must execute the pipeline", () => { + const pipeline = queue.drain(sharp()); + sinon.assert.calledWithMatch(pipeline.trim, { lineArt: true }); + }); }); }); }); -}); +} diff --git a/test/convert.js b/test/convert.js index 5940f91..ff20218 100644 --- a/test/convert.js +++ b/test/convert.js @@ -21,29 +21,27 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Standard lib. -const path = require("path"); -const { Readable } = require("stream"); +import path from "node:path"; +import { Readable } from "node:stream"; +import { fileURLToPath } from "node:url"; // Package modules. -const expect = require("must"); -const fs = require("fs-extra"); -const tempy = require("tempy"); +import expect from "must"; +import fs from "fs-extra"; +import tempy from "tempy"; // Local modules. -const convert = require("../lib/convert"); -const queue = require("../lib/queue"); -const tile = require("../cmd/output"); +import convert from "../lib/convert.js"; +import queue from "../lib/queue.js"; +import tile from "../cmd/output.js"; // Test suite. describe("convert", () => { const options = { sequentialRead: false }; // Default input. - const input = path.join(__dirname, "./fixtures/input.jpg"); + const input = fileURLToPath(new URL("./fixtures/input.jpg", import.meta.url)); describe("files", () => { // Default output. @@ -54,15 +52,13 @@ describe("convert", () => { beforeEach(() => { copy = tempy.file(); }); - beforeEach((done) => { - fs.copy(input, copy, done); - }); + beforeEach(async () => fs.copy(input, copy)); afterEach(() => { queue.length = 0; // Empty queue. }); - afterEach((done) => fs.remove(copy, done)); - afterEach((done) => fs.emptyDir(dest, done)); - after((done) => fs.remove(dest, done)); + afterEach(() => fs.remove(copy)); + afterEach(() => fs.emptyDir(dest)); + after(() => fs.remove(dest)); // Tests. it("must convert a file", () => { @@ -131,7 +127,7 @@ describe("convert", () => { beforeEach(() => { dest = tempy.file(); }); - afterEach((done) => fs.remove(dest, done)); + afterEach(() => fs.remove(dest)); // Tests. it("must convert a file", () => { diff --git a/test/index.js b/test/index.js index a152dff..eecab25 100644 --- a/test/index.js +++ b/test/index.js @@ -21,35 +21,35 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Standard lib. -const path = require("path"); +import { createRequire } from "node:module"; +import { fileURLToPath } from "node:url"; // Package modules. -const expect = require("must"); -const fs = require("fs-extra"); -const sinon = require("sinon"); -const tempy = require("tempy"); +import expect from "must"; +import fs from "fs-extra"; +import sinon from "sinon"; +import tempy from "tempy"; // Local modules. -const cli = require("../lib"); -const logger = require("./mocks/logger"); -const pkg = require("../package.json"); +import cli from "../lib/index.js"; +import logger from "./mocks/logger.js"; + +// Assets. +const pkg = createRequire(import.meta.url)("../package.json"); // Test suite. describe("CLI", () => { // Default input. - const input = path.join(__dirname, "./fixtures/input.jpg"); + const input = fileURLToPath(new URL("./fixtures/input.jpg", import.meta.url)); // Default output. let dest; before(() => { dest = tempy.directory(); }); - afterEach((done) => fs.emptyDir(dest, done)); - after((done) => fs.remove(dest, done)); + afterEach(() => fs.emptyDir(dest)); + after(() => fs.remove(dest)); // Reset. afterEach("error", () => logger.error.resetHistory()); diff --git a/test/mocks/logger.js b/test/mocks/logger.js index 174b9c5..34c4545 100644 --- a/test/mocks/logger.js +++ b/test/mocks/logger.js @@ -21,14 +21,11 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Package modules. -const sinon = require("sinon"); +import sinon from "sinon"; // Exports. -module.exports = { +export default { error: sinon.spy(), log: sinon.spy(), }; diff --git a/test/mocks/sharp.js b/test/mocks/sharp.js index 32d5a24..1af332b 100644 --- a/test/mocks/sharp.js +++ b/test/mocks/sharp.js @@ -21,12 +21,9 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Package modules. -const sharp = require("sharp"); -const sinon = require("sinon"); +import sharp from "sharp"; +import sinon from "sinon"; // Configure. const methods = Object.getOwnPropertyNames(sharp.prototype); @@ -41,4 +38,4 @@ sharp.prototype.restore = () => { }; // Exports. -module.exports = sharp; +export default sharp; diff --git a/test/utils.js b/test/utils.js index 9bc46a7..dc5464e 100644 --- a/test/utils.js +++ b/test/utils.js @@ -21,24 +21,21 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Strict mode. -"use strict"; - // Package modules. -const expect = require("must"); +import expect from "must"; // Local modules. -const { isDirectory, pick } = require("../lib/utils"); +import { isDirectory, pick } from "../lib/utils.js"; // Test suite. describe("utils", () => { describe("isDirectory", () => { it("must identify directories", () => { - expect(isDirectory(__dirname)).to.be.true(); + expect(isDirectory(new URL(".", import.meta.url))).to.be.true(); }); it("must return false for missing paths", () => { - expect(isDirectory(`${__dirname}/missing`)).to.be.false(); + expect(isDirectory(new URL("./missing", import.meta.url))).to.be.false(); }); }); From 2ba2430833be0c25d4eb0023abd0a49527a6f7a1 Mon Sep 17 00:00:00 2001 From: Mark van Seventer Date: Thu, 13 Aug 2026 23:28:19 -0700 Subject: [PATCH 5/6] Add CI workflow. --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ test/index.js | 7 ++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d2ad5b5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + pull_request: + push: + branches: + - main + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.9.0" + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Lint and test + run: npm test diff --git a/test/index.js b/test/index.js index eecab25..b995561 100644 --- a/test/index.js +++ b/test/index.js @@ -88,7 +88,12 @@ describe("CLI", () => { it("must display errors", () => { return cli([], { logger }).then(() => { sinon.assert.notCalled(logger.log); - sinon.assert.calledWithMatch(logger.error, "Missing required arguments"); + if (process.stdin.isTTY) { + sinon.assert.calledWithMatch( + logger.error, + "Missing required arguments", + ); + } sinon.assert.calledWithMatch( logger.error, "Specify --help for available options", From fd86854be5a1084b5bebaf881fe0c395e4447029 Mon Sep 17 00:00:00 2001 From: Mark van Seventer Date: Thu, 13 Aug 2026 23:29:17 -0700 Subject: [PATCH 6/6] Naming. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2ad5b5..1add7b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: pull_request: push: branches: - - main + - master permissions: contents: read