Skip to content

Commit

Permalink
Require Node.js 10 (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
1000ch authored May 29, 2020
1 parent bc02ebe commit 3faba64
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ language: node_js
os:
- linux
- osx
osx_image: xcode9.3
osx_image: xcode9.4
node_js:
- '14'
- '12'
- '10'
- '8'
- '6'
addons:
apt:
packages: nasm
packages:
- nasm
before_install: if [[ $TRAVIS_OS_NAME == osx ]]; then brew update && brew install nasm; fi;
22 changes: 12 additions & 10 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const binBuild = require('bin-build');
const log = require('logalot');
const bin = require('.');

const cpuNum = os.cpus().length;
const cpuNumber = os.cpus().length;

bin.run(['-version']).then(() => {
log.success('mozjpeg pre-build test passed successfully');
}).catch(error => {
}).catch(async error => {
log.warn(error.message);
log.warn('mozjpeg pre-build test failed');
log.info('compiling from source');
Expand All @@ -24,17 +24,19 @@ bin.run(['-version']).then(() => {
`--prefix="${bin.dest()}" --bindir="${bin.dest()}" --libdir="${bin.dest()}"`
].join(' ');

binBuild.file(path.resolve(__dirname, '../vendor/source/mozjpeg.tar.gz'), [
'autoreconf -fiv',
cfg,
`make -j${cpuNum}`,
`make install -j${cpuNum}`
]).then(() => {
try {
await binBuild.file(path.resolve(__dirname, '../vendor/source/mozjpeg.tar.gz'), [
'autoreconf -fiv',
cfg,
`make -j${cpuNumber}`,
`make install -j${cpuNumber}`
]);

log.success('mozjpeg built successfully');
}).catch(error => {
} catch (error) {
log.error(error.stack);

// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
});
}
});
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"repository": "imagemin/mozjpeg-bin",
"bin": "cli.js",
"engines": {
"node": ">=6"
"node": ">=10"
},
"scripts": {
"postinstall": "node lib/install.js",
"test": "xo && ava",
"test": "xo && ava --timeout=120s",
"build-linux": "docker build --tag imagemin/mozjpeg docker && docker run --rm --volume $(pwd)/vendor/linux:/src/out imagemin/mozjpeg cp cjpeg /src/out"
},
"files": [
Expand All @@ -36,12 +36,12 @@
"logalot": "^2.1.0"
},
"devDependencies": {
"ava": "*",
"ava": "^3.8.0",
"bin-check": "^4.1.0",
"compare-size": "^3.0.0",
"execa": "^1.0.0",
"tempy": "^0.2.1",
"xo": "*"
"execa": "^4.0.0",
"tempy": "^0.5.0",
"xo": "^0.30.0"
},
"ava": {
"serial": true
Expand Down
20 changes: 10 additions & 10 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ const binBuild = require('bin-build');
const compareSize = require('compare-size');
const mozjpeg = require('..');

const cpuNum = os.cpus().length;
const cpuNumber = os.cpus().length;

test('rebuild the mozjpeg binaries', async t => {
const tmp = tempy.directory();
const temporary = tempy.directory();
const cfg = [
'./configure --enable-static --disable-shared --disable-dependency-tracking --with-jpeg8',
`--prefix="${tmp}" --bindir="${tmp}" --libdir="${tmp}"`
`--prefix="${temporary}" --bindir="${temporary}" --libdir="${temporary}"`
].join(' ');

await binBuild.file(path.resolve(__dirname, '../vendor/source/mozjpeg.tar.gz'), [
'autoreconf -fiv',
cfg,
`make --jobs=${cpuNum}`,
`make install --jobs=${cpuNum}`
`make --jobs=${cpuNumber}`,
`make install --jobs=${cpuNumber}`
]);

t.true(fs.existsSync(path.join(tmp, 'cjpeg')));
t.true(fs.existsSync(path.join(temporary, 'cjpeg')));
});

test('return path to binary and verify that it is working', async t => {
t.true(await binCheck(mozjpeg, ['-version']));
});

test('minify a JPG', async t => {
const tmp = tempy.directory();
const temporary = tempy.directory();
const src = path.join(__dirname, 'fixtures/test.jpg');
const dest = path.join(tmp, 'test.jpg');
const dest = path.join(temporary, 'test.jpg');
const args = [
'-outfile',
dest,
src
];

await execa(mozjpeg, args);
const res = await compareSize(src, dest);
const result = await compareSize(src, dest);

t.true(res[dest] < res[src]);
t.true(result[dest] < result[src]);
});

0 comments on commit 3faba64

Please sign in to comment.