Skip to content

Commit

Permalink
build!: minimum supported Node.js version is 18.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 authored Jan 15, 2024
1 parent a893046 commit 53b80b5
Show file tree
Hide file tree
Showing 13 changed files with 7,920 additions and 16,096 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [18.x, 20.x, 21.x]
webpack-version: [latest]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (api) => {
"@babel/preset-env",
{
targets: {
node: "14.15.0",
node: "18.12.0",
},
},
],
Expand Down
23,914 changes: 7,869 additions & 16,045 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"main": "dist/index.js",
"types": "types/index.d.ts",
"engines": {
"node": ">= 14.15.0"
"node": ">= 18.12.0"
},
"scripts": {
"start": "npm run build -- -w",
Expand Down Expand Up @@ -54,28 +54,28 @@
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.7",
"@commitlint/cli": "^17.7.2",
"@commitlint/config-conventional": "^17.7.0",
"@types/node": "^18.15.11",
"@babel/preset-env": "^7.23.8",
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@types/node": "^20.11.2",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-jest": "^29.7.0",
"copy-webpack-plugin": "^9.1.0",
"cross-env": "^7.0.3",
"cspell": "^6.31.2",
"del": "^6.1.1",
"del-cli": "^4.0.1",
"cspell": "^8.3.2",
"del": "^7.1.0",
"del-cli": "^5.1.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.9.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^12.5.0",
"memfs": "^3.5.1",
"lint-staged": "^15.2.0",
"memfs": "^4.6.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"standard-version": "^9.3.1",
"typescript": "^4.9.5",
"prettier": "^3.2.2",
"standard-version": "^9.5.0",
"typescript": "^5.3.3",
"webpack": "^5.89.0"
},
"keywords": [
Expand Down
16 changes: 8 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class JsonMinimizerPlugin {
*/
static buildError(error, file, context) {
return new Error(
`"${file}" in "${context}" from Json Minimizer:\n${error}`
`"${file}" in "${context}" from Json Minimizer:\n${error}`,
);
}

Expand All @@ -105,7 +105,7 @@ class JsonMinimizerPlugin {
!compiler.webpack.ModuleFilenameHelpers.matchObject.bind(
// eslint-disable-next-line no-undefined
undefined,
this.options
this.options,
)(name)
) {
return false;
Expand All @@ -123,7 +123,7 @@ class JsonMinimizerPlugin {
const output = await cacheItem.getPromise();

return { name, info, inputSource: source, output, cacheItem };
})
}),
);

const { RawSource } = compiler.webpack.sources;
Expand Down Expand Up @@ -160,7 +160,7 @@ class JsonMinimizerPlugin {
compilation.errors.push(
/** @type {WebpackError} */ (
JsonMinimizerPlugin.buildError(error, name, compiler.context)
)
),
);

return;
Expand All @@ -177,7 +177,7 @@ class JsonMinimizerPlugin {
const { source } = output;

compilation.updateAsset(name, source, newInfo);
})()
})(),
);
}

Expand All @@ -199,7 +199,7 @@ class JsonMinimizerPlugin {
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
additionalAssets: true,
},
(assets) => this.optimize(compiler, compilation, assets)
(assets) => this.optimize(compiler, compilation, assets),
);

