@parcel/packager-js 2.0.0-dev.1781 → 2.0.0-dev.1795
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 +15 -7
- package/lib/ScopeHoistingPackager.js +8 -5
- package/lib/dev-prelude.js +4 -0
- package/lib/helpers.js +12 -3
- package/lib/index.js +2 -2
- package/package.json +8 -8
- package/src/DevPackager.js +19 -7
- package/src/ScopeHoistingPackager.js +10 -5
- package/src/dev-prelude.js +4 -0
- package/src/helpers.js +15 -3
- package/src/index.js +1 -1
package/lib/DevPackager.js
CHANGED
|
@@ -71,7 +71,7 @@ class DevPackager {
|
|
|
71
71
|
let prefix = this.getPrefix();
|
|
72
72
|
let lineOffset = (0, _utils().countLines)(prefix);
|
|
73
73
|
let script = null;
|
|
74
|
-
let
|
|
74
|
+
let usedHelpers = 0;
|
|
75
75
|
this.bundle.traverse(node => {
|
|
76
76
|
let wrapped = first ? '' : ',';
|
|
77
77
|
if (node.type === 'dependency') {
|
|
@@ -88,8 +88,8 @@ class DevPackager {
|
|
|
88
88
|
if (node.type === 'asset') {
|
|
89
89
|
let asset = node.value;
|
|
90
90
|
(0, _assert().default)(asset.type === 'js', 'all assets in a js bundle must be js assets');
|
|
91
|
-
if (typeof asset.meta.
|
|
92
|
-
|
|
91
|
+
if (typeof asset.meta.usedHelpers === 'number') {
|
|
92
|
+
usedHelpers |= asset.meta.usedHelpers;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// If this is the main entry of a script rather than a module, we need to hoist it
|
|
@@ -159,19 +159,27 @@ class DevPackager {
|
|
|
159
159
|
});
|
|
160
160
|
mainEntry = null;
|
|
161
161
|
}
|
|
162
|
+
if (usedHelpers & 4) {
|
|
163
|
+
prefix = prefix.replace('// INSERT_LOAD_HERE', 'newRequire.load = function (url) { return import(distDir + "/" + url); }');
|
|
164
|
+
}
|
|
162
165
|
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);
|
|
163
|
-
if (
|
|
166
|
+
if (usedHelpers & 1) {
|
|
164
167
|
// Generate a relative path from this bundle to the root of the dist dir.
|
|
165
168
|
let distDir = (0, _utils().relativePath)(_path().default.dirname(this.bundle.name), '');
|
|
166
169
|
if (distDir.endsWith('/')) {
|
|
167
170
|
distDir = distDir.slice(0, -1);
|
|
168
171
|
}
|
|
169
172
|
contents += ', ' + JSON.stringify(distDir);
|
|
170
|
-
} else if (
|
|
173
|
+
} else if (usedHelpers & 2) {
|
|
171
174
|
contents += ', null';
|
|
172
175
|
}
|
|
173
|
-
if (
|
|
174
|
-
|
|
176
|
+
if (usedHelpers & 2) {
|
|
177
|
+
// Ensure the public url always ends with a slash to code can easily join paths to it.
|
|
178
|
+
let publicUrl = this.bundle.target.publicUrl;
|
|
179
|
+
if (!publicUrl.endsWith('/')) {
|
|
180
|
+
publicUrl += '/';
|
|
181
|
+
}
|
|
182
|
+
contents += ', ' + JSON.stringify(publicUrl);
|
|
175
183
|
}
|
|
176
184
|
contents += ')\n';
|
|
177
185
|
|
|
@@ -393,14 +393,17 @@ class ScopeHoistingPackager {
|
|
|
393
393
|
if (code.includes('$parcel$global')) {
|
|
394
394
|
this.usedHelpers.add('$parcel$global');
|
|
395
395
|
}
|
|
396
|
-
let
|
|
397
|
-
if (typeof
|
|
398
|
-
if (
|
|
396
|
+
let usedHelpers = asset.meta.usedHelpers;
|
|
397
|
+
if (typeof usedHelpers === 'number') {
|
|
398
|
+
if (usedHelpers & 1) {
|
|
399
399
|
this.usedHelpers.add('$parcel$distDir');
|
|
400
400
|
}
|
|
401
|
-
if (
|
|
401
|
+
if (usedHelpers & 2) {
|
|
402
402
|
this.usedHelpers.add('$parcel$publicUrl');
|
|
403
403
|
}
|
|
404
|
+
if (usedHelpers & 4) {
|
|
405
|
+
this.usedHelpers.add('$parcel$import');
|
|
406
|
+
}
|
|
404
407
|
}
|
|
405
408
|
if (this.bundle.env.isNode() && asset.meta.has_node_replacements) {
|
|
406
409
|
const relPath = (0, _utils().normalizeSeparators)(_path().default.relative(this.bundle.target.distDir, _path().default.dirname(asset.filePath)));
|
|
@@ -1008,7 +1011,7 @@ ${code}
|
|
|
1008
1011
|
// Add the prelude if this is potentially the first JS bundle to load in a
|
|
1009
1012
|
// particular context (e.g. entry scripts in HTML, workers, etc.).
|
|
1010
1013
|
let parentBundles = this.bundleGraph.getParentBundles(this.bundle);
|
|
1011
|
-
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';
|
|
1014
|
+
let mightBeFirstJS = parentBundles.length === 0 || parentBundles.some(b => b.type !== 'js' || b.env.context !== this.bundle.env.context) || this.bundleGraph.getBundleGroupsContainingBundle(this.bundle).some(g => this.bundleGraph.isEntryBundleGroup(g)) || this.bundle.env.isIsolated() || this.bundle.bundleBehavior === 'isolated';
|
|
1012
1015
|
if (mightBeFirstJS) {
|
|
1013
1016
|
let preludeCode = (0, _helpers.prelude)(this.parcelRequireName);
|
|
1014
1017
|
res += preludeCode;
|
package/lib/dev-prelude.js
CHANGED
|
@@ -112,6 +112,10 @@
|
|
|
112
112
|
];
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
+
// Only insert newRequire.load when it is actually used.
|
|
116
|
+
// The code in this file is linted against ES5, so dynamic import is not allowed.
|
|
117
|
+
// INSERT_LOAD_HERE
|
|
118
|
+
|
|
115
119
|
Object.defineProperty(newRequire, 'root', {
|
|
116
120
|
get: function () {
|
|
117
121
|
return globalObject[parcelRequireName];
|
package/lib/helpers.js
CHANGED
|
@@ -141,10 +141,18 @@ const $parcel$distDir = (env, bundle) => {
|
|
|
141
141
|
if (distDir.endsWith('/')) {
|
|
142
142
|
distDir = distDir.slice(0, -1);
|
|
143
143
|
}
|
|
144
|
-
return `
|
|
144
|
+
return `var $parcel$distDir = ${JSON.stringify(distDir)};\n`;
|
|
145
145
|
};
|
|
146
146
|
const $parcel$publicUrl = (env, bundle) => {
|
|
147
|
-
|
|
147
|
+
// Ensure the public url always ends with a slash to code can easily join paths to it.
|
|
148
|
+
let publicUrl = bundle.target.publicUrl;
|
|
149
|
+
if (!publicUrl.endsWith('/')) {
|
|
150
|
+
publicUrl += '/';
|
|
151
|
+
}
|
|
152
|
+
return `var $parcel$publicUrl = ${JSON.stringify(publicUrl)};\n`;
|
|
153
|
+
};
|
|
154
|
+
const $parcel$import = env => {
|
|
155
|
+
return `var $parcel$import = ${fnExpr(env, ['url'], ['return import($parcel$distDir + "/" + url);'])};\n`;
|
|
148
156
|
};
|
|
149
157
|
const helpers = exports.helpers = {
|
|
150
158
|
$parcel$export,
|
|
@@ -153,5 +161,6 @@ const helpers = exports.helpers = {
|
|
|
153
161
|
$parcel$global,
|
|
154
162
|
$parcel$defineInteropFlag,
|
|
155
163
|
$parcel$distDir,
|
|
156
|
-
$parcel$publicUrl
|
|
164
|
+
$parcel$publicUrl,
|
|
165
|
+
$parcel$import
|
|
157
166
|
};
|
package/lib/index.js
CHANGED
|
@@ -56,7 +56,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
56
56
|
config,
|
|
57
57
|
options
|
|
58
58
|
}) {
|
|
59
|
-
var
|
|
59
|
+
var _conf$contents;
|
|
60
60
|
let packageKey = '@parcel/packager-js';
|
|
61
61
|
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
62
62
|
packageKey
|
|
@@ -75,7 +75,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
75
75
|
let packageName = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
76
76
|
packageKey: 'name'
|
|
77
77
|
});
|
|
78
|
-
let name = (packageName === null || packageName === void 0
|
|
78
|
+
let name = (packageName === null || packageName === void 0 ? void 0 : packageName.contents) ?? '';
|
|
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)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-js",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.1795+9f297b15c",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"source": "src/index.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 16.0.0",
|
|
20
|
-
"parcel": "^2.0.0-dev.
|
|
20
|
+
"parcel": "^2.0.0-dev.1793+9f297b15c"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.0.0-dev.
|
|
24
|
-
"@parcel/plugin": "2.0.0-dev.
|
|
25
|
-
"@parcel/rust": "2.13.3-dev.
|
|
23
|
+
"@parcel/diagnostic": "2.0.0-dev.1795+9f297b15c",
|
|
24
|
+
"@parcel/plugin": "2.0.0-dev.1795+9f297b15c",
|
|
25
|
+
"@parcel/rust": "2.13.3-dev.3418+9f297b15c",
|
|
26
26
|
"@parcel/source-map": "^2.1.1",
|
|
27
|
-
"@parcel/types": "2.0.0-dev.
|
|
28
|
-
"@parcel/utils": "2.0.0-dev.
|
|
27
|
+
"@parcel/types": "2.0.0-dev.1795+9f297b15c",
|
|
28
|
+
"@parcel/utils": "2.0.0-dev.1795+9f297b15c",
|
|
29
29
|
"globals": "^13.2.0",
|
|
30
30
|
"nullthrows": "^1.1.1"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "9f297b15c3cc3b74136232040b3149f0baae0060"
|
|
33
33
|
}
|
package/src/DevPackager.js
CHANGED
|
@@ -61,7 +61,7 @@ export class DevPackager {
|
|
|
61
61
|
let lineOffset = countLines(prefix);
|
|
62
62
|
let script: ?{|code: string, mapBuffer: ?Buffer|} = null;
|
|
63
63
|
|
|
64
|
-
let
|
|
64
|
+
let usedHelpers = 0;
|
|
65
65
|
this.bundle.traverse(node => {
|
|
66
66
|
let wrapped = first ? '' : ',';
|
|
67
67
|
|
|
@@ -89,8 +89,8 @@ export class DevPackager {
|
|
|
89
89
|
'all assets in a js bundle must be js assets',
|
|
90
90
|
);
|
|
91
91
|
|
|
92
|
-
if (typeof asset.meta.
|
|
93
|
-
|
|
92
|
+
if (typeof asset.meta.usedHelpers === 'number') {
|
|
93
|
+
usedHelpers |= asset.meta.usedHelpers;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// If this is the main entry of a script rather than a module, we need to hoist it
|
|
@@ -186,6 +186,13 @@ export class DevPackager {
|
|
|
186
186
|
mainEntry = null;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
if (usedHelpers & 4) {
|
|
190
|
+
prefix = prefix.replace(
|
|
191
|
+
'// INSERT_LOAD_HERE',
|
|
192
|
+
'newRequire.load = function (url) { return import(distDir + "/" + url); }',
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
189
196
|
let contents =
|
|
190
197
|
prefix +
|
|
191
198
|
'({' +
|
|
@@ -201,19 +208,24 @@ export class DevPackager {
|
|
|
201
208
|
', ' +
|
|
202
209
|
JSON.stringify(this.parcelRequireName);
|
|
203
210
|
|
|
204
|
-
if (
|
|
211
|
+
if (usedHelpers & 1) {
|
|
205
212
|
// Generate a relative path from this bundle to the root of the dist dir.
|
|
206
213
|
let distDir = relativePath(path.dirname(this.bundle.name), '');
|
|
207
214
|
if (distDir.endsWith('/')) {
|
|
208
215
|
distDir = distDir.slice(0, -1);
|
|
209
216
|
}
|
|
210
217
|
contents += ', ' + JSON.stringify(distDir);
|
|
211
|
-
} else if (
|
|
218
|
+
} else if (usedHelpers & 2) {
|
|
212
219
|
contents += ', null';
|
|
213
220
|
}
|
|
214
221
|
|
|
215
|
-
if (
|
|
216
|
-
|
|
222
|
+
if (usedHelpers & 2) {
|
|
223
|
+
// Ensure the public url always ends with a slash to code can easily join paths to it.
|
|
224
|
+
let publicUrl = this.bundle.target.publicUrl;
|
|
225
|
+
if (!publicUrl.endsWith('/')) {
|
|
226
|
+
publicUrl += '/';
|
|
227
|
+
}
|
|
228
|
+
contents += ', ' + JSON.stringify(publicUrl);
|
|
217
229
|
}
|
|
218
230
|
|
|
219
231
|
contents += ')\n';
|
|
@@ -516,14 +516,17 @@ export class ScopeHoistingPackager {
|
|
|
516
516
|
this.usedHelpers.add('$parcel$global');
|
|
517
517
|
}
|
|
518
518
|
|
|
519
|
-
let
|
|
520
|
-
if (typeof
|
|
521
|
-
if (
|
|
519
|
+
let usedHelpers = asset.meta.usedHelpers;
|
|
520
|
+
if (typeof usedHelpers === 'number') {
|
|
521
|
+
if (usedHelpers & 1) {
|
|
522
522
|
this.usedHelpers.add('$parcel$distDir');
|
|
523
523
|
}
|
|
524
|
-
if (
|
|
524
|
+
if (usedHelpers & 2) {
|
|
525
525
|
this.usedHelpers.add('$parcel$publicUrl');
|
|
526
526
|
}
|
|
527
|
+
if (usedHelpers & 4) {
|
|
528
|
+
this.usedHelpers.add('$parcel$import');
|
|
529
|
+
}
|
|
527
530
|
}
|
|
528
531
|
|
|
529
532
|
if (this.bundle.env.isNode() && asset.meta.has_node_replacements) {
|
|
@@ -1395,7 +1398,9 @@ ${code}
|
|
|
1395
1398
|
let parentBundles = this.bundleGraph.getParentBundles(this.bundle);
|
|
1396
1399
|
let mightBeFirstJS =
|
|
1397
1400
|
parentBundles.length === 0 ||
|
|
1398
|
-
parentBundles.some(
|
|
1401
|
+
parentBundles.some(
|
|
1402
|
+
b => b.type !== 'js' || b.env.context !== this.bundle.env.context,
|
|
1403
|
+
) ||
|
|
1399
1404
|
this.bundleGraph
|
|
1400
1405
|
.getBundleGroupsContainingBundle(this.bundle)
|
|
1401
1406
|
.some(g => this.bundleGraph.isEntryBundleGroup(g)) ||
|
package/src/dev-prelude.js
CHANGED
|
@@ -112,6 +112,10 @@
|
|
|
112
112
|
];
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
+
// Only insert newRequire.load when it is actually used.
|
|
116
|
+
// The code in this file is linted against ES5, so dynamic import is not allowed.
|
|
117
|
+
// INSERT_LOAD_HERE
|
|
118
|
+
|
|
115
119
|
Object.defineProperty(newRequire, 'root', {
|
|
116
120
|
get: function () {
|
|
117
121
|
return globalObject[parcelRequireName];
|
package/src/helpers.js
CHANGED
|
@@ -168,12 +168,23 @@ const $parcel$distDir = (env: Environment, bundle: NamedBundle): string => {
|
|
|
168
168
|
if (distDir.endsWith('/')) {
|
|
169
169
|
distDir = distDir.slice(0, -1);
|
|
170
170
|
}
|
|
171
|
-
return `
|
|
171
|
+
return `var $parcel$distDir = ${JSON.stringify(distDir)};\n`;
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
const $parcel$publicUrl = (env: Environment, bundle: NamedBundle): string => {
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
// Ensure the public url always ends with a slash to code can easily join paths to it.
|
|
176
|
+
let publicUrl = bundle.target.publicUrl;
|
|
177
|
+
if (!publicUrl.endsWith('/')) {
|
|
178
|
+
publicUrl += '/';
|
|
179
|
+
}
|
|
180
|
+
return `var $parcel$publicUrl = ${JSON.stringify(publicUrl)};\n`;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const $parcel$import = (env: Environment): string => {
|
|
184
|
+
return `var $parcel$import = ${fnExpr(
|
|
185
|
+
env,
|
|
186
|
+
['url'],
|
|
187
|
+
['return import($parcel$distDir + "/" + url);'],
|
|
177
188
|
)};\n`;
|
|
178
189
|
};
|
|
179
190
|
|
|
@@ -185,4 +196,5 @@ export const helpers = {
|
|
|
185
196
|
$parcel$defineInteropFlag,
|
|
186
197
|
$parcel$distDir,
|
|
187
198
|
$parcel$publicUrl,
|
|
199
|
+
$parcel$import,
|
|
188
200
|
};
|
package/src/index.js
CHANGED