@parcel/packager-js 2.0.0-rc.0 → 2.1.1
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 +3 -1
- package/lib/ScopeHoistingPackager.js +44 -19
- package/lib/dev-prelude.js +9 -7
- package/lib/helpers.js +1 -1
- package/package.json +8 -8
- package/src/DevPackager.js +5 -4
- package/src/ScopeHoistingPackager.js +54 -25
- package/src/dev-prelude.js +9 -7
- package/src/helpers.js +1 -1
package/lib/DevPackager.js
CHANGED
|
@@ -125,7 +125,9 @@ class DevPackager {
|
|
|
125
125
|
for (let dep of dependencies) {
|
|
126
126
|
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
127
127
|
|
|
128
|
-
if (
|
|
128
|
+
if (this.bundleGraph.isDependencySkipped(dep)) {
|
|
129
|
+
deps[(0, _utils2.getSpecifier)(dep)] = false;
|
|
130
|
+
} else if (resolved) {
|
|
129
131
|
deps[(0, _utils2.getSpecifier)(dep)] = this.bundleGraph.getAssetPublicId(resolved);
|
|
130
132
|
}
|
|
131
133
|
}
|
|
@@ -124,7 +124,7 @@ class ScopeHoistingPackager {
|
|
|
124
124
|
async package() {
|
|
125
125
|
var _sourceMap;
|
|
126
126
|
|
|
127
|
-
await this.loadAssets();
|
|
127
|
+
let wrappedAssets = await this.loadAssets();
|
|
128
128
|
this.buildExportedSymbols(); // If building a library, the target is actually another bundler rather
|
|
129
129
|
// than the final output that could be loaded in a browser. So, loader
|
|
130
130
|
// runtimes are excluded, and instead we add imports into the entry bundle
|
|
@@ -137,19 +137,13 @@ class ScopeHoistingPackager {
|
|
|
137
137
|
for (let b of bundles) {
|
|
138
138
|
this.externals.set((0, _utils().relativeBundlePath)(this.bundle, b), new Map());
|
|
139
139
|
}
|
|
140
|
-
}
|
|
141
|
-
// by replacing `import` statements in the code.
|
|
142
|
-
|
|
140
|
+
}
|
|
143
141
|
|
|
144
142
|
let res = '';
|
|
145
143
|
let lineCount = 0;
|
|
146
144
|
let sourceMap = null;
|
|
147
|
-
this.bundle.traverseAssets((asset, _, actions) => {
|
|
148
|
-
if (this.seenAssets.has(asset.id)) {
|
|
149
|
-
actions.skipChildren();
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
145
|
|
|
146
|
+
let processAsset = asset => {
|
|
153
147
|
let [content, map, lines] = this.visitAsset(asset);
|
|
154
148
|
|
|
155
149
|
if (sourceMap && map) {
|
|
@@ -160,6 +154,25 @@ class ScopeHoistingPackager {
|
|
|
160
154
|
|
|
161
155
|
res += content + '\n';
|
|
162
156
|
lineCount += lines + 1;
|
|
157
|
+
}; // Hoist wrapped asset to the top of the bundle to ensure that they are registered
|
|
158
|
+
// before they are used.
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
for (let asset of wrappedAssets) {
|
|
162
|
+
if (!this.seenAssets.has(asset.id)) {
|
|
163
|
+
processAsset(asset);
|
|
164
|
+
}
|
|
165
|
+
} // Add each asset that is directly connected to the bundle. Dependencies will be handled
|
|
166
|
+
// by replacing `import` statements in the code.
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
this.bundle.traverseAssets((asset, _, actions) => {
|
|
170
|
+
if (this.seenAssets.has(asset.id)) {
|
|
171
|
+
actions.skipChildren();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
processAsset(asset);
|
|
163
176
|
actions.skipChildren();
|
|
164
177
|
});
|
|
165
178
|
let [prelude, preludeLines] = this.buildBundlePrelude();
|
|
@@ -235,6 +248,7 @@ class ScopeHoistingPackager {
|
|
|
235
248
|
let queue = new (_utils().PromiseQueue)({
|
|
236
249
|
maxConcurrent: 32
|
|
237
250
|
});
|
|
251
|
+
let wrapped = [];
|
|
238
252
|
this.bundle.traverseAssets((asset, shouldWrap) => {
|
|
239
253
|
queue.add(async () => {
|
|
240
254
|
let [code, map] = await Promise.all([asset.getCode(), this.bundle.env.sourceMap ? asset.getMapBuffer() : null]);
|
|
@@ -244,12 +258,14 @@ class ScopeHoistingPackager {
|
|
|
244
258
|
}];
|
|
245
259
|
});
|
|
246
260
|
|
|
247
|
-
if (shouldWrap || asset.meta.shouldWrap || this.isAsyncBundle || this.bundle.env.sourceType === 'script' || this.bundleGraph.isAssetReferenced(this.bundle, asset) || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.meta.shouldWrap)) {
|
|
261
|
+
if (shouldWrap || asset.meta.shouldWrap || this.isAsyncBundle || this.bundle.env.sourceType === 'script' || this.bundleGraph.isAssetReferenced(this.bundle, asset) || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.meta.shouldWrap && dep.specifierType !== 'url')) {
|
|
248
262
|
this.wrappedAssets.add(asset.id);
|
|
263
|
+
wrapped.push(asset);
|
|
249
264
|
return true;
|
|
250
265
|
}
|
|
251
266
|
});
|
|
252
267
|
this.assetOutputs = new Map(await queue.run());
|
|
268
|
+
return wrapped;
|
|
253
269
|
}
|
|
254
270
|
|
|
255
271
|
buildExportedSymbols() {
|
|
@@ -555,7 +571,7 @@ ${code}
|
|
|
555
571
|
if (imported === '*') {
|
|
556
572
|
replacement = renamed;
|
|
557
573
|
} else if (imported === 'default') {
|
|
558
|
-
replacement =
|
|
574
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
559
575
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
560
576
|
} else {
|
|
561
577
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
@@ -686,7 +702,7 @@ ${code}
|
|
|
686
702
|
// and no __esModule flag, we need to resolve to the namespace instead.
|
|
687
703
|
|
|
688
704
|
|
|
689
|
-
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' && resolvedAsset.symbols.hasExportSymbol('*') && resolvedAsset.symbols.hasExportSymbol('default') && !resolvedAsset.symbols.hasExportSymbol('__esModule'); // Find the namespace object for the resolved module. If wrapped and this
|
|
705
|
+
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'); // Find the namespace object for the resolved module. If wrapped and this
|
|
690
706
|
// is an inline require (not top-level), use a parcelRequire call, otherwise
|
|
691
707
|
// the hoisted variable declared above. Otherwise, if not wrapped, use the
|
|
692
708
|
// namespace export symbol.
|
|
@@ -704,7 +720,9 @@ ${code}
|
|
|
704
720
|
// we need to use a member access off the namespace object rather
|
|
705
721
|
// than a direct reference. If importing default from a CJS module,
|
|
706
722
|
// use a helper to check the __esModule flag at runtime.
|
|
707
|
-
|
|
723
|
+
let kind = dep === null || dep === void 0 ? void 0 : dep.meta.kind;
|
|
724
|
+
|
|
725
|
+
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' && resolvedAsset.symbols.hasExportSymbol('*') && this.needsDefaultInterop(resolvedAsset)) {
|
|
708
726
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
709
727
|
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
710
728
|
} else {
|
|
@@ -749,7 +767,7 @@ ${code}
|
|
|
749
767
|
let prependLineCount = 0;
|
|
750
768
|
let append = '';
|
|
751
769
|
let shouldWrap = this.wrappedAssets.has(asset.id);
|
|
752
|
-
let usedSymbols = this.bundleGraph.getUsedSymbols(asset);
|
|
770
|
+
let usedSymbols = (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(asset));
|
|
753
771
|
let assetId = asset.meta.id;
|
|
754
772
|
(0, _assert().default)(typeof assetId === 'string'); // If the asset has a namespace export symbol, it is CommonJS.
|
|
755
773
|
// If there's no __esModule flag, and default is a used symbol, we need
|
|
@@ -760,7 +778,7 @@ ${code}
|
|
|
760
778
|
// The one case where this isn't true is in ESM library entries, where the only
|
|
761
779
|
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
762
780
|
// instead of the namespace object.
|
|
763
|
-
usedSymbols.has('*') && (this.bundle.env.outputFormat !== 'esmodule' || !this.bundle.env.isLibrary || asset !== this.bundle.getMainEntry() || this.bundleGraph.getIncomingDependencies(asset).some(dep => !dep.isEntry && this.bundleGraph.getUsedSymbols(dep).has('*'))) || // If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
781
|
+
usedSymbols.has('*') && (this.bundle.env.outputFormat !== 'esmodule' || !this.bundle.env.isLibrary || asset !== this.bundle.getMainEntry() || this.bundleGraph.getIncomingDependencies(asset).some(dep => !dep.isEntry && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'))) || // If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
764
782
|
// we fallback on the namespace object.
|
|
765
783
|
asset.symbols.hasExportSymbol('*') && [...usedSymbols].some(s => !asset.symbols.hasExportSymbol(s)) || // If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
766
784
|
// include the namespace object for the default export.
|
|
@@ -803,7 +821,7 @@ ${code}
|
|
|
803
821
|
}
|
|
804
822
|
|
|
805
823
|
let unused = incomingDeps.every(d => {
|
|
806
|
-
let symbols = this.bundleGraph.getUsedSymbols(d);
|
|
824
|
+
let symbols = (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(d));
|
|
807
825
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
808
826
|
});
|
|
809
827
|
return !unused;
|
|
@@ -849,16 +867,23 @@ ${code}
|
|
|
849
867
|
// $parcel$export calls for each used symbol of the dependency.
|
|
850
868
|
|
|
851
869
|
|
|
852
|
-
if (isWrapped || resolved.meta.staticExports === false || this.bundleGraph.getUsedSymbols(resolved).has('*')
|
|
870
|
+
if (isWrapped || resolved.meta.staticExports === false || (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(resolved)).has('*') || // an empty asset
|
|
871
|
+
!resolved.meta.hasCJSExports && resolved.symbols.hasExportSymbol('*')) {
|
|
853
872
|
let obj = this.getSymbolResolution(asset, resolved, '*', dep);
|
|
854
873
|
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
855
874
|
this.usedHelpers.add('$parcel$exportWildcard');
|
|
856
875
|
} else {
|
|
857
|
-
for (let symbol of this.bundleGraph.getUsedSymbols(dep)) {
|
|
876
|
+
for (let symbol of (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep))) {
|
|
877
|
+
if (symbol === 'default' || // `export * as ...` does not include the default export
|
|
878
|
+
symbol === '__esModule') {
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
|
|
858
882
|
let resolvedSymbol = this.getSymbolResolution(asset, resolved, symbol);
|
|
859
883
|
let get = this.buildFunctionExpression([], resolvedSymbol);
|
|
860
884
|
let set = asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolvedSymbol} = v`) : '';
|
|
861
885
|
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(symbol)}, ${get}${set});\n`;
|
|
886
|
+
this.usedHelpers.add('$parcel$export');
|
|
862
887
|
prependLineCount++;
|
|
863
888
|
}
|
|
864
889
|
}
|
|
@@ -960,7 +985,7 @@ ${code}
|
|
|
960
985
|
return true;
|
|
961
986
|
}
|
|
962
987
|
|
|
963
|
-
return asset.sideEffects === false && this.bundleGraph.getUsedSymbols(asset).size == 0 && !this.bundleGraph.isAssetReferenced(this.bundle, asset);
|
|
988
|
+
return asset.sideEffects === false && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(asset)).size == 0 && !this.bundleGraph.isAssetReferenced(this.bundle, asset);
|
|
964
989
|
}
|
|
965
990
|
|
|
966
991
|
isScriptEntry(asset) {
|
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, parcelRequireName, globalName) {
|
|
9
|
+
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
|
10
10
|
/* eslint-disable no-undef */
|
|
11
11
|
var globalObject =
|
|
12
12
|
typeof globalThis !== 'undefined'
|
|
@@ -80,11 +80,13 @@
|
|
|
80
80
|
return cache[name].exports;
|
|
81
81
|
|
|
82
82
|
function localRequire(x) {
|
|
83
|
-
|
|
83
|
+
var res = localRequire.resolve(x);
|
|
84
|
+
return res === false ? {} : newRequire(res);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
function resolve(x) {
|
|
87
|
-
|
|
88
|
+
var id = modules[name][1][x];
|
|
89
|
+
return id != null ? id : x;
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
|
|
@@ -99,9 +101,9 @@
|
|
|
99
101
|
newRequire.modules = modules;
|
|
100
102
|
newRequire.cache = cache;
|
|
101
103
|
newRequire.parent = previousRequire;
|
|
102
|
-
newRequire.register = function(id, exports) {
|
|
104
|
+
newRequire.register = function (id, exports) {
|
|
103
105
|
modules[id] = [
|
|
104
|
-
function(require, module) {
|
|
106
|
+
function (require, module) {
|
|
105
107
|
module.exports = exports;
|
|
106
108
|
},
|
|
107
109
|
{},
|
|
@@ -109,7 +111,7 @@
|
|
|
109
111
|
};
|
|
110
112
|
|
|
111
113
|
Object.defineProperty(newRequire, 'root', {
|
|
112
|
-
get: function() {
|
|
114
|
+
get: function () {
|
|
113
115
|
return globalObject[parcelRequireName];
|
|
114
116
|
},
|
|
115
117
|
});
|
|
@@ -131,7 +133,7 @@
|
|
|
131
133
|
|
|
132
134
|
// RequireJS
|
|
133
135
|
} else if (typeof define === 'function' && define.amd) {
|
|
134
|
-
define(function() {
|
|
136
|
+
define(function () {
|
|
135
137
|
return mainExports;
|
|
136
138
|
});
|
|
137
139
|
|
package/lib/helpers.js
CHANGED
|
@@ -43,7 +43,7 @@ const helpers = {
|
|
|
43
43
|
`,
|
|
44
44
|
$parcel$exportWildcard: `function $parcel$exportWildcard(dest, source) {
|
|
45
45
|
Object.keys(source).forEach(function(key) {
|
|
46
|
-
if (key === 'default' || key === '__esModule') {
|
|
46
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"source": "src/index.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "^2.
|
|
20
|
+
"parcel": "^2.1.1"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.
|
|
24
|
-
"@parcel/hash": "2.
|
|
25
|
-
"@parcel/plugin": "2.
|
|
26
|
-
"@parcel/source-map": "2.0.0
|
|
27
|
-
"@parcel/utils": "2.
|
|
23
|
+
"@parcel/diagnostic": "^2.1.1",
|
|
24
|
+
"@parcel/hash": "^2.1.1",
|
|
25
|
+
"@parcel/plugin": "^2.1.1",
|
|
26
|
+
"@parcel/source-map": "^2.0.0",
|
|
27
|
+
"@parcel/utils": "^2.1.1",
|
|
28
28
|
"globals": "^13.2.0",
|
|
29
29
|
"nullthrows": "^1.1.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "f53ffe772a8259d94ca2937d02fde149454112f3"
|
|
32
32
|
}
|
package/src/DevPackager.js
CHANGED
|
@@ -98,10 +98,11 @@ export class DevPackager {
|
|
|
98
98
|
let dependencies = this.bundleGraph.getDependencies(asset);
|
|
99
99
|
for (let dep of dependencies) {
|
|
100
100
|
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
101
|
-
if (
|
|
102
|
-
deps[getSpecifier(dep)] =
|
|
103
|
-
|
|
104
|
-
)
|
|
101
|
+
if (this.bundleGraph.isDependencySkipped(dep)) {
|
|
102
|
+
deps[getSpecifier(dep)] = false;
|
|
103
|
+
} else if (resolved) {
|
|
104
|
+
deps[getSpecifier(dep)] =
|
|
105
|
+
this.bundleGraph.getAssetPublicId(resolved);
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
|
@@ -28,7 +28,8 @@ const NON_ID_CONTINUE_RE = /[^$_\u200C\u200D\p{ID_Continue}]/gu;
|
|
|
28
28
|
|
|
29
29
|
// General regex used to replace imports with the resolved code, references with resolutions,
|
|
30
30
|
// and count the number of newlines in the file for source maps.
|
|
31
|
-
const REPLACEMENT_RE =
|
|
31
|
+
const REPLACEMENT_RE =
|
|
32
|
+
/\n|import\s+"([0-9a-f]{16}:.+?)";|(?:\$[0-9a-f]{16}\$exports)|(?:\$[0-9a-f]{16}\$(?:import|importAsync|require)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
32
33
|
|
|
33
34
|
const BUILTINS = Object.keys(globals.builtin);
|
|
34
35
|
const GLOBALS_BY_CONTEXT = {
|
|
@@ -108,7 +109,7 @@ export class ScopeHoistingPackager {
|
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
async package(): Promise<{|contents: string, map: ?SourceMap|}> {
|
|
111
|
-
await this.loadAssets();
|
|
112
|
+
let wrappedAssets = await this.loadAssets();
|
|
112
113
|
this.buildExportedSymbols();
|
|
113
114
|
|
|
114
115
|
// If building a library, the target is actually another bundler rather
|
|
@@ -126,17 +127,10 @@ export class ScopeHoistingPackager {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
// Add each asset that is directly connected to the bundle. Dependencies will be handled
|
|
130
|
-
// by replacing `import` statements in the code.
|
|
131
130
|
let res = '';
|
|
132
131
|
let lineCount = 0;
|
|
133
132
|
let sourceMap = null;
|
|
134
|
-
|
|
135
|
-
if (this.seenAssets.has(asset.id)) {
|
|
136
|
-
actions.skipChildren();
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
133
|
+
let processAsset = asset => {
|
|
140
134
|
let [content, map, lines] = this.visitAsset(asset);
|
|
141
135
|
if (sourceMap && map) {
|
|
142
136
|
sourceMap.addSourceMap(map, lineCount);
|
|
@@ -146,6 +140,25 @@ export class ScopeHoistingPackager {
|
|
|
146
140
|
|
|
147
141
|
res += content + '\n';
|
|
148
142
|
lineCount += lines + 1;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Hoist wrapped asset to the top of the bundle to ensure that they are registered
|
|
146
|
+
// before they are used.
|
|
147
|
+
for (let asset of wrappedAssets) {
|
|
148
|
+
if (!this.seenAssets.has(asset.id)) {
|
|
149
|
+
processAsset(asset);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Add each asset that is directly connected to the bundle. Dependencies will be handled
|
|
154
|
+
// by replacing `import` statements in the code.
|
|
155
|
+
this.bundle.traverseAssets((asset, _, actions) => {
|
|
156
|
+
if (this.seenAssets.has(asset.id)) {
|
|
157
|
+
actions.skipChildren();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
processAsset(asset);
|
|
149
162
|
actions.skipChildren();
|
|
150
163
|
});
|
|
151
164
|
|
|
@@ -225,8 +238,9 @@ export class ScopeHoistingPackager {
|
|
|
225
238
|
};
|
|
226
239
|
}
|
|
227
240
|
|
|
228
|
-
async loadAssets() {
|
|
241
|
+
async loadAssets(): Promise<Array<Asset>> {
|
|
229
242
|
let queue = new PromiseQueue({maxConcurrent: 32});
|
|
243
|
+
let wrapped = [];
|
|
230
244
|
this.bundle.traverseAssets((asset, shouldWrap) => {
|
|
231
245
|
queue.add(async () => {
|
|
232
246
|
let [code, map] = await Promise.all([
|
|
@@ -244,14 +258,16 @@ export class ScopeHoistingPackager {
|
|
|
244
258
|
this.bundleGraph.isAssetReferenced(this.bundle, asset) ||
|
|
245
259
|
this.bundleGraph
|
|
246
260
|
.getIncomingDependencies(asset)
|
|
247
|
-
.some(dep => dep.meta.shouldWrap)
|
|
261
|
+
.some(dep => dep.meta.shouldWrap && dep.specifierType !== 'url')
|
|
248
262
|
) {
|
|
249
263
|
this.wrappedAssets.add(asset.id);
|
|
264
|
+
wrapped.push(asset);
|
|
250
265
|
return true;
|
|
251
266
|
}
|
|
252
267
|
});
|
|
253
268
|
|
|
254
269
|
this.assetOutputs = new Map(await queue.run());
|
|
270
|
+
return wrapped;
|
|
255
271
|
}
|
|
256
272
|
|
|
257
273
|
buildExportedSymbols() {
|
|
@@ -580,7 +596,7 @@ ${code}
|
|
|
580
596
|
if (imported === '*') {
|
|
581
597
|
replacement = renamed;
|
|
582
598
|
} else if (imported === 'default') {
|
|
583
|
-
replacement =
|
|
599
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
584
600
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
585
601
|
} else {
|
|
586
602
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
@@ -741,7 +757,7 @@ ${code}
|
|
|
741
757
|
exportSymbol === 'default' &&
|
|
742
758
|
staticExports &&
|
|
743
759
|
!isWrapped &&
|
|
744
|
-
dep?.meta.kind === 'Import' &&
|
|
760
|
+
(dep?.meta.kind === 'Import' || dep?.meta.kind === 'Export') &&
|
|
745
761
|
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
746
762
|
resolvedAsset.symbols.hasExportSymbol('default') &&
|
|
747
763
|
!resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
@@ -771,8 +787,9 @@ ${code}
|
|
|
771
787
|
// we need to use a member access off the namespace object rather
|
|
772
788
|
// than a direct reference. If importing default from a CJS module,
|
|
773
789
|
// use a helper to check the __esModule flag at runtime.
|
|
790
|
+
let kind = dep?.meta.kind;
|
|
774
791
|
if (
|
|
775
|
-
dep
|
|
792
|
+
(!dep || kind === 'Import' || kind === 'Export') &&
|
|
776
793
|
exportSymbol === 'default' &&
|
|
777
794
|
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
778
795
|
this.needsDefaultInterop(resolvedAsset)
|
|
@@ -840,7 +857,7 @@ ${code}
|
|
|
840
857
|
let append = '';
|
|
841
858
|
|
|
842
859
|
let shouldWrap = this.wrappedAssets.has(asset.id);
|
|
843
|
-
let usedSymbols = this.bundleGraph.getUsedSymbols(asset);
|
|
860
|
+
let usedSymbols = nullthrows(this.bundleGraph.getUsedSymbols(asset));
|
|
844
861
|
let assetId = asset.meta.id;
|
|
845
862
|
invariant(typeof assetId === 'string');
|
|
846
863
|
|
|
@@ -865,7 +882,8 @@ ${code}
|
|
|
865
882
|
.getIncomingDependencies(asset)
|
|
866
883
|
.some(
|
|
867
884
|
dep =>
|
|
868
|
-
!dep.isEntry &&
|
|
885
|
+
!dep.isEntry &&
|
|
886
|
+
nullthrows(this.bundleGraph.getUsedSymbols(dep)).has('*'),
|
|
869
887
|
))) ||
|
|
870
888
|
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
871
889
|
// we fallback on the namespace object.
|
|
@@ -922,7 +940,7 @@ ${code}
|
|
|
922
940
|
}
|
|
923
941
|
|
|
924
942
|
let unused = incomingDeps.every(d => {
|
|
925
|
-
let symbols = this.bundleGraph.getUsedSymbols(d);
|
|
943
|
+
let symbols = nullthrows(this.bundleGraph.getUsedSymbols(d));
|
|
926
944
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
927
945
|
});
|
|
928
946
|
return !unused;
|
|
@@ -976,13 +994,25 @@ ${code}
|
|
|
976
994
|
if (
|
|
977
995
|
isWrapped ||
|
|
978
996
|
resolved.meta.staticExports === false ||
|
|
979
|
-
this.bundleGraph.getUsedSymbols(resolved).has('*')
|
|
997
|
+
nullthrows(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
998
|
+
// an empty asset
|
|
999
|
+
(!resolved.meta.hasCJSExports &&
|
|
1000
|
+
resolved.symbols.hasExportSymbol('*'))
|
|
980
1001
|
) {
|
|
981
1002
|
let obj = this.getSymbolResolution(asset, resolved, '*', dep);
|
|
982
1003
|
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
983
1004
|
this.usedHelpers.add('$parcel$exportWildcard');
|
|
984
1005
|
} else {
|
|
985
|
-
for (let symbol of
|
|
1006
|
+
for (let symbol of nullthrows(
|
|
1007
|
+
this.bundleGraph.getUsedSymbols(dep),
|
|
1008
|
+
)) {
|
|
1009
|
+
if (
|
|
1010
|
+
symbol === 'default' || // `export * as ...` does not include the default export
|
|
1011
|
+
symbol === '__esModule'
|
|
1012
|
+
) {
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
986
1016
|
let resolvedSymbol = this.getSymbolResolution(
|
|
987
1017
|
asset,
|
|
988
1018
|
resolved,
|
|
@@ -996,6 +1026,7 @@ ${code}
|
|
|
996
1026
|
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(
|
|
997
1027
|
symbol,
|
|
998
1028
|
)}, ${get}${set});\n`;
|
|
1029
|
+
this.usedHelpers.add('$parcel$export');
|
|
999
1030
|
prependLineCount++;
|
|
1000
1031
|
}
|
|
1001
1032
|
}
|
|
@@ -1028,10 +1059,8 @@ ${code}
|
|
|
1028
1059
|
}
|
|
1029
1060
|
|
|
1030
1061
|
// The output format may have specific things to add at the start of the bundle (e.g. imports).
|
|
1031
|
-
let [
|
|
1032
|
-
|
|
1033
|
-
outputFormatLines,
|
|
1034
|
-
] = this.outputFormat.buildBundlePrelude();
|
|
1062
|
+
let [outputFormatPrelude, outputFormatLines] =
|
|
1063
|
+
this.outputFormat.buildBundlePrelude();
|
|
1035
1064
|
res += outputFormatPrelude;
|
|
1036
1065
|
lines += outputFormatLines;
|
|
1037
1066
|
|
|
@@ -1122,7 +1151,7 @@ ${code}
|
|
|
1122
1151
|
|
|
1123
1152
|
return (
|
|
1124
1153
|
asset.sideEffects === false &&
|
|
1125
|
-
this.bundleGraph.getUsedSymbols(asset).size == 0 &&
|
|
1154
|
+
nullthrows(this.bundleGraph.getUsedSymbols(asset)).size == 0 &&
|
|
1126
1155
|
!this.bundleGraph.isAssetReferenced(this.bundle, asset)
|
|
1127
1156
|
);
|
|
1128
1157
|
}
|
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, parcelRequireName, globalName) {
|
|
9
|
+
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
|
10
10
|
/* eslint-disable no-undef */
|
|
11
11
|
var globalObject =
|
|
12
12
|
typeof globalThis !== 'undefined'
|
|
@@ -80,11 +80,13 @@
|
|
|
80
80
|
return cache[name].exports;
|
|
81
81
|
|
|
82
82
|
function localRequire(x) {
|
|
83
|
-
|
|
83
|
+
var res = localRequire.resolve(x);
|
|
84
|
+
return res === false ? {} : newRequire(res);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
function resolve(x) {
|
|
87
|
-
|
|
88
|
+
var id = modules[name][1][x];
|
|
89
|
+
return id != null ? id : x;
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
|
|
@@ -99,9 +101,9 @@
|
|
|
99
101
|
newRequire.modules = modules;
|
|
100
102
|
newRequire.cache = cache;
|
|
101
103
|
newRequire.parent = previousRequire;
|
|
102
|
-
newRequire.register = function(id, exports) {
|
|
104
|
+
newRequire.register = function (id, exports) {
|
|
103
105
|
modules[id] = [
|
|
104
|
-
function(require, module) {
|
|
106
|
+
function (require, module) {
|
|
105
107
|
module.exports = exports;
|
|
106
108
|
},
|
|
107
109
|
{},
|
|
@@ -109,7 +111,7 @@
|
|
|
109
111
|
};
|
|
110
112
|
|
|
111
113
|
Object.defineProperty(newRequire, 'root', {
|
|
112
|
-
get: function() {
|
|
114
|
+
get: function () {
|
|
113
115
|
return globalObject[parcelRequireName];
|
|
114
116
|
},
|
|
115
117
|
});
|
|
@@ -131,7 +133,7 @@
|
|
|
131
133
|
|
|
132
134
|
// RequireJS
|
|
133
135
|
} else if (typeof define === 'function' && define.amd) {
|
|
134
|
-
define(function() {
|
|
136
|
+
define(function () {
|
|
135
137
|
return mainExports;
|
|
136
138
|
});
|
|
137
139
|
|
package/src/helpers.js
CHANGED
|
@@ -38,7 +38,7 @@ export const helpers = {
|
|
|
38
38
|
`,
|
|
39
39
|
$parcel$exportWildcard: `function $parcel$exportWildcard(dest, source) {
|
|
40
40
|
Object.keys(source).forEach(function(key) {
|
|
41
|
-
if (key === 'default' || key === '__esModule') {
|
|
41
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|