@atlaspack/packager-js 2.18.1 → 2.18.3-typescript-08dcc1c9b.0
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/CHANGELOG.md +12 -1
- package/LICENSE +201 -0
- package/lib/DevPackager.js +8 -1
- package/lib/ScopeHoistingPackager.js +124 -16
- package/lib/dev-prelude.js +6 -6
- package/lib/index.js +3 -1
- package/package.json +14 -9
- package/src/{CJSOutputFormat.js → CJSOutputFormat.ts} +0 -1
- package/src/{DevPackager.js → DevPackager.ts} +18 -5
- package/src/{ESMOutputFormat.js → ESMOutputFormat.ts} +2 -3
- package/src/{GlobalOutputFormat.js → GlobalOutputFormat.ts} +0 -1
- package/src/{ScopeHoistingPackager.js → ScopeHoistingPackager.ts} +123 -41
- package/src/dev-prelude.js +6 -6
- package/src/{helpers.js → helpers.ts} +1 -2
- package/src/{index.js → index.ts} +13 -10
- package/src/{utils.js → utils.ts} +1 -2
- package/tsconfig.json +4 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
Asset,
|
|
5
3
|
BundleGraph,
|
|
@@ -41,7 +39,6 @@ import {
|
|
|
41
39
|
|
|
42
40
|
// General regex used to replace imports with the resolved code, references with resolutions,
|
|
43
41
|
// and count the number of newlines in the file for source maps.
|
|
44
|
-
//
|
|
45
42
|
// For conditional bundling the only difference in this regex is adding `importCond` where we have `importAsync` etc..
|
|
46
43
|
const REPLACEMENT_RE_CONDITIONAL =
|
|
47
44
|
/\n|import\s+"([0-9a-f]{16,20}:.+?)";|(?:\$[0-9a-f]{16,20}\$exports)|(?:\$[0-9a-f]{16,20}\$(?:import|importAsync|require|importCond)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
@@ -64,13 +61,13 @@ const GLOBALS_BY_CONTEXT = {
|
|
|
64
61
|
...Object.keys(globals.node),
|
|
65
62
|
...Object.keys(globals.browser),
|
|
66
63
|
]),
|
|
67
|
-
};
|
|
64
|
+
} as const;
|
|
68
65
|
|
|
69
66
|
const OUTPUT_FORMATS = {
|
|
70
67
|
esmodule: ESMOutputFormat,
|
|
71
68
|
commonjs: CJSOutputFormat,
|
|
72
69
|
global: GlobalOutputFormat,
|
|
73
|
-
};
|
|
70
|
+
} as const;
|
|
74
71
|
|
|
75
72
|
export interface OutputFormat {
|
|
76
73
|
buildBundlePrelude(): [string, number];
|
|
@@ -85,16 +82,23 @@ export class ScopeHoistingPackager {
|
|
|
85
82
|
useAsyncBundleRuntime: boolean;
|
|
86
83
|
outputFormat: OutputFormat;
|
|
87
84
|
isAsyncBundle: boolean;
|
|
88
|
-
globalNames:
|
|
89
|
-
|
|
85
|
+
globalNames: ReadonlySet<string>;
|
|
86
|
+
// @ts-expect-error TS2564
|
|
87
|
+
assetOutputs: Map<
|
|
88
|
+
string,
|
|
89
|
+
{
|
|
90
|
+
code: string;
|
|
91
|
+
map: Buffer | null | undefined;
|
|
92
|
+
}
|
|
93
|
+
>;
|
|
90
94
|
exportedSymbols: Map<
|
|
91
95
|
string,
|
|
92
|
-
{
|
|
93
|
-
asset: Asset
|
|
94
|
-
exportSymbol: string
|
|
95
|
-
local: string
|
|
96
|
-
exportAs: Array<string
|
|
97
|
-
|
|
96
|
+
{
|
|
97
|
+
asset: Asset;
|
|
98
|
+
exportSymbol: string;
|
|
99
|
+
local: string;
|
|
100
|
+
exportAs: Array<string>;
|
|
101
|
+
}
|
|
98
102
|
> = new Map();
|
|
99
103
|
externals: Map<string, Map<string, string>> = new Map();
|
|
100
104
|
topLevelNames: Map<string, number> = new Map();
|
|
@@ -132,7 +136,10 @@ export class ScopeHoistingPackager {
|
|
|
132
136
|
this.globalNames = GLOBALS_BY_CONTEXT[bundle.env.context];
|
|
133
137
|
}
|
|
134
138
|
|
|
135
|
-
async package(): Promise<{
|
|
139
|
+
async package(): Promise<{
|
|
140
|
+
contents: string;
|
|
141
|
+
map: SourceMap | null | undefined;
|
|
142
|
+
}> {
|
|
136
143
|
let {wrapped: wrappedAssets, constant: constantAssets} =
|
|
137
144
|
await this.loadAssets();
|
|
138
145
|
this.buildExportedSymbols();
|
|
@@ -155,9 +162,11 @@ export class ScopeHoistingPackager {
|
|
|
155
162
|
|
|
156
163
|
let res = '';
|
|
157
164
|
let lineCount = 0;
|
|
165
|
+
// @ts-expect-error TS7034
|
|
158
166
|
let sourceMap = null;
|
|
159
|
-
let processAsset = (asset) => {
|
|
167
|
+
let processAsset = (asset: Asset) => {
|
|
160
168
|
let [content, map, lines] = this.visitAsset(asset);
|
|
169
|
+
// @ts-expect-error TS7005
|
|
161
170
|
if (sourceMap && map) {
|
|
162
171
|
sourceMap.addSourceMap(map, lineCount);
|
|
163
172
|
} else if (this.bundle.env.sourceMap) {
|
|
@@ -203,6 +212,7 @@ export class ScopeHoistingPackager {
|
|
|
203
212
|
let [prelude, preludeLines] = this.buildBundlePrelude();
|
|
204
213
|
res = prelude + res;
|
|
205
214
|
lineCount += preludeLines;
|
|
215
|
+
// @ts-expect-error TS2339
|
|
206
216
|
sourceMap?.offsetLines(1, preludeLines);
|
|
207
217
|
|
|
208
218
|
let entries = this.bundle.getEntryAssets();
|
|
@@ -223,17 +233,20 @@ export class ScopeHoistingPackager {
|
|
|
223
233
|
this.bundleGraph.getAssetPublicId(entry),
|
|
224
234
|
)});\n`;
|
|
225
235
|
|
|
236
|
+
// @ts-expect-error TS2345
|
|
226
237
|
let entryExports = entry.symbols.get('*')?.local;
|
|
227
238
|
|
|
228
239
|
if (
|
|
229
240
|
entryExports &&
|
|
230
241
|
entry === mainEntry &&
|
|
242
|
+
// @ts-expect-error TS2345
|
|
231
243
|
this.exportedSymbols.has(entryExports)
|
|
232
244
|
) {
|
|
233
245
|
invariant(
|
|
234
246
|
!needsBundleQueue,
|
|
235
247
|
'Entry exports are not yet compaitble with async bundles',
|
|
236
248
|
);
|
|
249
|
+
// @ts-expect-error TS2731
|
|
237
250
|
res += `\nvar ${entryExports} = ${parcelRequire}`;
|
|
238
251
|
} else {
|
|
239
252
|
if (needsBundleQueue) {
|
|
@@ -277,6 +290,7 @@ export class ScopeHoistingPackager {
|
|
|
277
290
|
this.parcelRequireName,
|
|
278
291
|
);
|
|
279
292
|
if (sourceMap && map) {
|
|
293
|
+
// @ts-expect-error TS2339
|
|
280
294
|
sourceMap.addSourceMap(map, lineCount);
|
|
281
295
|
}
|
|
282
296
|
}
|
|
@@ -318,7 +332,7 @@ export class ScopeHoistingPackager {
|
|
|
318
332
|
.filter((b) => this.shouldBundleQueue(b))
|
|
319
333
|
.map((b) => b.publicId);
|
|
320
334
|
|
|
321
|
-
const conditions = [];
|
|
335
|
+
const conditions: Array<string> = [];
|
|
322
336
|
if (getFeatureFlag('conditionalBundlingApi')) {
|
|
323
337
|
const conditionSet = this.bundleGraph
|
|
324
338
|
.getConditionalBundleMapping()
|
|
@@ -360,13 +374,13 @@ export class ScopeHoistingPackager {
|
|
|
360
374
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
361
375
|
}
|
|
362
376
|
|
|
363
|
-
async loadAssets(): Promise<{
|
|
364
|
-
wrapped: Array<Asset
|
|
365
|
-
constant: Array<Asset
|
|
366
|
-
|
|
377
|
+
async loadAssets(): Promise<{
|
|
378
|
+
wrapped: Array<Asset>;
|
|
379
|
+
constant: Array<Asset>;
|
|
380
|
+
}> {
|
|
367
381
|
let queue = new PromiseQueue({maxConcurrent: 32});
|
|
368
|
-
let wrapped = [];
|
|
369
|
-
let constant = [];
|
|
382
|
+
let wrapped: Array<Asset> = [];
|
|
383
|
+
let constant: Array<Asset> = [];
|
|
370
384
|
this.bundle.traverseAssets((asset) => {
|
|
371
385
|
queue.add(async () => {
|
|
372
386
|
let [code, map] = await Promise.all([
|
|
@@ -453,6 +467,7 @@ export class ScopeHoistingPackager {
|
|
|
453
467
|
}
|
|
454
468
|
}
|
|
455
469
|
|
|
470
|
+
// @ts-expect-error TS2769
|
|
456
471
|
this.assetOutputs = new Map(await queue.run());
|
|
457
472
|
return {wrapped, constant};
|
|
458
473
|
}
|
|
@@ -488,6 +503,7 @@ export class ScopeHoistingPackager {
|
|
|
488
503
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
489
504
|
let entry = this.bundle.getMainEntry();
|
|
490
505
|
if (entry && !this.wrappedAssets.has(entry.id)) {
|
|
506
|
+
// @ts-expect-error TS2345
|
|
491
507
|
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
492
508
|
|
|
493
509
|
for (let {
|
|
@@ -505,6 +521,7 @@ export class ScopeHoistingPackager {
|
|
|
505
521
|
}
|
|
506
522
|
|
|
507
523
|
let symbols = this.exportedSymbols.get(
|
|
524
|
+
// @ts-expect-error TS2345
|
|
508
525
|
symbol === '*' ? nullthrows(entry.symbols.get('*')?.local) : symbol,
|
|
509
526
|
)?.exportAs;
|
|
510
527
|
|
|
@@ -512,6 +529,7 @@ export class ScopeHoistingPackager {
|
|
|
512
529
|
symbols = [];
|
|
513
530
|
this.exportedSymbols.set(symbol, {
|
|
514
531
|
asset,
|
|
532
|
+
// @ts-expect-error TS2322
|
|
515
533
|
exportSymbol,
|
|
516
534
|
local: symbol,
|
|
517
535
|
exportAs: symbols,
|
|
@@ -522,6 +540,7 @@ export class ScopeHoistingPackager {
|
|
|
522
540
|
exportAs = 'default';
|
|
523
541
|
}
|
|
524
542
|
|
|
543
|
+
// @ts-expect-error TS2345
|
|
525
544
|
symbols.push(exportAs);
|
|
526
545
|
} else if (symbol === null) {
|
|
527
546
|
// TODO `meta.exportsIdentifier[exportSymbol]` should be exported
|
|
@@ -567,7 +586,7 @@ export class ScopeHoistingPackager {
|
|
|
567
586
|
return `${obj}[${JSON.stringify(property)}]`;
|
|
568
587
|
}
|
|
569
588
|
|
|
570
|
-
visitAsset(asset: Asset): [string,
|
|
589
|
+
visitAsset(asset: Asset): [string, SourceMap | null | undefined, number] {
|
|
571
590
|
invariant(!this.seenAssets.has(asset.id), 'Already visited asset');
|
|
572
591
|
this.seenAssets.add(asset.id);
|
|
573
592
|
|
|
@@ -582,8 +601,8 @@ export class ScopeHoistingPackager {
|
|
|
582
601
|
buildAsset(
|
|
583
602
|
asset: Asset,
|
|
584
603
|
code: string,
|
|
585
|
-
map
|
|
586
|
-
): [string,
|
|
604
|
+
map?: Buffer | null,
|
|
605
|
+
): [string, SourceMap | null | undefined, number] {
|
|
587
606
|
let shouldWrap = this.wrappedAssets.has(asset.id);
|
|
588
607
|
let deps = this.bundleGraph.getDependencies(asset);
|
|
589
608
|
|
|
@@ -618,6 +637,7 @@ export class ScopeHoistingPackager {
|
|
|
618
637
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
619
638
|
depCode += code + '\n';
|
|
620
639
|
if (sourceMap && map) {
|
|
640
|
+
// @ts-expect-error TS2551
|
|
621
641
|
sourceMap.addSourceMap(map, lineCount);
|
|
622
642
|
}
|
|
623
643
|
lineCount += lines + 1;
|
|
@@ -654,7 +674,9 @@ export class ScopeHoistingPackager {
|
|
|
654
674
|
code += append;
|
|
655
675
|
|
|
656
676
|
let lineCount = 0;
|
|
657
|
-
|
|
677
|
+
// @ts-expect-error TS2552
|
|
678
|
+
let depContent: Array<[string, NodeSourceMap | null | undefined, number]> =
|
|
679
|
+
[];
|
|
658
680
|
if (depMap.size === 0 && replacements.size === 0) {
|
|
659
681
|
// If there are no dependencies or replacements, use a simple function to count the number of lines.
|
|
660
682
|
lineCount = countLines(code) - 1;
|
|
@@ -756,6 +778,7 @@ export class ScopeHoistingPackager {
|
|
|
756
778
|
}
|
|
757
779
|
|
|
758
780
|
if (map) {
|
|
781
|
+
// @ts-expect-error TS2551
|
|
759
782
|
sourceMap.addSourceMap(map, lineCount);
|
|
760
783
|
}
|
|
761
784
|
}
|
|
@@ -812,6 +835,7 @@ ${code}
|
|
|
812
835
|
if (!depCode) continue;
|
|
813
836
|
code += depCode + '\n';
|
|
814
837
|
if (sourceMap && map) {
|
|
838
|
+
// @ts-expect-error TS2551
|
|
815
839
|
sourceMap.addSourceMap(map, lineCount);
|
|
816
840
|
}
|
|
817
841
|
lineCount += lines + 1;
|
|
@@ -894,10 +918,12 @@ ${code}
|
|
|
894
918
|
}
|
|
895
919
|
|
|
896
920
|
for (let [imported, {local}] of dep.symbols) {
|
|
921
|
+
// @ts-expect-error TS2367
|
|
897
922
|
if (local === '*') {
|
|
898
923
|
continue;
|
|
899
924
|
}
|
|
900
925
|
|
|
926
|
+
// @ts-expect-error TS2345
|
|
901
927
|
let symbol = this.getSymbolResolution(asset, resolved, imported, dep);
|
|
902
928
|
replacements.set(
|
|
903
929
|
local,
|
|
@@ -934,6 +960,7 @@ ${code}
|
|
|
934
960
|
(this.bundle.env.outputFormat === 'commonjs' &&
|
|
935
961
|
asset === this.bundle.getMainEntry())
|
|
936
962
|
) {
|
|
963
|
+
// @ts-expect-error TS2345
|
|
937
964
|
let exportsName = asset.symbols.get('*')?.local || `$${assetId}$exports`;
|
|
938
965
|
replacements.set(exportsName, 'module.exports');
|
|
939
966
|
}
|
|
@@ -977,8 +1004,11 @@ ${code}
|
|
|
977
1004
|
|
|
978
1005
|
for (let [imported, {local}] of dep.symbols) {
|
|
979
1006
|
// If already imported, just add the already renamed variable to the mapping.
|
|
1007
|
+
// @ts-expect-error TS2345
|
|
980
1008
|
let renamed = external.get(imported);
|
|
1009
|
+
// @ts-expect-error TS2367
|
|
981
1010
|
if (renamed && local !== '*' && replacements) {
|
|
1011
|
+
// @ts-expect-error TS2345
|
|
982
1012
|
replacements.set(local, renamed);
|
|
983
1013
|
continue;
|
|
984
1014
|
}
|
|
@@ -990,7 +1020,9 @@ ${code}
|
|
|
990
1020
|
if (!renamed) {
|
|
991
1021
|
if (referencedBundle) {
|
|
992
1022
|
let entry = nullthrows(referencedBundle.getMainEntry());
|
|
1023
|
+
// @ts-expect-error TS2322
|
|
993
1024
|
renamed =
|
|
1025
|
+
// @ts-expect-error TS2345
|
|
994
1026
|
entry.symbols.get('*')?.local ??
|
|
995
1027
|
`$${String(entry.meta.id)}$exports`;
|
|
996
1028
|
} else {
|
|
@@ -999,13 +1031,17 @@ ${code}
|
|
|
999
1031
|
);
|
|
1000
1032
|
}
|
|
1001
1033
|
|
|
1034
|
+
// @ts-expect-error TS2345
|
|
1002
1035
|
external.set('*', renamed);
|
|
1003
1036
|
}
|
|
1004
1037
|
|
|
1038
|
+
// @ts-expect-error TS2367
|
|
1005
1039
|
if (local !== '*' && replacements) {
|
|
1006
1040
|
let replacement;
|
|
1041
|
+
// @ts-expect-error TS2367
|
|
1007
1042
|
if (imported === '*') {
|
|
1008
1043
|
replacement = renamed;
|
|
1044
|
+
// @ts-expect-error TS2367
|
|
1009
1045
|
} else if (imported === 'default') {
|
|
1010
1046
|
let needsDefaultInterop = true;
|
|
1011
1047
|
if (referencedBundle) {
|
|
@@ -1019,36 +1055,44 @@ ${code}
|
|
|
1019
1055
|
replacement = `${renamed}.default`;
|
|
1020
1056
|
}
|
|
1021
1057
|
} else {
|
|
1058
|
+
// @ts-expect-error TS2345
|
|
1022
1059
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
1023
1060
|
}
|
|
1024
1061
|
|
|
1062
|
+
// @ts-expect-error TS2345
|
|
1025
1063
|
replacements.set(local, replacement);
|
|
1026
1064
|
}
|
|
1027
1065
|
} else {
|
|
1028
1066
|
let property;
|
|
1029
1067
|
if (referencedBundle) {
|
|
1030
1068
|
let entry = nullthrows(referencedBundle.getMainEntry());
|
|
1069
|
+
// @ts-expect-error TS2345
|
|
1031
1070
|
if (entry.symbols.hasExportSymbol('*')) {
|
|
1032
1071
|
// If importing * and the referenced module has a * export (e.g. CJS), use default instead.
|
|
1033
1072
|
// This mirrors the logic in buildExportedSymbols.
|
|
1034
1073
|
property = imported;
|
|
1074
|
+
// @ts-expect-error TS2322
|
|
1035
1075
|
imported =
|
|
1036
1076
|
referencedBundle?.env.outputFormat === 'esmodule'
|
|
1037
1077
|
? 'default'
|
|
1038
1078
|
: '*';
|
|
1039
1079
|
} else {
|
|
1080
|
+
// @ts-expect-error TS2367
|
|
1040
1081
|
if (imported === '*') {
|
|
1041
1082
|
let exportedSymbols = this.bundleGraph.getExportedSymbols(entry);
|
|
1083
|
+
// @ts-expect-error TS2367
|
|
1042
1084
|
if (local === '*') {
|
|
1043
1085
|
// Re-export all symbols.
|
|
1044
1086
|
for (let exported of exportedSymbols) {
|
|
1045
1087
|
if (exported.symbol) {
|
|
1088
|
+
// @ts-expect-error TS2345
|
|
1046
1089
|
external.set(exported.exportSymbol, exported.symbol);
|
|
1047
1090
|
}
|
|
1048
1091
|
}
|
|
1049
1092
|
continue;
|
|
1050
1093
|
}
|
|
1051
1094
|
}
|
|
1095
|
+
// @ts-expect-error TS2322
|
|
1052
1096
|
renamed = this.bundleGraph.getSymbolResolution(
|
|
1053
1097
|
entry,
|
|
1054
1098
|
imported,
|
|
@@ -1061,30 +1105,40 @@ ${code}
|
|
|
1061
1105
|
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
1062
1106
|
// local variables do not shadow it.
|
|
1063
1107
|
if (!renamed) {
|
|
1108
|
+
// @ts-expect-error TS2345
|
|
1064
1109
|
if (this.exportedSymbols.has(local)) {
|
|
1110
|
+
// @ts-expect-error TS2322
|
|
1065
1111
|
renamed = local;
|
|
1112
|
+
// @ts-expect-error TS2367
|
|
1066
1113
|
} else if (imported === 'default' || imported === '*') {
|
|
1067
1114
|
renamed = this.getTopLevelName(
|
|
1068
1115
|
`$${this.bundle.publicId}$${specifier}`,
|
|
1069
1116
|
);
|
|
1070
1117
|
} else {
|
|
1071
1118
|
renamed = this.getTopLevelName(
|
|
1119
|
+
// @ts-expect-error TS2731
|
|
1072
1120
|
`$${this.bundle.publicId}$${imported}`,
|
|
1073
1121
|
);
|
|
1074
1122
|
}
|
|
1075
1123
|
}
|
|
1076
1124
|
|
|
1125
|
+
// @ts-expect-error TS2345
|
|
1077
1126
|
external.set(imported, renamed);
|
|
1127
|
+
// @ts-expect-error TS2367
|
|
1078
1128
|
if (local !== '*' && replacements) {
|
|
1079
1129
|
let replacement = renamed;
|
|
1130
|
+
// @ts-expect-error TS2367
|
|
1080
1131
|
if (property === '*') {
|
|
1081
1132
|
replacement = renamed;
|
|
1133
|
+
// @ts-expect-error TS2367
|
|
1082
1134
|
} else if (property === 'default') {
|
|
1083
1135
|
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
1084
1136
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
1085
1137
|
} else if (property) {
|
|
1138
|
+
// @ts-expect-error TS2345
|
|
1086
1139
|
replacement = this.getPropertyAccess(renamed, property);
|
|
1087
1140
|
}
|
|
1141
|
+
// @ts-expect-error TS2345
|
|
1088
1142
|
replacements.set(local, replacement);
|
|
1089
1143
|
}
|
|
1090
1144
|
}
|
|
@@ -1123,6 +1177,7 @@ ${code}
|
|
|
1123
1177
|
asset: resolvedAsset,
|
|
1124
1178
|
exportSymbol,
|
|
1125
1179
|
symbol,
|
|
1180
|
+
// @ts-expect-error TS2345
|
|
1126
1181
|
} = this.bundleGraph.getSymbolResolution(resolved, imported, this.bundle);
|
|
1127
1182
|
|
|
1128
1183
|
if (
|
|
@@ -1181,8 +1236,11 @@ ${code}
|
|
|
1181
1236
|
staticExports &&
|
|
1182
1237
|
!isWrapped &&
|
|
1183
1238
|
(dep?.meta.kind === 'Import' || dep?.meta.kind === 'Export') &&
|
|
1239
|
+
// @ts-expect-error TS2345
|
|
1184
1240
|
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
1241
|
+
// @ts-expect-error TS2345
|
|
1185
1242
|
resolvedAsset.symbols.hasExportSymbol('default') &&
|
|
1243
|
+
// @ts-expect-error TS2345
|
|
1186
1244
|
!resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
1187
1245
|
|
|
1188
1246
|
// Find the namespace object for the resolved module. If wrapped and this
|
|
@@ -1198,7 +1256,9 @@ ${code}
|
|
|
1198
1256
|
} else if (isWrapped && dep) {
|
|
1199
1257
|
obj = `$${publicId}`;
|
|
1200
1258
|
} else {
|
|
1259
|
+
// @ts-expect-error TS2345
|
|
1201
1260
|
obj = resolvedAsset.symbols.get('*')?.local || `$${assetId}$exports`;
|
|
1261
|
+
// @ts-expect-error TS2345
|
|
1202
1262
|
obj = replacements?.get(obj) || obj;
|
|
1203
1263
|
}
|
|
1204
1264
|
|
|
@@ -1211,6 +1271,7 @@ ${code}
|
|
|
1211
1271
|
// Directly use module.exports for wrapped assets importing themselves.
|
|
1212
1272
|
return 'module.exports';
|
|
1213
1273
|
} else {
|
|
1274
|
+
// @ts-expect-error TS2322
|
|
1214
1275
|
return obj;
|
|
1215
1276
|
}
|
|
1216
1277
|
} else if (
|
|
@@ -1225,17 +1286,21 @@ ${code}
|
|
|
1225
1286
|
if (
|
|
1226
1287
|
(!dep || kind === 'Import' || kind === 'Export') &&
|
|
1227
1288
|
exportSymbol === 'default' &&
|
|
1289
|
+
// @ts-expect-error TS2345
|
|
1228
1290
|
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
1229
1291
|
this.needsDefaultInterop(resolvedAsset)
|
|
1230
1292
|
) {
|
|
1231
1293
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
1294
|
+
// @ts-expect-error TS2731
|
|
1232
1295
|
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
1233
1296
|
} else {
|
|
1297
|
+
// @ts-expect-error TS2345
|
|
1234
1298
|
return this.getPropertyAccess(obj, exportSymbol);
|
|
1235
1299
|
}
|
|
1236
1300
|
} else if (!symbol) {
|
|
1237
1301
|
invariant(false, 'Asset was skipped or not found.');
|
|
1238
1302
|
} else {
|
|
1303
|
+
// @ts-expect-error TS2322
|
|
1239
1304
|
return replacements?.get(symbol) || symbol;
|
|
1240
1305
|
}
|
|
1241
1306
|
}
|
|
@@ -1298,8 +1363,11 @@ ${code}
|
|
|
1298
1363
|
// If there's no __esModule flag, and default is a used symbol, we need
|
|
1299
1364
|
// to insert an interop helper.
|
|
1300
1365
|
let defaultInterop =
|
|
1366
|
+
// @ts-expect-error TS2345
|
|
1301
1367
|
asset.symbols.hasExportSymbol('*') &&
|
|
1368
|
+
// @ts-expect-error TS2345
|
|
1302
1369
|
usedSymbols.has('default') &&
|
|
1370
|
+
// @ts-expect-error TS2345
|
|
1303
1371
|
!asset.symbols.hasExportSymbol('__esModule');
|
|
1304
1372
|
|
|
1305
1373
|
let usedNamespace;
|
|
@@ -1308,33 +1376,33 @@ ${code}
|
|
|
1308
1376
|
asset.meta.isConstantModule
|
|
1309
1377
|
) {
|
|
1310
1378
|
// Only set usedNamespace if there is an incoming dependency in the current bundle that uses '*'
|
|
1311
|
-
usedNamespace = this.bundleGraph
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
);
|
|
1379
|
+
usedNamespace = this.bundleGraph.getIncomingDependencies(asset).some(
|
|
1380
|
+
(dep) =>
|
|
1381
|
+
this.bundle.hasDependency(dep) &&
|
|
1382
|
+
// @ts-expect-error TS2345
|
|
1383
|
+
nullthrows(this.bundleGraph.getUsedSymbols(dep)).has('*'),
|
|
1384
|
+
);
|
|
1318
1385
|
} else {
|
|
1319
1386
|
usedNamespace =
|
|
1320
1387
|
// If the asset has * in its used symbols, we might need the exports namespace.
|
|
1321
1388
|
// The one case where this isn't true is in ESM library entries, where the only
|
|
1322
1389
|
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
1323
1390
|
// instead of the namespace object.
|
|
1391
|
+
// @ts-expect-error TS2345
|
|
1324
1392
|
(usedSymbols.has('*') &&
|
|
1325
1393
|
(this.bundle.env.outputFormat !== 'esmodule' ||
|
|
1326
1394
|
!this.bundle.env.isLibrary ||
|
|
1327
1395
|
asset !== this.bundle.getMainEntry() ||
|
|
1328
|
-
this.bundleGraph
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
(dep)
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
))) ||
|
|
1396
|
+
this.bundleGraph.getIncomingDependencies(asset).some(
|
|
1397
|
+
(dep) =>
|
|
1398
|
+
!dep.isEntry &&
|
|
1399
|
+
this.bundle.hasDependency(dep) &&
|
|
1400
|
+
// @ts-expect-error TS2345
|
|
1401
|
+
nullthrows(this.bundleGraph.getUsedSymbols(dep)).has('*'),
|
|
1402
|
+
))) ||
|
|
1336
1403
|
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
1337
1404
|
// we fallback on the namespace object.
|
|
1405
|
+
// @ts-expect-error TS2345
|
|
1338
1406
|
(asset.symbols.hasExportSymbol('*') &&
|
|
1339
1407
|
[...usedSymbols].some((s) => !asset.symbols.hasExportSymbol(s))) ||
|
|
1340
1408
|
// If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
@@ -1371,6 +1439,7 @@ ${code}
|
|
|
1371
1439
|
// Insert the __esModule interop flag for this module if it has a `default` export
|
|
1372
1440
|
// and the namespace symbol is used.
|
|
1373
1441
|
// TODO: only if required by CJS?
|
|
1442
|
+
// @ts-expect-error TS2345
|
|
1374
1443
|
if (asset.symbols.hasExportSymbol('default') && usedSymbols.has('*')) {
|
|
1375
1444
|
prepend += `\n$parcel$defineInteropFlag($${assetId}$exports);\n`;
|
|
1376
1445
|
prependLineCount += 2;
|
|
@@ -1389,6 +1458,7 @@ ${code}
|
|
|
1389
1458
|
let isWrapped = resolved && resolved.meta.shouldWrap;
|
|
1390
1459
|
|
|
1391
1460
|
for (let [imported, {local}] of dep.symbols) {
|
|
1461
|
+
// @ts-expect-error TS2367
|
|
1392
1462
|
if (imported === '*' && local === '*') {
|
|
1393
1463
|
if (!resolved) {
|
|
1394
1464
|
// Re-exporting an external module. This should have already been handled in buildReplacements.
|
|
@@ -1406,9 +1476,11 @@ ${code}
|
|
|
1406
1476
|
if (
|
|
1407
1477
|
isWrapped ||
|
|
1408
1478
|
resolved.meta.staticExports === false ||
|
|
1479
|
+
// @ts-expect-error TS2345
|
|
1409
1480
|
nullthrows(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
1410
1481
|
// an empty asset
|
|
1411
1482
|
(!resolved.meta.hasCJSExports &&
|
|
1483
|
+
// @ts-expect-error TS2345
|
|
1412
1484
|
resolved.symbols.hasExportSymbol('*'))
|
|
1413
1485
|
) {
|
|
1414
1486
|
let obj = this.getSymbolResolution(
|
|
@@ -1425,7 +1497,9 @@ ${code}
|
|
|
1425
1497
|
this.bundleGraph.getUsedSymbols(dep),
|
|
1426
1498
|
)) {
|
|
1427
1499
|
if (
|
|
1500
|
+
// @ts-expect-error TS2367
|
|
1428
1501
|
symbol === 'default' || // `export * as ...` does not include the default export
|
|
1502
|
+
// @ts-expect-error TS2367
|
|
1429
1503
|
symbol === '__esModule'
|
|
1430
1504
|
) {
|
|
1431
1505
|
continue;
|
|
@@ -1434,6 +1508,7 @@ ${code}
|
|
|
1434
1508
|
let resolvedSymbol = this.getSymbolResolution(
|
|
1435
1509
|
asset,
|
|
1436
1510
|
resolved,
|
|
1511
|
+
// @ts-expect-error TS2345
|
|
1437
1512
|
symbol,
|
|
1438
1513
|
undefined,
|
|
1439
1514
|
replacements,
|
|
@@ -1459,6 +1534,7 @@ ${code}
|
|
|
1459
1534
|
// re-exported symbols rather than only symbols declared in this asset.
|
|
1460
1535
|
let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
|
|
1461
1536
|
let usedExports = [...asset.symbols.exportSymbols()].filter((symbol) => {
|
|
1537
|
+
// @ts-expect-error TS2367
|
|
1462
1538
|
if (symbol === '*') {
|
|
1463
1539
|
return false;
|
|
1464
1540
|
}
|
|
@@ -1475,6 +1551,7 @@ ${code}
|
|
|
1475
1551
|
// No used symbols available for the asset, make sure we keep all of them
|
|
1476
1552
|
if (!symbols) return false;
|
|
1477
1553
|
|
|
1554
|
+
// @ts-expect-error TS2345
|
|
1478
1555
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
1479
1556
|
});
|
|
1480
1557
|
return !unused;
|
|
@@ -1490,6 +1567,7 @@ ${code}
|
|
|
1490
1567
|
let resolved = this.getSymbolResolution(
|
|
1491
1568
|
asset,
|
|
1492
1569
|
asset,
|
|
1570
|
+
// @ts-expect-error TS2345
|
|
1493
1571
|
exp,
|
|
1494
1572
|
undefined,
|
|
1495
1573
|
replacements,
|
|
@@ -1545,8 +1623,10 @@ ${code}
|
|
|
1545
1623
|
}
|
|
1546
1624
|
|
|
1547
1625
|
for (let helper of this.usedHelpers) {
|
|
1626
|
+
// @ts-expect-error TS7053
|
|
1548
1627
|
let currentHelper = helpers[helper];
|
|
1549
1628
|
if (typeof currentHelper === 'function') {
|
|
1629
|
+
// @ts-expect-error TS7053
|
|
1550
1630
|
currentHelper = helpers[helper](this.bundle.env);
|
|
1551
1631
|
}
|
|
1552
1632
|
res += currentHelper;
|
|
@@ -1619,7 +1699,9 @@ ${code}
|
|
|
1619
1699
|
|
|
1620
1700
|
needsDefaultInterop(asset: Asset): boolean {
|
|
1621
1701
|
if (
|
|
1702
|
+
// @ts-expect-error TS2345
|
|
1622
1703
|
asset.symbols.hasExportSymbol('*') &&
|
|
1704
|
+
// @ts-expect-error TS2345
|
|
1623
1705
|
!asset.symbols.hasExportSymbol('default')
|
|
1624
1706
|
) {
|
|
1625
1707
|
return true;
|
package/src/dev-prelude.js
CHANGED
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
typeof globalThis !== 'undefined'
|
|
13
13
|
? globalThis
|
|
14
14
|
: typeof self !== 'undefined'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
? self
|
|
16
|
+
: typeof window !== 'undefined'
|
|
17
|
+
? window
|
|
18
|
+
: typeof global !== 'undefined'
|
|
19
|
+
? global
|
|
20
|
+
: {};
|
|
21
21
|
/* eslint-enable no-undef */
|
|
22
22
|
|
|
23
23
|
// Save the require from previous bundle to this closure if any
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {Environment} from '@atlaspack/types';
|
|
3
2
|
|
|
4
3
|
export const prelude = (parcelRequireName: string): string => `
|
|
@@ -166,4 +165,4 @@ export const helpers = {
|
|
|
166
165
|
$parcel$interopDefault,
|
|
167
166
|
$parcel$global,
|
|
168
167
|
$parcel$defineInteropFlag,
|
|
169
|
-
};
|
|
168
|
+
} as const;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {Async} from '@atlaspack/types';
|
|
3
2
|
import type SourceMap from '@parcel/source-map';
|
|
4
3
|
import {Packager} from '@atlaspack/plugin';
|
|
@@ -6,7 +5,7 @@ import {
|
|
|
6
5
|
replaceInlineReferences,
|
|
7
6
|
replaceURLReferences,
|
|
8
7
|
validateSchema,
|
|
9
|
-
|
|
8
|
+
SchemaEntity,
|
|
10
9
|
} from '@atlaspack/utils';
|
|
11
10
|
import {encodeJSONKeyComponent} from '@atlaspack/diagnostic';
|
|
12
11
|
import {hashString} from '@atlaspack/rust';
|
|
@@ -14,10 +13,10 @@ import nullthrows from 'nullthrows';
|
|
|
14
13
|
import {DevPackager} from './DevPackager';
|
|
15
14
|
import {ScopeHoistingPackager} from './ScopeHoistingPackager';
|
|
16
15
|
|
|
17
|
-
type JSPackagerConfig = {
|
|
18
|
-
parcelRequireName: string
|
|
19
|
-
unstable_asyncBundleRuntime: boolean
|
|
20
|
-
|
|
16
|
+
type JSPackagerConfig = {
|
|
17
|
+
parcelRequireName: string;
|
|
18
|
+
unstable_asyncBundleRuntime: boolean;
|
|
19
|
+
};
|
|
21
20
|
|
|
22
21
|
const CONFIG_SCHEMA: SchemaEntity = {
|
|
23
22
|
type: 'object',
|
|
@@ -29,7 +28,7 @@ const CONFIG_SCHEMA: SchemaEntity = {
|
|
|
29
28
|
additionalProperties: false,
|
|
30
29
|
};
|
|
31
30
|
|
|
32
|
-
export default
|
|
31
|
+
export default new Packager({
|
|
33
32
|
async loadConfig({config, options}): Promise<JSPackagerConfig> {
|
|
34
33
|
let packageKey = '@atlaspack/packager-js';
|
|
35
34
|
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
@@ -62,8 +61,10 @@ export default (new Packager({
|
|
|
62
61
|
|
|
63
62
|
let name = packageName?.contents ?? '';
|
|
64
63
|
return {
|
|
64
|
+
// @ts-expect-error TS2345
|
|
65
65
|
parcelRequireName: 'parcelRequire' + hashString(name).slice(-4),
|
|
66
66
|
unstable_asyncBundleRuntime: Boolean(
|
|
67
|
+
// @ts-expect-error TS2339
|
|
67
68
|
conf?.contents?.unstable_asyncBundleRuntime,
|
|
68
69
|
),
|
|
69
70
|
};
|
|
@@ -137,11 +138,13 @@ export default (new Packager({
|
|
|
137
138
|
map,
|
|
138
139
|
});
|
|
139
140
|
},
|
|
140
|
-
})
|
|
141
|
+
}) as Packager<unknown, unknown>;
|
|
141
142
|
|
|
142
143
|
async function getSourceMapSuffix(
|
|
143
|
-
getSourceMapReference: (
|
|
144
|
-
|
|
144
|
+
getSourceMapReference: (
|
|
145
|
+
arg1?: SourceMap | null | undefined,
|
|
146
|
+
) => Async<string | null | undefined>,
|
|
147
|
+
map?: SourceMap | null,
|
|
145
148
|
): Promise<string> {
|
|
146
149
|
let sourcemapReference = await getSourceMapReference(map);
|
|
147
150
|
if (sourcemapReference != null) {
|