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

[WIP] Drop node 10 and webpack 4 #2834

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 1 addition & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [10.x, 12.x, 14.x, 16.x]
webpack-version: [4, latest]
node-version: [12.x, 14.x, 16.x]
dev-server-version: [latest, next]
exclude:
- node-version: 10.x
Expand Down Expand Up @@ -85,9 +84,6 @@ jobs:
- name: Install dependencies
run: yarn

- name: Install webpack ${{ matrix.webpack-version }}
run: yarn add -W webpack@${{ matrix.webpack-version }}

- name: Install webpack-dev-server ${{ matrix.webpack-version }}
run: yarn add -W webpack-dev-server@${{ matrix.dev-server-version }}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/webpack/webpack-cli.git"
},
"engines": {
"node": ">=10.13.0"
"node": ">=12.13.0"
},
"keywords": [
"webpack",
Expand Down
220 changes: 8 additions & 212 deletions packages/webpack-cli/lib/webpack-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,111 +568,6 @@ class WebpackCLI {
alias: "j",
description: "Prints result as JSON or store it in a file.",
},

// For webpack@4
{
name: "entry",
configs: [
{
type: "string",
},
],
multiple: true,
description: "The entry point(s) of your application e.g. ./src/main.js.",
},
{
name: "output-path",
alias: "o",
configs: [
{
type: "string",
},
],
description: "Output location of the file generated by webpack e.g. ./dist/.",
},
{
name: "target",
alias: "t",
configs: [
{
type: "string",
},
],
multiple: this.webpack.cli !== undefined,
description: "Sets the build target e.g. node.",
},
{
name: "devtool",
configs: [
{
type: "string",
},
{
type: "enum",
values: [false],
},
],
negative: true,
alias: "d",
description: "Determine source maps to use.",
negatedDescription: "Do not generate source maps.",
},
{
name: "mode",
configs: [
{
type: "string",
},
],
description: "Defines the mode to pass to webpack.",
},
{
name: "name",
configs: [
{
type: "string",
},
],
description:
"Name of the configuration. Used when loading multiple configurations.",
},
{
name: "stats",
configs: [
{
type: "string",
},
{
type: "boolean",
},
],
negative: true,
description: "It instructs webpack on how to treat the stats e.g. verbose.",
negatedDescription: "Disable stats output.",
},
{
name: "watch",
configs: [
{
type: "boolean",
},
],
negative: true,
alias: "w",
description: "Watch for files changes.",
negatedDescription: "Do not watch for file changes.",
},
{
name: "watch-options-stdin",
configs: [
{
type: "boolean",
},
],
negative: true,
description: "Stop watching when stdin stream has ended.",
negatedDescription: "Do not stop watching when stdin stream has ended.",
},
];

// Extract all the flags being exported from core.
Expand Down Expand Up @@ -1886,103 +1781,16 @@ class WebpackCLI {
: setupDefaultOptions(config.options);
}

// Logic for webpack@4
// TODO remove after drop webpack@4
const processLegacyArguments = (configOptions) => {
if (options.entry) {
configOptions.entry = options.entry;
}

if (options.outputPath) {
configOptions.output = {
...configOptions.output,
...{ path: path.resolve(options.outputPath) },
};
}

if (options.target) {
configOptions.target = options.target;
}

if (typeof options.devtool !== "undefined") {
configOptions.devtool = options.devtool;
}

if (options.mode) {
configOptions.mode = options.mode;
} else if (
!configOptions.mode &&
process.env &&
process.env.NODE_ENV &&
(process.env.NODE_ENV === "development" ||
process.env.NODE_ENV === "production" ||
process.env.NODE_ENV === "none")
) {
configOptions.mode = process.env.NODE_ENV;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep these logic, for procee.env.NODE_ENV


if (options.name) {
configOptions.name = options.name;
}

if (typeof options.stats !== "undefined") {
configOptions.stats = options.stats;
}

if (typeof options.watch !== "undefined") {
configOptions.watch = options.watch;
}

if (typeof options.watchOptionsStdin !== "undefined") {
configOptions.watchOptions = {
...configOptions.watchOptions,
...{ stdin: options.watchOptionsStdin },
};
}

return configOptions;
};

config.options = Array.isArray(config.options)
? config.options.map((options) => processLegacyArguments(options))
: processLegacyArguments(config.options);

// Apply `stats` and `stats.colors` options
const applyStatsColors = (configOptions) => {
// TODO remove after drop webpack@4
const statsForWebpack4 = this.webpack.Stats && this.webpack.Stats.presetToOptions;

if (statsForWebpack4) {
if (typeof configOptions.stats === "undefined") {
configOptions.stats = {};
} else if (
typeof configOptions.stats === "boolean" ||
typeof configOptions.stats === "string"
) {
if (
typeof configOptions.stats === "string" &&
configOptions.stats !== "none" &&
configOptions.stats !== "verbose" &&
configOptions.stats !== "detailed" &&
configOptions.stats !== "minimal" &&
configOptions.stats !== "errors-only" &&
configOptions.stats !== "errors-warnings"
) {
return configOptions;
}

configOptions.stats = this.webpack.Stats.presetToOptions(configOptions.stats);
}
} else {
if (typeof configOptions.stats === "undefined") {
configOptions.stats = { preset: "normal" };
} else if (typeof configOptions.stats === "boolean") {
configOptions.stats = configOptions.stats
? { preset: "normal" }
: { preset: "none" };
} else if (typeof configOptions.stats === "string") {
configOptions.stats = { preset: configOptions.stats };
}
if (typeof configOptions.stats === "undefined") {
configOptions.stats = { preset: "normal" };
} else if (typeof configOptions.stats === "boolean") {
configOptions.stats = configOptions.stats
? { preset: "normal" }
: { preset: "none" };
} else if (typeof configOptions.stats === "string") {
configOptions.stats = { preset: configOptions.stats };
}

let colors;
Expand Down Expand Up @@ -2094,11 +1902,6 @@ class WebpackCLI {
process.exit(2);
}

// TODO webpack@4 return Watching and MultiWatching instead Compiler and MultiCompiler, remove this after drop webpack@4
if (compiler && compiler.compiler) {
compiler = compiler.compiler;
}

return compiler;
}

Expand Down Expand Up @@ -2137,13 +1940,6 @@ class WebpackCLI {
? compiler.options.stats
: undefined;

// TODO webpack@4 doesn't support `{ children: [{ colors: true }, { colors: true }] }` for stats
const statsForWebpack4 = this.webpack.Stats && this.webpack.Stats.presetToOptions;

if (compiler.compilers && statsForWebpack4) {
statsOptions.colors = statsOptions.children.some((child) => child.colors);
}

if (options.json && createJsonStringifyStream) {
const handleWriteError = (error) => {
this.logger.error(error);
Expand Down
31 changes: 0 additions & 31 deletions test/api/__snapshots__/CLI.test.js.snap.webpack4

This file was deleted.

20 changes: 0 additions & 20 deletions test/api/__snapshots__/scaffold-utils.test.js.snap.webpack4

This file was deleted.

Loading