mirror of https://github.com/webpack/webpack.git
perf: avoid extra jobs for build dependencies (#19905)
This commit is contained in:
parent
a796d25769
commit
ab9f78b8f6
|
@ -45,8 +45,8 @@ let FS_ACCURACY = 2000;
|
||||||
|
|
||||||
const EMPTY_SET = new Set();
|
const EMPTY_SET = new Set();
|
||||||
|
|
||||||
const RBDT_RESOLVE_CJS = 0;
|
const RBDT_RESOLVE_INITIAL = 0;
|
||||||
const RBDT_RESOLVE_ESM = 1;
|
const RBDT_RESOLVE_FILE = 1;
|
||||||
const RBDT_RESOLVE_DIRECTORY = 2;
|
const RBDT_RESOLVE_DIRECTORY = 2;
|
||||||
const RBDT_RESOLVE_CJS_FILE = 3;
|
const RBDT_RESOLVE_CJS_FILE = 3;
|
||||||
const RBDT_RESOLVE_CJS_FILE_AS_CHILD = 4;
|
const RBDT_RESOLVE_CJS_FILE_AS_CHILD = 4;
|
||||||
|
@ -56,7 +56,7 @@ const RBDT_FILE = 7;
|
||||||
const RBDT_DIRECTORY_DEPENDENCIES = 8;
|
const RBDT_DIRECTORY_DEPENDENCIES = 8;
|
||||||
const RBDT_FILE_DEPENDENCIES = 9;
|
const RBDT_FILE_DEPENDENCIES = 9;
|
||||||
|
|
||||||
/** @typedef {RBDT_RESOLVE_CJS | RBDT_RESOLVE_ESM | RBDT_RESOLVE_DIRECTORY | RBDT_RESOLVE_CJS_FILE | RBDT_RESOLVE_CJS_FILE_AS_CHILD | RBDT_RESOLVE_ESM_FILE | RBDT_DIRECTORY | RBDT_FILE | RBDT_DIRECTORY_DEPENDENCIES | RBDT_FILE_DEPENDENCIES} JobType */
|
/** @typedef {RBDT_RESOLVE_INITIAL | RBDT_RESOLVE_FILE | RBDT_RESOLVE_DIRECTORY | RBDT_RESOLVE_CJS_FILE | RBDT_RESOLVE_CJS_FILE_AS_CHILD | RBDT_RESOLVE_ESM_FILE | RBDT_DIRECTORY | RBDT_FILE | RBDT_DIRECTORY_DEPENDENCIES | RBDT_FILE_DEPENDENCIES} JobType */
|
||||||
|
|
||||||
const INVALID = Symbol("invalid");
|
const INVALID = Symbol("invalid");
|
||||||
|
|
||||||
|
@ -1623,16 +1623,12 @@ class FileSystemInfo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Job} job job
|
* @param {Job} job job
|
||||||
* @returns {`resolve commonjs file ${string}${string}`|`resolve esm file ${string}${string}`|`resolve esm ${string}${string}`|`resolve directory ${string}`|`file ${string}`|`unknown ${string} ${string}`|`resolve commonjs ${string}${string}`|`directory ${string}`|`file dependencies ${string}`|`directory dependencies ${string}`} result
|
* @returns {string} result
|
||||||
*/
|
*/
|
||||||
const jobToString = (job) => {
|
const jobToString = (job) => {
|
||||||
switch (job.type) {
|
switch (job.type) {
|
||||||
case RBDT_RESOLVE_CJS:
|
case RBDT_RESOLVE_FILE:
|
||||||
return `resolve commonjs ${job.path}${expectedToString(
|
return `resolve file ${job.path}${expectedToString(job.expected)}`;
|
||||||
job.expected
|
|
||||||
)}`;
|
|
||||||
case RBDT_RESOLVE_ESM:
|
|
||||||
return `resolve esm ${job.path}${expectedToString(job.expected)}`;
|
|
||||||
case RBDT_RESOLVE_DIRECTORY:
|
case RBDT_RESOLVE_DIRECTORY:
|
||||||
return `resolve directory ${job.path}`;
|
return `resolve directory ${job.path}`;
|
||||||
case RBDT_RESOLVE_CJS_FILE:
|
case RBDT_RESOLVE_CJS_FILE:
|
||||||
|
@ -1674,7 +1670,7 @@ class FileSystemInfo {
|
||||||
deps,
|
deps,
|
||||||
(dep) =>
|
(dep) =>
|
||||||
/** @type {Job} */ ({
|
/** @type {Job} */ ({
|
||||||
type: RBDT_RESOLVE_CJS,
|
type: RBDT_RESOLVE_INITIAL,
|
||||||
context,
|
context,
|
||||||
path: dep,
|
path: dep,
|
||||||
expected: undefined,
|
expected: undefined,
|
||||||
|
@ -1778,27 +1774,23 @@ class FileSystemInfo {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
switch (type) {
|
const resolvedType =
|
||||||
case RBDT_RESOLVE_CJS: {
|
type === RBDT_RESOLVE_INITIAL
|
||||||
const isDirectory = /[\\/]$/.test(path);
|
? /[\\/]$/.test(path)
|
||||||
if (isDirectory) {
|
? RBDT_RESOLVE_DIRECTORY
|
||||||
resolveDirectory(path.slice(0, -1));
|
: RBDT_RESOLVE_FILE
|
||||||
} else {
|
: type;
|
||||||
resolveFile(path, "f", resolveCjs);
|
switch (resolvedType) {
|
||||||
}
|
case RBDT_RESOLVE_FILE: {
|
||||||
break;
|
resolveFile(
|
||||||
}
|
path,
|
||||||
case RBDT_RESOLVE_ESM: {
|
"f",
|
||||||
const isDirectory = /[\\/]$/.test(path);
|
/\.mjs$/.test(path) ? resolveEsm : resolveCjs
|
||||||
if (isDirectory) {
|
);
|
||||||
resolveDirectory(path.slice(0, -1));
|
|
||||||
} else {
|
|
||||||
resolveFile(path);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RBDT_RESOLVE_DIRECTORY: {
|
case RBDT_RESOLVE_DIRECTORY: {
|
||||||
resolveDirectory(path);
|
resolveDirectory(RBDT_RESOLVE_INITIAL ? path.slice(0, -1) : path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RBDT_RESOLVE_CJS_FILE: {
|
case RBDT_RESOLVE_CJS_FILE: {
|
||||||
|
@ -1963,6 +1955,7 @@ class FileSystemInfo {
|
||||||
const context = dirname(this.fs, path);
|
const context = dirname(this.fs, path);
|
||||||
const source = /** @type {Buffer} */ (content).toString();
|
const source = /** @type {Buffer} */ (content).toString();
|
||||||
const [imports] = lexer.parse(source);
|
const [imports] = lexer.parse(source);
|
||||||
|
const added = new Set();
|
||||||
for (const imp of imports) {
|
for (const imp of imports) {
|
||||||
try {
|
try {
|
||||||
let dependency;
|
let dependency;
|
||||||
|
@ -1985,6 +1978,8 @@ class FileSystemInfo {
|
||||||
// We should not track Node.js build dependencies
|
// We should not track Node.js build dependencies
|
||||||
if (dependency.startsWith("node:")) continue;
|
if (dependency.startsWith("node:")) continue;
|
||||||
if (builtinModules.has(dependency)) continue;
|
if (builtinModules.has(dependency)) continue;
|
||||||
|
// Avoid extra jobs for identical imports
|
||||||
|
if (added.has(dependency)) continue;
|
||||||
|
|
||||||
push({
|
push({
|
||||||
type: RBDT_RESOLVE_ESM_FILE,
|
type: RBDT_RESOLVE_ESM_FILE,
|
||||||
|
|
Loading…
Reference in New Issue