Comparing version 8.0.1 to 9.0.0
52
index.js
@@ -1,30 +0,25 @@ | ||
import {Buffer} from 'node:buffer'; | ||
import {promises as fsPromises} from 'node:fs'; | ||
import {promisify} from 'node:util'; | ||
import fsPromises from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import fs from 'graceful-fs'; | ||
import FileType from 'file-type'; | ||
import {fileTypeFromBuffer} from 'file-type'; | ||
import {globby} from 'globby'; | ||
import pPipe from 'p-pipe'; | ||
import replaceExt from 'replace-ext'; | ||
import junk from 'junk'; | ||
import changeFileExtension from 'change-file-extension'; | ||
import {isNotJunk} from 'junk'; | ||
import convertToUnixPath from 'slash'; | ||
import {assertUint8Array} from 'uint8array-extras'; | ||
import {isBrowser} from 'environment'; | ||
import ow from 'ow'; | ||
const readFile = promisify(fs.readFile); | ||
const writeFile = promisify(fs.writeFile); | ||
const handleFile = async (sourcePath, {destination, plugins = []}) => { | ||
if (plugins && !Array.isArray(plugins)) { | ||
throw new TypeError('The `plugins` option should be an `Array`'); | ||
} | ||
ow(plugins, ow.optional.array.message('The `plugins` option should be an `Array`')); | ||
let data = await readFile(sourcePath); | ||
let data = await fsPromises.readFile(sourcePath); | ||
data = await (plugins.length > 0 ? pPipe(...plugins)(data) : data); | ||
const {ext} = await FileType.fromBuffer(data) || {ext: path.extname(sourcePath)}; | ||
const {ext} = await fileTypeFromBuffer(data) ?? {ext: path.extname(sourcePath)}; | ||
let destinationPath = destination ? path.join(destination, path.basename(sourcePath)) : undefined; | ||
destinationPath = ext === 'webp' ? replaceExt(destinationPath, '.webp') : destinationPath; | ||
destinationPath = ext === 'webp' ? changeFileExtension(destinationPath, 'webp') : destinationPath; | ||
const returnValue = { | ||
data, | ||
data: new Uint8Array(data), | ||
sourcePath, | ||
@@ -39,3 +34,3 @@ destinationPath, | ||
await fsPromises.mkdir(path.dirname(returnValue.destinationPath), {recursive: true}); | ||
await writeFile(returnValue.destinationPath, returnValue.data); | ||
await fsPromises.writeFile(returnValue.destinationPath, returnValue.data); | ||
@@ -46,6 +41,8 @@ return returnValue; | ||
export default async function imagemin(input, {glob = true, ...options} = {}) { | ||
if (!Array.isArray(input)) { | ||
throw new TypeError(`Expected an \`Array\`, got \`${typeof input}\``); | ||
if (isBrowser) { | ||
throw new Error('This package does not work in the browser.'); | ||
} | ||
ow(input, ow.array); | ||
const unixFilePaths = input.map(path => convertToUnixPath(path)); | ||
@@ -56,3 +53,3 @@ const filePaths = glob ? await globby(unixFilePaths, {onlyFiles: true}) : input; | ||
filePaths | ||
.filter(filePath => junk.not(path.basename(filePath))) | ||
.filter(filePath => isNotJunk(path.basename(filePath))) | ||
.map(async filePath => { | ||
@@ -69,12 +66,15 @@ try { | ||
imagemin.buffer = async (input, {plugins = []} = {}) => { | ||
if (!Buffer.isBuffer(input)) { | ||
throw new TypeError(`Expected a \`Buffer\`, got \`${typeof input}\``); | ||
imagemin.buffer = async (data, {plugins = []} = {}) => { | ||
if (isBrowser) { | ||
throw new Error('This package does not work in the browser.'); | ||
} | ||
assertUint8Array(data); | ||
if (plugins.length === 0) { | ||
return input; | ||
return new Uint8Array(data); | ||
} | ||
return pPipe(...plugins)(input); | ||
// The `new Uint8Array` can be removed if all plugins are changed to return `Uint8Array` instead of `Buffer`. | ||
return new Uint8Array(await pPipe(...plugins)(data)); | ||
}; |
{ | ||
"name": "imagemin", | ||
"version": "8.0.1", | ||
"version": "9.0.0", | ||
"description": "Minify images seamlessly", | ||
"license": "MIT", | ||
"repository": "imagemin/imagemin", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=18" | ||
}, | ||
@@ -30,20 +31,21 @@ "scripts": { | ||
"dependencies": { | ||
"file-type": "^16.5.3", | ||
"globby": "^12.0.0", | ||
"graceful-fs": "^4.2.8", | ||
"junk": "^3.1.0", | ||
"change-file-extension": "^0.1.1", | ||
"environment": "^1.0.0", | ||
"file-type": "^19.0.0", | ||
"globby": "^14.0.1", | ||
"junk": "^4.0.1", | ||
"ow": "^2.0.0", | ||
"p-pipe": "^4.0.0", | ||
"replace-ext": "^2.0.0", | ||
"slash": "^3.0.0" | ||
"slash": "^5.1.0", | ||
"uint8array-extras": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"del": "^6.0.0", | ||
"ava": "^6.1.2", | ||
"del": "^7.1.0", | ||
"imagemin-jpegtran": "^7.0.0", | ||
"imagemin-svgo": "^9.0.0", | ||
"imagemin-webp": "^6.0.0", | ||
"is-jpg": "^2.0.0", | ||
"tempy": "^1.0.1", | ||
"xo": "^0.43.0" | ||
"imagemin-svgo": "^10.0.1", | ||
"imagemin-webp": "^8.0.0", | ||
"tempy": "^3.1.0", | ||
"xo": "^0.58.0" | ||
} | ||
} |
@@ -24,15 +24,2 @@ # imagemin | ||
<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> | ||
<br> | ||
<a href="https://strapi.io/?ref=sindresorhus"> | ||
@@ -56,5 +43,5 @@ <div> | ||
```sh | ||
npm install imagemin | ||
``` | ||
$ npm install imagemin | ||
``` | ||
@@ -79,3 +66,3 @@ ## Usage | ||
console.log(files); | ||
//=> [{data: <Buffer 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …] | ||
//=> [{data: <Uint8Array 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …] | ||
``` | ||
@@ -87,3 +74,3 @@ | ||
Returns `Promise<object[]>` in the format `{data: Buffer, sourcePath: string, destinationPath: string}`. | ||
Returns `Promise<object[]>` in the format `{data: Uint8Array, sourcePath: string, destinationPath: string}`. | ||
@@ -110,3 +97,3 @@ #### input | ||
[Plugins](https://www.npmjs.com/browse/keyword/imageminplugin) to use. | ||
The [plugins](https://www.npmjs.com/browse/keyword/imageminplugin) to use. | ||
@@ -120,11 +107,11 @@ ##### glob | ||
### imagemin.buffer(buffer, options?) | ||
### imagemin.buffer(data, options?) | ||
Returns `Promise<Buffer>`. | ||
Returns `Promise<Uint8Array>`. | ||
#### buffer | ||
#### data | ||
Type: `Buffer` | ||
Type: `Uint8Array` | ||
Buffer to optimize. | ||
The image data to optimize. | ||
@@ -144,4 +131,2 @@ #### options | ||
- [imagemin-cli](https://github.com/imagemin/imagemin-cli) - CLI for this module | ||
- [imagemin-app](https://github.com/imagemin/imagemin-app) - GUI app for this module | ||
- [gulp-imagemin](https://github.com/sindresorhus/gulp-imagemin) - Gulp plugin | ||
- [grunt-contrib-imagemin](https://github.com/gruntjs/grunt-contrib-imagemin) - Grunt plugin |
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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
7
1
6730
9
61
126
+ Addedchange-file-extension@^0.1.1
+ Addedenvironment@^1.0.0
+ Addedow@^2.0.0
+ Addeduint8array-extras@^1.1.0
+ Added@sec-ant/readable-stream@0.4.1(transitive)
+ Added@sindresorhus/is@6.3.1(transitive)
+ Added@sindresorhus/merge-streams@2.3.0(transitive)
+ Addedcallsites@4.2.0(transitive)
+ Addedchange-file-extension@0.1.1(transitive)
+ Addedconvert-hrtime@5.0.0(transitive)
+ Addeddot-prop@8.0.2(transitive)
+ Addedenvironment@1.1.0(transitive)
+ Addedfast-equals@5.0.1(transitive)
+ Addedfile-type@19.6.0(transitive)
+ Addedfunction-timeout@1.0.2(transitive)
+ Addedget-stream@9.0.1(transitive)
+ Addedglobby@14.0.2(transitive)
+ Addedidentifier-regex@1.0.0(transitive)
+ Addedis-identifier@1.0.1(transitive)
+ Addedis-stream@4.0.1(transitive)
+ Addedjunk@4.0.1(transitive)
+ Addedow@2.0.0(transitive)
+ Addedpath-type@5.0.0(transitive)
+ Addedpeek-readable@5.3.1(transitive)
+ Addedreserved-identifiers@1.0.0(transitive)
+ Addedslash@5.1.0(transitive)
+ Addedstrtok3@9.0.1(transitive)
+ Addedsuper-regex@1.0.0(transitive)
+ Addedtime-span@5.1.0(transitive)
+ Addedtoken-types@6.0.0(transitive)
+ Addedtype-fest@3.13.1(transitive)
+ Addeduint8array-extras@1.4.0(transitive)
+ Addedunicorn-magic@0.1.0(transitive)
- Removedgraceful-fs@^4.2.8
- Removedreplace-ext@^2.0.0
- Removedarray-union@3.0.1(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removedfile-type@16.5.4(transitive)
- Removedglobby@12.2.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedinherits@2.0.4(transitive)
- Removedjunk@3.1.0(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpeek-readable@4.1.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedreadable-web-to-node-stream@3.0.2(transitive)
- Removedreplace-ext@2.0.0(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedslash@3.0.04.0.0(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrtok3@6.3.0(transitive)
- Removedtoken-types@4.2.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updatedfile-type@^19.0.0
Updatedglobby@^14.0.1
Updatedjunk@^4.0.1
Updatedslash@^5.1.0