From 064d12cce35a5cbe3164f668aaa8060f8fc2f8c4 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 25 May 2019 20:58:49 +0700 Subject: [PATCH] Require Node.js 8 --- .editorconfig | 4 +- .gitattributes | 3 +- .gitignore | 1 + .travis.yml | 2 +- lib/index.js | 4 +- lib/install.js | 41 +++++++++++--------- license | 20 ++-------- package.json | 103 +++++++++++++++++++++---------------------------- readme.md | 13 +++---- test/test.js | 16 ++++---- 10 files changed, 91 insertions(+), 116 deletions(-) diff --git a/.editorconfig b/.editorconfig index 91ab352..1c6314a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[*.{json,yml}] -indent_size = 2 +[*.yml] indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index 61d6319..cfedc8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules +yarn.lock vendor/optipng* vendor/man diff --git a/.travis.yml b/.travis.yml index 5ee97ab..728c89e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: + - '12' - '10' - '8' - - '6' before_install: - 'sudo chown $USER /usr/local' diff --git a/lib/index.js b/lib/index.js index a8d3ee5..1214214 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,9 +1,9 @@ 'use strict'; const path = require('path'); const BinWrapper = require('bin-wrapper'); -const pkg = require('../package.json'); +const packageJson = require('../package.json'); -const url = `https://raw.githubusercontent.com/imagemin/optipng-bin/v${pkg.version}/vendor/`; +const url = `https://raw.githubusercontent.com/imagemin/optipng-bin/v${packageJson.version}/vendor/`; module.exports = new BinWrapper() .src(`${url}macos/optipng`, 'darwin') diff --git a/lib/install.js b/lib/install.js index 3cd136c..781e2b8 100644 --- a/lib/install.js +++ b/lib/install.js @@ -4,23 +4,28 @@ const binBuild = require('bin-build'); const log = require('logalot'); const bin = require('.'); -bin.run(['--version']).then(() => { - log.success('optipng pre-build test passed successfully'); -}).catch(error => { - log.warn(error.message); - log.warn('optipng pre-build test failed'); - log.info('compiling from source'); +(async () => { + try { + await bin.run(['--version']); + log.success('optipng pre-build test passed successfully'); + } catch (error) { + log.warn(error.message); + log.warn('optipng pre-build test failed'); + log.info('compiling from source'); - // From https://sourceforge.net/projects/optipng/files/OptiPNG/ - binBuild.file(path.resolve(__dirname, '../vendor/source/optipng.tar.gz'), [ - `./configure --with-system-zlib --prefix="${bin.dest()}" --bindir="${bin.dest()}"`, - 'make install' - ]).then(() => { - log.success('optipng built successfully'); - }).catch(error => { - log.error(error.stack); + try { + // From https://sourceforge.net/projects/optipng/files/OptiPNG/ + await binBuild.file(path.resolve(__dirname, '../vendor/source/optipng.tar.gz'), [ + `./configure --with-system-zlib --prefix="${bin.dest()}" --bindir="${bin.dest()}"`, + 'make install' + ]); - // eslint-disable-next-line unicorn/no-process-exit - process.exit(1); - }); -}); + log.success('optipng built successfully'); + } catch (error) { + log.error(error.stack); + + // eslint-disable-next-line unicorn/no-process-exit + process.exit(1); + } + } +})(); diff --git a/license b/license index 92dec7a..3c5fecb 100644 --- a/license +++ b/license @@ -1,21 +1,9 @@ -The MIT License (MIT) +MIT License Copyright (c) Imagemin -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: +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 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. +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. diff --git a/package.json b/package.json index def5ff5..94bbd5a 100644 --- a/package.json +++ b/package.json @@ -1,62 +1,45 @@ { - "name": "optipng-bin", - "version": "5.1.0", - "description": "OptiPNG wrapper that makes it seamlessly available as a local dependency", - "license": "MIT", - "repository": "imagemin/optipng-bin", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "maintainers": [ - { - "name": "Kevin Mårtensson", - "email": "kevinmartensson@gmail.com", - "url": "github.com/kevva" - }, - { - "name": "Shinnosuke Watanabe", - "url": "github.com/shinnn" - } - ], - "bin": { - "optipng": "cli.js" - }, - "engines": { - "node": ">=6" - }, - "scripts": { - "postinstall": "node lib/install.js", - "test": "xo && ava" - }, - "files": [ - "index.js", - "cli.js", - "lib", - "vendor/source" - ], - "keywords": [ - "imagemin", - "compress", - "image", - "img", - "minify", - "optimize", - "png", - "optipng" - ], - "dependencies": { - "bin-build": "^3.0.0", - "bin-wrapper": "^4.0.0", - "logalot": "^2.0.0" - }, - "devDependencies": { - "ava": "*", - "bin-check": "^4.0.1", - "compare-size": "^3.0.0", - "execa": "^1.0.0", - "tempy": "^0.2.1", - "xo": "*" - } + "name": "optipng-bin", + "version": "5.1.0", + "description": "OptiPNG wrapper that makes it seamlessly available as a local dependency", + "license": "MIT", + "repository": "imagemin/optipng-bin", + "bin": { + "optipng": "cli.js" + }, + "engines": { + "node": ">=8" + }, + "scripts": { + "postinstall": "node lib/install.js", + "test": "xo && ava" + }, + "files": [ + "index.js", + "cli.js", + "lib", + "vendor/source" + ], + "keywords": [ + "imagemin", + "compress", + "image", + "minify", + "optimize", + "png", + "optipng" + ], + "dependencies": { + "bin-build": "^3.0.0", + "bin-wrapper": "^4.0.0", + "logalot": "^2.0.0" + }, + "devDependencies": { + "ava": "^1.4.1", + "bin-check": "^4.0.1", + "compare-size": "^3.0.0", + "execa": "^1.0.0", + "tempy": "^0.3.0", + "xo": "^0.24.0" + } } diff --git a/readme.md b/readme.md index 7d47773..bea350e 100644 --- a/readme.md +++ b/readme.md @@ -15,12 +15,16 @@ $ npm install --save optipng-bin ## Usage ```js +const {promisify} = require('util'); const {execFile} = require('child_process'); const optipng = require('optipng-bin'); -execFile(optipng, ['-out', 'output.png', 'input.png'], err => { +const execFileP = promsify(execFile); + +(async () => { + await execFile(optipng, ['-out', 'output.png', 'input.png']); console.log('Image minified!'); -}); +})(); ``` @@ -33,8 +37,3 @@ $ npm install --global optipng-bin ``` $ optipng --help ``` - - -## License - -MIT © [Imagemin](https://github.com/imagemin) diff --git a/test/test.js b/test/test.js index afe4017..c296ca4 100644 --- a/test/test.js +++ b/test/test.js @@ -32,19 +32,19 @@ test('return path to binary and verify that it is working', async t => { test('minify a PNG', async t => { const tmp = tempy.directory(); - const src = path.join(__dirname, 'fixtures/test.png'); - const dest = path.join(tmp, 'test.png'); - const args = [ + const sourcePath = path.join(__dirname, 'fixtures/test.png'); + const destinationPath = path.join(tmp, 'test.png'); + const arguments_ = [ '-strip', 'all', '-clobber', '-out', - dest, - src + destinationPath, + sourcePath ]; - await execa(optipng, args); - const res = await compareSize(src, dest); + await execa(optipng, arguments_); + const result = await compareSize(sourcePath, destinationPath); - t.true(res[dest] < res[src]); + t.true(result[destinationPath] < result[sourcePath]); });