@atlaspack/packager-js 2.12.1-dev.3368 → 2.12.1-dev.3401
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/DevPackager.js +7 -7
- package/lib/ESMOutputFormat.js +2 -2
- package/lib/ScopeHoistingPackager.js +55 -55
- package/lib/dev-prelude.js +8 -8
- package/lib/helpers.js +39 -39
- package/lib/index.js +4 -4
- package/lib/utils.js +5 -5
- package/package.json +8 -8
- package/src/DevPackager.js +8 -8
- package/src/ESMOutputFormat.js +2 -2
- package/src/ScopeHoistingPackager.js +56 -56
- package/src/dev-prelude.js +8 -8
- package/src/helpers.js +46 -48
- package/src/index.js +6 -6
- package/src/utils.js +25 -28
package/lib/DevPackager.js
CHANGED
|
@@ -43,11 +43,11 @@ var _utils2 = require("./utils");
|
|
|
43
43
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
44
44
|
const PRELUDE = _fs().default.readFileSync(_path().default.join(__dirname, 'dev-prelude.js'), 'utf8').trim().replace(/;$/, '');
|
|
45
45
|
class DevPackager {
|
|
46
|
-
constructor(options, bundleGraph, bundle,
|
|
46
|
+
constructor(options, bundleGraph, bundle, parcelRequireName) {
|
|
47
47
|
this.options = options;
|
|
48
48
|
this.bundleGraph = bundleGraph;
|
|
49
49
|
this.bundle = bundle;
|
|
50
|
-
this.
|
|
50
|
+
this.parcelRequireName = parcelRequireName;
|
|
51
51
|
}
|
|
52
52
|
async package() {
|
|
53
53
|
// Load assets
|
|
@@ -118,8 +118,8 @@ class DevPackager {
|
|
|
118
118
|
wrapped += ']';
|
|
119
119
|
if (this.bundle.env.isNode() && asset.meta.has_node_replacements === true) {
|
|
120
120
|
const relPath = (0, _utils().normalizeSeparators)(_path().default.relative(this.bundle.target.distDir, _path().default.dirname(asset.filePath)));
|
|
121
|
-
wrapped = wrapped.replace('$
|
|
122
|
-
wrapped = wrapped.replace('$
|
|
121
|
+
wrapped = wrapped.replace('$parcel$dirnameReplace', relPath);
|
|
122
|
+
wrapped = wrapped.replace('$parcel$filenameReplace', relPath);
|
|
123
123
|
}
|
|
124
124
|
if (this.bundle.env.sourceMap) {
|
|
125
125
|
if (mapBuffer) {
|
|
@@ -145,18 +145,18 @@ class DevPackager {
|
|
|
145
145
|
});
|
|
146
146
|
mainEntry = null;
|
|
147
147
|
}
|
|
148
|
-
let contents = prefix + '({' + assets + '},' + JSON.stringify(entries.map(asset => this.bundleGraph.getAssetPublicId(asset))) + ', ' + JSON.stringify(mainEntry ? this.bundleGraph.getAssetPublicId(mainEntry) : null) + ', ' + JSON.stringify(this.
|
|
148
|
+
let contents = prefix + '({' + assets + '},' + JSON.stringify(entries.map(asset => this.bundleGraph.getAssetPublicId(asset))) + ', ' + JSON.stringify(mainEntry ? this.bundleGraph.getAssetPublicId(mainEntry) : null) + ', ' + JSON.stringify(this.parcelRequireName) + ')' + '\n';
|
|
149
149
|
|
|
150
150
|
// The entry asset of a script bundle gets hoisted outside the bundle wrapper function
|
|
151
151
|
// so that its variables become globals. We need to replace any require calls for
|
|
152
|
-
// runtimes with a
|
|
152
|
+
// runtimes with a parcelRequire call.
|
|
153
153
|
if (this.bundle.env.sourceType === 'script' && script) {
|
|
154
154
|
let entryMap;
|
|
155
155
|
let mapBuffer = script.mapBuffer;
|
|
156
156
|
if (mapBuffer) {
|
|
157
157
|
entryMap = new (_sourceMap().default)(this.options.projectRoot, mapBuffer);
|
|
158
158
|
}
|
|
159
|
-
contents += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, script.code, entryMap, this.
|
|
159
|
+
contents += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, script.code, entryMap, this.parcelRequireName);
|
|
160
160
|
if (this.bundle.env.sourceMap && entryMap) {
|
|
161
161
|
map.addSourceMap(entryMap, lineOffset);
|
|
162
162
|
}
|
package/lib/ESMOutputFormat.js
CHANGED
|
@@ -76,7 +76,7 @@ class ESMOutputFormat {
|
|
|
76
76
|
exportAs
|
|
77
77
|
} of this.packager.exportedSymbols.values()) {
|
|
78
78
|
if (this.packager.wrappedAssets.has(asset.id)) {
|
|
79
|
-
let obj = `
|
|
79
|
+
let obj = `parcelRequire("${this.packager.bundleGraph.getAssetPublicId(asset)}")`;
|
|
80
80
|
res += `\nvar ${local} = ${this.packager.getPropertyAccess(obj, exportSymbol)};`;
|
|
81
81
|
lines++;
|
|
82
82
|
}
|
|
@@ -97,7 +97,7 @@ class ESMOutputFormat {
|
|
|
97
97
|
}
|
|
98
98
|
if (this.packager.needsPrelude && this.packager.shouldBundleQueue(this.packager.bundle)) {
|
|
99
99
|
// Should be last thing the bundle executes on intial eval
|
|
100
|
-
res += `\n$
|
|
100
|
+
res += `\n$parcel$global.rlb(${JSON.stringify(this.packager.bundle.publicId)})`;
|
|
101
101
|
lines++;
|
|
102
102
|
}
|
|
103
103
|
return [res, lines];
|
|
@@ -89,11 +89,11 @@ class ScopeHoistingPackager {
|
|
|
89
89
|
needsPrelude = false;
|
|
90
90
|
usedHelpers = new Set();
|
|
91
91
|
externalAssets = new Set();
|
|
92
|
-
constructor(options, bundleGraph, bundle,
|
|
92
|
+
constructor(options, bundleGraph, bundle, parcelRequireName, useAsyncBundleRuntime) {
|
|
93
93
|
this.options = options;
|
|
94
94
|
this.bundleGraph = bundleGraph;
|
|
95
95
|
this.bundle = bundle;
|
|
96
|
-
this.
|
|
96
|
+
this.parcelRequireName = parcelRequireName;
|
|
97
97
|
this.useAsyncBundleRuntime = useAsyncBundleRuntime;
|
|
98
98
|
let OutputFormat = OUTPUT_FORMATS[this.bundle.env.outputFormat];
|
|
99
99
|
this.outputFormat = new OutputFormat(this);
|
|
@@ -166,20 +166,20 @@ class ScopeHoistingPackager {
|
|
|
166
166
|
}
|
|
167
167
|
let needsBundleQueue = this.shouldBundleQueue(this.bundle);
|
|
168
168
|
|
|
169
|
-
// If any of the entry assets are wrapped, call
|
|
169
|
+
// If any of the entry assets are wrapped, call parcelRequire so they are executed.
|
|
170
170
|
for (let entry of entries) {
|
|
171
171
|
if (this.wrappedAssets.has(entry.id) && !this.isScriptEntry(entry)) {
|
|
172
172
|
var _entry$symbols$get;
|
|
173
|
-
let
|
|
173
|
+
let parcelRequire = `parcelRequire(${JSON.stringify(this.bundleGraph.getAssetPublicId(entry))});\n`;
|
|
174
174
|
let entryExports = (_entry$symbols$get = entry.symbols.get('*')) === null || _entry$symbols$get === void 0 ? void 0 : _entry$symbols$get.local;
|
|
175
175
|
if (entryExports && entry === mainEntry && this.exportedSymbols.has(entryExports)) {
|
|
176
176
|
(0, _assert().default)(!needsBundleQueue, 'Entry exports are not yet compaitble with async bundles');
|
|
177
|
-
res += `\nvar ${entryExports} = ${
|
|
177
|
+
res += `\nvar ${entryExports} = ${parcelRequire}`;
|
|
178
178
|
} else {
|
|
179
179
|
if (needsBundleQueue) {
|
|
180
|
-
|
|
180
|
+
parcelRequire = this.runWhenReady(this.bundle, parcelRequire);
|
|
181
181
|
}
|
|
182
|
-
res += `\n${
|
|
182
|
+
res += `\n${parcelRequire}`;
|
|
183
183
|
}
|
|
184
184
|
lineCount += 2;
|
|
185
185
|
}
|
|
@@ -190,7 +190,7 @@ class ScopeHoistingPackager {
|
|
|
190
190
|
|
|
191
191
|
// The entry asset of a script bundle gets hoisted outside the bundle wrapper so that
|
|
192
192
|
// its top-level variables become globals like a real browser script. We need to replace
|
|
193
|
-
// all dependency references for runtimes with a
|
|
193
|
+
// all dependency references for runtimes with a parcelRequire call.
|
|
194
194
|
if (this.bundle.env.outputFormat === 'global' && this.bundle.env.sourceType === 'script') {
|
|
195
195
|
res += '\n';
|
|
196
196
|
lineCount++;
|
|
@@ -203,7 +203,7 @@ class ScopeHoistingPackager {
|
|
|
203
203
|
if (mapBuffer) {
|
|
204
204
|
map = new (_sourceMap2().default)(this.options.projectRoot, mapBuffer);
|
|
205
205
|
}
|
|
206
|
-
res += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, code, map, this.
|
|
206
|
+
res += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, code, map, this.parcelRequireName);
|
|
207
207
|
if (sourceMap && map) {
|
|
208
208
|
sourceMap.addSourceMap(map, lineCount);
|
|
209
209
|
}
|
|
@@ -225,7 +225,7 @@ class ScopeHoistingPackager {
|
|
|
225
225
|
return codeToRun;
|
|
226
226
|
}
|
|
227
227
|
let params = [JSON.stringify(this.bundle.publicId), (0, _helpers.fnExpr)(this.bundle.env, [], [codeToRun]), JSON.stringify(deps)];
|
|
228
|
-
return `$
|
|
228
|
+
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
229
229
|
}
|
|
230
230
|
async loadAssets() {
|
|
231
231
|
let queue = new (_utils().PromiseQueue)({
|
|
@@ -384,13 +384,13 @@ class ScopeHoistingPackager {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
// TODO: maybe a meta prop?
|
|
387
|
-
if (code.includes('$
|
|
388
|
-
this.usedHelpers.add('$
|
|
387
|
+
if (code.includes('$parcel$global')) {
|
|
388
|
+
this.usedHelpers.add('$parcel$global');
|
|
389
389
|
}
|
|
390
390
|
if (this.bundle.env.isNode() && asset.meta.has_node_replacements) {
|
|
391
391
|
const relPath = (0, _utils().normalizeSeparators)(_path().default.relative(this.bundle.target.distDir, _path().default.dirname(asset.filePath)));
|
|
392
|
-
code = code.replace('$
|
|
393
|
-
code = code.replace('$
|
|
392
|
+
code = code.replace('$parcel$dirnameReplace', relPath);
|
|
393
|
+
code = code.replace('$parcel$filenameReplace', relPath);
|
|
394
394
|
}
|
|
395
395
|
let [depMap, replacements] = this.buildReplacements(asset, deps);
|
|
396
396
|
let [prepend, prependLines, append] = this.buildAssetPrelude(asset, deps, replacements);
|
|
@@ -433,15 +433,15 @@ class ScopeHoistingPackager {
|
|
|
433
433
|
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
434
434
|
let skipped = this.bundleGraph.isDependencySkipped(dep);
|
|
435
435
|
if (resolved && !skipped) {
|
|
436
|
-
// Hoist variable declarations for the referenced
|
|
436
|
+
// Hoist variable declarations for the referenced parcelRequire dependencies
|
|
437
437
|
// after the dependency is declared. This handles the case where the resulting asset
|
|
438
438
|
// is wrapped, but the dependency in this asset is not marked as wrapped. This means
|
|
439
439
|
// that it was imported/required at the top-level, so its side effects should run immediately.
|
|
440
|
-
let [res, lines] = this.
|
|
440
|
+
let [res, lines] = this.getHoistedParcelRequires(asset, dep, resolved);
|
|
441
441
|
let map;
|
|
442
442
|
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved.id)) {
|
|
443
443
|
// If this asset is wrapped, we need to hoist the code for the dependency
|
|
444
|
-
// outside our
|
|
444
|
+
// outside our parcelRequire.register wrapper. This is safe because all
|
|
445
445
|
// assets referenced by this asset will also be wrapped. Otherwise, inline the
|
|
446
446
|
// asset content where the import statement was.
|
|
447
447
|
if (shouldWrap) {
|
|
@@ -455,7 +455,7 @@ class ScopeHoistingPackager {
|
|
|
455
455
|
}
|
|
456
456
|
|
|
457
457
|
// Push this asset's source mappings down by the number of lines in the dependency
|
|
458
|
-
// plus the number of hoisted
|
|
458
|
+
// plus the number of hoisted parcelRequires. Then insert the source map for the dependency.
|
|
459
459
|
if (sourceMap) {
|
|
460
460
|
if (lines > 0) {
|
|
461
461
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
@@ -486,13 +486,13 @@ class ScopeHoistingPackager {
|
|
|
486
486
|
});
|
|
487
487
|
}
|
|
488
488
|
|
|
489
|
-
// If the asset is wrapped, we need to insert the dependency code outside the
|
|
489
|
+
// If the asset is wrapped, we need to insert the dependency code outside the parcelRequire.register
|
|
490
490
|
// wrapper. Dependencies must be inserted AFTER the asset is registered so that circular dependencies work.
|
|
491
491
|
if (shouldWrap) {
|
|
492
|
-
// Offset by one line for the
|
|
492
|
+
// Offset by one line for the parcelRequire.register wrapper.
|
|
493
493
|
sourceMap === null || sourceMap === void 0 || sourceMap.offsetLines(1, 1);
|
|
494
494
|
lineCount++;
|
|
495
|
-
code = `
|
|
495
|
+
code = `parcelRegister(${JSON.stringify(this.bundleGraph.getAssetPublicId(asset))}, function(module, exports) {
|
|
496
496
|
${code}
|
|
497
497
|
});
|
|
498
498
|
`;
|
|
@@ -634,8 +634,8 @@ ${code}
|
|
|
634
634
|
needsDefaultInterop = this.needsDefaultInterop(entry);
|
|
635
635
|
}
|
|
636
636
|
if (needsDefaultInterop) {
|
|
637
|
-
replacement = `($
|
|
638
|
-
this.usedHelpers.add('$
|
|
637
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
638
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
639
639
|
} else {
|
|
640
640
|
replacement = `${renamed}.default`;
|
|
641
641
|
}
|
|
@@ -688,8 +688,8 @@ ${code}
|
|
|
688
688
|
if (property === '*') {
|
|
689
689
|
replacement = renamed;
|
|
690
690
|
} else if (property === 'default') {
|
|
691
|
-
replacement = `($
|
|
692
|
-
this.usedHelpers.add('$
|
|
691
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
692
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
693
693
|
} else if (property) {
|
|
694
694
|
replacement = this.getPropertyAccess(renamed, property);
|
|
695
695
|
}
|
|
@@ -729,17 +729,17 @@ ${code}
|
|
|
729
729
|
let isExternalCommonJS = !isWrapped && this.bundle.env.isLibrary && this.bundle.env.outputFormat === 'commonjs' && !this.bundle.hasAsset(resolvedAsset);
|
|
730
730
|
|
|
731
731
|
// If the resolved asset is wrapped, but imported at the top-level by this asset,
|
|
732
|
-
// then we hoist
|
|
732
|
+
// then we hoist parcelRequire calls to the top of this asset so side effects run immediately.
|
|
733
733
|
if (isWrapped && dep && !(dep !== null && dep !== void 0 && dep.meta.shouldWrap) && symbol !== false && (
|
|
734
734
|
// Only do this if the asset is part of a different bundle (so it was definitely
|
|
735
|
-
//
|
|
735
|
+
// parcelRequire.register'ed there), or if it is indeed registered in this bundle.
|
|
736
736
|
!this.bundle.hasAsset(resolvedAsset) || !this.shouldSkipAsset(resolvedAsset))) {
|
|
737
737
|
let hoisted = this.hoistedRequires.get(dep.id);
|
|
738
738
|
if (!hoisted) {
|
|
739
739
|
hoisted = new Map();
|
|
740
740
|
this.hoistedRequires.set(dep.id, hoisted);
|
|
741
741
|
}
|
|
742
|
-
hoisted.set(resolvedAsset.id, `var $${publicId} =
|
|
742
|
+
hoisted.set(resolvedAsset.id, `var $${publicId} = parcelRequire(${JSON.stringify(publicId)});`);
|
|
743
743
|
}
|
|
744
744
|
if (isWrapped) {
|
|
745
745
|
this.needsPrelude = true;
|
|
@@ -750,15 +750,15 @@ ${code}
|
|
|
750
750
|
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && ((dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' || (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Export') && resolvedAsset.symbols.hasExportSymbol('*') && resolvedAsset.symbols.hasExportSymbol('default') && !resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
751
751
|
|
|
752
752
|
// Find the namespace object for the resolved module. If wrapped and this
|
|
753
|
-
// is an inline require (not top-level), use a
|
|
753
|
+
// is an inline require (not top-level), use a parcelRequire call, otherwise
|
|
754
754
|
// the hoisted variable declared above. Otherwise, if not wrapped, use the
|
|
755
755
|
// namespace export symbol.
|
|
756
756
|
let assetId = resolvedAsset.meta.id;
|
|
757
757
|
(0, _assert().default)(typeof assetId === 'string');
|
|
758
758
|
let obj;
|
|
759
759
|
if (isWrapped && (!dep || dep !== null && dep !== void 0 && dep.meta.shouldWrap)) {
|
|
760
|
-
// Wrap in extra parenthesis to not change semantics, e.g.`new (
|
|
761
|
-
obj = `(
|
|
760
|
+
// Wrap in extra parenthesis to not change semantics, e.g.`new (parcelRequire("..."))()`.
|
|
761
|
+
obj = `(parcelRequire(${JSON.stringify(publicId)}))`;
|
|
762
762
|
} else if (isWrapped && dep) {
|
|
763
763
|
obj = `$${publicId}`;
|
|
764
764
|
} else {
|
|
@@ -781,8 +781,8 @@ ${code}
|
|
|
781
781
|
// use a helper to check the __esModule flag at runtime.
|
|
782
782
|
let kind = dep === null || dep === void 0 ? void 0 : dep.meta.kind;
|
|
783
783
|
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' && resolvedAsset.symbols.hasExportSymbol('*') && this.needsDefaultInterop(resolvedAsset)) {
|
|
784
|
-
this.usedHelpers.add('$
|
|
785
|
-
return `(/*@__PURE__*/$
|
|
784
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
785
|
+
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
786
786
|
} else {
|
|
787
787
|
return this.getPropertyAccess(obj, exportSymbol);
|
|
788
788
|
}
|
|
@@ -792,7 +792,7 @@ ${code}
|
|
|
792
792
|
return (replacements === null || replacements === void 0 ? void 0 : replacements.get(symbol)) || symbol;
|
|
793
793
|
}
|
|
794
794
|
}
|
|
795
|
-
|
|
795
|
+
getHoistedParcelRequires(parentAsset, dep, resolved) {
|
|
796
796
|
if (resolved.type !== 'js') {
|
|
797
797
|
return ['', 0];
|
|
798
798
|
}
|
|
@@ -803,11 +803,11 @@ ${code}
|
|
|
803
803
|
|
|
804
804
|
// If the resolved asset is wrapped and is imported in the top-level by this asset,
|
|
805
805
|
// we need to run side effects when this asset runs. If the resolved asset is not
|
|
806
|
-
// the first one in the hoisted requires, we need to insert a
|
|
806
|
+
// the first one in the hoisted requires, we need to insert a parcelRequire here
|
|
807
807
|
// so it runs first.
|
|
808
808
|
if (isWrapped && !dep.meta.shouldWrap && (!hoisted || hoisted.keys().next().value !== resolved.id) && !this.bundleGraph.isDependencySkipped(dep) && !this.shouldSkipAsset(resolved)) {
|
|
809
809
|
this.needsPrelude = true;
|
|
810
|
-
res += `
|
|
810
|
+
res += `parcelRequire(${JSON.stringify(this.bundleGraph.getAssetPublicId(resolved))});`;
|
|
811
811
|
}
|
|
812
812
|
if (hoisted) {
|
|
813
813
|
this.needsPrelude = true;
|
|
@@ -861,9 +861,9 @@ ${code}
|
|
|
861
861
|
// and the namespace symbol is used.
|
|
862
862
|
// TODO: only if required by CJS?
|
|
863
863
|
if (asset.symbols.hasExportSymbol('default') && usedSymbols.has('*')) {
|
|
864
|
-
prepend += `\n$
|
|
864
|
+
prepend += `\n$parcel$defineInteropFlag($${assetId}$exports);\n`;
|
|
865
865
|
prependLineCount += 2;
|
|
866
|
-
this.usedHelpers.add('$
|
|
866
|
+
this.usedHelpers.add('$parcel$defineInteropFlag');
|
|
867
867
|
}
|
|
868
868
|
|
|
869
869
|
// Find wildcard re-export dependencies, and make sure their exports are also included in
|
|
@@ -882,20 +882,20 @@ ${code}
|
|
|
882
882
|
if (!resolved) {
|
|
883
883
|
// Re-exporting an external module. This should have already been handled in buildReplacements.
|
|
884
884
|
let external = (0, _nullthrows().default)((0, _nullthrows().default)(this.externals.get(dep.specifier)).get('*'));
|
|
885
|
-
append += `$
|
|
886
|
-
this.usedHelpers.add('$
|
|
885
|
+
append += `$parcel$exportWildcard($${assetId}$exports, ${external});\n`;
|
|
886
|
+
this.usedHelpers.add('$parcel$exportWildcard');
|
|
887
887
|
continue;
|
|
888
888
|
}
|
|
889
889
|
|
|
890
|
-
// If the resolved asset has an exports object, use the $
|
|
890
|
+
// If the resolved asset has an exports object, use the $parcel$exportWildcard helper
|
|
891
891
|
// to re-export all symbols. Otherwise, if there's no namespace object available, add
|
|
892
|
-
// $
|
|
892
|
+
// $parcel$export calls for each used symbol of the dependency.
|
|
893
893
|
if (isWrapped || resolved.meta.staticExports === false || (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
894
894
|
// an empty asset
|
|
895
895
|
!resolved.meta.hasCJSExports && resolved.symbols.hasExportSymbol('*')) {
|
|
896
896
|
let obj = this.getSymbolResolution(asset, resolved, '*', dep, replacements);
|
|
897
|
-
append += `$
|
|
898
|
-
this.usedHelpers.add('$
|
|
897
|
+
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
898
|
+
this.usedHelpers.add('$parcel$exportWildcard');
|
|
899
899
|
} else {
|
|
900
900
|
for (let symbol of (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep))) {
|
|
901
901
|
if (symbol === 'default' ||
|
|
@@ -906,8 +906,8 @@ ${code}
|
|
|
906
906
|
let resolvedSymbol = this.getSymbolResolution(asset, resolved, symbol, undefined, replacements);
|
|
907
907
|
let get = this.buildFunctionExpression([], resolvedSymbol);
|
|
908
908
|
let set = asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolvedSymbol} = v`) : '';
|
|
909
|
-
prepend += `$
|
|
910
|
-
this.usedHelpers.add('$
|
|
909
|
+
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(symbol)}, ${get}${set});\n`;
|
|
910
|
+
this.usedHelpers.add('$parcel$export');
|
|
911
911
|
prependLineCount++;
|
|
912
912
|
}
|
|
913
913
|
}
|
|
@@ -936,7 +936,7 @@ ${code}
|
|
|
936
936
|
return !unused;
|
|
937
937
|
});
|
|
938
938
|
if (usedExports.length > 0) {
|
|
939
|
-
// Insert $
|
|
939
|
+
// Insert $parcel$export calls for each of the used exports. This creates a getter/setter
|
|
940
940
|
// for the symbol so that when the value changes the object property also changes. This is
|
|
941
941
|
// required to simulate ESM live bindings. It's easier to do it this way rather than inserting
|
|
942
942
|
// additional assignments after each mutation of the original binding.
|
|
@@ -946,9 +946,9 @@ ${code}
|
|
|
946
946
|
let get = this.buildFunctionExpression([], resolved);
|
|
947
947
|
let isEsmExport = !!((_asset$symbols$get2 = asset.symbols.get(exp)) !== null && _asset$symbols$get2 !== void 0 && (_asset$symbols$get2 = _asset$symbols$get2.meta) !== null && _asset$symbols$get2 !== void 0 && _asset$symbols$get2.isEsm);
|
|
948
948
|
let set = !isEsmExport && asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`) : '';
|
|
949
|
-
return `$
|
|
949
|
+
return `$parcel$export($${assetId}$exports, ${JSON.stringify(exp)}, ${get}${set});`;
|
|
950
950
|
}).join('\n')}\n`;
|
|
951
|
-
this.usedHelpers.add('$
|
|
951
|
+
this.usedHelpers.add('$parcel$export');
|
|
952
952
|
prependLineCount += 1 + usedExports.length;
|
|
953
953
|
}
|
|
954
954
|
}
|
|
@@ -977,7 +977,7 @@ ${code}
|
|
|
977
977
|
|
|
978
978
|
// Add used helpers.
|
|
979
979
|
if (this.needsPrelude) {
|
|
980
|
-
this.usedHelpers.add('$
|
|
980
|
+
this.usedHelpers.add('$parcel$global');
|
|
981
981
|
}
|
|
982
982
|
for (let helper of this.usedHelpers) {
|
|
983
983
|
let currentHelper = _helpers.helpers[helper];
|
|
@@ -995,7 +995,7 @@ ${code}
|
|
|
995
995
|
let parentBundles = this.bundleGraph.getParentBundles(this.bundle);
|
|
996
996
|
let mightBeFirstJS = parentBundles.length === 0 || parentBundles.some(b => b.type !== 'js') || this.bundleGraph.getBundleGroupsContainingBundle(this.bundle).some(g => this.bundleGraph.isEntryBundleGroup(g)) || this.bundle.env.isIsolated() || this.bundle.bundleBehavior === 'isolated';
|
|
997
997
|
if (mightBeFirstJS) {
|
|
998
|
-
let preludeCode = (0, _helpers.prelude)(this.
|
|
998
|
+
let preludeCode = (0, _helpers.prelude)(this.parcelRequireName);
|
|
999
999
|
res += preludeCode;
|
|
1000
1000
|
if (enableSourceMaps) {
|
|
1001
1001
|
lines += (0, _utils().countLines)(preludeCode) - 1;
|
|
@@ -1008,11 +1008,11 @@ ${code}
|
|
|
1008
1008
|
}
|
|
1009
1009
|
}
|
|
1010
1010
|
} else {
|
|
1011
|
-
// Otherwise, get the current
|
|
1012
|
-
const escaped = JSON.stringify(this.
|
|
1013
|
-
res += `var
|
|
1011
|
+
// Otherwise, get the current parcelRequire global.
|
|
1012
|
+
const escaped = JSON.stringify(this.parcelRequireName);
|
|
1013
|
+
res += `var parcelRequire = $parcel$global[${escaped}];\n`;
|
|
1014
1014
|
lines++;
|
|
1015
|
-
res += `var
|
|
1015
|
+
res += `var parcelRegister = parcelRequire.register;\n`;
|
|
1016
1016
|
lines++;
|
|
1017
1017
|
}
|
|
1018
1018
|
}
|
package/lib/dev-prelude.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// anything defined in a previous bundle is accessed via the
|
|
7
7
|
// orig method which is the require for previous bundles
|
|
8
8
|
|
|
9
|
-
(function (modules, entry, mainEntry,
|
|
9
|
+
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
|
10
10
|
/* eslint-disable no-undef */
|
|
11
11
|
var globalObject =
|
|
12
12
|
typeof globalThis !== 'undefined'
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
|
|
23
23
|
// Save the require from previous bundle to this closure if any
|
|
24
24
|
var previousRequire =
|
|
25
|
-
typeof globalObject[
|
|
26
|
-
globalObject[
|
|
25
|
+
typeof globalObject[parcelRequireName] === 'function' &&
|
|
26
|
+
globalObject[parcelRequireName];
|
|
27
27
|
|
|
28
28
|
var cache = previousRequire.cache || {};
|
|
29
29
|
// Do not use `require` to prevent Webpack from trying to bundle this call
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
// cache jump to the current global require ie. the last bundle
|
|
40
40
|
// that was added to the page.
|
|
41
41
|
var currentRequire =
|
|
42
|
-
typeof globalObject[
|
|
43
|
-
globalObject[
|
|
42
|
+
typeof globalObject[parcelRequireName] === 'function' &&
|
|
43
|
+
globalObject[parcelRequireName];
|
|
44
44
|
if (!jumped && currentRequire) {
|
|
45
45
|
return currentRequire(name, true);
|
|
46
46
|
}
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
this.exports = {};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
newRequire.
|
|
99
|
+
newRequire.isParcelRequire = true;
|
|
100
100
|
newRequire.Module = Module;
|
|
101
101
|
newRequire.modules = modules;
|
|
102
102
|
newRequire.cache = cache;
|
|
@@ -112,11 +112,11 @@
|
|
|
112
112
|
|
|
113
113
|
Object.defineProperty(newRequire, 'root', {
|
|
114
114
|
get: function () {
|
|
115
|
-
return globalObject[
|
|
115
|
+
return globalObject[parcelRequireName];
|
|
116
116
|
},
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
-
globalObject[
|
|
119
|
+
globalObject[parcelRequireName] = newRequire;
|
|
120
120
|
|
|
121
121
|
for (var i = 0; i < entry.length; i++) {
|
|
122
122
|
newRequire(entry[i]);
|
package/lib/helpers.js
CHANGED
|
@@ -4,22 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.prelude = exports.helpers = exports.fnExpr = exports.bundleQueuePrelude = void 0;
|
|
7
|
-
const prelude =
|
|
8
|
-
var $
|
|
9
|
-
var $
|
|
7
|
+
const prelude = parcelRequireName => `
|
|
8
|
+
var $parcel$modules = {};
|
|
9
|
+
var $parcel$inits = {};
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var parcelRequire = $parcel$global[${JSON.stringify(parcelRequireName)}];
|
|
12
12
|
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
if (id in $
|
|
16
|
-
return $
|
|
13
|
+
if (parcelRequire == null) {
|
|
14
|
+
parcelRequire = function(id) {
|
|
15
|
+
if (id in $parcel$modules) {
|
|
16
|
+
return $parcel$modules[id].exports;
|
|
17
17
|
}
|
|
18
|
-
if (id in $
|
|
19
|
-
var init = $
|
|
20
|
-
delete $
|
|
18
|
+
if (id in $parcel$inits) {
|
|
19
|
+
var init = $parcel$inits[id];
|
|
20
|
+
delete $parcel$inits[id];
|
|
21
21
|
var module = {id: id, exports: {}};
|
|
22
|
-
$
|
|
22
|
+
$parcel$modules[id] = module;
|
|
23
23
|
init.call(module.exports, module, module.exports);
|
|
24
24
|
return module.exports;
|
|
25
25
|
}
|
|
@@ -28,14 +28,14 @@ if (atlaspackRequire == null) {
|
|
|
28
28
|
throw err;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
$
|
|
31
|
+
parcelRequire.register = function register(id, init) {
|
|
32
|
+
$parcel$inits[id] = init;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
$
|
|
35
|
+
$parcel$global[${JSON.stringify(parcelRequireName)}] = parcelRequire;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
var
|
|
38
|
+
var parcelRegister = parcelRequire.register;
|
|
39
39
|
`;
|
|
40
40
|
exports.prelude = prelude;
|
|
41
41
|
const fnExpr = (env, params, body) => {
|
|
@@ -47,34 +47,34 @@ const fnExpr = (env, params, body) => {
|
|
|
47
47
|
};
|
|
48
48
|
exports.fnExpr = fnExpr;
|
|
49
49
|
const bundleQueuePrelude = env => `
|
|
50
|
-
if (!$
|
|
50
|
+
if (!$parcel$global.lb) {
|
|
51
51
|
// Set of loaded bundles
|
|
52
|
-
$
|
|
52
|
+
$parcel$global.lb = new Set();
|
|
53
53
|
// Queue of bundles to execute once they're dep bundles are loaded
|
|
54
|
-
$
|
|
54
|
+
$parcel$global.bq = [];
|
|
55
55
|
|
|
56
56
|
// Register loaded bundle
|
|
57
|
-
$
|
|
57
|
+
$parcel$global.rlb = ${fnExpr(env, ['bundle'], ['$parcel$global.lb.add(bundle);', '$parcel$global.pq();'])}
|
|
58
58
|
|
|
59
59
|
// Run when ready
|
|
60
|
-
$
|
|
60
|
+
$parcel$global.rwr = ${fnExpr(env,
|
|
61
61
|
// b = bundle public id
|
|
62
62
|
// r = run function to execute the bundle entry
|
|
63
63
|
// d = list of dependent bundles this bundle requires before executing
|
|
64
|
-
['b', 'r', 'd'], ['$
|
|
64
|
+
['b', 'r', 'd'], ['$parcel$global.bq.push({b, r, d});', '$parcel$global.pq();'])}
|
|
65
65
|
|
|
66
66
|
// Process queue
|
|
67
|
-
$
|
|
67
|
+
$parcel$global.pq = ${fnExpr(env, [], [`var runnableEntry = $parcel$global.bq.find(${fnExpr(env, ['i'], [`return i.d.every(${fnExpr(env, ['dep'], ['return $parcel$global.lb.has(dep);'])});`])});`, 'if (runnableEntry) {', `$parcel$global.bq = $parcel$global.bq.filter(${fnExpr(env, ['i'], ['return i.b !== runnableEntry.b;'])});`, 'runnableEntry.r();', '$parcel$global.pq();', '}'])}
|
|
68
68
|
}
|
|
69
69
|
`;
|
|
70
70
|
exports.bundleQueuePrelude = bundleQueuePrelude;
|
|
71
|
-
const $
|
|
72
|
-
function $
|
|
71
|
+
const $parcel$export = `
|
|
72
|
+
function $parcel$export(e, n, v, s) {
|
|
73
73
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
74
74
|
}
|
|
75
75
|
`;
|
|
76
|
-
const $
|
|
77
|
-
function $
|
|
76
|
+
const $parcel$exportWildcard = `
|
|
77
|
+
function $parcel$exportWildcard(dest, source) {
|
|
78
78
|
Object.keys(source).forEach(function(key) {
|
|
79
79
|
if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
|
|
80
80
|
return;
|
|
@@ -91,19 +91,19 @@ function $atlaspack$exportWildcard(dest, source) {
|
|
|
91
91
|
return dest;
|
|
92
92
|
}
|
|
93
93
|
`;
|
|
94
|
-
const $
|
|
95
|
-
function $
|
|
94
|
+
const $parcel$interopDefault = `
|
|
95
|
+
function $parcel$interopDefault(a) {
|
|
96
96
|
return a && a.__esModule ? a.default : a;
|
|
97
97
|
}
|
|
98
98
|
`;
|
|
99
|
-
const $
|
|
99
|
+
const $parcel$global = env => {
|
|
100
100
|
if (env.supports('global-this')) {
|
|
101
101
|
return `
|
|
102
|
-
var $
|
|
102
|
+
var $parcel$global = globalThis;
|
|
103
103
|
`;
|
|
104
104
|
}
|
|
105
105
|
return `
|
|
106
|
-
var $
|
|
106
|
+
var $parcel$global =
|
|
107
107
|
typeof globalThis !== 'undefined'
|
|
108
108
|
? globalThis
|
|
109
109
|
: typeof self !== 'undefined'
|
|
@@ -115,15 +115,15 @@ const $atlaspack$global = env => {
|
|
|
115
115
|
: {};
|
|
116
116
|
`;
|
|
117
117
|
};
|
|
118
|
-
const $
|
|
119
|
-
function $
|
|
118
|
+
const $parcel$defineInteropFlag = `
|
|
119
|
+
function $parcel$defineInteropFlag(a) {
|
|
120
120
|
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
121
121
|
}
|
|
122
122
|
`;
|
|
123
123
|
const helpers = exports.helpers = {
|
|
124
|
-
$
|
|
125
|
-
$
|
|
126
|
-
$
|
|
127
|
-
$
|
|
128
|
-
$
|
|
124
|
+
$parcel$export,
|
|
125
|
+
$parcel$exportWildcard,
|
|
126
|
+
$parcel$interopDefault,
|
|
127
|
+
$parcel$global,
|
|
128
|
+
$parcel$defineInteropFlag
|
|
129
129
|
};
|
package/lib/index.js
CHANGED
|
@@ -70,14 +70,14 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
70
70
|
}, packageKey, `Invalid config for ${packageKey}`);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
// Generate a name for the global
|
|
74
|
-
// This allows multiple
|
|
73
|
+
// Generate a name for the global parcelRequire function that is unique to this project.
|
|
74
|
+
// This allows multiple parcel builds to coexist on the same page.
|
|
75
75
|
let packageName = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
76
76
|
packageKey: 'name'
|
|
77
77
|
});
|
|
78
78
|
let name = (packageName === null || packageName === void 0 || (_packageName$contents = packageName.contents) === null || _packageName$contents === void 0 ? void 0 : _packageName$contents.name) ?? '';
|
|
79
79
|
return {
|
|
80
|
-
|
|
80
|
+
parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
|
|
81
81
|
unstable_asyncBundleRuntime: Boolean(conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime)
|
|
82
82
|
};
|
|
83
83
|
},
|
|
@@ -100,7 +100,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
if (contents == null) {
|
|
103
|
-
let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).
|
|
103
|
+
let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName, (0, _nullthrows().default)(config).unstable_asyncBundleRuntime) : new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
|
|
104
104
|
({
|
|
105
105
|
contents,
|
|
106
106
|
map
|