@parcel/packager-js 2.0.1 → 2.2.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/ESMOutputFormat.js +2 -2
- package/lib/ScopeHoistingPackager.js +25 -9
- package/lib/dev-prelude.js +4 -2
- package/lib/helpers.js +1 -1
- package/lib/utils.js +1 -1
- package/package.json +7 -7
- package/src/DevPackager.js +3 -1
- package/src/ScopeHoistingPackager.js +25 -10
- package/src/dev-prelude.js +4 -2
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
|
}
|
package/lib/ESMOutputFormat.js
CHANGED
|
@@ -23,8 +23,8 @@ class ESMOutputFormat {
|
|
|
23
23
|
if (imported === 'default'
|
|
24
24
|
/* || isCommonJS*/
|
|
25
25
|
) {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
defaultSpecifier = symbol;
|
|
27
|
+
} else if (imported === '*') {
|
|
28
28
|
namespaceSpecifier = `* as ${symbol}`;
|
|
29
29
|
} else {
|
|
30
30
|
let specifier = imported;
|
|
@@ -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]);
|
|
@@ -246,10 +260,12 @@ class ScopeHoistingPackager {
|
|
|
246
260
|
|
|
247
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() {
|
package/lib/dev-prelude.js
CHANGED
|
@@ -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
|
|
package/lib/helpers.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.replaceScriptDependencies = replaceScriptDependencies;
|
|
7
6
|
exports.getSpecifier = getSpecifier;
|
|
7
|
+
exports.replaceScriptDependencies = replaceScriptDependencies;
|
|
8
8
|
|
|
9
9
|
function _nullthrows() {
|
|
10
10
|
const data = _interopRequireDefault(require("nullthrows"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.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.2.1"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "^2.
|
|
24
|
-
"@parcel/hash": "^2.
|
|
25
|
-
"@parcel/plugin": "^2.
|
|
23
|
+
"@parcel/diagnostic": "^2.2.1",
|
|
24
|
+
"@parcel/hash": "^2.2.1",
|
|
25
|
+
"@parcel/plugin": "^2.2.1",
|
|
26
26
|
"@parcel/source-map": "^2.0.0",
|
|
27
|
-
"@parcel/utils": "^2.
|
|
27
|
+
"@parcel/utils": "^2.2.1",
|
|
28
28
|
"globals": "^13.2.0",
|
|
29
29
|
"nullthrows": "^1.1.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "74fcc3fbe80cea993bff10e158df3d0f701973c7"
|
|
32
32
|
}
|
package/src/DevPackager.js
CHANGED
|
@@ -98,7 +98,9 @@ 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 (
|
|
101
|
+
if (this.bundleGraph.isDependencySkipped(dep)) {
|
|
102
|
+
deps[getSpecifier(dep)] = false;
|
|
103
|
+
} else if (resolved) {
|
|
102
104
|
deps[getSpecifier(dep)] =
|
|
103
105
|
this.bundleGraph.getAssetPublicId(resolved);
|
|
104
106
|
}
|
|
@@ -109,7 +109,7 @@ export class ScopeHoistingPackager {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
async package(): Promise<{|contents: string, map: ?SourceMap|}> {
|
|
112
|
-
await this.loadAssets();
|
|
112
|
+
let wrappedAssets = await this.loadAssets();
|
|
113
113
|
this.buildExportedSymbols();
|
|
114
114
|
|
|
115
115
|
// If building a library, the target is actually another bundler rather
|
|
@@ -127,17 +127,10 @@ export class ScopeHoistingPackager {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
// Add each asset that is directly connected to the bundle. Dependencies will be handled
|
|
131
|
-
// by replacing `import` statements in the code.
|
|
132
130
|
let res = '';
|
|
133
131
|
let lineCount = 0;
|
|
134
132
|
let sourceMap = null;
|
|
135
|
-
|
|
136
|
-
if (this.seenAssets.has(asset.id)) {
|
|
137
|
-
actions.skipChildren();
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
133
|
+
let processAsset = asset => {
|
|
141
134
|
let [content, map, lines] = this.visitAsset(asset);
|
|
142
135
|
if (sourceMap && map) {
|
|
143
136
|
sourceMap.addSourceMap(map, lineCount);
|
|
@@ -147,6 +140,25 @@ export class ScopeHoistingPackager {
|
|
|
147
140
|
|
|
148
141
|
res += content + '\n';
|
|
149
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);
|
|
150
162
|
actions.skipChildren();
|
|
151
163
|
});
|
|
152
164
|
|
|
@@ -226,8 +238,9 @@ export class ScopeHoistingPackager {
|
|
|
226
238
|
};
|
|
227
239
|
}
|
|
228
240
|
|
|
229
|
-
async loadAssets() {
|
|
241
|
+
async loadAssets(): Promise<Array<Asset>> {
|
|
230
242
|
let queue = new PromiseQueue({maxConcurrent: 32});
|
|
243
|
+
let wrapped = [];
|
|
231
244
|
this.bundle.traverseAssets((asset, shouldWrap) => {
|
|
232
245
|
queue.add(async () => {
|
|
233
246
|
let [code, map] = await Promise.all([
|
|
@@ -248,11 +261,13 @@ export class ScopeHoistingPackager {
|
|
|
248
261
|
.some(dep => dep.meta.shouldWrap && dep.specifierType !== 'url')
|
|
249
262
|
) {
|
|
250
263
|
this.wrappedAssets.add(asset.id);
|
|
264
|
+
wrapped.push(asset);
|
|
251
265
|
return true;
|
|
252
266
|
}
|
|
253
267
|
});
|
|
254
268
|
|
|
255
269
|
this.assetOutputs = new Map(await queue.run());
|
|
270
|
+
return wrapped;
|
|
256
271
|
}
|
|
257
272
|
|
|
258
273
|
buildExportedSymbols() {
|
package/src/dev-prelude.js
CHANGED
|
@@ -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
|
|