Comparing version 6.0.0 to 6.1.0
42
index.js
@@ -13,18 +13,16 @@ 'use strict'; | ||
const handleFile = (input, output, opts) => fsP.readFile(input).then(data => { | ||
const handleFile = (input, output, options) => fsP.readFile(input).then(data => { | ||
const dest = output ? path.join(output, path.basename(input)) : null; | ||
if (opts.plugins && !Array.isArray(opts.plugins)) { | ||
throw new TypeError('The plugins option should be an `Array`'); | ||
if (options.plugins && !Array.isArray(options.plugins)) { | ||
throw new TypeError('The `plugins` option should be an `Array`'); | ||
} | ||
const pipe = opts.plugins.length > 0 ? pPipe(opts.plugins)(data) : Promise.resolve(data); | ||
const pipe = options.plugins.length > 0 ? pPipe(options.plugins)(data) : Promise.resolve(data); | ||
return pipe | ||
.then(buf => { | ||
buf = buf.length < data.length ? buf : data; | ||
.then(buffer => { | ||
const ret = { | ||
data: buf, | ||
path: (fileType(buf) && fileType(buf).ext === 'webp') ? replaceExt(dest, '.webp') : dest | ||
data: buffer, | ||
path: (fileType(buffer) && fileType(buffer).ext === 'webp') ? replaceExt(dest, '.webp') : dest | ||
}; | ||
@@ -40,9 +38,9 @@ | ||
}) | ||
.catch(err => { | ||
err.message = `Error in file: ${input}\n\n${err.message}`; | ||
throw err; | ||
.catch(error => { | ||
error.message = `Error in file: ${input}\n\n${error.message}`; | ||
throw error; | ||
}); | ||
}); | ||
module.exports = (input, output, opts) => { | ||
module.exports = (input, output, options) => { | ||
if (!Array.isArray(input)) { | ||
@@ -53,13 +51,13 @@ return Promise.reject(new TypeError(`Expected an \`Array\`, got \`${typeof input}\``)); | ||
if (typeof output === 'object') { | ||
opts = output; | ||
options = output; | ||
output = null; | ||
} | ||
opts = Object.assign({plugins: []}, opts); | ||
opts.plugins = opts.use || opts.plugins; | ||
options = Object.assign({plugins: []}, options); | ||
options.plugins = options.use || options.plugins; | ||
return globby(input, {onlyFiles: true}).then(paths => Promise.all(paths.map(x => handleFile(x, output, opts)))); | ||
return globby(input, {onlyFiles: true}).then(paths => Promise.all(paths.map(x => handleFile(x, output, options)))); | ||
}; | ||
module.exports.buffer = (input, opts) => { | ||
module.exports.buffer = (input, options) => { | ||
if (!Buffer.isBuffer(input)) { | ||
@@ -69,10 +67,10 @@ return Promise.reject(new TypeError(`Expected a \`Buffer\`, got \`${typeof input}\``)); | ||
opts = Object.assign({plugins: []}, opts); | ||
opts.plugins = opts.use || opts.plugins; | ||
options = Object.assign({plugins: []}, options); | ||
options.plugins = options.use || options.plugins; | ||
if (opts.plugins.length === 0) { | ||
if (options.plugins.length === 0) { | ||
return Promise.resolve(input); | ||
} | ||
return pPipe(opts.plugins)(input).then(buf => (buf.length < input.length ? buf : input)); | ||
return pPipe(options.plugins)(input); | ||
}; |
{ | ||
"name": "imagemin", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "Minify images", | ||
@@ -28,18 +28,19 @@ "license": "MIT", | ||
"dependencies": { | ||
"file-type": "^8.1.0", | ||
"file-type": "^10.7.0", | ||
"globby": "^8.0.1", | ||
"make-dir": "^1.0.0", | ||
"p-pipe": "^1.1.0", | ||
"pify": "^3.0.0", | ||
"pify": "^4.0.1", | ||
"replace-ext": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"ava": "^1.0.1", | ||
"del": "^3.0.0", | ||
"imagemin-jpegtran": "^5.0.0", | ||
"imagemin-webp": "^4.0.0", | ||
"imagemin-jpegtran": "^6.0.0", | ||
"imagemin-svgo": "^7.0.0", | ||
"imagemin-webp": "^5.0.0", | ||
"is-jpg": "^2.0.0", | ||
"tempy": "^0.2.1", | ||
"xo": "*" | ||
"xo": "^0.23.0" | ||
} | ||
} |
@@ -38,3 +38,3 @@ # imagemin [![Build Status](https://travis-ci.org/imagemin/imagemin.svg?branch=master)](https://travis-ci.org/imagemin/imagemin) [![Build status](https://ci.appveyor.com/api/projects/status/wlnem7wef63k4n1t?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/imagemin) | ||
Returns `Promise<Object[]>` in the format `{data: Buffer, path: String}`. | ||
Returns `Promise<Object[]>` in the format `{data: Buffer, path: string}`. | ||
@@ -41,0 +41,0 @@ #### input |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5811
8
57
+ Addedfile-type@10.11.0(transitive)
+ Addedpify@4.0.1(transitive)
- Removedfile-type@8.1.0(transitive)
Updatedfile-type@^10.7.0
Updatedpify@^4.0.1