@atlaspack/packager-js 2.23.1 → 2.23.2
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/CHANGELOG.md +15 -0
- package/dist/CJSOutputFormat.js +34 -0
- package/dist/DevPackager.js +202 -0
- package/dist/ESMOutputFormat.js +102 -0
- package/dist/GlobalOutputFormat.js +18 -0
- package/dist/ScopeHoistingPackager.js +1362 -0
- package/dist/helpers.js +170 -0
- package/dist/index.js +101 -0
- package/dist/utils.js +60 -0
- package/lib/ESMOutputFormat.js +1 -1
- package/lib/ScopeHoistingPackager.js +61 -73
- package/lib/types/ScopeHoistingPackager.d.ts +6 -8
- package/package.json +6 -7
- package/src/ESMOutputFormat.ts +1 -1
- package/src/ScopeHoistingPackager.ts +80 -88
- package/tsconfig.json +25 -2
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -97,13 +97,13 @@ const OUTPUT_FORMATS = {
|
|
|
97
97
|
global: _GlobalOutputFormat.GlobalOutputFormat
|
|
98
98
|
};
|
|
99
99
|
class ScopeHoistingPackager {
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
assetOutputs = new Map();
|
|
102
101
|
exportedSymbols = new Map();
|
|
103
102
|
externals = new Map();
|
|
104
103
|
topLevelNames = new Map();
|
|
105
104
|
seenAssets = new Set();
|
|
106
105
|
wrappedAssets = new Set();
|
|
106
|
+
constantAssets = new Set();
|
|
107
107
|
hoistedRequires = new Map();
|
|
108
108
|
seenHoistedRequires = new Set();
|
|
109
109
|
needsPrelude = false;
|
|
@@ -124,10 +124,7 @@ class ScopeHoistingPackager {
|
|
|
124
124
|
}
|
|
125
125
|
async package() {
|
|
126
126
|
var _sourceMap;
|
|
127
|
-
|
|
128
|
-
wrapped: wrappedAssets,
|
|
129
|
-
constant: constantAssets
|
|
130
|
-
} = await this.loadAssets();
|
|
127
|
+
await this.loadAssets();
|
|
131
128
|
this.buildExportedSymbols();
|
|
132
129
|
|
|
133
130
|
// If building a library, the target is actually another bundler rather
|
|
@@ -144,14 +141,12 @@ class ScopeHoistingPackager {
|
|
|
144
141
|
}
|
|
145
142
|
let res = '';
|
|
146
143
|
let lineCount = 0;
|
|
147
|
-
// @ts-expect-error TS7034
|
|
148
144
|
let sourceMap = null;
|
|
149
145
|
let processAsset = asset => {
|
|
150
146
|
this.seenHoistedRequires.clear();
|
|
151
147
|
let [content, map, lines] = this.visitAsset(asset);
|
|
152
|
-
|
|
153
|
-
// @ts-expect-error TS7005
|
|
154
148
|
if (sourceMap && map) {
|
|
149
|
+
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
155
150
|
sourceMap.addSourceMap(map, lineCount);
|
|
156
151
|
} else if (this.bundle.env.sourceMap) {
|
|
157
152
|
sourceMap = map;
|
|
@@ -161,8 +156,8 @@ class ScopeHoistingPackager {
|
|
|
161
156
|
};
|
|
162
157
|
if ((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') || this.useBothScopeHoistingImprovements) {
|
|
163
158
|
// Write out all constant modules used by this bundle
|
|
164
|
-
for (let asset of constantAssets) {
|
|
165
|
-
if (!this.seenAssets.has(asset
|
|
159
|
+
for (let asset of this.constantAssets) {
|
|
160
|
+
if (!this.seenAssets.has(asset)) {
|
|
166
161
|
processAsset(asset);
|
|
167
162
|
}
|
|
168
163
|
}
|
|
@@ -170,8 +165,8 @@ class ScopeHoistingPackager {
|
|
|
170
165
|
|
|
171
166
|
// Hoist wrapped asset to the top of the bundle to ensure that they are registered
|
|
172
167
|
// before they are used.
|
|
173
|
-
for (let asset of wrappedAssets) {
|
|
174
|
-
if (!this.seenAssets.has(asset
|
|
168
|
+
for (let asset of this.wrappedAssets) {
|
|
169
|
+
if (!this.seenAssets.has(asset)) {
|
|
175
170
|
processAsset(asset);
|
|
176
171
|
}
|
|
177
172
|
}
|
|
@@ -179,7 +174,7 @@ class ScopeHoistingPackager {
|
|
|
179
174
|
// Add each asset that is directly connected to the bundle. Dependencies will be handled
|
|
180
175
|
// by replacing `import` statements in the code.
|
|
181
176
|
this.bundle.traverseAssets((asset, _, actions) => {
|
|
182
|
-
if (this.seenAssets.has(asset
|
|
177
|
+
if (this.seenAssets.has(asset)) {
|
|
183
178
|
actions.skipChildren();
|
|
184
179
|
return;
|
|
185
180
|
}
|
|
@@ -189,7 +184,7 @@ class ScopeHoistingPackager {
|
|
|
189
184
|
let [prelude, preludeLines] = this.buildBundlePrelude();
|
|
190
185
|
res = prelude + res;
|
|
191
186
|
lineCount += preludeLines;
|
|
192
|
-
// @ts-expect-error TS2339
|
|
187
|
+
// @ts-expect-error TS2339 - offsetLines method exists but missing from @parcel/source-map type definitions
|
|
193
188
|
(_sourceMap = sourceMap) === null || _sourceMap === void 0 || _sourceMap.offsetLines(1, preludeLines);
|
|
194
189
|
let entries = this.bundle.getEntryAssets();
|
|
195
190
|
let mainEntry = this.bundle.getMainEntry();
|
|
@@ -217,7 +212,7 @@ class ScopeHoistingPackager {
|
|
|
217
212
|
|
|
218
213
|
// If any of the entry assets are wrapped, call parcelRequire so they are executed.
|
|
219
214
|
for (let entry of entries) {
|
|
220
|
-
if (this.wrappedAssets.has(entry
|
|
215
|
+
if (this.wrappedAssets.has(entry) && !this.isScriptEntry(entry)) {
|
|
221
216
|
var _entry$symbols$get;
|
|
222
217
|
let parcelRequire = `parcelRequire(${JSON.stringify(this.bundleGraph.getAssetPublicId(entry))});\n`;
|
|
223
218
|
let entryExports = (_entry$symbols$get = entry.symbols.get('*')) === null || _entry$symbols$get === void 0 ? void 0 : _entry$symbols$get.local;
|
|
@@ -247,14 +242,14 @@ class ScopeHoistingPackager {
|
|
|
247
242
|
let {
|
|
248
243
|
code,
|
|
249
244
|
map: mapBuffer
|
|
250
|
-
} = (0, _nullthrows().default)(this.assetOutputs.get(mainEntry
|
|
245
|
+
} = (0, _nullthrows().default)(this.assetOutputs.get(mainEntry));
|
|
251
246
|
let map;
|
|
252
247
|
if (mapBuffer) {
|
|
253
248
|
map = new (_sourceMap2().default)(this.options.projectRoot, mapBuffer);
|
|
254
249
|
}
|
|
255
250
|
res += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, code, map, this.parcelRequireName);
|
|
256
251
|
if (sourceMap && map) {
|
|
257
|
-
// @ts-expect-error TS2339
|
|
252
|
+
// @ts-expect-error TS2339 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
258
253
|
sourceMap.addSourceMap(map, lineCount);
|
|
259
254
|
}
|
|
260
255
|
}
|
|
@@ -301,12 +296,10 @@ class ScopeHoistingPackager {
|
|
|
301
296
|
let queue = new (_utils().PromiseQueue)({
|
|
302
297
|
maxConcurrent: 32
|
|
303
298
|
});
|
|
304
|
-
let wrapped = [];
|
|
305
|
-
let constant = [];
|
|
306
299
|
this.bundle.traverseAssets(asset => {
|
|
307
300
|
queue.add(async () => {
|
|
308
301
|
let [code, map] = await Promise.all([asset.getCode(), this.bundle.env.sourceMap ? asset.getMapBuffer() : null]);
|
|
309
|
-
return [asset
|
|
302
|
+
return [asset, {
|
|
310
303
|
code,
|
|
311
304
|
map
|
|
312
305
|
}];
|
|
@@ -314,10 +307,9 @@ class ScopeHoistingPackager {
|
|
|
314
307
|
if (asset.meta.shouldWrap || this.bundle.env.sourceType === 'script' || this.bundleGraph.isAssetReferenced(this.bundle, asset) || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.meta.shouldWrap && dep.specifierType !== 'url')) {
|
|
315
308
|
// Don't wrap constant "entry" modules _except_ if they are referenced by any lazy dependency
|
|
316
309
|
if (!asset.meta.isConstantModule || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.priority === 'lazy')) {
|
|
317
|
-
this.wrappedAssets.add(asset
|
|
318
|
-
wrapped.push(asset);
|
|
310
|
+
this.wrappedAssets.add(asset);
|
|
319
311
|
} else if (((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') || this.useBothScopeHoistingImprovements) && asset.meta.isConstantModule) {
|
|
320
|
-
|
|
312
|
+
this.constantAssets.add(asset);
|
|
321
313
|
}
|
|
322
314
|
}
|
|
323
315
|
});
|
|
@@ -330,18 +322,20 @@ class ScopeHoistingPackager {
|
|
|
330
322
|
if (!(0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2')) {
|
|
331
323
|
// Make all entry assets wrapped, to avoid any top level hoisting
|
|
332
324
|
for (let entryAsset of this.bundle.getEntryAssets()) {
|
|
333
|
-
if (!this.wrappedAssets.has(entryAsset
|
|
334
|
-
this.wrappedAssets.add(entryAsset
|
|
335
|
-
wrapped.push(entryAsset);
|
|
325
|
+
if (!this.wrappedAssets.has(entryAsset)) {
|
|
326
|
+
this.wrappedAssets.add(entryAsset);
|
|
336
327
|
}
|
|
337
328
|
}
|
|
338
329
|
}
|
|
339
|
-
|
|
330
|
+
|
|
331
|
+
// We need to make a new copy here so that we can add to the list and
|
|
332
|
+
// iterate the newly added items, without mutating the wrappedAssets set
|
|
333
|
+
let moduleGroupParents = [...this.wrappedAssets.values()];
|
|
340
334
|
if ((0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2')) {
|
|
341
335
|
// The main entry needs to be check to find assets that would have gone in
|
|
342
336
|
// the top level scope
|
|
343
337
|
let mainEntry = this.bundle.getMainEntry();
|
|
344
|
-
if (mainEntry && !this.wrappedAssets.has(mainEntry
|
|
338
|
+
if (mainEntry && !this.wrappedAssets.has(mainEntry)) {
|
|
345
339
|
moduleGroupParents.unshift(mainEntry);
|
|
346
340
|
}
|
|
347
341
|
}
|
|
@@ -350,13 +344,12 @@ class ScopeHoistingPackager {
|
|
|
350
344
|
if (asset === moduleGroupParentAsset) {
|
|
351
345
|
return;
|
|
352
346
|
}
|
|
353
|
-
if (this.wrappedAssets.has(asset
|
|
347
|
+
if (this.wrappedAssets.has(asset)) {
|
|
354
348
|
actions.skipChildren();
|
|
355
349
|
return;
|
|
356
350
|
}
|
|
357
351
|
if (!asset.meta.isConstantModule && (assignedAssets.has(asset) || this.isReExported(asset))) {
|
|
358
|
-
|
|
359
|
-
this.wrappedAssets.add(asset.id);
|
|
352
|
+
this.wrappedAssets.add(asset);
|
|
360
353
|
|
|
361
354
|
// This also needs to be added to the traversal so that we iterate
|
|
362
355
|
// it during this check.
|
|
@@ -368,29 +361,22 @@ class ScopeHoistingPackager {
|
|
|
368
361
|
}, moduleGroupParentAsset);
|
|
369
362
|
}
|
|
370
363
|
} else {
|
|
371
|
-
for (let wrappedAssetRoot of
|
|
364
|
+
for (let wrappedAssetRoot of this.wrappedAssets) {
|
|
372
365
|
this.bundle.traverseAssets((asset, _, actions) => {
|
|
373
366
|
if (asset === wrappedAssetRoot) {
|
|
374
367
|
return;
|
|
375
368
|
}
|
|
376
|
-
if (this.wrappedAssets.has(asset
|
|
369
|
+
if (this.wrappedAssets.has(asset)) {
|
|
377
370
|
actions.skipChildren();
|
|
378
371
|
return;
|
|
379
372
|
}
|
|
380
373
|
if (!asset.meta.isConstantModule) {
|
|
381
|
-
this.wrappedAssets.add(asset
|
|
382
|
-
wrapped.push(asset);
|
|
374
|
+
this.wrappedAssets.add(asset);
|
|
383
375
|
}
|
|
384
376
|
}, wrappedAssetRoot);
|
|
385
377
|
}
|
|
386
378
|
}
|
|
387
|
-
|
|
388
|
-
// @ts-expect-error TS2769
|
|
389
379
|
this.assetOutputs = new Map(await queue.run());
|
|
390
|
-
return {
|
|
391
|
-
wrapped,
|
|
392
|
-
constant
|
|
393
|
-
};
|
|
394
380
|
}
|
|
395
381
|
isReExported(asset) {
|
|
396
382
|
let parentSymbols = this.bundleGraph.getIncomingDependencies(asset).map(dep => this.bundleGraph.getAssetWithDependency(dep)).flatMap(parent => {
|
|
@@ -409,7 +395,7 @@ class ScopeHoistingPackager {
|
|
|
409
395
|
|
|
410
396
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
411
397
|
let entry = this.bundle.getMainEntry();
|
|
412
|
-
if (entry && !this.wrappedAssets.has(entry
|
|
398
|
+
if (entry && !this.wrappedAssets.has(entry)) {
|
|
413
399
|
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
414
400
|
for (let {
|
|
415
401
|
asset,
|
|
@@ -478,19 +464,19 @@ class ScopeHoistingPackager {
|
|
|
478
464
|
return `${obj}[${JSON.stringify(property)}]`;
|
|
479
465
|
}
|
|
480
466
|
visitAsset(asset) {
|
|
481
|
-
(0, _assert().default)(!this.seenAssets.has(asset
|
|
482
|
-
this.seenAssets.add(asset
|
|
467
|
+
(0, _assert().default)(!this.seenAssets.has(asset), 'Already visited asset');
|
|
468
|
+
this.seenAssets.add(asset);
|
|
483
469
|
let {
|
|
484
470
|
code,
|
|
485
471
|
map
|
|
486
|
-
} = (0, _nullthrows().default)(this.assetOutputs.get(asset
|
|
472
|
+
} = (0, _nullthrows().default)(this.assetOutputs.get(asset));
|
|
487
473
|
return this.buildAsset(asset, code, map);
|
|
488
474
|
}
|
|
489
475
|
getAssetFilePath(asset) {
|
|
490
476
|
return _path().default.relative(this.options.projectRoot, asset.filePath);
|
|
491
477
|
}
|
|
492
478
|
buildAsset(asset, code, map) {
|
|
493
|
-
let shouldWrap = this.wrappedAssets.has(asset
|
|
479
|
+
let shouldWrap = this.wrappedAssets.has(asset);
|
|
494
480
|
let deps = this.bundleGraph.getDependencies(asset);
|
|
495
481
|
let sourceMap = this.bundle.env.sourceMap && map ? new (_sourceMap2().default)(this.options.projectRoot, map) : null;
|
|
496
482
|
|
|
@@ -510,14 +496,21 @@ class ScopeHoistingPackager {
|
|
|
510
496
|
}
|
|
511
497
|
continue;
|
|
512
498
|
}
|
|
513
|
-
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
499
|
+
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved)) {
|
|
500
|
+
if (this.useBothScopeHoistingImprovements && this.wrappedAssets.has(resolved)) {
|
|
501
|
+
// When the dep is wrapped then we just need to drop a side effect
|
|
502
|
+
// require instead of inlining
|
|
503
|
+
depCode += `parcelRequire("${this.bundleGraph.getAssetPublicId(resolved)}");\n`;
|
|
504
|
+
lineCount += 1;
|
|
505
|
+
} else {
|
|
506
|
+
let [code, map, lines] = this.visitAsset(resolved);
|
|
507
|
+
depCode += code + '\n';
|
|
508
|
+
if (sourceMap && map) {
|
|
509
|
+
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
510
|
+
sourceMap.addSourceMap(map, lineCount);
|
|
511
|
+
}
|
|
512
|
+
lineCount += lines + 1;
|
|
519
513
|
}
|
|
520
|
-
lineCount += lines + 1;
|
|
521
514
|
}
|
|
522
515
|
}
|
|
523
516
|
return [depCode, sourceMap, lineCount];
|
|
@@ -540,7 +533,6 @@ class ScopeHoistingPackager {
|
|
|
540
533
|
}
|
|
541
534
|
code += append;
|
|
542
535
|
let lineCount = 0;
|
|
543
|
-
// @ts-expect-error TS2552
|
|
544
536
|
let depContent = [];
|
|
545
537
|
if (depMap.size === 0 && replacements.size === 0) {
|
|
546
538
|
// If there are no dependencies or replacements, use a simple function to count the number of lines.
|
|
@@ -584,13 +576,13 @@ class ScopeHoistingPackager {
|
|
|
584
576
|
if (!(0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2')) {
|
|
585
577
|
[res, lines] = this.getHoistedParcelRequires(asset, dep, resolved);
|
|
586
578
|
}
|
|
587
|
-
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved
|
|
579
|
+
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved)) {
|
|
588
580
|
// If this asset is wrapped, we need to hoist the code for the dependency
|
|
589
581
|
// outside our parcelRequire.register wrapper. This is safe because all
|
|
590
582
|
// assets referenced by this asset will also be wrapped. Otherwise, inline the
|
|
591
583
|
// asset content where the import statement was.
|
|
592
584
|
if (this.useBothScopeHoistingImprovements) {
|
|
593
|
-
if (!resolved.meta.isConstantModule && !this.wrappedAssets.has(resolved
|
|
585
|
+
if (!resolved.meta.isConstantModule && !this.wrappedAssets.has(resolved)) {
|
|
594
586
|
let [depCode, depMap, depLines] = this.visitAsset(resolved);
|
|
595
587
|
if (_utils().debugTools['asset-file-names-in-output']) {
|
|
596
588
|
let resolvedPath = this.getAssetFilePath(resolved);
|
|
@@ -633,7 +625,7 @@ class ScopeHoistingPackager {
|
|
|
633
625
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
634
626
|
}
|
|
635
627
|
if (map) {
|
|
636
|
-
// @ts-expect-error TS2551
|
|
628
|
+
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
637
629
|
sourceMap.addSourceMap(map, lineCount);
|
|
638
630
|
}
|
|
639
631
|
}
|
|
@@ -678,7 +670,7 @@ ${code}
|
|
|
678
670
|
if (!depCode) continue;
|
|
679
671
|
code += depCode + '\n';
|
|
680
672
|
if (sourceMap && map) {
|
|
681
|
-
// @ts-expect-error TS2551
|
|
673
|
+
// @ts-expect-error TS2551 - addSourceMap method exists but missing from @parcel/source-map type definitions
|
|
682
674
|
sourceMap.addSourceMap(map, lineCount);
|
|
683
675
|
}
|
|
684
676
|
lineCount += lines + 1;
|
|
@@ -747,7 +739,7 @@ ${code}
|
|
|
747
739
|
|
|
748
740
|
// If this asset is wrapped, we need to replace the exports namespace with `module.exports`,
|
|
749
741
|
// which will be provided to us by the wrapper.
|
|
750
|
-
if (this.wrappedAssets.has(asset
|
|
742
|
+
if (this.wrappedAssets.has(asset) || this.bundle.env.outputFormat === 'commonjs' && asset === this.bundle.getMainEntry()) {
|
|
751
743
|
var _asset$symbols$get;
|
|
752
744
|
let exportsName = ((_asset$symbols$get = asset.symbols.get('*')) === null || _asset$symbols$get === void 0 ? void 0 : _asset$symbols$get.local) || `$${assetId}$exports`;
|
|
753
745
|
replacements.set(exportsName, 'module.exports');
|
|
@@ -845,9 +837,7 @@ ${code}
|
|
|
845
837
|
continue;
|
|
846
838
|
}
|
|
847
839
|
}
|
|
848
|
-
|
|
849
|
-
// @ts-expect-error TS2322
|
|
850
|
-
renamed = this.bundleGraph.getSymbolResolution(entry, imported, this.bundle).symbol;
|
|
840
|
+
renamed = this.bundleGraph.getSymbolResolution(entry, imported, this.bundle).symbol || undefined;
|
|
851
841
|
}
|
|
852
842
|
}
|
|
853
843
|
|
|
@@ -888,7 +878,7 @@ ${code}
|
|
|
888
878
|
}
|
|
889
879
|
return false;
|
|
890
880
|
}
|
|
891
|
-
return !this.bundle.hasAsset(resolved) && !this.externalAssets.has(resolved) || this.wrappedAssets.has(resolved
|
|
881
|
+
return !this.bundle.hasAsset(resolved) && !this.externalAssets.has(resolved) || this.wrappedAssets.has(resolved) && resolved !== parentAsset;
|
|
892
882
|
}
|
|
893
883
|
getSymbolResolution(parentAsset, resolved, imported, dep, replacements) {
|
|
894
884
|
let {
|
|
@@ -915,12 +905,12 @@ ${code}
|
|
|
915
905
|
// Only do this if the asset is part of a different bundle (so it was definitely
|
|
916
906
|
// parcelRequire.register'ed there), or if it is indeed registered in this bundle.
|
|
917
907
|
!this.bundle.hasAsset(resolvedAsset) || !this.shouldSkipAsset(resolvedAsset))) {
|
|
918
|
-
let hoisted = this.hoistedRequires.get(dep
|
|
908
|
+
let hoisted = this.hoistedRequires.get(dep);
|
|
919
909
|
if (!hoisted) {
|
|
920
910
|
hoisted = new Map();
|
|
921
|
-
this.hoistedRequires.set(dep
|
|
911
|
+
this.hoistedRequires.set(dep, hoisted);
|
|
922
912
|
}
|
|
923
|
-
hoisted.set(resolvedAsset
|
|
913
|
+
hoisted.set(resolvedAsset, `var $${publicId} = parcelRequire(${JSON.stringify(publicId)});`);
|
|
924
914
|
}
|
|
925
915
|
if (isWrapped) {
|
|
926
916
|
this.needsPrelude = true;
|
|
@@ -949,7 +939,7 @@ ${code}
|
|
|
949
939
|
}
|
|
950
940
|
if (imported === '*' || exportSymbol === '*' || isDefaultInterop) {
|
|
951
941
|
// Resolve to the namespace object if requested or this is a CJS default interop reqiure.
|
|
952
|
-
if (parentAsset === resolvedAsset && this.wrappedAssets.has(resolvedAsset
|
|
942
|
+
if (parentAsset === resolvedAsset && this.wrappedAssets.has(resolvedAsset)) {
|
|
953
943
|
// Directly use module.exports for wrapped assets importing themselves.
|
|
954
944
|
return 'module.exports';
|
|
955
945
|
} else {
|
|
@@ -977,7 +967,7 @@ ${code}
|
|
|
977
967
|
if (resolved.type !== 'js') {
|
|
978
968
|
return ['', 0];
|
|
979
969
|
}
|
|
980
|
-
let hoisted = this.hoistedRequires.get(dep
|
|
970
|
+
let hoisted = this.hoistedRequires.get(dep);
|
|
981
971
|
let res = '';
|
|
982
972
|
let lineCount = 0;
|
|
983
973
|
let isWrapped = this.isWrapped(resolved, parentAsset);
|
|
@@ -986,7 +976,7 @@ ${code}
|
|
|
986
976
|
// we need to run side effects when this asset runs. If the resolved asset is not
|
|
987
977
|
// the first one in the hoisted requires, we need to insert a parcelRequire here
|
|
988
978
|
// so it runs first.
|
|
989
|
-
if (isWrapped && !dep.meta.shouldWrap && (!hoisted || hoisted.keys().next().value !== resolved
|
|
979
|
+
if (isWrapped && !dep.meta.shouldWrap && (!hoisted || hoisted.keys().next().value !== resolved) && !this.bundleGraph.isDependencySkipped(dep) && !this.shouldSkipAsset(resolved)) {
|
|
990
980
|
this.needsPrelude = true;
|
|
991
981
|
res += `parcelRequire(${JSON.stringify(this.bundleGraph.getAssetPublicId(resolved))});`;
|
|
992
982
|
}
|
|
@@ -1010,7 +1000,7 @@ ${code}
|
|
|
1010
1000
|
let prepend = '';
|
|
1011
1001
|
let prependLineCount = 0;
|
|
1012
1002
|
let append = '';
|
|
1013
|
-
let shouldWrap = this.wrappedAssets.has(asset
|
|
1003
|
+
let shouldWrap = this.wrappedAssets.has(asset);
|
|
1014
1004
|
let usedSymbols = (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(asset));
|
|
1015
1005
|
let assetId = asset.meta.id;
|
|
1016
1006
|
(0, _assert().default)(typeof assetId === 'string');
|
|
@@ -1188,10 +1178,8 @@ ${code}
|
|
|
1188
1178
|
this.usedHelpers.add('$parcel$global');
|
|
1189
1179
|
}
|
|
1190
1180
|
for (let helper of this.usedHelpers) {
|
|
1191
|
-
// @ts-expect-error TS7053
|
|
1192
1181
|
let currentHelper = _helpers.helpers[helper];
|
|
1193
1182
|
if (typeof currentHelper === 'function') {
|
|
1194
|
-
// @ts-expect-error TS7053
|
|
1195
1183
|
currentHelper = _helpers.helpers[helper](this.bundle.env);
|
|
1196
1184
|
}
|
|
1197
1185
|
res += currentHelper;
|
|
@@ -13,7 +13,7 @@ export declare class ScopeHoistingPackager {
|
|
|
13
13
|
outputFormat: OutputFormat;
|
|
14
14
|
isAsyncBundle: boolean;
|
|
15
15
|
globalNames: ReadonlySet<string>;
|
|
16
|
-
assetOutputs: Map<
|
|
16
|
+
assetOutputs: Map<Asset, {
|
|
17
17
|
code: string;
|
|
18
18
|
map: Buffer | null | undefined;
|
|
19
19
|
}>;
|
|
@@ -25,9 +25,10 @@ export declare class ScopeHoistingPackager {
|
|
|
25
25
|
}>;
|
|
26
26
|
externals: Map<string, Map<string, string>>;
|
|
27
27
|
topLevelNames: Map<string, number>;
|
|
28
|
-
seenAssets: Set<
|
|
29
|
-
wrappedAssets: Set<
|
|
30
|
-
|
|
28
|
+
seenAssets: Set<Asset>;
|
|
29
|
+
wrappedAssets: Set<Asset>;
|
|
30
|
+
constantAssets: Set<Asset>;
|
|
31
|
+
hoistedRequires: Map<Dependency, Map<Asset, string>>;
|
|
31
32
|
seenHoistedRequires: Set<string>;
|
|
32
33
|
needsPrelude: boolean;
|
|
33
34
|
usedHelpers: Set<string>;
|
|
@@ -41,10 +42,7 @@ export declare class ScopeHoistingPackager {
|
|
|
41
42
|
}>;
|
|
42
43
|
shouldBundleQueue(bundle: NamedBundle): boolean;
|
|
43
44
|
runWhenReady(bundle: NamedBundle, codeToRun: string): string;
|
|
44
|
-
loadAssets(): Promise<
|
|
45
|
-
wrapped: Array<Asset>;
|
|
46
|
-
constant: Array<Asset>;
|
|
47
|
-
}>;
|
|
45
|
+
loadAssets(): Promise<void>;
|
|
48
46
|
isReExported(asset: Asset): boolean;
|
|
49
47
|
buildExportedSymbols(): void;
|
|
50
48
|
getTopLevelName(name: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.23.
|
|
3
|
+
"version": "2.23.2",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,19 +17,18 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@atlaspack/diagnostic": "2.14.4",
|
|
20
|
-
"@atlaspack/feature-flags": "2.25.
|
|
21
|
-
"@atlaspack/plugin": "2.14.
|
|
22
|
-
"@atlaspack/rust": "3.8.
|
|
20
|
+
"@atlaspack/feature-flags": "2.25.2",
|
|
21
|
+
"@atlaspack/plugin": "2.14.32",
|
|
22
|
+
"@atlaspack/rust": "3.8.2",
|
|
23
23
|
"@parcel/source-map": "^2.1.1",
|
|
24
|
-
"@atlaspack/types": "2.15.
|
|
25
|
-
"@atlaspack/utils": "
|
|
24
|
+
"@atlaspack/types": "2.15.22",
|
|
25
|
+
"@atlaspack/utils": "3.0.0",
|
|
26
26
|
"globals": "^13.2.0",
|
|
27
27
|
"nullthrows": "^1.1.1",
|
|
28
28
|
"outdent": "^0.8.0"
|
|
29
29
|
},
|
|
30
30
|
"type": "commonjs",
|
|
31
31
|
"scripts": {
|
|
32
|
-
"check-ts": "tsc --emitDeclarationOnly --rootDir src",
|
|
33
32
|
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
34
33
|
}
|
|
35
34
|
}
|
package/src/ESMOutputFormat.ts
CHANGED
|
@@ -83,7 +83,7 @@ export class ESMOutputFormat implements OutputFormat {
|
|
|
83
83
|
local,
|
|
84
84
|
exportAs,
|
|
85
85
|
} of this.packager.exportedSymbols.values()) {
|
|
86
|
-
if (this.packager.wrappedAssets.has(asset
|
|
86
|
+
if (this.packager.wrappedAssets.has(asset)) {
|
|
87
87
|
let obj = `parcelRequire("${this.packager.bundleGraph.getAssetPublicId(
|
|
88
88
|
asset,
|
|
89
89
|
)}")`;
|