@atlaspack/packager-js 2.14.5-canary.79 → 2.14.5-canary.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ScopeHoistingPackager.js +39 -16
- package/package.json +8 -8
- package/src/ScopeHoistingPackager.js +65 -32
|
@@ -115,7 +115,10 @@ class ScopeHoistingPackager {
|
|
|
115
115
|
}
|
|
116
116
|
async package() {
|
|
117
117
|
var _sourceMap;
|
|
118
|
-
let
|
|
118
|
+
let {
|
|
119
|
+
wrapped: wrappedAssets,
|
|
120
|
+
constant: constantAssets
|
|
121
|
+
} = await this.loadAssets();
|
|
119
122
|
this.buildExportedSymbols();
|
|
120
123
|
|
|
121
124
|
// If building a library, the target is actually another bundler rather
|
|
@@ -143,6 +146,14 @@ class ScopeHoistingPackager {
|
|
|
143
146
|
res += content + '\n';
|
|
144
147
|
lineCount += lines + 1;
|
|
145
148
|
};
|
|
149
|
+
if ((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix')) {
|
|
150
|
+
// Write out all constant modules used by this bundle
|
|
151
|
+
for (let asset of constantAssets) {
|
|
152
|
+
if (!this.seenAssets.has(asset.id)) {
|
|
153
|
+
processAsset(asset);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
146
157
|
|
|
147
158
|
// Hoist wrapped asset to the top of the bundle to ensure that they are registered
|
|
148
159
|
// before they are used.
|
|
@@ -265,6 +276,7 @@ class ScopeHoistingPackager {
|
|
|
265
276
|
maxConcurrent: 32
|
|
266
277
|
});
|
|
267
278
|
let wrapped = [];
|
|
279
|
+
let constant = [];
|
|
268
280
|
this.bundle.traverseAssets(asset => {
|
|
269
281
|
queue.add(async () => {
|
|
270
282
|
let [code, map] = await Promise.all([asset.getCode(), this.bundle.env.sourceMap ? asset.getMapBuffer() : null]);
|
|
@@ -278,6 +290,8 @@ class ScopeHoistingPackager {
|
|
|
278
290
|
if (!asset.meta.isConstantModule || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.priority === 'lazy')) {
|
|
279
291
|
this.wrappedAssets.add(asset.id);
|
|
280
292
|
wrapped.push(asset);
|
|
293
|
+
} else if ((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') && asset.meta.isConstantModule) {
|
|
294
|
+
constant.push(asset);
|
|
281
295
|
}
|
|
282
296
|
}
|
|
283
297
|
});
|
|
@@ -332,7 +346,10 @@ class ScopeHoistingPackager {
|
|
|
332
346
|
}
|
|
333
347
|
}
|
|
334
348
|
this.assetOutputs = new Map(await queue.run());
|
|
335
|
-
return
|
|
349
|
+
return {
|
|
350
|
+
wrapped,
|
|
351
|
+
constant
|
|
352
|
+
};
|
|
336
353
|
}
|
|
337
354
|
isReExported(asset) {
|
|
338
355
|
let parentSymbols = this.bundleGraph.getIncomingDependencies(asset).map(dep => this.bundleGraph.getAssetWithDependency(dep)).flatMap(parent => {
|
|
@@ -916,20 +933,26 @@ ${code}
|
|
|
916
933
|
// If there's no __esModule flag, and default is a used symbol, we need
|
|
917
934
|
// to insert an interop helper.
|
|
918
935
|
let defaultInterop = asset.symbols.hasExportSymbol('*') && usedSymbols.has('default') && !asset.symbols.hasExportSymbol('__esModule');
|
|
919
|
-
let usedNamespace
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
936
|
+
let usedNamespace;
|
|
937
|
+
if ((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') && asset.meta.isConstantModule) {
|
|
938
|
+
// Only set usedNamespace if there is an incoming dependency in the current bundle that uses '*'
|
|
939
|
+
usedNamespace = this.bundleGraph.getIncomingDependencies(asset).some(dep => this.bundle.hasDependency(dep) && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'));
|
|
940
|
+
} else {
|
|
941
|
+
usedNamespace =
|
|
942
|
+
// If the asset has * in its used symbols, we might need the exports namespace.
|
|
943
|
+
// The one case where this isn't true is in ESM library entries, where the only
|
|
944
|
+
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
945
|
+
// instead of the namespace object.
|
|
946
|
+
usedSymbols.has('*') && (this.bundle.env.outputFormat !== 'esmodule' || !this.bundle.env.isLibrary || asset !== this.bundle.getMainEntry() || this.bundleGraph.getIncomingDependencies(asset).some(dep => !dep.isEntry && this.bundle.hasDependency(dep) && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'))) ||
|
|
947
|
+
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
948
|
+
// we fallback on the namespace object.
|
|
949
|
+
asset.symbols.hasExportSymbol('*') && [...usedSymbols].some(s => !asset.symbols.hasExportSymbol(s)) ||
|
|
950
|
+
// If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
951
|
+
// include the namespace object for the default export.
|
|
952
|
+
this.exportedSymbols.has(`$${assetId}$exports`) ||
|
|
953
|
+
// CommonJS library bundle entries always need a namespace.
|
|
954
|
+
this.bundle.env.isLibrary && this.bundle.env.outputFormat === 'commonjs' && asset === this.bundle.getMainEntry();
|
|
955
|
+
}
|
|
933
956
|
|
|
934
957
|
// If the asset doesn't have static exports, should wrap, the namespace is used,
|
|
935
958
|
// or we need default interop, then we need to synthesize a namespace object for
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.80+10fbcfbfa",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
"node": ">= 16.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@atlaspack/diagnostic": "2.14.1-canary.
|
|
19
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
20
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
21
|
-
"@atlaspack/rust": "3.2.1-canary.
|
|
22
|
-
"@atlaspack/types": "2.14.5-canary.
|
|
23
|
-
"@atlaspack/utils": "2.14.5-canary.
|
|
18
|
+
"@atlaspack/diagnostic": "2.14.1-canary.148+10fbcfbfa",
|
|
19
|
+
"@atlaspack/feature-flags": "2.14.1-canary.148+10fbcfbfa",
|
|
20
|
+
"@atlaspack/plugin": "2.14.5-canary.80+10fbcfbfa",
|
|
21
|
+
"@atlaspack/rust": "3.2.1-canary.80+10fbcfbfa",
|
|
22
|
+
"@atlaspack/types": "2.14.5-canary.80+10fbcfbfa",
|
|
23
|
+
"@atlaspack/utils": "2.14.5-canary.80+10fbcfbfa",
|
|
24
24
|
"@parcel/source-map": "^2.1.1",
|
|
25
25
|
"globals": "^13.2.0",
|
|
26
26
|
"nullthrows": "^1.1.1"
|
|
27
27
|
},
|
|
28
28
|
"type": "commonjs",
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "10fbcfbfa49c7a83da5d7c40983e36e87f524a75"
|
|
30
30
|
}
|
|
@@ -134,7 +134,8 @@ export class ScopeHoistingPackager {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
async package(): Promise<{|contents: string, map: ?SourceMap|}> {
|
|
137
|
-
let wrappedAssets
|
|
137
|
+
let {wrapped: wrappedAssets, constant: constantAssets} =
|
|
138
|
+
await this.loadAssets();
|
|
138
139
|
this.buildExportedSymbols();
|
|
139
140
|
|
|
140
141
|
// If building a library, the target is actually another bundler rather
|
|
@@ -168,6 +169,15 @@ export class ScopeHoistingPackager {
|
|
|
168
169
|
lineCount += lines + 1;
|
|
169
170
|
};
|
|
170
171
|
|
|
172
|
+
if (getFeatureFlag('inlineConstOptimisationFix')) {
|
|
173
|
+
// Write out all constant modules used by this bundle
|
|
174
|
+
for (let asset of constantAssets) {
|
|
175
|
+
if (!this.seenAssets.has(asset.id)) {
|
|
176
|
+
processAsset(asset);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
171
181
|
// Hoist wrapped asset to the top of the bundle to ensure that they are registered
|
|
172
182
|
// before they are used.
|
|
173
183
|
for (let asset of wrappedAssets) {
|
|
@@ -354,9 +364,13 @@ export class ScopeHoistingPackager {
|
|
|
354
364
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
355
365
|
}
|
|
356
366
|
|
|
357
|
-
async loadAssets(): Promise<
|
|
367
|
+
async loadAssets(): Promise<{|
|
|
368
|
+
wrapped: Array<Asset>,
|
|
369
|
+
constant: Array<Asset>,
|
|
370
|
+
|}> {
|
|
358
371
|
let queue = new PromiseQueue({maxConcurrent: 32});
|
|
359
372
|
let wrapped = [];
|
|
373
|
+
let constant = [];
|
|
360
374
|
this.bundle.traverseAssets((asset) => {
|
|
361
375
|
queue.add(async () => {
|
|
362
376
|
let [code, map] = await Promise.all([
|
|
@@ -384,6 +398,11 @@ export class ScopeHoistingPackager {
|
|
|
384
398
|
) {
|
|
385
399
|
this.wrappedAssets.add(asset.id);
|
|
386
400
|
wrapped.push(asset);
|
|
401
|
+
} else if (
|
|
402
|
+
getFeatureFlag('inlineConstOptimisationFix') &&
|
|
403
|
+
asset.meta.isConstantModule
|
|
404
|
+
) {
|
|
405
|
+
constant.push(asset);
|
|
387
406
|
}
|
|
388
407
|
}
|
|
389
408
|
});
|
|
@@ -455,8 +474,7 @@ export class ScopeHoistingPackager {
|
|
|
455
474
|
}
|
|
456
475
|
|
|
457
476
|
this.assetOutputs = new Map(await queue.run());
|
|
458
|
-
|
|
459
|
-
return wrapped;
|
|
477
|
+
return {wrapped, constant};
|
|
460
478
|
}
|
|
461
479
|
|
|
462
480
|
isReExported(asset: Asset): boolean {
|
|
@@ -1281,34 +1299,49 @@ ${code}
|
|
|
1281
1299
|
usedSymbols.has('default') &&
|
|
1282
1300
|
!asset.symbols.hasExportSymbol('__esModule');
|
|
1283
1301
|
|
|
1284
|
-
let usedNamespace
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
.
|
|
1295
|
-
.
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1302
|
+
let usedNamespace;
|
|
1303
|
+
if (
|
|
1304
|
+
getFeatureFlag('inlineConstOptimisationFix') &&
|
|
1305
|
+
asset.meta.isConstantModule
|
|
1306
|
+
) {
|
|
1307
|
+
// Only set usedNamespace if there is an incoming dependency in the current bundle that uses '*'
|
|
1308
|
+
usedNamespace = this.bundleGraph
|
|
1309
|
+
.getIncomingDependencies(asset)
|
|
1310
|
+
.some(
|
|
1311
|
+
(dep) =>
|
|
1312
|
+
this.bundle.hasDependency(dep) &&
|
|
1313
|
+
nullthrows(this.bundleGraph.getUsedSymbols(dep)).has('*'),
|
|
1314
|
+
);
|
|
1315
|
+
} else {
|
|
1316
|
+
usedNamespace =
|
|
1317
|
+
// If the asset has * in its used symbols, we might need the exports namespace.
|
|
1318
|
+
// The one case where this isn't true is in ESM library entries, where the only
|
|
1319
|
+
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
1320
|
+
// instead of the namespace object.
|
|
1321
|
+
(usedSymbols.has('*') &&
|
|
1322
|
+
(this.bundle.env.outputFormat !== 'esmodule' ||
|
|
1323
|
+
!this.bundle.env.isLibrary ||
|
|
1324
|
+
asset !== this.bundle.getMainEntry() ||
|
|
1325
|
+
this.bundleGraph
|
|
1326
|
+
.getIncomingDependencies(asset)
|
|
1327
|
+
.some(
|
|
1328
|
+
(dep) =>
|
|
1329
|
+
!dep.isEntry &&
|
|
1330
|
+
this.bundle.hasDependency(dep) &&
|
|
1331
|
+
nullthrows(this.bundleGraph.getUsedSymbols(dep)).has('*'),
|
|
1332
|
+
))) ||
|
|
1333
|
+
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
1334
|
+
// we fallback on the namespace object.
|
|
1335
|
+
(asset.symbols.hasExportSymbol('*') &&
|
|
1336
|
+
[...usedSymbols].some((s) => !asset.symbols.hasExportSymbol(s))) ||
|
|
1337
|
+
// If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
1338
|
+
// include the namespace object for the default export.
|
|
1339
|
+
this.exportedSymbols.has(`$${assetId}$exports`) ||
|
|
1340
|
+
// CommonJS library bundle entries always need a namespace.
|
|
1341
|
+
(this.bundle.env.isLibrary &&
|
|
1342
|
+
this.bundle.env.outputFormat === 'commonjs' &&
|
|
1343
|
+
asset === this.bundle.getMainEntry());
|
|
1344
|
+
}
|
|
1312
1345
|
|
|
1313
1346
|
// If the asset doesn't have static exports, should wrap, the namespace is used,
|
|
1314
1347
|
// or we need default interop, then we need to synthesize a namespace object for
|