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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: test
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version:
- 18
- 16
- 14
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- 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
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
'use strict';
module.exports = require('./lib').path();
import lib from './lib/index.js';

export default lib.path();
15 changes: 9 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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;
27 changes: 14 additions & 13 deletions lib/install.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
'use strict';
const path = require('path');
const binBuild = require('bin-build');
const log = require('logalot');
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(() => {
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'), [
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()}`,
]);

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);
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "jpeg-recompress-bin",
"version": "5.1.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",
"type": "module",
"exports": "./index.js",
"author": {
"name": "Shogo Sensui",
"email": "shogosensui@gmail.com",
Expand All @@ -29,11 +31,11 @@
"jpeg-recompress": "cli.js"
},
"engines": {
"node": ">=10"
"node": "^14.13.1 || >=16.0.0"
},
"scripts": {
"postinstall": "node lib/install.js",
"test": "xo && ava"
"test": "xo && ava --timeout=120s"
},
"files": [
"cli.js",
Expand All @@ -54,15 +56,14 @@
],
"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",
"ava": "^4.2.0",
"bin-check": "^4.0.1",
"compare-size": "^3.0.0",
"execa": "^4.0.0",
"tempy": "^0.5.0",
"xo": "^0.30.0"
"execa": "^6.1.0",
"tempy": "^3.0.0",
"xo": "^0.48.0"
}
}
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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=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

Expand All @@ -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');
});
```
Expand Down
34 changes: 18 additions & 16 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
'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 {temporaryDirectory} 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') {
t.pass('Build for win32 and linux is not supported');
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(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')));
Expand All @@ -30,16 +32,16 @@ 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 temporary = temporaryDirectory();
const src = fileURLToPath(new URL('fixtures/test.jpg', import.meta.url));
const dest = path.join(temporary, 'test.jpg');
const args = [
'--quality',
'high',
'--min',
'60',
src,
dest
dest,
];

await execa(jpegRecompress, args);
Expand Down