@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/utils.js
CHANGED
|
@@ -15,16 +15,16 @@ function _nullthrows() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
// This replaces
|
|
19
|
-
//
|
|
18
|
+
// This replaces __parcel__require__ references left by the transformer with
|
|
19
|
+
// parcelRequire calls of the resolved asset id. This lets runtimes work within
|
|
20
20
|
// script bundles, which must be outside the bundle wrapper so their variables are global.
|
|
21
|
-
function replaceScriptDependencies(bundleGraph, bundle, code, map,
|
|
21
|
+
function replaceScriptDependencies(bundleGraph, bundle, code, map, parcelRequireName) {
|
|
22
22
|
let entry = (0, _nullthrows().default)(bundle.getMainEntry());
|
|
23
23
|
let dependencies = bundleGraph.getDependencies(entry);
|
|
24
24
|
let lineCount = 0;
|
|
25
25
|
let offset = 0;
|
|
26
26
|
let columnStartIndex = 0;
|
|
27
|
-
code = code.replace(/\n|
|
|
27
|
+
code = code.replace(/\n|__parcel__require__\(['"](.*?)['"]\)/g, (m, s, i) => {
|
|
28
28
|
if (m === '\n') {
|
|
29
29
|
columnStartIndex = i + offset + 1;
|
|
30
30
|
lineCount++;
|
|
@@ -33,7 +33,7 @@ function replaceScriptDependencies(bundleGraph, bundle, code, map, atlaspackRequ
|
|
|
33
33
|
let dep = (0, _nullthrows().default)(dependencies.find(d => getSpecifier(d) === s));
|
|
34
34
|
let resolved = (0, _nullthrows().default)(bundleGraph.getResolvedAsset(dep, bundle));
|
|
35
35
|
let publicId = bundleGraph.getAssetPublicId(resolved);
|
|
36
|
-
let replacement = `${
|
|
36
|
+
let replacement = `${parcelRequireName}("${publicId}")`;
|
|
37
37
|
if (map) {
|
|
38
38
|
let lengthDifference = replacement.length - m.length;
|
|
39
39
|
if (lengthDifference !== 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.12.1-dev.
|
|
3
|
+
"version": "2.12.1-dev.3401+b483af77f",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
"source": "src/index.js",
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">= 16.0.0",
|
|
16
|
-
"
|
|
16
|
+
"parcel": "^2.12.1-dev.3401+b483af77f"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.12.1-dev.
|
|
20
|
-
"@atlaspack/plugin": "2.12.1-dev.
|
|
21
|
-
"@atlaspack/rust": "2.12.1-dev.
|
|
22
|
-
"@atlaspack/types": "2.12.1-dev.
|
|
23
|
-
"@atlaspack/utils": "2.12.1-dev.
|
|
19
|
+
"@atlaspack/diagnostic": "2.12.1-dev.3401+b483af77f",
|
|
20
|
+
"@atlaspack/plugin": "2.12.1-dev.3401+b483af77f",
|
|
21
|
+
"@atlaspack/rust": "2.12.1-dev.3401+b483af77f",
|
|
22
|
+
"@atlaspack/types": "2.12.1-dev.3401+b483af77f",
|
|
23
|
+
"@atlaspack/utils": "2.12.1-dev.3401+b483af77f",
|
|
24
24
|
"@parcel/source-map": "^2.1.1",
|
|
25
25
|
"globals": "^13.2.0",
|
|
26
26
|
"nullthrows": "^1.1.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "b483af77f02d1258c8dad156e097b94f83671d8e"
|
|
29
29
|
}
|
package/src/DevPackager.js
CHANGED
|
@@ -22,18 +22,18 @@ export class DevPackager {
|
|
|
22
22
|
options: PluginOptions;
|
|
23
23
|
bundleGraph: BundleGraph<NamedBundle>;
|
|
24
24
|
bundle: NamedBundle;
|
|
25
|
-
|
|
25
|
+
parcelRequireName: string;
|
|
26
26
|
|
|
27
27
|
constructor(
|
|
28
28
|
options: PluginOptions,
|
|
29
29
|
bundleGraph: BundleGraph<NamedBundle>,
|
|
30
30
|
bundle: NamedBundle,
|
|
31
|
-
|
|
31
|
+
parcelRequireName: string,
|
|
32
32
|
) {
|
|
33
33
|
this.options = options;
|
|
34
34
|
this.bundleGraph = bundleGraph;
|
|
35
35
|
this.bundle = bundle;
|
|
36
|
-
this.
|
|
36
|
+
this.parcelRequireName = parcelRequireName;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
async package(): Promise<{|contents: string, map: ?SourceMap|}> {
|
|
@@ -132,8 +132,8 @@ export class DevPackager {
|
|
|
132
132
|
path.dirname(asset.filePath),
|
|
133
133
|
),
|
|
134
134
|
);
|
|
135
|
-
wrapped = wrapped.replace('$
|
|
136
|
-
wrapped = wrapped.replace('$
|
|
135
|
+
wrapped = wrapped.replace('$parcel$dirnameReplace', relPath);
|
|
136
|
+
wrapped = wrapped.replace('$parcel$filenameReplace', relPath);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
if (this.bundle.env.sourceMap) {
|
|
@@ -183,13 +183,13 @@ export class DevPackager {
|
|
|
183
183
|
mainEntry ? this.bundleGraph.getAssetPublicId(mainEntry) : null,
|
|
184
184
|
) +
|
|
185
185
|
', ' +
|
|
186
|
-
JSON.stringify(this.
|
|
186
|
+
JSON.stringify(this.parcelRequireName) +
|
|
187
187
|
')' +
|
|
188
188
|
'\n';
|
|
189
189
|
|
|
190
190
|
// The entry asset of a script bundle gets hoisted outside the bundle wrapper function
|
|
191
191
|
// so that its variables become globals. We need to replace any require calls for
|
|
192
|
-
// runtimes with a
|
|
192
|
+
// runtimes with a parcelRequire call.
|
|
193
193
|
if (this.bundle.env.sourceType === 'script' && script) {
|
|
194
194
|
let entryMap;
|
|
195
195
|
let mapBuffer = script.mapBuffer;
|
|
@@ -201,7 +201,7 @@ export class DevPackager {
|
|
|
201
201
|
this.bundle,
|
|
202
202
|
script.code,
|
|
203
203
|
entryMap,
|
|
204
|
-
this.
|
|
204
|
+
this.parcelRequireName,
|
|
205
205
|
);
|
|
206
206
|
if (this.bundle.env.sourceMap && entryMap) {
|
|
207
207
|
map.addSourceMap(entryMap, lineOffset);
|
package/src/ESMOutputFormat.js
CHANGED
|
@@ -85,7 +85,7 @@ export class ESMOutputFormat implements OutputFormat {
|
|
|
85
85
|
exportAs,
|
|
86
86
|
} of this.packager.exportedSymbols.values()) {
|
|
87
87
|
if (this.packager.wrappedAssets.has(asset.id)) {
|
|
88
|
-
let obj = `
|
|
88
|
+
let obj = `parcelRequire("${this.packager.bundleGraph.getAssetPublicId(
|
|
89
89
|
asset,
|
|
90
90
|
)}")`;
|
|
91
91
|
res += `\nvar ${local} = ${this.packager.getPropertyAccess(
|
|
@@ -118,7 +118,7 @@ export class ESMOutputFormat implements OutputFormat {
|
|
|
118
118
|
this.packager.shouldBundleQueue(this.packager.bundle)
|
|
119
119
|
) {
|
|
120
120
|
// Should be last thing the bundle executes on intial eval
|
|
121
|
-
res += `\n$
|
|
121
|
+
res += `\n$parcel$global.rlb(${JSON.stringify(
|
|
122
122
|
this.packager.bundle.publicId,
|
|
123
123
|
)})`;
|
|
124
124
|
lines++;
|
|
@@ -72,7 +72,7 @@ export class ScopeHoistingPackager {
|
|
|
72
72
|
options: PluginOptions;
|
|
73
73
|
bundleGraph: BundleGraph<NamedBundle>;
|
|
74
74
|
bundle: NamedBundle;
|
|
75
|
-
|
|
75
|
+
parcelRequireName: string;
|
|
76
76
|
useAsyncBundleRuntime: boolean;
|
|
77
77
|
outputFormat: OutputFormat;
|
|
78
78
|
isAsyncBundle: boolean;
|
|
@@ -100,13 +100,13 @@ export class ScopeHoistingPackager {
|
|
|
100
100
|
options: PluginOptions,
|
|
101
101
|
bundleGraph: BundleGraph<NamedBundle>,
|
|
102
102
|
bundle: NamedBundle,
|
|
103
|
-
|
|
103
|
+
parcelRequireName: string,
|
|
104
104
|
useAsyncBundleRuntime: boolean,
|
|
105
105
|
) {
|
|
106
106
|
this.options = options;
|
|
107
107
|
this.bundleGraph = bundleGraph;
|
|
108
108
|
this.bundle = bundle;
|
|
109
|
-
this.
|
|
109
|
+
this.parcelRequireName = parcelRequireName;
|
|
110
110
|
this.useAsyncBundleRuntime = useAsyncBundleRuntime;
|
|
111
111
|
|
|
112
112
|
let OutputFormat = OUTPUT_FORMATS[this.bundle.env.outputFormat];
|
|
@@ -191,10 +191,10 @@ export class ScopeHoistingPackager {
|
|
|
191
191
|
|
|
192
192
|
let needsBundleQueue = this.shouldBundleQueue(this.bundle);
|
|
193
193
|
|
|
194
|
-
// If any of the entry assets are wrapped, call
|
|
194
|
+
// If any of the entry assets are wrapped, call parcelRequire so they are executed.
|
|
195
195
|
for (let entry of entries) {
|
|
196
196
|
if (this.wrappedAssets.has(entry.id) && !this.isScriptEntry(entry)) {
|
|
197
|
-
let
|
|
197
|
+
let parcelRequire = `parcelRequire(${JSON.stringify(
|
|
198
198
|
this.bundleGraph.getAssetPublicId(entry),
|
|
199
199
|
)});\n`;
|
|
200
200
|
|
|
@@ -209,13 +209,13 @@ export class ScopeHoistingPackager {
|
|
|
209
209
|
!needsBundleQueue,
|
|
210
210
|
'Entry exports are not yet compaitble with async bundles',
|
|
211
211
|
);
|
|
212
|
-
res += `\nvar ${entryExports} = ${
|
|
212
|
+
res += `\nvar ${entryExports} = ${parcelRequire}`;
|
|
213
213
|
} else {
|
|
214
214
|
if (needsBundleQueue) {
|
|
215
|
-
|
|
215
|
+
parcelRequire = this.runWhenReady(this.bundle, parcelRequire);
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
res += `\n${
|
|
218
|
+
res += `\n${parcelRequire}`;
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
lineCount += 2;
|
|
@@ -228,7 +228,7 @@ export class ScopeHoistingPackager {
|
|
|
228
228
|
|
|
229
229
|
// The entry asset of a script bundle gets hoisted outside the bundle wrapper so that
|
|
230
230
|
// its top-level variables become globals like a real browser script. We need to replace
|
|
231
|
-
// all dependency references for runtimes with a
|
|
231
|
+
// all dependency references for runtimes with a parcelRequire call.
|
|
232
232
|
if (
|
|
233
233
|
this.bundle.env.outputFormat === 'global' &&
|
|
234
234
|
this.bundle.env.sourceType === 'script'
|
|
@@ -249,7 +249,7 @@ export class ScopeHoistingPackager {
|
|
|
249
249
|
this.bundle,
|
|
250
250
|
code,
|
|
251
251
|
map,
|
|
252
|
-
this.
|
|
252
|
+
this.parcelRequireName,
|
|
253
253
|
);
|
|
254
254
|
if (sourceMap && map) {
|
|
255
255
|
sourceMap.addSourceMap(map, lineCount);
|
|
@@ -294,7 +294,7 @@ export class ScopeHoistingPackager {
|
|
|
294
294
|
JSON.stringify(deps),
|
|
295
295
|
];
|
|
296
296
|
|
|
297
|
-
return `$
|
|
297
|
+
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
async loadAssets(): Promise<Array<Asset>> {
|
|
@@ -498,16 +498,16 @@ export class ScopeHoistingPackager {
|
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
// TODO: maybe a meta prop?
|
|
501
|
-
if (code.includes('$
|
|
502
|
-
this.usedHelpers.add('$
|
|
501
|
+
if (code.includes('$parcel$global')) {
|
|
502
|
+
this.usedHelpers.add('$parcel$global');
|
|
503
503
|
}
|
|
504
504
|
|
|
505
505
|
if (this.bundle.env.isNode() && asset.meta.has_node_replacements) {
|
|
506
506
|
const relPath = normalizeSeparators(
|
|
507
507
|
path.relative(this.bundle.target.distDir, path.dirname(asset.filePath)),
|
|
508
508
|
);
|
|
509
|
-
code = code.replace('$
|
|
510
|
-
code = code.replace('$
|
|
509
|
+
code = code.replace('$parcel$dirnameReplace', relPath);
|
|
510
|
+
code = code.replace('$parcel$filenameReplace', relPath);
|
|
511
511
|
}
|
|
512
512
|
|
|
513
513
|
let [depMap, replacements] = this.buildReplacements(asset, deps);
|
|
@@ -558,11 +558,11 @@ export class ScopeHoistingPackager {
|
|
|
558
558
|
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
559
559
|
let skipped = this.bundleGraph.isDependencySkipped(dep);
|
|
560
560
|
if (resolved && !skipped) {
|
|
561
|
-
// Hoist variable declarations for the referenced
|
|
561
|
+
// Hoist variable declarations for the referenced parcelRequire dependencies
|
|
562
562
|
// after the dependency is declared. This handles the case where the resulting asset
|
|
563
563
|
// is wrapped, but the dependency in this asset is not marked as wrapped. This means
|
|
564
564
|
// that it was imported/required at the top-level, so its side effects should run immediately.
|
|
565
|
-
let [res, lines] = this.
|
|
565
|
+
let [res, lines] = this.getHoistedParcelRequires(
|
|
566
566
|
asset,
|
|
567
567
|
dep,
|
|
568
568
|
resolved,
|
|
@@ -573,7 +573,7 @@ export class ScopeHoistingPackager {
|
|
|
573
573
|
!this.seenAssets.has(resolved.id)
|
|
574
574
|
) {
|
|
575
575
|
// If this asset is wrapped, we need to hoist the code for the dependency
|
|
576
|
-
// outside our
|
|
576
|
+
// outside our parcelRequire.register wrapper. This is safe because all
|
|
577
577
|
// assets referenced by this asset will also be wrapped. Otherwise, inline the
|
|
578
578
|
// asset content where the import statement was.
|
|
579
579
|
if (shouldWrap) {
|
|
@@ -587,7 +587,7 @@ export class ScopeHoistingPackager {
|
|
|
587
587
|
}
|
|
588
588
|
|
|
589
589
|
// Push this asset's source mappings down by the number of lines in the dependency
|
|
590
|
-
// plus the number of hoisted
|
|
590
|
+
// plus the number of hoisted parcelRequires. Then insert the source map for the dependency.
|
|
591
591
|
if (sourceMap) {
|
|
592
592
|
if (lines > 0) {
|
|
593
593
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
@@ -624,14 +624,14 @@ export class ScopeHoistingPackager {
|
|
|
624
624
|
});
|
|
625
625
|
}
|
|
626
626
|
|
|
627
|
-
// If the asset is wrapped, we need to insert the dependency code outside the
|
|
627
|
+
// If the asset is wrapped, we need to insert the dependency code outside the parcelRequire.register
|
|
628
628
|
// wrapper. Dependencies must be inserted AFTER the asset is registered so that circular dependencies work.
|
|
629
629
|
if (shouldWrap) {
|
|
630
|
-
// Offset by one line for the
|
|
630
|
+
// Offset by one line for the parcelRequire.register wrapper.
|
|
631
631
|
sourceMap?.offsetLines(1, 1);
|
|
632
632
|
lineCount++;
|
|
633
633
|
|
|
634
|
-
code = `
|
|
634
|
+
code = `parcelRegister(${JSON.stringify(
|
|
635
635
|
this.bundleGraph.getAssetPublicId(asset),
|
|
636
636
|
)}, function(module, exports) {
|
|
637
637
|
${code}
|
|
@@ -842,8 +842,8 @@ ${code}
|
|
|
842
842
|
needsDefaultInterop = this.needsDefaultInterop(entry);
|
|
843
843
|
}
|
|
844
844
|
if (needsDefaultInterop) {
|
|
845
|
-
replacement = `($
|
|
846
|
-
this.usedHelpers.add('$
|
|
845
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
846
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
847
847
|
} else {
|
|
848
848
|
replacement = `${renamed}.default`;
|
|
849
849
|
}
|
|
@@ -909,8 +909,8 @@ ${code}
|
|
|
909
909
|
if (property === '*') {
|
|
910
910
|
replacement = renamed;
|
|
911
911
|
} else if (property === 'default') {
|
|
912
|
-
replacement = `($
|
|
913
|
-
this.usedHelpers.add('$
|
|
912
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
913
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
914
914
|
} else if (property) {
|
|
915
915
|
replacement = this.getPropertyAccess(renamed, property);
|
|
916
916
|
}
|
|
@@ -976,14 +976,14 @@ ${code}
|
|
|
976
976
|
!this.bundle.hasAsset(resolvedAsset);
|
|
977
977
|
|
|
978
978
|
// If the resolved asset is wrapped, but imported at the top-level by this asset,
|
|
979
|
-
// then we hoist
|
|
979
|
+
// then we hoist parcelRequire calls to the top of this asset so side effects run immediately.
|
|
980
980
|
if (
|
|
981
981
|
isWrapped &&
|
|
982
982
|
dep &&
|
|
983
983
|
!dep?.meta.shouldWrap &&
|
|
984
984
|
symbol !== false &&
|
|
985
985
|
// Only do this if the asset is part of a different bundle (so it was definitely
|
|
986
|
-
//
|
|
986
|
+
// parcelRequire.register'ed there), or if it is indeed registered in this bundle.
|
|
987
987
|
(!this.bundle.hasAsset(resolvedAsset) ||
|
|
988
988
|
!this.shouldSkipAsset(resolvedAsset))
|
|
989
989
|
) {
|
|
@@ -995,7 +995,7 @@ ${code}
|
|
|
995
995
|
|
|
996
996
|
hoisted.set(
|
|
997
997
|
resolvedAsset.id,
|
|
998
|
-
`var $${publicId} =
|
|
998
|
+
`var $${publicId} = parcelRequire(${JSON.stringify(publicId)});`,
|
|
999
999
|
);
|
|
1000
1000
|
}
|
|
1001
1001
|
|
|
@@ -1015,15 +1015,15 @@ ${code}
|
|
|
1015
1015
|
!resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
1016
1016
|
|
|
1017
1017
|
// Find the namespace object for the resolved module. If wrapped and this
|
|
1018
|
-
// is an inline require (not top-level), use a
|
|
1018
|
+
// is an inline require (not top-level), use a parcelRequire call, otherwise
|
|
1019
1019
|
// the hoisted variable declared above. Otherwise, if not wrapped, use the
|
|
1020
1020
|
// namespace export symbol.
|
|
1021
1021
|
let assetId = resolvedAsset.meta.id;
|
|
1022
1022
|
invariant(typeof assetId === 'string');
|
|
1023
1023
|
let obj;
|
|
1024
1024
|
if (isWrapped && (!dep || dep?.meta.shouldWrap)) {
|
|
1025
|
-
// Wrap in extra parenthesis to not change semantics, e.g.`new (
|
|
1026
|
-
obj = `(
|
|
1025
|
+
// Wrap in extra parenthesis to not change semantics, e.g.`new (parcelRequire("..."))()`.
|
|
1026
|
+
obj = `(parcelRequire(${JSON.stringify(publicId)}))`;
|
|
1027
1027
|
} else if (isWrapped && dep) {
|
|
1028
1028
|
obj = `$${publicId}`;
|
|
1029
1029
|
} else {
|
|
@@ -1057,8 +1057,8 @@ ${code}
|
|
|
1057
1057
|
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
1058
1058
|
this.needsDefaultInterop(resolvedAsset)
|
|
1059
1059
|
) {
|
|
1060
|
-
this.usedHelpers.add('$
|
|
1061
|
-
return `(/*@__PURE__*/$
|
|
1060
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
1061
|
+
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
1062
1062
|
} else {
|
|
1063
1063
|
return this.getPropertyAccess(obj, exportSymbol);
|
|
1064
1064
|
}
|
|
@@ -1069,7 +1069,7 @@ ${code}
|
|
|
1069
1069
|
}
|
|
1070
1070
|
}
|
|
1071
1071
|
|
|
1072
|
-
|
|
1072
|
+
getHoistedParcelRequires(
|
|
1073
1073
|
parentAsset: Asset,
|
|
1074
1074
|
dep: Dependency,
|
|
1075
1075
|
resolved: Asset,
|
|
@@ -1085,7 +1085,7 @@ ${code}
|
|
|
1085
1085
|
|
|
1086
1086
|
// If the resolved asset is wrapped and is imported in the top-level by this asset,
|
|
1087
1087
|
// we need to run side effects when this asset runs. If the resolved asset is not
|
|
1088
|
-
// the first one in the hoisted requires, we need to insert a
|
|
1088
|
+
// the first one in the hoisted requires, we need to insert a parcelRequire here
|
|
1089
1089
|
// so it runs first.
|
|
1090
1090
|
if (
|
|
1091
1091
|
isWrapped &&
|
|
@@ -1095,7 +1095,7 @@ ${code}
|
|
|
1095
1095
|
!this.shouldSkipAsset(resolved)
|
|
1096
1096
|
) {
|
|
1097
1097
|
this.needsPrelude = true;
|
|
1098
|
-
res += `
|
|
1098
|
+
res += `parcelRequire(${JSON.stringify(
|
|
1099
1099
|
this.bundleGraph.getAssetPublicId(resolved),
|
|
1100
1100
|
)});`;
|
|
1101
1101
|
}
|
|
@@ -1186,9 +1186,9 @@ ${code}
|
|
|
1186
1186
|
// and the namespace symbol is used.
|
|
1187
1187
|
// TODO: only if required by CJS?
|
|
1188
1188
|
if (asset.symbols.hasExportSymbol('default') && usedSymbols.has('*')) {
|
|
1189
|
-
prepend += `\n$
|
|
1189
|
+
prepend += `\n$parcel$defineInteropFlag($${assetId}$exports);\n`;
|
|
1190
1190
|
prependLineCount += 2;
|
|
1191
|
-
this.usedHelpers.add('$
|
|
1191
|
+
this.usedHelpers.add('$parcel$defineInteropFlag');
|
|
1192
1192
|
}
|
|
1193
1193
|
|
|
1194
1194
|
// Find wildcard re-export dependencies, and make sure their exports are also included in
|
|
@@ -1209,14 +1209,14 @@ ${code}
|
|
|
1209
1209
|
let external = nullthrows(
|
|
1210
1210
|
nullthrows(this.externals.get(dep.specifier)).get('*'),
|
|
1211
1211
|
);
|
|
1212
|
-
append += `$
|
|
1213
|
-
this.usedHelpers.add('$
|
|
1212
|
+
append += `$parcel$exportWildcard($${assetId}$exports, ${external});\n`;
|
|
1213
|
+
this.usedHelpers.add('$parcel$exportWildcard');
|
|
1214
1214
|
continue;
|
|
1215
1215
|
}
|
|
1216
1216
|
|
|
1217
|
-
// If the resolved asset has an exports object, use the $
|
|
1217
|
+
// If the resolved asset has an exports object, use the $parcel$exportWildcard helper
|
|
1218
1218
|
// to re-export all symbols. Otherwise, if there's no namespace object available, add
|
|
1219
|
-
// $
|
|
1219
|
+
// $parcel$export calls for each used symbol of the dependency.
|
|
1220
1220
|
if (
|
|
1221
1221
|
isWrapped ||
|
|
1222
1222
|
resolved.meta.staticExports === false ||
|
|
@@ -1232,8 +1232,8 @@ ${code}
|
|
|
1232
1232
|
dep,
|
|
1233
1233
|
replacements,
|
|
1234
1234
|
);
|
|
1235
|
-
append += `$
|
|
1236
|
-
this.usedHelpers.add('$
|
|
1235
|
+
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
1236
|
+
this.usedHelpers.add('$parcel$exportWildcard');
|
|
1237
1237
|
} else {
|
|
1238
1238
|
for (let symbol of nullthrows(
|
|
1239
1239
|
this.bundleGraph.getUsedSymbols(dep),
|
|
@@ -1257,10 +1257,10 @@ ${code}
|
|
|
1257
1257
|
? ', ' +
|
|
1258
1258
|
this.buildFunctionExpression(['v'], `${resolvedSymbol} = v`)
|
|
1259
1259
|
: '';
|
|
1260
|
-
prepend += `$
|
|
1260
|
+
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(
|
|
1261
1261
|
symbol,
|
|
1262
1262
|
)}, ${get}${set});\n`;
|
|
1263
|
-
this.usedHelpers.add('$
|
|
1263
|
+
this.usedHelpers.add('$parcel$export');
|
|
1264
1264
|
prependLineCount++;
|
|
1265
1265
|
}
|
|
1266
1266
|
}
|
|
@@ -1291,7 +1291,7 @@ ${code}
|
|
|
1291
1291
|
});
|
|
1292
1292
|
|
|
1293
1293
|
if (usedExports.length > 0) {
|
|
1294
|
-
// Insert $
|
|
1294
|
+
// Insert $parcel$export calls for each of the used exports. This creates a getter/setter
|
|
1295
1295
|
// for the symbol so that when the value changes the object property also changes. This is
|
|
1296
1296
|
// required to simulate ESM live bindings. It's easier to do it this way rather than inserting
|
|
1297
1297
|
// additional assignments after each mutation of the original binding.
|
|
@@ -1310,12 +1310,12 @@ ${code}
|
|
|
1310
1310
|
!isEsmExport && asset.meta.hasCJSExports
|
|
1311
1311
|
? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`)
|
|
1312
1312
|
: '';
|
|
1313
|
-
return `$
|
|
1313
|
+
return `$parcel$export($${assetId}$exports, ${JSON.stringify(
|
|
1314
1314
|
exp,
|
|
1315
1315
|
)}, ${get}${set});`;
|
|
1316
1316
|
})
|
|
1317
1317
|
.join('\n')}\n`;
|
|
1318
|
-
this.usedHelpers.add('$
|
|
1318
|
+
this.usedHelpers.add('$parcel$export');
|
|
1319
1319
|
prependLineCount += 1 + usedExports.length;
|
|
1320
1320
|
}
|
|
1321
1321
|
}
|
|
@@ -1351,7 +1351,7 @@ ${code}
|
|
|
1351
1351
|
|
|
1352
1352
|
// Add used helpers.
|
|
1353
1353
|
if (this.needsPrelude) {
|
|
1354
|
-
this.usedHelpers.add('$
|
|
1354
|
+
this.usedHelpers.add('$parcel$global');
|
|
1355
1355
|
}
|
|
1356
1356
|
|
|
1357
1357
|
for (let helper of this.usedHelpers) {
|
|
@@ -1379,7 +1379,7 @@ ${code}
|
|
|
1379
1379
|
this.bundle.bundleBehavior === 'isolated';
|
|
1380
1380
|
|
|
1381
1381
|
if (mightBeFirstJS) {
|
|
1382
|
-
let preludeCode = prelude(this.
|
|
1382
|
+
let preludeCode = prelude(this.parcelRequireName);
|
|
1383
1383
|
res += preludeCode;
|
|
1384
1384
|
if (enableSourceMaps) {
|
|
1385
1385
|
lines += countLines(preludeCode) - 1;
|
|
@@ -1393,11 +1393,11 @@ ${code}
|
|
|
1393
1393
|
}
|
|
1394
1394
|
}
|
|
1395
1395
|
} else {
|
|
1396
|
-
// Otherwise, get the current
|
|
1397
|
-
const escaped = JSON.stringify(this.
|
|
1398
|
-
res += `var
|
|
1396
|
+
// Otherwise, get the current parcelRequire global.
|
|
1397
|
+
const escaped = JSON.stringify(this.parcelRequireName);
|
|
1398
|
+
res += `var parcelRequire = $parcel$global[${escaped}];\n`;
|
|
1399
1399
|
lines++;
|
|
1400
|
-
res += `var
|
|
1400
|
+
res += `var parcelRegister = parcelRequire.register;\n`;
|
|
1401
1401
|
lines++;
|
|
1402
1402
|
}
|
|
1403
1403
|
}
|
package/src/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]);
|