imagemin
Advanced tools
Comparing version 7.0.1 to 8.0.0
30
index.js
@@ -1,11 +0,10 @@ | ||
'use strict'; | ||
const {promisify} = require('util'); | ||
const path = require('path'); | ||
const fs = require('graceful-fs'); | ||
const fileType = require('file-type'); | ||
const globby = require('globby'); | ||
const makeDir = require('make-dir'); | ||
const pPipe = require('p-pipe'); | ||
const replaceExt = require('replace-ext'); | ||
const junk = require('junk'); | ||
import {promisify} from 'util'; | ||
import path from 'path'; | ||
import fs from 'graceful-fs'; | ||
import {promises as fsPromises} from 'fs'; | ||
import FileType from 'file-type'; | ||
import globby from 'globby'; | ||
import pPipe from 'p-pipe'; | ||
import replaceExt from 'replace-ext'; | ||
import junk from 'junk'; | ||
@@ -23,4 +22,5 @@ const readFile = promisify(fs.readFile); | ||
const {ext} = await FileType.fromBuffer(data); | ||
let destinationPath = destination ? path.join(destination, path.basename(sourcePath)) : undefined; | ||
destinationPath = (fileType(data) && fileType(data).ext === 'webp') ? replaceExt(destinationPath, '.webp') : destinationPath; | ||
destinationPath = ext === 'webp' ? replaceExt(destinationPath, '.webp') : destinationPath; | ||
@@ -37,3 +37,3 @@ const returnValue = { | ||
await makeDir(path.dirname(returnValue.destinationPath)); | ||
await fsPromises.mkdir(path.dirname(returnValue.destinationPath), {recursive: true}); | ||
await writeFile(returnValue.destinationPath, returnValue.data); | ||
@@ -44,3 +44,3 @@ | ||
module.exports = async (input, {glob = true, ...options} = {}) => { | ||
export default async function imagemin(input, {glob = true, ...options} = {}) { | ||
if (!Array.isArray(input)) { | ||
@@ -64,5 +64,5 @@ throw new TypeError(`Expected an \`Array\`, got \`${typeof input}\``); | ||
); | ||
}; | ||
} | ||
module.exports.buffer = async (input, {plugins = []} = {}) => { | ||
imagemin.buffer = async (input, {plugins = []} = {}) => { | ||
if (!Buffer.isBuffer(input)) { | ||
@@ -69,0 +69,0 @@ throw new TypeError(`Expected a \`Buffer\`, got \`${typeof input}\``); |
{ | ||
"name": "imagemin", | ||
"version": "7.0.1", | ||
"version": "8.0.0", | ||
"description": "Minify images seamlessly", | ||
"license": "MIT", | ||
"repository": "imagemin/imagemin", | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
}, | ||
@@ -28,20 +30,19 @@ "scripts": { | ||
"dependencies": { | ||
"file-type": "^12.0.0", | ||
"globby": "^10.0.0", | ||
"graceful-fs": "^4.2.2", | ||
"file-type": "^14.6.0", | ||
"globby": "^11.0.3", | ||
"graceful-fs": "^4.2.6", | ||
"junk": "^3.1.0", | ||
"make-dir": "^3.0.0", | ||
"p-pipe": "^3.0.0", | ||
"replace-ext": "^1.0.0" | ||
"p-pipe": "^4.0.0", | ||
"replace-ext": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.1.0", | ||
"del": "^4.1.1", | ||
"imagemin-jpegtran": "^6.0.0", | ||
"imagemin-svgo": "^7.0.0", | ||
"imagemin-webp": "^5.0.0", | ||
"ava": "^3.15.0", | ||
"del": "^6.0.0", | ||
"imagemin-jpegtran": "^7.0.0", | ||
"imagemin-svgo": "^9.0.0", | ||
"imagemin-webp": "^6.0.0", | ||
"is-jpg": "^2.0.0", | ||
"tempy": "^0.3.0", | ||
"xo": "^0.24.0" | ||
"tempy": "^1.0.1", | ||
"xo": "^0.39.1" | ||
} | ||
} |
@@ -1,15 +0,36 @@ | ||
# imagemin [![Build Status](https://travis-ci.org/imagemin/imagemin.svg?branch=master)](https://travis-ci.org/imagemin/imagemin) | ||
# imagemin ![GitHub Actions Status](https://github.com/imagemin/imagemin/workflows/CI/badge.svg?branch=master) | ||
> Minify images seamlessly | ||
<br> | ||
--- | ||
<div align="center"> | ||
<sup>Gumlet is helping make open source sustainable by sponsoring Sindre Sorhus.</sup> | ||
<a href="https://www.gumlet.com"> | ||
<div> | ||
<img src="https://sindresorhus.com/assets/thanks/gumlet-logo.svg" width="300"/> | ||
</div> | ||
<sup><b>Optimised Image Delivery made simple</b></sup> | ||
</a> | ||
<p> | ||
<p> | ||
<sup> | ||
<a href="https://github.com/sponsors/sindresorhus">Sindre Sorhus' open source work is supported by the community</a> | ||
</sup> | ||
</p> | ||
<sup>Special thanks to:</sup> | ||
<br> | ||
<br> | ||
<a href="https://standardresume.co/tech"> | ||
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="180"> | ||
</a> | ||
<br> | ||
<br> | ||
<a href="https://doppler.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=imagemin&utm_source=github"> | ||
<div> | ||
<img src="https://dashboard.doppler.com/imgs/logo-long.svg" width="240" alt="Doppler"> | ||
</div> | ||
<b>All your environment variables, in one place</b> | ||
<div> | ||
<span>Stop struggling with scattered API keys, hacking together home-brewed tools,</span> | ||
<br> | ||
<span>and avoiding access controls. Keep your team and servers in sync with Doppler.</span> | ||
</div> | ||
</a> | ||
</p> | ||
</div> | ||
@@ -19,2 +40,3 @@ | ||
<br> | ||
@@ -27,27 +49,23 @@ ## Install | ||
## Usage | ||
```js | ||
const imagemin = require('imagemin'); | ||
const imageminJpegtran = require('imagemin-jpegtran'); | ||
const imageminPngquant = require('imagemin-pngquant'); | ||
import imagemin from 'imagemin'; | ||
import imageminJpegtran from 'imagemin-jpegtran'; | ||
import imageminPngquant from 'imagemin-pngquant'; | ||
(async () => { | ||
const files = await imagemin(['images/*.{jpg,png}'], { | ||
destination: 'build/images', | ||
plugins: [ | ||
imageminJpegtran(), | ||
imageminPngquant({ | ||
quality: [0.6, 0.8] | ||
}) | ||
] | ||
}); | ||
const files = await imagemin(['images/*.{jpg,png}'], { | ||
destination: 'build/images', | ||
plugins: [ | ||
imageminJpegtran(), | ||
imageminPngquant({ | ||
quality: [0.6, 0.8] | ||
}) | ||
] | ||
}); | ||
console.log(files); | ||
//=> [{data: <Buffer 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …] | ||
})(); | ||
console.log(files); | ||
//=> [{data: <Buffer 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …] | ||
``` | ||
## API | ||
@@ -83,3 +101,3 @@ | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `true` | ||
@@ -86,0 +104,0 @@ |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6915
6
138
Yes
3
+ Added@tokenizer/token@0.1.10.3.0(transitive)
+ Addedfile-type@14.7.1(transitive)
+ Addedglobby@11.1.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedp-pipe@4.0.0(transitive)
+ Addedpeek-readable@4.1.0(transitive)
+ Addedreadable-web-to-node-stream@2.0.0(transitive)
+ Addedreplace-ext@2.0.0(transitive)
+ Addedstrtok3@6.3.0(transitive)
+ Addedtoken-types@2.1.1(transitive)
+ Addedtypedarray-to-buffer@3.1.5(transitive)
- Removedmake-dir@^3.0.0
- Removed@types/glob@7.2.0(transitive)
- Removed@types/minimatch@5.1.2(transitive)
- Removed@types/node@20.14.8(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfile-type@12.4.2(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedglobby@10.0.2(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-pipe@3.1.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedreplace-ext@1.0.1(transitive)
- Removedsemver@6.3.1(transitive)
- Removedundici-types@5.26.5(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedfile-type@^14.6.0
Updatedglobby@^11.0.3
Updatedgraceful-fs@^4.2.6
Updatedp-pipe@^4.0.0
Updatedreplace-ext@^2.0.0