@parcel/packager-js 2.0.0-dev.1528 → 2.0.0-dev.1557
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/ScopeHoistingPackager.js +10 -4
- package/lib/index.js +16 -17
- package/package.json +9 -9
- package/src/ScopeHoistingPackager.js +9 -0
- package/src/index.js +19 -14
|
@@ -271,6 +271,7 @@ class ScopeHoistingPackager {
|
|
|
271
271
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
272
272
|
let entry = this.bundle.getMainEntry();
|
|
273
273
|
if (entry && !this.wrappedAssets.has(entry.id)) {
|
|
274
|
+
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
274
275
|
for (let {
|
|
275
276
|
asset,
|
|
276
277
|
exportAs,
|
|
@@ -279,6 +280,12 @@ class ScopeHoistingPackager {
|
|
|
279
280
|
} of this.bundleGraph.getExportedSymbols(entry)) {
|
|
280
281
|
if (typeof symbol === 'string') {
|
|
281
282
|
var _this$exportedSymbols, _entry$symbols$get2;
|
|
283
|
+
// If the module has a namespace (e.g. commonjs), and this is not an entry, only export the namespace
|
|
284
|
+
// as default, without individual exports. This mirrors the importing logic in addExternal, avoiding
|
|
285
|
+
// extra unused exports and potential for non-identifier export names.
|
|
286
|
+
if (hasNamespace && this.isAsyncBundle && exportAs !== '*') {
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
282
289
|
let symbols = (_this$exportedSymbols = this.exportedSymbols.get(symbol === '*' ? (0, _nullthrows().default)((_entry$symbols$get2 = entry.symbols.get('*')) === null || _entry$symbols$get2 === void 0 ? void 0 : _entry$symbols$get2.local) : symbol)) === null || _this$exportedSymbols === void 0 ? void 0 : _this$exportedSymbols.exportAs;
|
|
283
290
|
if (!symbols) {
|
|
284
291
|
symbols = [];
|
|
@@ -403,7 +410,6 @@ class ScopeHoistingPackager {
|
|
|
403
410
|
let offset = 0;
|
|
404
411
|
let columnStartIndex = 0;
|
|
405
412
|
code = code.replace(REPLACEMENT_RE, (m, d, i) => {
|
|
406
|
-
var _replacements$get;
|
|
407
413
|
if (m === '\n') {
|
|
408
414
|
columnStartIndex = i + offset + 1;
|
|
409
415
|
lineCount++;
|
|
@@ -463,7 +469,7 @@ class ScopeHoistingPackager {
|
|
|
463
469
|
}
|
|
464
470
|
|
|
465
471
|
// If it wasn't a dependency, then it was an inline replacement (e.g. $id$import$foo -> $id$export$foo).
|
|
466
|
-
let replacement =
|
|
472
|
+
let replacement = replacements.get(m) ?? m;
|
|
467
473
|
if (sourceMap) {
|
|
468
474
|
// Offset the source map columns for this line if the replacement was a different length.
|
|
469
475
|
// This assumes that the match and replacement both do not contain any newlines.
|
|
@@ -606,9 +612,9 @@ ${code}
|
|
|
606
612
|
renamed = external.get('*');
|
|
607
613
|
if (!renamed) {
|
|
608
614
|
if (referencedBundle) {
|
|
609
|
-
var _entry$symbols$
|
|
615
|
+
var _entry$symbols$get3;
|
|
610
616
|
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
611
|
-
renamed = (
|
|
617
|
+
renamed = ((_entry$symbols$get3 = entry.symbols.get('*')) === null || _entry$symbols$get3 === void 0 ? void 0 : _entry$symbols$get3.local) ?? `$${String(entry.meta.id)}$exports`;
|
|
612
618
|
} else {
|
|
613
619
|
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${specifier}`);
|
|
614
620
|
}
|
package/lib/index.js
CHANGED
|
@@ -32,13 +32,6 @@ function _rust() {
|
|
|
32
32
|
};
|
|
33
33
|
return data;
|
|
34
34
|
}
|
|
35
|
-
function _path() {
|
|
36
|
-
const data = _interopRequireDefault(require("path"));
|
|
37
|
-
_path = function () {
|
|
38
|
-
return data;
|
|
39
|
-
};
|
|
40
|
-
return data;
|
|
41
|
-
}
|
|
42
35
|
function _nullthrows() {
|
|
43
36
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
44
37
|
_nullthrows = function () {
|
|
@@ -63,23 +56,29 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
63
56
|
config,
|
|
64
57
|
options
|
|
65
58
|
}) {
|
|
66
|
-
var
|
|
67
|
-
// Generate a name for the global parcelRequire function that is unique to this project.
|
|
68
|
-
// This allows multiple parcel builds to coexist on the same page.
|
|
69
|
-
let pkg = await config.getConfigFrom(_path().default.join(options.projectRoot, 'index'), ['package.json']);
|
|
59
|
+
var _packageName$contents, _conf$contents;
|
|
70
60
|
let packageKey = '@parcel/packager-js';
|
|
71
|
-
|
|
61
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
62
|
+
packageKey
|
|
63
|
+
});
|
|
64
|
+
if (conf !== null && conf !== void 0 && conf.contents) {
|
|
72
65
|
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
73
|
-
data:
|
|
74
|
-
source: await options.inputFS.readFile(
|
|
75
|
-
filePath:
|
|
66
|
+
data: conf === null || conf === void 0 ? void 0 : conf.contents,
|
|
67
|
+
source: await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
68
|
+
filePath: conf.filePath,
|
|
76
69
|
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)(packageKey)}`
|
|
77
70
|
}, packageKey, `Invalid config for ${packageKey}`);
|
|
78
71
|
}
|
|
79
|
-
|
|
72
|
+
|
|
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
|
+
let packageName = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
76
|
+
packageKey: 'name'
|
|
77
|
+
});
|
|
78
|
+
let name = (packageName === null || packageName === void 0 || (_packageName$contents = packageName.contents) === null || _packageName$contents === void 0 ? void 0 : _packageName$contents.name) ?? '';
|
|
80
79
|
return {
|
|
81
80
|
parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
|
|
82
|
-
unstable_asyncBundleRuntime: Boolean(
|
|
81
|
+
unstable_asyncBundleRuntime: Boolean(conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime)
|
|
83
82
|
};
|
|
84
83
|
},
|
|
85
84
|
async package({
|
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.1557+e87c13686",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
"main": "lib/index.js",
|
|
17
17
|
"source": "src/index.js",
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
20
|
-
"parcel": "^2.0.0-dev.
|
|
19
|
+
"node": ">= 16.0.0",
|
|
20
|
+
"parcel": "^2.0.0-dev.1555+e87c13686"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.0.0-dev.
|
|
24
|
-
"@parcel/plugin": "2.0.0-dev.
|
|
25
|
-
"@parcel/rust": "2.12.1-dev.
|
|
23
|
+
"@parcel/diagnostic": "2.0.0-dev.1557+e87c13686",
|
|
24
|
+
"@parcel/plugin": "2.0.0-dev.1557+e87c13686",
|
|
25
|
+
"@parcel/rust": "2.12.1-dev.3204+e87c13686",
|
|
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.1557+e87c13686",
|
|
28
|
+
"@parcel/utils": "2.0.0-dev.1557+e87c13686",
|
|
29
29
|
"globals": "^13.2.0",
|
|
30
30
|
"nullthrows": "^1.1.1"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "e87c13686e8fa4ad96cc61c19d9e4fcf9c372f2e"
|
|
33
33
|
}
|
|
@@ -354,6 +354,8 @@ export class ScopeHoistingPackager {
|
|
|
354
354
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
355
355
|
let entry = this.bundle.getMainEntry();
|
|
356
356
|
if (entry && !this.wrappedAssets.has(entry.id)) {
|
|
357
|
+
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
358
|
+
|
|
357
359
|
for (let {
|
|
358
360
|
asset,
|
|
359
361
|
exportAs,
|
|
@@ -361,6 +363,13 @@ export class ScopeHoistingPackager {
|
|
|
361
363
|
exportSymbol,
|
|
362
364
|
} of this.bundleGraph.getExportedSymbols(entry)) {
|
|
363
365
|
if (typeof symbol === 'string') {
|
|
366
|
+
// If the module has a namespace (e.g. commonjs), and this is not an entry, only export the namespace
|
|
367
|
+
// as default, without individual exports. This mirrors the importing logic in addExternal, avoiding
|
|
368
|
+
// extra unused exports and potential for non-identifier export names.
|
|
369
|
+
if (hasNamespace && this.isAsyncBundle && exportAs !== '*') {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
|
|
364
373
|
let symbols = this.exportedSymbols.get(
|
|
365
374
|
symbol === '*' ? nullthrows(entry.symbols.get('*')?.local) : symbol,
|
|
366
375
|
)?.exportAs;
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
} from '@parcel/utils';
|
|
11
11
|
import {encodeJSONKeyComponent} from '@parcel/diagnostic';
|
|
12
12
|
import {hashString} from '@parcel/rust';
|
|
13
|
-
import path from 'path';
|
|
14
13
|
import nullthrows from 'nullthrows';
|
|
15
14
|
import {DevPackager} from './DevPackager';
|
|
16
15
|
import {ScopeHoistingPackager} from './ScopeHoistingPackager';
|
|
@@ -32,22 +31,18 @@ const CONFIG_SCHEMA: SchemaEntity = {
|
|
|
32
31
|
|
|
33
32
|
export default (new Packager({
|
|
34
33
|
async loadConfig({config, options}): Promise<JSPackagerConfig> {
|
|
35
|
-
// Generate a name for the global parcelRequire function that is unique to this project.
|
|
36
|
-
// This allows multiple parcel builds to coexist on the same page.
|
|
37
|
-
let pkg = await config.getConfigFrom(
|
|
38
|
-
path.join(options.projectRoot, 'index'),
|
|
39
|
-
['package.json'],
|
|
40
|
-
);
|
|
41
|
-
|
|
42
34
|
let packageKey = '@parcel/packager-js';
|
|
35
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
36
|
+
packageKey,
|
|
37
|
+
});
|
|
43
38
|
|
|
44
|
-
if (
|
|
39
|
+
if (conf?.contents) {
|
|
45
40
|
validateSchema.diagnostic(
|
|
46
41
|
CONFIG_SCHEMA,
|
|
47
42
|
{
|
|
48
|
-
data:
|
|
49
|
-
source: await options.inputFS.readFile(
|
|
50
|
-
filePath:
|
|
43
|
+
data: conf?.contents,
|
|
44
|
+
source: await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
45
|
+
filePath: conf.filePath,
|
|
51
46
|
prependKey: `/${encodeJSONKeyComponent(packageKey)}`,
|
|
52
47
|
},
|
|
53
48
|
packageKey,
|
|
@@ -55,11 +50,21 @@ export default (new Packager({
|
|
|
55
50
|
);
|
|
56
51
|
}
|
|
57
52
|
|
|
58
|
-
|
|
53
|
+
// Generate a name for the global parcelRequire function that is unique to this project.
|
|
54
|
+
// This allows multiple parcel builds to coexist on the same page.
|
|
55
|
+
let packageName = await config.getConfigFrom(
|
|
56
|
+
options.projectRoot + '/index',
|
|
57
|
+
[],
|
|
58
|
+
{
|
|
59
|
+
packageKey: 'name',
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
let name = packageName?.contents?.name ?? '';
|
|
59
64
|
return {
|
|
60
65
|
parcelRequireName: 'parcelRequire' + hashString(name).slice(-4),
|
|
61
66
|
unstable_asyncBundleRuntime: Boolean(
|
|
62
|
-
|
|
67
|
+
conf?.contents?.unstable_asyncBundleRuntime,
|
|
63
68
|
),
|
|
64
69
|
};
|
|
65
70
|
},
|