Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Update to Node 14 #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This is a simple plugin that uses [Imagemin](https://github.com/imagemin/imagemi

`npm install imagemin-webpack-plugin`

Requires node >=4.0.0
Requires node >=14.0.0

## Example Usage

Expand Down
64 changes: 34 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@
"prepublishOnly": "babel src --out-dir dist --copy-files --source-maps"
},
"engines": {
"node": ">=8.0.0"
"node": ">=14.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Klathmon/imagemin-webpack-plugin.git"
},
"standard": {},
"babel": {
"plugins": [
"transform-runtime",
"transform-object-rest-spread"
"@babel/plugin-transform-runtime"
],
"presets": [
[
"env",
"@babel/preset-env",
{
"targets": {
"node": 8
"node": 14
}
}
]
Expand All @@ -43,35 +41,41 @@
"bugs": {
"url": "https://github.com/Klathmon/imagemin-webpack-plugin/issues"
},
"standard": {
"ignore": [
"*.ts"
]
},
"homepage": "https://github.com/Klathmon/imagemin-webpack-plugin#readme",
"dependencies": {
"@types/imagemin-gifsicle": "^5.2.0",
"@types/imagemin-jpegtran": "^5.0.0",
"@types/imagemin-optipng": "^5.2.0",
"@types/imagemin-svgo": "^7.0.0",
"@types/webpack": "^4.4.24",
"async-throttle": "^1.1.0",
"babel-runtime": "^6.18.0",
"imagemin": "^6.1.0",
"imagemin-gifsicle": "^6.0.1",
"imagemin-jpegtran": "^6.0.0",
"imagemin-optipng": "^7.0.0",
"imagemin-pngquant": "^6.0.0",
"imagemin-svgo": "^7.0.0",
"imagemin": "^7.0.1",
"imagemin-gifsicle": "^7.0.0",
"imagemin-jpegtran": "^7.0.0",
"imagemin-optipng": "^8.0.0",
"imagemin-pngquant": "^9.0.2",
"imagemin-svgo": "^9.0.0",
"lodash.map": "^4.6.0",
"minimatch": "^3.0.4",
"mkdirp": "^0.5.1",
"util.promisify": "^1.0.0",
"webpack-sources": "^1.1.0"
"minimatch": "^5.1.0",
"mkdirp": "^1.0.4",
"util.promisify": "^1.1.1",
"webpack-sources": "^3.2.3"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^8.2.6",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"np": "^2.20.1",
"rimraf": "^2.6.2",
"standard": "^11.0.1"
"@babel/cli": "^7.17.10",
"@babel/core": "^7.18.0",
"@babel/eslint-parser": "^7.17.0",
"@babel/plugin-transform-runtime": "^7.18.0",
"@babel/preset-env": "^7.18.0",
"@babel/runtime": "^7.18.0",
"@types/imagemin-gifsicle": "^7.0.1",
"@types/imagemin-jpegtran": "^5.0.0",
"@types/imagemin-optipng": "^5.2.0",
"@types/imagemin-svgo": "^9.0.1",
"@types/webpack": "^5.28.0",
"eslint": "^8.16.0",
"np": "^7.6.1",
"rimraf": "^3.0.2",
"standard": "^17.0.0"
}
}
2 changes: 1 addition & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function buildTestFunction (rawTestValue, minFileSize, maxFileSize) {
* @return {Boolean}
*/
return (filename, assetSource) => {
for (let func of testFunctions) {
for (const func of testFunctions) {
if (func(filename) === true) {
return assetSource.length > minFileSize && assetSource.length <= maxFileSize
}
Expand Down
71 changes: 35 additions & 36 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
import { Options as GifsicleOptions } from 'imagemin-gifsicle';
import { Options as JpegTranOptions } from 'imagemin-jpegtran';
import { Options as OptiPngOptions } from 'imagemin-optipng';
import { Options as SvgoOptions } from 'imagemin-svgo';
import {Options as GifsicleOptions} from 'imagemin-gifsicle';
import {Options as JpegTranOptions} from 'imagemin-jpegtran';
import {Options as OptiPngOptions} from 'imagemin-optipng';
import {Options as SvgoOptions} from 'imagemin-svgo';
import {EntryPlugin} from 'webpack';

import { Plugin } from 'webpack';

export default ImageminWebpackPlugin;

declare class ImageminWebpackPlugin extends Plugin {
constructor(options: ImageminWebpackPlugin.Options);
declare class ImageminWebpackPlugin extends EntryPlugin {
constructor(options: ImageminWebpackPlugin.Options);
}

declare namespace ImageminWebpackPlugin {
type TestOption = RegExp | string | ((file: string) => boolean);
type TestOption = RegExp | string | ((file: string) => boolean);

// Generic options for plugins missing typings
interface ExternalOptions {
[key: string]: any;
}
// Generic options for plugins missing typings
interface ExternalOptions {
[key: string]: any;
}

interface Options {
disable?: boolean;
test?: TestOption | TestOption[];
maxConcurrency?: number;
optipng?: OptiPngOptions | null;
gifsicle?: GifsicleOptions | null;
jpegtran?: JpegTranOptions | null;
svgo?: SvgoOptions | null;
pngquant?: ExternalOptions | null;
plugins?: Promise<Buffer>[] | [];
externalImages?: {
context: string;
sources: string[] | (() => string[]);
destination?: string | (() => string);
fileName?: string | null;
};
minFileSize?: number;
maxFileSize?: number;
cacheFolder?: string;
onlyUseIfSmaller?: boolean;
}
interface Options {
disable?: boolean;
test?: TestOption | TestOption[];
maxConcurrency?: number;
optipng?: OptiPngOptions | null;
gifsicle?: GifsicleOptions | null;
jpegtran?: JpegTranOptions | null;
svgo?: SvgoOptions | null;
pngquant?: ExternalOptions | null;
plugins?: Promise<Buffer>[] | [];
externalImages?: {
context: string;
sources: string[] | (() => string[]);
destination?: string | (() => string);
fileName?: string | null;
};
minFileSize?: number;
maxFileSize?: number;
cacheFolder?: string;
onlyUseIfSmaller?: boolean;
}
}

export default ImageminWebpackPlugin;
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'path'
import { cpus } from 'os'
import map from 'lodash.map'
import imageminSvgo from 'imagemin-svgo'
import createThrottle from 'async-throttle'
import imageminSvgo from 'imagemin-svgo'
import imageminOptipng from 'imagemin-optipng'
import imageminPngquant from 'imagemin-pngquant'
import imageminGifsicle from 'imagemin-gifsicle'
import imageminJpegtran from 'imagemin-jpegtran'
import map from 'lodash.map'
import path from 'path'
import { cpus } from 'os'
import RawSource from 'webpack-sources/lib/RawSource'

import {
Expand Down Expand Up @@ -64,7 +64,7 @@ export default class ImageminPlugin {

// As long as the options aren't `null` then include the plugin. Let the destructuring above
// control whether the plugin is included by default or not.
for (let [plugin, pluginOptions] of [
for (const [plugin, pluginOptions] of [
[imageminOptipng, optipng],
[imageminGifsicle, gifsicle],
[imageminJpegtran, jpegtran],
Expand Down Expand Up @@ -138,7 +138,7 @@ export default class ImageminPlugin {
if (testFunction(filename, assetSource)) {
// Use the helper function to get the file from cache if possible, or
// run the optimize function and store it in the cache when done
let optimizedImageBuffer = await getFromCacheIfPossible(cacheFolder, assetSource, () => {
const optimizedImageBuffer = await getFromCacheIfPossible(cacheFolder, assetSource, () => {
return optimizeImage(assetSource, this.options)
})

Expand Down Expand Up @@ -176,7 +176,7 @@ export default class ImageminPlugin {
if (testFunction(filename, fileData)) {
// Use the helper function to get the file from cache if possible, or
// run the optimize function and store it in the cache when done
let optimizedImageBuffer = await getFromCacheIfPossible(cacheFolder, fileData, async () => {
const optimizedImageBuffer = await getFromCacheIfPossible(cacheFolder, fileData, async () => {
return optimizeImage(fileData, this.options.imageminOptions)
})

Expand Down
Loading