Skip to content

Commit 29d86ab

Browse files
authored
refactor: centralize esm dependency category (#22316)
1 parent 581d97f commit 29d86ab

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎lib/Compilation.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,6 @@ const { toError } = ErrorHelpers;
546546
/** @type {AssetInfo} */
547547
const EMPTY_ASSET_INFO = Object.freeze({});
548548

549-
const esmDependencyCategory = "esm";
550-
551549
// TODO in the next major release: remove
552550
const deprecatedNormalModuleLoaderHook = util.deprecate(
553551
/**
@@ -2197,7 +2195,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
21972195
// mostly esm dependencies would be used
21982196
// so we don't allocate extra string for them
21992197
const cacheKey =
2200-
category === esmDependencyCategory
2198+
category === Dependency.ESM_CATEGORY
22012199
? resourceIdent
22022200
: `${category}${resourceIdent}`;
22032201
let list = /** @type {FactoryCacheValue} */ (factoryCacheValue).get(

‎lib/graph/Dependency.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ const LAZY_UNTIL_ID = /** @type {"id"} */ ("id");
120120
const LAZY_UNTIL_FALLBACK = /** @type {"*"} */ ("*");
121121
const LAZY_UNTIL_REQUEST = /** @type {"@"} */ ("@");
122122

123+
/**
124+
* The category used by dependencies created from ECMAScript module syntax.
125+
* @type {"esm"}
126+
*/
127+
const ESM_CATEGORY = "esm";
128+
123129
const TRANSITIVE = /** @type {symbol} */ (Symbol("transitive"));
124130

125131
const getIgnoredModule = memoize(() => {
@@ -554,5 +560,6 @@ Dependency.LAZY_UNTIL_LOCAL = LAZY_UNTIL_LOCAL;
554560
Dependency.LAZY_UNTIL_ID = LAZY_UNTIL_ID;
555561
Dependency.LAZY_UNTIL_FALLBACK = LAZY_UNTIL_FALLBACK;
556562
Dependency.LAZY_UNTIL_REQUEST = LAZY_UNTIL_REQUEST;
563+
Dependency.ESM_CATEGORY = ESM_CATEGORY;
557564

558565
module.exports = Dependency;

‎lib/optimize/LazyBarrel.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ class LazyBarrelInfo {
219219
}
220220
}
221221

222-
const esmDependencyCategory = "esm";
223-
224222
/**
225223
* Owns the per side-effect-free module lazy barrel state for a `Compilation`,
226224
* keeping the deferral bookkeeping out of `Compilation` itself.
@@ -326,7 +324,7 @@ class LazyBarrelController {
326324
const category = dep.category;
327325
// Match the request grouping key of `processDependencyForResolving`
328326
const requestKey =
329-
category === esmDependencyCategory
327+
category === Dependency.ESM_CATEGORY
330328
? resourceIdent
331329
: `${category}${resourceIdent}`;
332330
if (info === undefined) info = new LazyBarrelInfo();
@@ -351,7 +349,7 @@ class LazyBarrelController {
351349
"getLazyUntil" in dep &&
352350
(dep.getLazyUntil() === null ||
353351
dep.getLazyUntil() === Dependency.LAZY_UNTIL_REQUEST) &&
354-
dep.category === esmDependencyCategory &&
352+
dep.category === Dependency.ESM_CATEGORY &&
355353
"setLazy" in dep &&
356354
dep.getResourceIdentifier() !== null
357355
) {

‎types.d.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5109,6 +5109,7 @@ declare class ConstDependency extends NullDependency {
51095109
static LAZY_UNTIL_ID: "id";
51105110
static LAZY_UNTIL_FALLBACK: "*";
51115111
static LAZY_UNTIL_REQUEST: "@";
5112+
static ESM_CATEGORY: "esm";
51125113
}
51135114
declare class ConstDependencyTemplate extends NullDependencyTemplate {
51145115
constructor();
@@ -6917,6 +6918,7 @@ declare class Dependency {
69176918
static LAZY_UNTIL_ID: "id";
69186919
static LAZY_UNTIL_FALLBACK: "*";
69196920
static LAZY_UNTIL_REQUEST: "@";
6921+
static ESM_CATEGORY: "esm";
69206922
}
69216923
declare interface DependencyConstructor {
69226924
new (...args: any[]): Dependency;
@@ -7652,6 +7654,7 @@ declare class ESMImportDependency extends ModuleDependency {
76527654
static LAZY_UNTIL_ID: "id";
76537655
static LAZY_UNTIL_FALLBACK: "*";
76547656
static LAZY_UNTIL_REQUEST: "@";
7657+
static ESM_CATEGORY: "esm";
76557658
}
76567659
declare abstract class ESMImportSideEffectDependency extends ESMImportDependency {
76577660
unusedSpecifiers?: UnusedSpecifiers;
@@ -18036,6 +18039,7 @@ declare class ModuleDependency extends Dependency {
1803618039
static LAZY_UNTIL_ID: "id";
1803718040
static LAZY_UNTIL_FALLBACK: "*";
1803818041
static LAZY_UNTIL_REQUEST: "@";
18042+
static ESM_CATEGORY: "esm";
1803918043
}
1804018044

1804118045
/**
@@ -20410,6 +20414,7 @@ declare class NullDependency extends Dependency {
2041020414
static LAZY_UNTIL_ID: "id";
2041120415
static LAZY_UNTIL_FALLBACK: "*";
2041220416
static LAZY_UNTIL_REQUEST: "@";
20417+
static ESM_CATEGORY: "esm";
2041320418
}
2041420419
declare class NullDependencyTemplate extends DependencyTemplate {
2041520420
constructor();

0 commit comments

Comments
 (0)