Skip to content

Commit 88bc300

Browse files
authored
feat!: minimum supported webpack version is 5.0.0 (#1389)
1 parent 02a2b33 commit 88bc300

File tree

8 files changed

+4
-143
lines changed

8 files changed

+4
-143
lines changed

.github/workflows/nodejs.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ jobs:
6464
os: [ubuntu-latest, windows-latest, macos-latest]
6565
node-version: [14.x, 16.x, 18.x, 19.x]
6666
webpack-version: [latest]
67-
include:
68-
- node-version: 16.x
69-
os: ubuntu-latest
70-
webpack-version: 4
7167

7268
runs-on: ${{ matrix.os }}
7369

@@ -83,10 +79,6 @@ jobs:
8379
- name: Install dependencies
8480
run: npm ci
8581

86-
- name: Install webpack ${{ matrix.webpack-version }}
87-
if: matrix.webpack-version == '4'
88-
run: npm i webpack@${{ matrix.webpack-version }}
89-
9082
- name: Run tests for webpack version ${{ matrix.webpack-version }}
9183
run: npm run test:coverage -- --ci
9284

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"types"
4545
],
4646
"peerDependencies": {
47-
"webpack": "^4.0.0 || ^5.0.0"
47+
"webpack": "^5.0.0"
4848
},
4949
"dependencies": {
5050
"colorette": "^2.0.10",

src/utils/setupHooks.js

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const webpack = require("webpack");
21
const { isColorSupported } = require("colorette");
32

43
/** @typedef {import("webpack").Configuration} Configuration */
@@ -12,8 +11,6 @@ const { isColorSupported } = require("colorette");
1211
/** @typedef {Configuration["stats"]} StatsOptions */
1312
/** @typedef {{ children: Configuration["stats"][] }} MultiStatsOptions */
1413
/** @typedef {Exclude<Configuration["stats"], boolean | string | undefined>} NormalizedStatsOptions */
15-
// TODO remove `color` after dropping webpack v4
16-
/** @typedef {{ children: StatsOptions[], colors?: any }} MultiNormalizedStatsOptions */
1714

1815
/**
1916
* @template {IncomingMessage} Request
@@ -33,31 +30,11 @@ function setupHooks(context) {
3330
context.stats = undefined;
3431
}
3532

36-
// @ts-ignore
37-
const statsForWebpack4 = webpack.Stats && webpack.Stats.presetToOptions;
38-
3933
/**
4034
* @param {Configuration["stats"]} statsOptions
4135
* @returns {NormalizedStatsOptions}
4236
*/
4337
function normalizeStatsOptions(statsOptions) {
44-
if (statsForWebpack4) {
45-
if (typeof statsOptions === "undefined") {
46-
// eslint-disable-next-line no-param-reassign
47-
statsOptions = {};
48-
} else if (
49-
typeof statsOptions === "boolean" ||
50-
typeof statsOptions === "string"
51-
) {
52-
// @ts-ignore
53-
// eslint-disable-next-line no-param-reassign
54-
statsOptions = webpack.Stats.presetToOptions(statsOptions);
55-
}
56-
57-
// @ts-ignore
58-
return statsOptions;
59-
}
60-
6138
if (typeof statsOptions === "undefined") {
6239
// eslint-disable-next-line no-param-reassign
6340
statsOptions = { preset: "normal" };
@@ -99,7 +76,7 @@ function setupHooks(context) {
9976
);
10077

10178
/**
102-
* @type {StatsOptions | MultiStatsOptions | NormalizedStatsOptions | MultiNormalizedStatsOptions}
79+
* @type {StatsOptions | MultiStatsOptions | NormalizedStatsOptions}
10380
*/
10481
let statsOptions;
10582

@@ -122,7 +99,7 @@ function setupHooks(context) {
12299
}
123100

124101
if (isMultiCompilerMode) {
125-
/** @type {MultiNormalizedStatsOptions} */
102+
/** @type {MultiStatsOptions} */
126103
(statsOptions).children =
127104
/** @type {MultiStatsOptions} */
128105
(statsOptions).children.map(
@@ -153,24 +130,6 @@ function setupHooks(context) {
153130
}
154131
}
155132

156-
// TODO webpack@4 doesn't support `{ children: [{ colors: true }, { colors: true }] }` for stats
157-
if (
158-
/** @type {MultiCompiler} */
159-
(compiler).compilers &&
160-
statsForWebpack4
161-
) {
162-
/** @type {MultiNormalizedStatsOptions} */
163-
(statsOptions).colors =
164-
/** @type {MultiNormalizedStatsOptions} */
165-
(statsOptions).children.some(
166-
/**
167-
* @param {StatsOptions} child
168-
*/
169-
// @ts-ignore
170-
(child) => child.colors
171-
);
172-
}
173-
174133
const printedStats = stats.toString(statsOptions);
175134

176135
// Avoid extra empty line when `stats: 'none'`

src/utils/setupOutputFileSystem.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const path = require("path");
2-
31
const memfs = require("memfs");
42

53
/** @typedef {import("webpack").MultiCompiler} MultiCompiler */
@@ -17,27 +15,9 @@ function setupOutputFileSystem(context) {
1715
if (context.options.outputFileSystem) {
1816
const { outputFileSystem: outputFileSystemFromOptions } = context.options;
1917

20-
// Todo remove when we drop webpack@4 support
21-
if (typeof outputFileSystemFromOptions.join !== "function") {
22-
throw new Error(
23-
"Invalid options: options.outputFileSystem.join() method is expected"
24-
);
25-
}
26-
27-
// Todo remove when we drop webpack@4 support
28-
// @ts-ignore
29-
if (typeof outputFileSystemFromOptions.mkdirp !== "function") {
30-
throw new Error(
31-
"Invalid options: options.outputFileSystem.mkdirp() method is expected"
32-
);
33-
}
34-
3518
outputFileSystem = outputFileSystemFromOptions;
3619
} else {
3720
outputFileSystem = memfs.createFsFromVolume(new memfs.Volume());
38-
// TODO: remove when we drop webpack@4 support
39-
// @ts-ignore
40-
outputFileSystem.join = path.join.bind(path);
4121
}
4222

4323
const compilers =

test/middleware.test.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,8 +3106,6 @@ describe.each([
31063106
expect(new instance.context.outputFileSystem.Stats()).toBeInstanceOf(
31073107
Stats
31083108
);
3109-
expect(compiler.outputFileSystem).toHaveProperty("join");
3110-
expect(compiler.outputFileSystem).toHaveProperty("mkdirp");
31113109
});
31123110
});
31133111

@@ -3221,38 +3219,6 @@ describe.each([
32213219
expect(instance.context.outputFileSystem).toHaveProperty("mkdirp");
32223220
});
32233221
});
3224-
3225-
describe("should throw an error on the invalid fs value - no join method", () => {
3226-
it("should throw an error", () => {
3227-
expect(() => {
3228-
const compiler = getCompiler(webpackConfig);
3229-
3230-
middleware(compiler, {
3231-
outputFileSystem: {
3232-
mkdirp: () => {},
3233-
},
3234-
});
3235-
}).toThrow(
3236-
"Invalid options: options.outputFileSystem.join() method is expected"
3237-
);
3238-
});
3239-
});
3240-
3241-
describe("should throw an error on the invalid fs value - no mkdirp method", () => {
3242-
it("should throw an error", () => {
3243-
expect(() => {
3244-
const compiler = getCompiler(webpackConfig);
3245-
3246-
middleware(compiler, {
3247-
outputFileSystem: {
3248-
join: () => {},
3249-
},
3250-
});
3251-
}).toThrow(
3252-
"Invalid options: options.outputFileSystem.mkdirp() method is expected"
3253-
);
3254-
});
3255-
});
32563222
});
32573223

