Skip to content

Commit c3ca150

Browse files
committed
perf(webpack-cli): defer CLI require until after local-install check
bin/cli.js required both `import-local` and the full CLI implementation up front. Reorder so: - a run delegated to a local install returns without loading the outer installation's CLI lib (+commander), and - WEBPACK_CLI_SKIP_IMPORT_LOCAL short-circuits before requiring `import-local` at all (10 fewer modules loaded on that path). The typical local invocation is unchanged. Behavior is preserved (import-local still runs by default). https://claude.ai/code/session_01TKJqMqs6zkot18iBUae52n
1 parent 6e1e3fc commit c3ca150

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack-cli": patch
3+
---
4+
5+
Defer requiring the CLI implementation until after the local-installation check in the `webpack` bin. A run delegated to a local `webpack-cli` no longer loads the outer installation's modules, and `WEBPACK_CLI_SKIP_IMPORT_LOCAL` now also skips loading `import-local` itself.

packages/webpack-cli/bin/cli.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
"use strict";
44

5-
const importLocal = require("import-local");
5+
// Prefer the local installation of `webpack-cli` when one exists. Run this
6+
// before requiring the (heavier) CLI implementation: a delegated run then never
7+
// loads it, and `WEBPACK_CLI_SKIP_IMPORT_LOCAL` skips loading `import-local` too.
8+
if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL && require("import-local")(__filename)) {
9+
return;
10+
}
11+
12+
process.title = "webpack";
13+
614
const WebpackCLI = require("../lib/webpack-cli").default;
715

816
const runCLI = async (args) => {
@@ -16,14 +24,5 @@ const runCLI = async (args) => {
1624
}
1725
};
1826

19-
if (
20-
!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL && // Prefer the local installation of `webpack-cli`
21-
importLocal(__filename)
22-
) {
23-
return;
24-
}
25-
26-
process.title = "webpack";
27-
2827
// eslint-disable-next-line unicorn/prefer-top-level-await
2928
runCLI(process.argv);

0 commit comments

Comments
 (0)