compilation.hooks.statsPrinter.tap(pluginName, (stats) => {
Expand All @@ -210,9 +210,9 @@ class JsonMinimizerPlugin {
(minimized, { green, formatFlag }) =>
minimized
? /** @type {Function} */ (green)(
/** @type {Function} */ (formatFlag)("minimized")
/** @type {Function} */ (formatFlag)("minimized"),
)
: ""
: "",
);
});
});
Expand Down
22 changes: 11 additions & 11 deletions test/JsonMinimizerPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("JsonMinimizerPlugin", () => {
{
loader: path.resolve(
__dirname,
"./helpers/emitAssetInChildCompilationLoader"
"./helpers/emitAssetInChildCompilationLoader",
),
},
],
Expand Down Expand Up @@ -105,19 +105,19 @@ describe("JsonMinimizerPlugin", () => {
const statsErrors = getErrors(stats);

expect(statsErrors[0]).toContain(
`Error: "broken-json-syntax.json" in "/test/fixtures" from Json Minimizer:`
`Error: "broken-json-syntax.json" in "/test/fixtures" from Json Minimizer:`,
);

if (
process.version.startsWith("v19") ||
process.version.startsWith("v20")
process.version.startsWith("v20") ||
process.version.startsWith("v21")
) {
expect(statsErrors[0]).toContain(
`SyntaxError: Expected property name or '}' in JSON at position 4`
`SyntaxError: Expected property name or '}' in JSON at position 4`,
);
} else {
expect(statsErrors[0]).toContain(
`SyntaxError: Unexpected token s in JSON at position 4`
`SyntaxError: Unexpected token s in JSON at position 4`,
);
}

Expand Down Expand Up @@ -149,7 +149,7 @@ describe("JsonMinimizerPlugin", () => {
expect(newStats.compilation.emittedAssets.size).toBe(0);

expect(readAssets(compiler, newStats, /\.json$/i)).toMatchSnapshot(
"assets"
"assets",
);
expect(getWarnings(newStats)).toMatchSnapshot("errors");
expect(getErrors(newStats)).toMatchSnapshot("warnings");
Expand Down Expand Up @@ -183,7 +183,7 @@ describe("JsonMinimizerPlugin", () => {
expect(newStats.compilation.emittedAssets.size).toBe(0);

expect(readAssets(compiler, newStats, /\.json$/i)).toMatchSnapshot(
"assets"
"assets",
);
expect(getWarnings(newStats)).toMatchSnapshot("errors");
expect(getErrors(newStats)).toMatchSnapshot("warnings");
Expand Down Expand Up @@ -217,7 +217,7 @@ describe("JsonMinimizerPlugin", () => {
expect(newStats.compilation.emittedAssets.size).toBe(0);

expect(readAssets(compiler, newStats, /\.json$/i)).toMatchSnapshot(
"assets"
"assets",
);
expect(getWarnings(newStats)).toMatchSnapshot("errors");
expect(getErrors(newStats)).toMatchSnapshot("warnings");
Expand Down Expand Up @@ -254,7 +254,7 @@ describe("JsonMinimizerPlugin", () => {
expect(newStats.compilation.emittedAssets.size).toBe(2);

expect(readAssets(compiler, newStats, /\.json$/i)).toMatchSnapshot(
"assets"
"assets",
);
expect(getWarnings(newStats)).toMatchSnapshot("errors");
expect(getErrors(newStats)).toMatchSnapshot("warnings");
Expand Down Expand Up @@ -288,7 +288,7 @@ describe("JsonMinimizerPlugin", () => {
expect(newStats.compilation.emittedAssets.size).toBe(6);

expect(readAssets(compiler, newStats, /\.json$/i)).toMatchSnapshot(
"assets"
"assets",
);
expect(getWarnings(newStats)).toMatchSnapshot("errors");
expect(getErrors(newStats)).toMatchSnapshot("warnings");
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/EmitNewAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export default class EmitNewAsset {
"secretBase": "Super tower",
"active": true
}
`)
`),
);
}
},
);
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/ModifyExistingAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class ExistingCommentsFile {
compilation.hooks.additionalAssets.tap(plugin, () => {
// eslint-disable-next-line no-param-reassign
compilation.assets[this.options.name] = new RawSource(
JSON.stringify({ modified: true })
JSON.stringify({ modified: true }),
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/emitAssetInChildCompilationLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function loader() {

const childCompiler = this._compilation.createChildCompiler(
`preloader`,
this.options
this.options,
);

new PreCopyPlugin().apply(childCompiler);
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/getCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function getCompiler(jsonFixture, config = {}) {
],
}),
]
: []
: [],
),
module: {
rules: [].concat(
Expand All @@ -49,11 +49,11 @@ export default function getCompiler(jsonFixture, config = {}) {
},
},
]
: []
: [],
),
},
...config,
}
},
);

if (!config.outputFileSystem) {
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/normalizeErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ function removeCWD(str) {

export default (errors) =>
errors.map((error) =>
removeCWD(error.toString().split("\n").slice(0, 2).join("\n"))
removeCWD(error.toString().split("\n").slice(0, 2).join("\n")),
);
2 changes: 1 addition & 1 deletion test/helpers/normalizedSourceMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export default function normalizedSourceMap(map) {
return map.replace(
// eslint-disable-next-line no-useless-escape
/"sources":\[([\d\w\/\:\"\'].*)\]\,\"names\"/i,
`"sources": [replaced for tests], "names"`
`"sources": [replaced for tests], "names"`,
);
}
14 changes: 7 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,8 @@ declare namespace JsonMinimizerPlugin {
InternalPluginOptions,
};
}
type Compiler = import("webpack").Compiler;
type BasePluginOptions = {
test?: Rule | undefined;
include?: Rule | undefined;
exclude?: Rule | undefined;
minimizerOptions?: JSONOptions | undefined;
};
type Schema = import("schema-utils/declarations/validate").Schema;
type Compiler = import("webpack").Compiler;
type Compilation = import("webpack").Compilation;
type Asset = import("webpack").Asset;
type WebpackError = import("webpack").WebpackError;
Expand All @@ -96,6 +90,12 @@ type JSONOptions = {
| undefined;
space?: string | number | undefined;
};
type BasePluginOptions = {
test?: Rule | undefined;
include?: Rule | undefined;
exclude?: Rule | undefined;
minimizerOptions?: JSONOptions | undefined;
};
type MinimizedResult = {
code: string;
};
Expand Down

0 comments on commit 53b80b5

Please sign in to comment.