From d700522a759d488bc23b5c29f28c8937e073d195 Mon Sep 17 00:00:00 2001 From: Shogo Sensui Date: Sun, 28 Feb 2021 16:32:53 +0900 Subject: [PATCH 01/11] Use GitHub Actions instead (#26) --- .github/workflows/test.yml | 66 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 11 ------- readme.md | 2 +- 3 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f9f9370 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,66 @@ +name: test + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + linux: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x, 14.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test + env: + CI: true + + macos: + runs-on: macos-latest + + strategy: + matrix: + node-version: [10.x, 12.x, 14.x] + + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: brew install mozjpeg + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test + env: + CI: true + + windows: + runs-on: windows-latest + + strategy: + matrix: + node-version: [10.x, 12.x, 14.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test + env: + CI: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9cc9de4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: node_js -node_js: - - '14' - - '12' - - '10' -os: - - linux - - windows - - osx -before_install: - - if [[ $TRAVIS_OS_NAME == 'osx' ]]; then brew install mozjpeg; fi diff --git a/readme.md b/readme.md index 61061f5..53df82d 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# jpeg-recompress-bin [![Build Status](https://travis-ci.org/imagemin/jpeg-recompress-bin.svg?branch=master)](https://travis-ci.org/imagemin/jpeg-recompress-bin) +# jpeg-recompress-bin ![GitHub Actions Status](https://github.com/imagemin/jpeg-recompress-bin/workflows/test/badge.svg?branch=master) > Compress JPEGs by re-encoding to the smallest JPEG quality while keeping perceived visual quality the same and by making sure huffman tables are optimized From 155a82e7a9d1adba9a527e6da88d54d3a7ee2a3e Mon Sep 17 00:00:00 2001 From: 1000ch Date: Fri, 22 Oct 2021 23:44:57 +0900 Subject: [PATCH 02/11] Use console.log to remove logalot --- lib/install.js | 13 ++++++------- package.json | 3 +-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/install.js b/lib/install.js index 30db7dd..1b30294 100644 --- a/lib/install.js +++ b/lib/install.js @@ -1,21 +1,20 @@ 'use strict'; const path = require('path'); const binBuild = require('bin-build'); -const log = require('logalot'); const bin = require('.'); bin.run(['--version']).then(() => { - log.success('jpeg-recompress pre-build test passed successfully'); + console.log('jpeg-recompress pre-build test passed successfully'); }).catch(async error => { - log.warn(error.message); - log.warn('jpeg-recompress pre-build test failed'); + console.warn(error.message); + console.warn('jpeg-recompress pre-build test failed'); if (process.platform === 'win32' || process.platform === 'linux') { // eslint-disable-next-line unicorn/no-process-exit process.exit(1); } - log.info('compiling from source'); + console.info('compiling from source'); try { await binBuild.file(path.resolve(__dirname, '../vendor/source/jpeg-archive-2.2.0.tar.gz'), [ @@ -23,9 +22,9 @@ bin.run(['--version']).then(() => { `make && mv ${bin.use()} ${bin.path()}` ]); - log.success('jpeg-recompress built successfully'); + console.log('jpeg-recompress built successfully'); } catch (error) { - log.error(error.stack); + console.error(error.stack); // eslint-disable-next-line unicorn/no-process-exit process.exit(1); diff --git a/package.json b/package.json index bf9b878..925b5ba 100644 --- a/package.json +++ b/package.json @@ -54,8 +54,7 @@ ], "dependencies": { "bin-build": "^3.0.0", - "bin-wrapper": "^4.1.0", - "logalot": "^2.0.0" + "bin-wrapper": "^4.1.0" }, "devDependencies": { "ava": "^3.8.0", From 4750e562717621525881ca3de50002cca68c96ae Mon Sep 17 00:00:00 2001 From: 1000ch Date: Fri, 22 Oct 2021 23:46:35 +0900 Subject: [PATCH 03/11] 5.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 925b5ba..a950307 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpeg-recompress-bin", - "version": "5.1.1", + "version": "5.1.2", "description": "jpeg-recompress wrapper that makes it seamlessly available as a local dependency", "license": "MIT", "repository": "imagemin/jpeg-recompress-bin", From c51c5547b75ba70b2f28a12c4db726772251999b Mon Sep 17 00:00:00 2001 From: Shogo Sensui Date: Sat, 23 Oct 2021 02:01:46 +0900 Subject: [PATCH 04/11] Use native ESM (#28) --- .github/workflows/test.yml | 81 ++++++++++---------------------------- cli.js | 6 +-- index.js | 5 ++- lib/index.js | 15 ++++--- lib/install.js | 14 ++++--- package.json | 13 +++--- readme.md | 8 ++-- test/test.js | 30 +++++++------- 8 files changed, 71 insertions(+), 101 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f9f9370..a333f72 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,66 +1,27 @@ name: test - on: - push: - branches: - - master - pull_request: - branches: - - master - + - push + - pull_request jobs: - linux: - runs-on: ubuntu-latest - + test: + name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} strategy: matrix: - node-version: [10.x, 12.x, 14.x] - + node-version: + - 16 + - 14 + - 12 + os: + - ubuntu-latest + - macos-latest + - windows-latest steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm test - env: - CI: true - - macos: - runs-on: macos-latest - - strategy: - matrix: - node-version: [10.x, 12.x, 14.x] - - steps: - - uses: actions/checkout@v2 - - name: Install dependencies - run: brew install mozjpeg - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm test - env: - CI: true - - windows: - runs-on: windows-latest - - strategy: - matrix: - node-version: [10.x, 12.x, 14.x] - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm install - - run: npm test - env: - CI: true + - uses: actions/checkout@v2 + - if: contains(matrix.os, 'macos') + run: brew install mozjpeg + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/cli.js b/cli.js index 0b0686b..3e2e403 100644 --- a/cli.js +++ b/cli.js @@ -1,7 +1,7 @@ #!/usr/bin/env node -'use strict'; -const {spawn} = require('child_process'); -const jpegRecompress = require('.'); +import {spawn} from 'node:child_process'; +import process from 'node:process'; +import jpegRecompress from './index.js'; const input = process.argv.slice(2); diff --git a/index.js b/index.js index fb0971d..b4ce886 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,3 @@ -'use strict'; -module.exports = require('./lib').path(); +import lib from './lib/index.js'; + +export default lib.path(); diff --git a/lib/index.js b/lib/index.js index db60ef9..a433fcf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,13 +1,16 @@ -'use strict'; -const path = require('path'); -const BinWrapper = require('bin-wrapper'); -const pkg = require('../package.json'); +import fs from 'node:fs'; +import process from 'node:process'; +import {fileURLToPath} from 'node:url'; +import BinWrapper from 'bin-wrapper'; +const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url))); const url = `https://raw.github.com/imagemin/jpeg-recompress-bin/v${pkg.version}/vendor/`; -module.exports = new BinWrapper() +const binWrapper = new BinWrapper() .src(`${url}osx/jpeg-recompress`, 'darwin') .src(`${url}linux/jpeg-recompress`, 'linux') .src(`${url}win/jpeg-recompress.exe`, 'win32') - .dest(path.resolve(__dirname, '../vendor')) + .dest(fileURLToPath(new URL('../vendor', import.meta.url))) .use(process.platform === 'win32' ? 'jpeg-recompress.exe' : 'jpeg-recompress'); + +export default binWrapper; diff --git a/lib/install.js b/lib/install.js index 1b30294..6a64823 100644 --- a/lib/install.js +++ b/lib/install.js @@ -1,7 +1,7 @@ -'use strict'; -const path = require('path'); -const binBuild = require('bin-build'); -const bin = require('.'); +import process from 'node:process'; +import {fileURLToPath} from 'node:url'; +import binBuild from 'bin-build'; +import bin from './index.js'; bin.run(['--version']).then(() => { console.log('jpeg-recompress pre-build test passed successfully'); @@ -17,9 +17,11 @@ bin.run(['--version']).then(() => { console.info('compiling from source'); try { - await binBuild.file(path.resolve(__dirname, '../vendor/source/jpeg-archive-2.2.0.tar.gz'), [ + const source = fileURLToPath(new URL('../vendor/source/jpeg-archive-2.2.0.tar.gz', import.meta.url)); + + await binBuild.file(source, [ `mkdir -p ${bin.dest()}`, - `make && mv ${bin.use()} ${bin.path()}` + `make && mv ${bin.use()} ${bin.path()}`, ]); console.log('jpeg-recompress built successfully'); diff --git a/package.json b/package.json index a950307..1091b28 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "jpeg-recompress wrapper that makes it seamlessly available as a local dependency", "license": "MIT", "repository": "imagemin/jpeg-recompress-bin", + "type": "module", "author": { "name": "Shogo Sensui", "email": "shogosensui@gmail.com", @@ -29,11 +30,11 @@ "jpeg-recompress": "cli.js" }, "engines": { - "node": ">=10" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { "postinstall": "node lib/install.js", - "test": "xo && ava" + "test": "xo && ava --timeout=120s" }, "files": [ "cli.js", @@ -57,11 +58,11 @@ "bin-wrapper": "^4.1.0" }, "devDependencies": { - "ava": "^3.8.0", + "ava": "^3.15.0", "bin-check": "^4.0.1", "compare-size": "^3.0.0", - "execa": "^4.0.0", - "tempy": "^0.5.0", - "xo": "^0.30.0" + "execa": "^5.1.1", + "tempy": "^2.0.0", + "xo": "^0.45.0" } } diff --git a/readme.md b/readme.md index 53df82d..2b550fa 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# jpeg-recompress-bin ![GitHub Actions Status](https://github.com/imagemin/jpeg-recompress-bin/workflows/test/badge.svg?branch=master) +# jpeg-recompress-bin ![GitHub Actions Status](https://github.com/imagemin/jpeg-recompress-bin/workflows/test/badge.svg?branch=main) > Compress JPEGs by re-encoding to the smallest JPEG quality while keeping perceived visual quality the same and by making sure huffman tables are optimized @@ -15,10 +15,10 @@ $ npm install --save jpeg-recompress-bin ## Usage ```js -const {execFile} = require('child_process'); -const jpegRecompress = require('jpeg-recompress-bin'); +import {execFile} from 'node:child_process'; +import jpegRecompress from 'jpeg-recompress-bin'; -execFile(jpegRecompress, ['--quality high', '--min 60', 'input.jpg', 'output.jpg'], err => { +execFile(jpegRecompress, ['--quality high', '--min 60', 'input.jpg', 'output.jpg'], error => { console.log('Image minified'); }); ``` diff --git a/test/test.js b/test/test.js index d2fc715..280d1f1 100644 --- a/test/test.js +++ b/test/test.js @@ -1,13 +1,14 @@ -'use strict'; -const fs = require('fs'); -const path = require('path'); -const test = require('ava'); -const execa = require('execa'); -const tempy = require('tempy'); -const binCheck = require('bin-check'); -const binBuild = require('bin-build'); -const compareSize = require('compare-size'); -const jpegRecompress = require('..'); +import fs from 'node:fs'; +import path from 'node:path'; +import process from 'node:process'; +import {fileURLToPath} from 'node:url'; +import test from 'ava'; +import execa from 'execa'; +import tempy from 'tempy'; +import binCheck from 'bin-check'; +import binBuild from 'bin-build'; +import compareSize from 'compare-size'; +import jpegRecompress from '../index.js'; test('rebuild the jpeg-recompress binaries', async t => { if (process.platform === 'win32' || process.platform === 'linux') { @@ -16,10 +17,11 @@ test('rebuild the jpeg-recompress binaries', async t => { } const temporary = tempy.directory(); + const source = fileURLToPath(new URL('../vendor/source/jpeg-archive-2.2.0.tar.gz', import.meta.url)); - await binBuild.file(path.resolve(__dirname, '../vendor/source/jpeg-archive-2.2.0.tar.gz'), [ + await binBuild.file(source, [ `mkdir -p ${temporary}`, - `make && mv jpeg-recompress ${path.join(temporary, 'jpeg-recompress')}` + `make && mv jpeg-recompress ${path.join(temporary, 'jpeg-recompress')}`, ]); t.true(fs.existsSync(path.join(temporary, 'jpeg-recompress'))); @@ -31,7 +33,7 @@ test('return path to binary and verify that it is working', async t => { test('minify a JPG', async t => { const temporary = tempy.directory(); - const src = path.join(__dirname, 'fixtures/test.jpg'); + const src = fileURLToPath(new URL('fixtures/test.jpg', import.meta.url)); const dest = path.join(temporary, 'test.jpg'); const args = [ '--quality', @@ -39,7 +41,7 @@ test('minify a JPG', async t => { '--min', '60', src, - dest + dest, ]; await execa(jpegRecompress, args); From 4583349226b45f5efc7304220bffe2aaa651abab Mon Sep 17 00:00:00 2001 From: 1000ch Date: Sat, 23 Oct 2021 11:41:32 +0900 Subject: [PATCH 05/11] 6.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1091b28..fbffede 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpeg-recompress-bin", - "version": "5.1.2", + "version": "6.0.0", "description": "jpeg-recompress wrapper that makes it seamlessly available as a local dependency", "license": "MIT", "repository": "imagemin/jpeg-recompress-bin", From 6716a74c1cbdefdbdeb819435c79fada71b26ae6 Mon Sep 17 00:00:00 2001 From: 1000ch Date: Wed, 10 Nov 2021 14:57:40 +0900 Subject: [PATCH 06/11] Specify exports field --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index fbffede..9cd865a 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "license": "MIT", "repository": "imagemin/jpeg-recompress-bin", "type": "module", + "exports": "./index.js", "author": { "name": "Shogo Sensui", "email": "shogosensui@gmail.com", From 87457b8c8b1ef995ab20cc6f28f3cd992429952b Mon Sep 17 00:00:00 2001 From: 1000ch Date: Wed, 10 Nov 2021 14:58:12 +0900 Subject: [PATCH 07/11] 6.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9cd865a..ee7a188 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpeg-recompress-bin", - "version": "6.0.0", + "version": "6.0.1", "description": "jpeg-recompress wrapper that makes it seamlessly available as a local dependency", "license": "MIT", "repository": "imagemin/jpeg-recompress-bin", From ba0809fabc009f07fa94bc70ff71c51ccb03e531 Mon Sep 17 00:00:00 2001 From: Shogo Sensui Date: Mon, 2 May 2022 13:23:09 +0900 Subject: [PATCH 08/11] Drop Node.js 12 support (#29) --- .github/workflows/test.yml | 1 - package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a333f72..7e5e2e3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,6 @@ jobs: node-version: - 16 - 14 - - 12 os: - ubuntu-latest - macos-latest diff --git a/package.json b/package.json index ee7a188..9dca303 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "jpeg-recompress": "cli.js" }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": "^14.13.1 || >=16.0.0" }, "scripts": { "postinstall": "node lib/install.js", From eda94371dd2bc21b8ab6274e01c6ac95b8476563 Mon Sep 17 00:00:00 2001 From: Shogo Sensui Date: Mon, 2 May 2022 13:33:55 +0900 Subject: [PATCH 09/11] Update dependencies (#30) --- package.json | 8 ++++---- test/test.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 9dca303..eec9927 100644 --- a/package.json +++ b/package.json @@ -59,11 +59,11 @@ "bin-wrapper": "^4.1.0" }, "devDependencies": { - "ava": "^3.15.0", + "ava": "^4.2.0", "bin-check": "^4.0.1", "compare-size": "^3.0.0", - "execa": "^5.1.1", - "tempy": "^2.0.0", - "xo": "^0.45.0" + "execa": "^6.1.0", + "tempy": "^3.0.0", + "xo": "^0.48.0" } } diff --git a/test/test.js b/test/test.js index 280d1f1..c7fcb26 100644 --- a/test/test.js +++ b/test/test.js @@ -3,8 +3,8 @@ import path from 'node:path'; import process from 'node:process'; import {fileURLToPath} from 'node:url'; import test from 'ava'; -import execa from 'execa'; -import tempy from 'tempy'; +import {execa} from 'execa'; +import {temporaryDirectory} from 'tempy'; import binCheck from 'bin-check'; import binBuild from 'bin-build'; import compareSize from 'compare-size'; @@ -16,7 +16,7 @@ test('rebuild the jpeg-recompress binaries', async t => { return; } - const temporary = tempy.directory(); + const temporary = temporaryDirectory(); const source = fileURLToPath(new URL('../vendor/source/jpeg-archive-2.2.0.tar.gz', import.meta.url)); await binBuild.file(source, [ @@ -32,7 +32,7 @@ test('return path to binary and verify that it is working', async t => { }); test('minify a JPG', async t => { - const temporary = tempy.directory(); + const temporary = temporaryDirectory(); const src = fileURLToPath(new URL('fixtures/test.jpg', import.meta.url)); const dest = path.join(temporary, 'test.jpg'); const args = [ From 88fefa87279e0ea7469e2a95a75585c969db255a Mon Sep 17 00:00:00 2001 From: 1000ch Date: Fri, 6 May 2022 21:40:49 +0900 Subject: [PATCH 10/11] Test on Node.js 18 --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e5e2e3..1e0ef91 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,7 @@ jobs: strategy: matrix: node-version: + - 18 - 16 - 14 os: From 91b218f4a95bb1c18ea31caafde4c61fc35e793a Mon Sep 17 00:00:00 2001 From: 1000ch Date: Fri, 6 May 2022 21:41:38 +0900 Subject: [PATCH 11/11] 7.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eec9927..d264ac8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpeg-recompress-bin", - "version": "6.0.1", + "version": "7.0.0", "description": "jpeg-recompress wrapper that makes it seamlessly available as a local dependency", "license": "MIT", "repository": "imagemin/jpeg-recompress-bin",