32583224
describe("index option", () => {

test/utils/setupOutputFileSystem.test.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ describe("setupOutputFileSystem", () => {
2626
// make sure that this is the default fs created
2727
expect(context.compiler.outputFileSystem.testFs).toBeTruthy();
2828
expect(context.outputFileSystem.testFs).toBeTruthy();
29-
// the join value of the fs is set for webpack@4
30-
expect(context.outputFileSystem.join).toBeTruthy();
3129
expect(createFsFromVolume.mock.calls.length).toEqual(1);
3230
});
3331

@@ -46,34 +44,6 @@ describe("setupOutputFileSystem", () => {
4644
});
4745
});
4846

49-
it("should throw on provided fs without join method", () => {
50-
const context = {
51-
compiler: {},
52-
options: {
53-
outputFileSystem: {},
54-
},
55-
};
56-
57-
expect(() => {
58-
setupOutputFileSystem(context);
59-
}).toThrow(/join/);
60-
});
61-
62-
it("should throw on provided fs without mkdirp method", () => {
63-
const context = {
64-
compiler: {},
65-
options: {
66-
outputFileSystem: {
67-
join: () => {},
68-
},
69-
},
70-
};
71-
72-
expect(() => {
73-
setupOutputFileSystem(context);
74-
}).toThrow(/mkdirp/);
75-
});
76-
7747
it("should use provided fs with correct methods", () => {
7848
const context = {
7949
compiler: {},

types/utils/setupHooks.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export = setupHooks;
1010
/** @typedef {Configuration["stats"]} StatsOptions */
1111
/** @typedef {{ children: Configuration["stats"][] }} MultiStatsOptions */
1212
/** @typedef {Exclude<Configuration["stats"], boolean | string | undefined>} NormalizedStatsOptions */
13-
/** @typedef {{ children: StatsOptions[], colors?: any }} MultiNormalizedStatsOptions */
1413
/**
1514
* @template {IncomingMessage} Request
1615
* @template {ServerResponse} Response
@@ -32,7 +31,6 @@ declare namespace setupHooks {
3231
StatsOptions,
3332
MultiStatsOptions,
3433
NormalizedStatsOptions,
35-
MultiNormalizedStatsOptions,
3634
};
3735
}
3836
type Configuration = import("webpack").Configuration;
@@ -50,7 +48,3 @@ type NormalizedStatsOptions = Exclude<
5048
Configuration["stats"],
5149
boolean | string | undefined
5250
>;
53-
type MultiNormalizedStatsOptions = {
54-
children: StatsOptions[];
55-
colors?: any;
56-
};

0 commit comments

Comments
 (0)