diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3b8aa86..9c27cac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,12 +10,11 @@ jobs: fail-fast: false matrix: node-version: - - 16 - - 14 - - 12 + - 22 + - 18 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/cli.js b/cli.js index 357db2e..bb30582 100755 --- a/cli.js +++ b/cli.js @@ -1,5 +1,4 @@ #!/usr/bin/env node -import {Buffer} from 'node:buffer'; import process from 'node:process'; import arrify from 'arrify'; import meow from 'meow'; @@ -9,6 +8,7 @@ import ora from 'ora'; import plur from 'plur'; import stripIndent from 'strip-indent'; import pairs from 'lodash.pairs'; +import {isUint8Array} from 'uint8array-extras'; const cli = meow(` Usage @@ -34,7 +34,7 @@ const cli = meow(` flags: { plugin: { type: 'string', - alias: 'p', + shortFlag: 'p', isMultiple: true, default: [ 'gifsicle', @@ -45,14 +45,14 @@ const cli = meow(` }, outDir: { type: 'string', - alias: 'o', + shortFlag: 'o', }, }, }); const requirePlugins = plugins => Promise.all(plugins.map(async ([plugin, options]) => { try { - const {default: _plugin} = await import(`imagemin-${plugin}`); // eslint-disable-line node/no-unsupported-features/es-syntax + const {default: _plugin} = await import(`imagemin-${plugin}`); return _plugin(options); } catch { console.error(stripIndent(` @@ -88,7 +88,7 @@ const run = async (input, {outDir, plugin} = {}) => { const plugins = await requirePlugins(pluginOptions); const spinner = ora('Minifying images'); - if (Buffer.isBuffer(input)) { + if (isUint8Array(input)) { process.stdout.write(await imagemin.buffer(input, {plugins})); return; } @@ -129,10 +129,9 @@ if (cli.input.length === 0 && process.stdin.isTTY) { process.exit(1); } -(async () => { - await run( - cli.input.length > 0 - ? cli.input - : await getStdin.buffer(), - cli.flags); -})(); +await run( + cli.input.length > 0 + ? cli.input + : await getStdin.buffer(), + cli.flags, +); diff --git a/package.json b/package.json index 1d12b63..3d856f9 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,13 @@ "description": "Minify images seamlessly", "license": "MIT", "repository": "imagemin/imagemin-cli", - "funding": "https://github.com/imagemin/imagemin-cli?sponsor=1", + "funding": "https://github.com/sponsors/sindresorhus", "type": "module", "bin": { - "imagemin": "cli.js" + "imagemin": "./cli.js" }, "engines": { - "node": ">=12.20" + "node": ">=18" }, "scripts": { "test": "xo && ava" @@ -34,30 +34,33 @@ "dependencies": { "arrify": "^3.0.0", "get-stdin": "^9.0.0", - "imagemin": "^8.0.0", + "imagemin": "^9.0.0", "lodash.pairs": "^3.0.1", - "meow": "^10.1.1", - "ora": "^5.4.1", - "plur": "^4.0.0", - "strip-indent": "^4.0.0" + "meow": "^13.2.0", + "ora": "^8.0.1", + "plur": "^5.1.0", + "strip-indent": "^4.0.0", + "uint8array-extras": "^1.1.0" }, "devDependencies": { - "ava": "^3.15.0", - "execa": "^5.1.1", + "ava": "^6.1.2", + "execa": "^8.0.1", "imagemin-pngquant": "^9.0.2", - "typescript": "^4.3.5", - "xo": "^0.43.0" + "xo": "^0.58.0" }, "optionalDependencies": { "imagemin-gifsicle": "^7.0.0", "imagemin-jpegtran": "^7.0.0", "imagemin-optipng": "^8.0.0", - "imagemin-svgo": "^9.0.0" + "imagemin-svgo": "^10.0.1" + }, + "ava": { + "workerThreads": false }, "xo": { "rules": { - "node/process-exit-as-throw": 2, - "node/no-unsupported-features": "off" + "n/process-exit-as-throw": 2, + "n/no-unsupported-features": "off" } } } diff --git a/readme.md b/readme.md index 7a00d30..87726b1 100644 --- a/readme.md +++ b/readme.md @@ -6,8 +6,8 @@ ## Install -``` -$ npm install --global imagemin-cli +```sh +npm install --global imagemin-cli ``` ## Usage diff --git a/test.js b/test.js index ab5bf67..a27a41a 100644 --- a/test.js +++ b/test.js @@ -3,8 +3,7 @@ import fs from 'node:fs'; import {dirname} from 'node:path'; import {fileURLToPath} from 'node:url'; import process from 'node:process'; - -import execa from 'execa'; +import {execa} from 'execa'; import test from 'ava'; const __dirname = dirname(fileURLToPath(import.meta.url));