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/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index 8cd4c17..0000000 --- a/.github/funding.yml +++ /dev/null @@ -1,2 +0,0 @@ -github: sindresorhus -tidelift: npm/imagemin-mozjpeg diff --git a/.github/security.md b/.github/security.md deleted file mode 100644 index 5358dc5..0000000 --- a/.github/security.md +++ /dev/null @@ -1,3 +0,0 @@ -# Security Policy - -To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..c17807f --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,28 @@ +name: Node CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x, 12.x] + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: yarn install, and test + run: yarn && yarn test && yarn coverage + env: + CI: true + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage/lcov.info diff --git a/.gitignore b/.gitignore index 239ecff..f6df091 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -node_modules +node_modules/ +.nyc_output/ +coverage/ yarn.lock diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 64576a1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -os: - - linux - - windows - - osx -osx_image: xcode8.3 -language: node_js -node_js: - - '10' - - '8' - - '6' diff --git a/index.js b/index.js index 44c9e99..7ef3dc4 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,19 @@ 'use strict'; const execa = require('execa'); const isJpg = require('is-jpg'); -const mozjpeg = require('mozjpeg'); +const mozjpeg = require('@mole-inc/mozjpeg'); -module.exports = options => buffer => { +module.exports = options => async buffer => { options = {trellis: true, trellisDC: true, overshoot: true, ...options}; if (!Buffer.isBuffer(buffer)) { - return Promise.reject(new TypeError('Expected a buffer')); + throw new TypeError('Expected a buffer'); } if (!isJpg(buffer)) { - return Promise.resolve(buffer); + return buffer; } const args = []; @@ -86,9 +86,10 @@ module.exports = options => buffer => { args.push('-sample', options.sample.join(',')); } - return execa.stdout(mozjpeg, args, { + const {stdout} = await execa(mozjpeg, args, { encoding: null, input: buffer, maxBuffer: Infinity }); + return stdout; }; diff --git a/license b/license index 3c5fecb..acb18e5 100644 --- a/license +++ b/license @@ -1,6 +1,4 @@ -MIT License - -Copyright (c) Imagemin +Copyright 2020-present MOLE inc. and its affiliates. 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: diff --git a/package.json b/package.json index df3b3c4..89ebf3b 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,22 @@ { - "name": "imagemin-mozjpeg", + "name": "@mole-inc/imagemin-mozjpeg", "version": "8.0.0", "description": "Imagemin plugin for mozjpeg", "license": "MIT", - "repository": "imagemin/imagemin-mozjpeg", - "author": { - "name": "Kevin Mårtensson", - "email": "kevinmartensson@gmail.com", - "url": "github.com/kevva" + "repository": { + "type": "git", + "url": "https://github.com/mole-inc/imagemin-mozjpeg.git" }, - "maintainers": [ - { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - { - "name": "Shinnosuke Watanabe", - "url": "github.com/shinnn" - } - ], "engines": { - "node": ">=6" + "node": ">=10.13.0" }, "scripts": { - "test": "xo && ava" + "test": "xo && nyc ava", + "coverage": "nyc report --reporter=lcov", + "release": "standard-version" + }, + "publishConfig": { + "access": "public" }, "files": [ "index.js" @@ -41,14 +33,18 @@ "optimize" ], "dependencies": { - "execa": "^1.0.0", + "execa": "^4.0.0", "is-jpg": "^2.0.0", - "mozjpeg": "^6.0.0" + "@mole-inc/mozjpeg": "^7.0.2" }, "devDependencies": { - "ava": "^1.0.1", + "@commitlint/cli": "^8.3.5", + "@commitlint/config-conventional": "^8.3.4", + "ava": "^3.7.0", + "husky": "^4.2.5", "is-progressive": "^3.0.0", - "pify": "^4.0.0", - "xo": "^0.23.0" + "nyc": "^15.0.1", + "standard-version": "^7.1.0", + "xo": "^0.29.1" } } diff --git a/readme.md b/readme.md index 1007910..098afc8 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,12 @@ -# imagemin-mozjpeg [![Build Status](https://travis-ci.org/imagemin/imagemin-mozjpeg.svg?branch=master)](https://travis-ci.org/imagemin/imagemin-mozjpeg) +# imagemin-mozjpeg ![Node CI](https://github.com/mole-inc/imagemin-mozjpeg/workflows/Node%20CI/badge.svg) -> [Imagemin](https://github.com/imagemin/imagemin) plugin for [mozjpeg](https://github.com/mozilla/mozjpeg) +> [Imagemin](https://github.com/imagemin/imagemin) plugin for [mozjpeg](https://github.com/mole-inc/mozjpeg) ## Install ``` -$ npm install imagemin-mozjpeg +$ npm install @mole-inc/imagemin-mozjpeg ``` @@ -14,7 +14,7 @@ $ npm install imagemin-mozjpeg ```js const imagemin = require('imagemin'); -const imageminMozjpeg = require('imagemin-mozjpeg'); +const imageminMozjpeg = require('@mole-inc/imagemin-mozjpeg'); (async () => { await imagemin(['images/*.jpg'], 'build/images', { @@ -30,7 +30,7 @@ const imageminMozjpeg = require('imagemin-mozjpeg'); ## API -### imageminMozjpeg([options])(buffer) +### imageminMozjpeg(options?)(buffer) Returns a `Promise`. @@ -174,4 +174,6 @@ Buffer to optimize. ## License -MIT © [Imagemin](https://github.com/imagemin) +This is a fork of [imagemin/imagemin-mozjpeg](https://github.com/imagemin/imagemin-mozjpeg). + +see license file. diff --git a/test.js b/test.js index 22da8a8..27f2653 100644 --- a/test.js +++ b/test.js @@ -1,15 +1,15 @@ -import fs from 'fs'; -import path from 'path'; -import isJpg from 'is-jpg'; -import isProgressive from 'is-progressive'; -import pify from 'pify'; -import test from 'ava'; -import m from '.'; +const fs = require('fs'); +const path = require('path'); +const isJpg = require('is-jpg'); +const isProgressive = require('is-progressive'); +const test = require('ava'); +const {promisify} = require('util'); -const fsP = pify(fs); +const m = require('.'); +const readFileP = promisify(fs.readFile); test('optimize a JPG', async t => { - const buf = await fsP.readFile(path.join(__dirname, 'fixture.jpg')); + const buf = await readFileP(path.join(__dirname, 'fixture.jpg')); const data = await m()(buf); t.true(data.length < buf.length); @@ -18,22 +18,22 @@ test('optimize a JPG', async t => { }); test('support mozjpeg options', async t => { - const buf = await fsP.readFile(path.join(__dirname, 'fixture.jpg')); + const buf = await readFileP(path.join(__dirname, 'fixture.jpg')); const data = await m({progressive: false})(buf); t.false(isProgressive.buffer(data)); }); test('skip optimizing a non-JPG file', async t => { - const buf = await fsP.readFile(__filename); + const buf = await readFileP(__filename); const data = await m()(buf); t.deepEqual(data, buf); }); test('throw error when a JPG is corrupt', async t => { - const buf = await fsP.readFile(path.join(__dirname, 'fixture-corrupt.jpg')); + const buf = await readFileP(path.join(__dirname, 'fixture-corrupt.jpg')); await t.throwsAsync(async () => { await m()(buf); - }, /Corrupt JPEG data/); + }, {instanceOf: Error, message: /Corrupt JPEG data/}); });