@atlaspack/packager-js 2.19.0 → 2.19.1-typescript-17c3d1dec.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 +0 -1
- package/LICENSE +201 -0
- package/lib/CJSOutputFormat.d.ts +7 -0
- package/lib/DevPackager.d.ts +15 -0
- package/lib/DevPackager.js +8 -1
- package/lib/ESMOutputFormat.d.ts +7 -0
- package/lib/GlobalOutputFormat.d.ts +7 -0
- package/lib/ScopeHoistingPackager.d.ts +65 -0
- package/lib/ScopeHoistingPackager.js +124 -16
- package/lib/dev-prelude.js +6 -6
- package/lib/helpers.d.ts +11 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +4 -10
- package/lib/utils.d.ts +6 -0
- package/package.json +16 -11
- 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 -15
- 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();
|
|
@@ -227,17 +237,20 @@ export class ScopeHoistingPackager {
|
|
|
227
237
|
this.bundleGraph.getAssetPublicId(entry),
|
|
228
238
|
)});\n`;
|
|
229
239
|
|
|
240
|
+
// @ts-expect-error TS2345
|
|
230
241
|
let entryExports = entry.symbols.get('*')?.local;
|
|
231
242
|
|
|
232
243
|
if (
|
|
233
244
|
entryExports &&
|
|
234
245
|
entry === mainEntry &&
|
|
246
|
+
// @ts-expect-error TS2345
|
|
235
247
|
this.exportedSymbols.has(entryExports)
|
|
236
248
|
) {
|
|
237
249
|
invariant(
|
|
238
250
|
!needsBundleQueue,
|
|
239
251
|
'Entry exports are not yet compaitble with async bundles',
|
|
240
252
|
);
|
|
253
|
+
// @ts-expect-error TS2731
|
|
241
254
|
res += `\nvar ${entryExports} = ${parcelRequire}`;
|
|
242
255
|
} else {
|
|
243
256
|
if (needsBundleQueue) {
|
|
@@ -281,6 +294,7 @@ export class ScopeHoistingPackager {
|
|
|
281
294
|
this.parcelRequireName,
|
|
282
295
|
);
|
|
283
296
|
if (sourceMap && map) {
|
|
297
|
+
// @ts-expect-error TS2339
|
|
284
298
|
sourceMap.addSourceMap(map, lineCount);
|
|
285
299
|
}
|
|
286
300
|
}
|
|
@@ -322,7 +336,7 @@ export class ScopeHoistingPackager {
|
|
|
322
336
|
.filter((b) => this.shouldBundleQueue(b))
|
|
323
337
|
.map((b) => b.publicId);
|
|
324
338
|
|
|
325
|
-
const conditions = [];
|
|
339
|
+
const conditions: Array<string> = [];
|
|
326
340
|
if (getFeatureFlag('conditionalBundlingApi')) {
|
|
327
341
|
const conditionSet = this.bundleGraph
|
|
328
342
|
.getConditionalBundleMapping()
|
|
@@ -364,13 +378,13 @@ export class ScopeHoistingPackager {
|
|
|
364
378
|
return `$parcel$global.rwr(${params.join(', ')});`;
|
|
365
379
|
}
|
|
366
380
|
|
|
367
|
-
async loadAssets(): Promise<{
|
|
368
|
-
wrapped: Array<Asset
|
|
369
|
-
constant: Array<Asset
|
|
370
|
-
|
|
381
|
+
async loadAssets(): Promise<{
|
|
382
|
+
wrapped: Array<Asset>;
|
|
383
|
+
constant: Array<Asset>;
|
|
384
|
+
}> {
|
|
371
385
|
let queue = new PromiseQueue({maxConcurrent: 32});
|
|
372
|
-
let wrapped = [];
|
|
373
|
-
let constant = [];
|
|
386
|
+
let wrapped: Array<Asset> = [];
|
|
387
|
+
let constant: Array<Asset> = [];
|
|
374
388
|
this.bundle.traverseAssets((asset) => {
|
|
375
389
|
queue.add(async () => {
|
|
376
390
|
let [code, map] = await Promise.all([
|
|
@@ -457,6 +471,7 @@ export class ScopeHoistingPackager {
|
|
|
457
471
|
}
|
|
458
472
|
}
|
|
459
473
|
|
|
474
|
+
// @ts-expect-error TS2769
|
|
460
475
|
this.assetOutputs = new Map(await queue.run());
|
|
461
476
|
return {wrapped, constant};
|
|
462
477
|
}
|
|
@@ -492,6 +507,7 @@ export class ScopeHoistingPackager {
|
|
|
492
507
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
493
508
|
let entry = this.bundle.getMainEntry();
|
|
494
509
|
if (entry && !this.wrappedAssets.has(entry.id)) {
|
|
510
|
+
// @ts-expect-error TS2345
|
|
495
511
|
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
496
512
|
|
|
497
513
|
for (let {
|
|
@@ -509,6 +525,7 @@ export class ScopeHoistingPackager {
|
|
|
509
525
|
}
|
|
510
526
|
|
|
511
527
|
let symbols = this.exportedSymbols.get(
|
|
528
|
+
// @ts-expect-error TS2345
|
|
512
529
|
symbol === '*' ? nullthrows(entry.symbols.get('*')?.local) : symbol,
|
|
513
530
|
)?.exportAs;
|
|
514
531
|
|
|
@@ -516,6 +533,7 @@ export class ScopeHoistingPackager {
|
|
|
516
533
|
symbols = [];
|
|
517
534
|
this.exportedSymbols.set(symbol, {
|
|
518
535
|
asset,
|
|
536
|
+
// @ts-expect-error TS2322
|
|
519
537
|
exportSymbol,
|
|
520
538
|
local: symbol,
|
|
521
539
|
exportAs: symbols,
|
|
@@ -526,6 +544,7 @@ export class ScopeHoistingPackager {
|
|
|
526
544
|
exportAs = 'default';
|
|
527
545
|
}
|
|
528
546
|
|
|
547
|
+
// @ts-expect-error TS2345
|
|
529
548
|
symbols.push(exportAs);
|
|
530
549
|
} else if (symbol === null) {
|
|
531
550
|
// TODO `meta.exportsIdentifier[exportSymbol]` should be exported
|
|
@@ -571,7 +590,7 @@ export class ScopeHoistingPackager {
|
|
|
571
590
|
return `${obj}[${JSON.stringify(property)}]`;
|
|
572
591
|
}
|
|
573
592
|
|
|
574
|
-
visitAsset(asset: Asset): [string,
|
|
593
|
+
visitAsset(asset: Asset): [string, SourceMap | null | undefined, number] {
|
|
575
594
|
invariant(!this.seenAssets.has(asset.id), 'Already visited asset');
|
|
576
595
|
this.seenAssets.add(asset.id);
|
|
577
596
|
|
|
@@ -586,8 +605,8 @@ export class ScopeHoistingPackager {
|
|
|
586
605
|
buildAsset(
|
|
587
606
|
asset: Asset,
|
|
588
607
|
code: string,
|
|
589
|
-
map
|
|
590
|
-
): [string,
|
|
608
|
+
map?: Buffer | null,
|
|
609
|
+
): [string, SourceMap | null | undefined, number] {
|
|
591
610
|
let shouldWrap = this.wrappedAssets.has(asset.id);
|
|
592
611
|
let deps = this.bundleGraph.getDependencies(asset);
|
|
593
612
|
|
|
@@ -622,6 +641,7 @@ export class ScopeHoistingPackager {
|
|
|
622
641
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
623
642
|
depCode += code + '\n';
|
|
624
643
|
if (sourceMap && map) {
|
|
644
|
+
// @ts-expect-error TS2551
|
|
625
645
|
sourceMap.addSourceMap(map, lineCount);
|
|
626
646
|
}
|
|
627
647
|
lineCount += lines + 1;
|
|
@@ -658,7 +678,9 @@ export class ScopeHoistingPackager {
|
|
|
658
678
|
code += append;
|
|
659
679
|
|
|
660
680
|
let lineCount = 0;
|
|
661
|
-
|
|
681
|
+
// @ts-expect-error TS2552
|
|
682
|
+
let depContent: Array<[string, NodeSourceMap | null | undefined, number]> =
|
|
683
|
+
[];
|
|
662
684
|
if (depMap.size === 0 && replacements.size === 0) {
|
|
663
685
|
// If there are no dependencies or replacements, use a simple function to count the number of lines.
|
|
664
686
|
lineCount = countLines(code) - 1;
|
|
@@ -760,6 +782,7 @@ export class ScopeHoistingPackager {
|
|
|
760
782
|
}
|
|
761
783
|
|
|
762
784
|
if (map) {
|
|
785
|
+
// @ts-expect-error TS2551
|
|
763
786
|
sourceMap.addSourceMap(map, lineCount);
|
|
764
787
|
}
|
|
765
788
|
}
|
|
@@ -816,6 +839,7 @@ ${code}
|
|
|
816
839
|
if (!depCode) continue;
|
|
817
840
|
code += depCode + '\n';
|
|
818
841
|
if (sourceMap && map) {
|
|
842
|
+
// @ts-expect-error TS2551
|
|
819
843
|
sourceMap.addSourceMap(map, lineCount);
|
|
820
844
|
}
|
|
821
845
|
lineCount += lines + 1;
|
|
@@ -898,10 +922,12 @@ ${code}
|
|
|
898
922
|
}
|
|
899
923
|
|
|
900
924
|
for (let [imported, {local}] of dep.symbols) {
|
|
925
|
+
// @ts-expect-error TS2367
|
|
901
926
|
if (local === '*') {
|
|
902
927
|
continue;
|
|
903
928
|
}
|
|
904
929
|
|
|
930
|
+
// @ts-expect-error TS2345
|
|
905
931
|
let symbol = this.getSymbolResolution(asset, resolved, imported, dep);
|
|
906
932
|
replacements.set(
|
|
907
933
|
local,
|
|
@@ -938,6 +964,7 @@ ${code}
|
|
|
938
964
|
(this.bundle.env.outputFormat === 'commonjs' &&
|
|
939
965
|
asset === this.bundle.getMainEntry())
|
|
940
966
|
) {
|
|
967
|
+
// @ts-expect-error TS2345
|
|
941
968
|
let exportsName = asset.symbols.get('*')?.local || `$${assetId}$exports`;
|
|
942
969
|
replacements.set(exportsName, 'module.exports');
|
|
943
970
|
}
|
|
@@ -981,8 +1008,11 @@ ${code}
|
|
|
981
1008
|
|
|
982
1009
|
for (let [imported, {local}] of dep.symbols) {
|
|
983
1010
|
// If already imported, just add the already renamed variable to the mapping.
|
|
1011
|
+
// @ts-expect-error TS2345
|
|
984
1012
|
let renamed = external.get(imported);
|
|
1013
|
+
// @ts-expect-error TS2367
|
|
985
1014
|
if (renamed && local !== '*' && replacements) {
|
|
1015
|
+
// @ts-expect-error TS2345
|
|
986
1016
|
replacements.set(local, renamed);
|
|
987
1017
|
continue;
|
|
988
1018
|
}
|
|
@@ -994,7 +1024,9 @@ ${code}
|
|
|
994
1024
|
if (!renamed) {
|
|
995
1025
|
if (referencedBundle) {
|
|
996
1026
|
let entry = nullthrows(referencedBundle.getMainEntry());
|
|
1027
|
+
// @ts-expect-error TS2322
|
|
997
1028
|
renamed =
|
|
1029
|
+
// @ts-expect-error TS2345
|
|
998
1030
|
entry.symbols.get('*')?.local ??
|
|
999
1031
|
`$${String(entry.meta.id)}$exports`;
|
|
1000
1032
|
} else {
|
|
@@ -1003,13 +1035,17 @@ ${code}
|
|
|
1003
1035
|
);
|
|
1004
1036
|
}
|
|
1005
1037
|
|
|
1038
|
+
// @ts-expect-error TS2345
|
|
1006
1039
|
external.set('*', renamed);
|
|
1007
1040
|
}
|
|
1008
1041
|
|
|
1042
|
+
// @ts-expect-error TS2367
|
|
1009
1043
|
if (local !== '*' && replacements) {
|
|
1010
1044
|
let replacement;
|
|
1045
|
+
// @ts-expect-error TS2367
|
|
1011
1046
|
if (imported === '*') {
|
|
1012
1047
|
replacement = renamed;
|
|
1048
|
+
// @ts-expect-error TS2367
|
|
1013
1049
|
} else if (imported === 'default') {
|
|
1014
1050
|
let needsDefaultInterop = true;
|
|
1015
1051
|
if (referencedBundle) {
|
|
@@ -1023,36 +1059,44 @@ ${code}
|
|
|
1023
1059
|
replacement = `${renamed}.default`;
|
|
1024
1060
|
}
|
|
1025
1061
|
} else {
|
|
1062
|
+
// @ts-expect-error TS2345
|
|
1026
1063
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
1027
1064
|
}
|
|
1028
1065
|
|
|
1066
|
+
// @ts-expect-error TS2345
|
|
1029
1067
|
replacements.set(local, replacement);
|
|
1030
1068
|
}
|
|
1031
1069
|
} else {
|
|
1032
1070
|
let property;
|
|
1033
1071
|
if (referencedBundle) {
|
|
1034
1072
|
let entry = nullthrows(referencedBundle.getMainEntry());
|
|
1073
|
+
// @ts-expect-error TS2345
|
|
1035
1074
|
if (entry.symbols.hasExportSymbol('*')) {
|
|
1036
1075
|
// If importing * and the referenced module has a * export (e.g. CJS), use default instead.
|
|
1037
1076
|
// This mirrors the logic in buildExportedSymbols.
|
|
1038
1077
|
property = imported;
|
|
1078
|
+
// @ts-expect-error TS2322
|
|
1039
1079
|
imported =
|
|
1040
1080
|
referencedBundle?.env.outputFormat === 'esmodule'
|
|
1041
1081
|
? 'default'
|
|
1042
1082
|
: '*';
|
|
1043
1083
|
} else {
|
|
1084
|
+
// @ts-expect-error TS2367
|
|
1044
1085
|
if (imported === '*') {
|
|
1045
1086
|
let exportedSymbols = this.bundleGraph.getExportedSymbols(entry);
|
|
1087
|
+
// @ts-expect-error TS2367
|
|
1046
1088
|
if (local === '*') {
|
|
1047
1089
|
// Re-export all symbols.
|
|
1048
1090
|
for (let exported of exportedSymbols) {
|
|
1049
1091
|
if (exported.symbol) {
|
|
1092
|
+
// @ts-expect-error TS2345
|
|
1050
1093
|
external.set(exported.exportSymbol, exported.symbol);
|
|
1051
1094
|
}
|
|
1052
1095
|
}
|
|
1053
1096
|
continue;
|
|
1054
1097
|
}
|
|
1055
1098
|
}
|
|
1099
|
+
// @ts-expect-error TS2322
|
|
1056
1100
|
renamed = this.bundleGraph.getSymbolResolution(
|
|
1057
1101
|
entry,
|
|
1058
1102
|
imported,
|
|
@@ -1065,30 +1109,40 @@ ${code}
|
|
|
1065
1109
|
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
1066
1110
|
// local variables do not shadow it.
|
|
1067
1111
|
if (!renamed) {
|
|
1112
|
+
// @ts-expect-error TS2345
|
|
1068
1113
|
if (this.exportedSymbols.has(local)) {
|
|
1114
|
+
// @ts-expect-error TS2322
|
|
1069
1115
|
renamed = local;
|
|
1116
|
+
// @ts-expect-error TS2367
|
|
1070
1117
|
} else if (imported === 'default' || imported === '*') {
|
|
1071
1118
|
renamed = this.getTopLevelName(
|
|
1072
1119
|
`$${this.bundle.publicId}$${specifier}`,
|
|
1073
1120
|
);
|
|
1074
1121
|
} else {
|
|
1075
1122
|
renamed = this.getTopLevelName(
|
|
1123
|
+
// @ts-expect-error TS2731
|
|
1076
1124
|
`$${this.bundle.publicId}$${imported}`,
|
|
1077
1125
|
);
|
|
1078
1126
|
}
|
|
1079
1127
|
}
|
|
1080
1128
|
|
|
1129
|
+
// @ts-expect-error TS2345
|
|
1081
1130
|
external.set(imported, renamed);
|
|
1131
|
+
// @ts-expect-error TS2367
|
|
1082
1132
|
if (local !== '*' && replacements) {
|
|
1083
1133
|
let replacement = renamed;
|
|
1134
|
+
// @ts-expect-error TS2367
|
|
1084
1135
|
if (property === '*') {
|
|
1085
1136
|
replacement = renamed;
|
|
1137
|
+
// @ts-expect-error TS2367
|
|
1086
1138
|
} else if (property === 'default') {
|
|
1087
1139
|
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
1088
1140
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
1089
1141
|
} else if (property) {
|
|
1142
|
+
// @ts-expect-error TS2345
|
|
1090
1143
|
replacement = this.getPropertyAccess(renamed, property);
|
|
1091
1144
|
}
|
|
1145
|
+
// @ts-expect-error TS2345
|
|
1092
1146
|
replacements.set(local, replacement);
|
|
1093
1147
|
}
|
|
1094
1148
|
}
|
|
@@ -1127,6 +1181,7 @@ ${code}
|
|
|
1127
1181
|
asset: resolvedAsset,
|
|
1128
1182
|
exportSymbol,
|
|
1129
1183
|
symbol,
|
|
1184
|
+
// @ts-expect-error TS2345
|
|
1130
1185
|
} = this.bundleGraph.getSymbolResolution(resolved, imported, this.bundle);
|
|
1131
1186
|
|
|
1132
1187
|
if (
|
|
@@ -1185,8 +1240,11 @@ ${code}
|
|
|
1185
1240
|
staticExports &&
|
|
1186
1241
|
!isWrapped &&
|
|
1187
1242
|
(dep?.meta.kind === 'Import' || dep?.meta.kind === 'Export') &&
|
|
1243
|
+
// @ts-expect-error TS2345
|
|
1188
1244
|
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
1245
|
+
// @ts-expect-error TS2345
|
|
1189
1246
|
resolvedAsset.symbols.hasExportSymbol('default') &&
|
|
1247
|
+
// @ts-expect-error TS2345
|
|
1190
1248
|
!resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
1191
1249
|
|
|
1192
1250
|
// Find the namespace object for the resolved module. If wrapped and this
|
|
@@ -1202,7 +1260,9 @@ ${code}
|
|
|
1202
1260
|
} else if (isWrapped && dep) {
|
|
1203
1261
|
obj = `$${publicId}`;
|
|
1204
1262
|
} else {
|
|
1263
|
+
// @ts-expect-error TS2345
|
|
1205
1264
|
obj = resolvedAsset.symbols.get('*')?.local || `$${assetId}$exports`;
|
|
1265
|
+
// @ts-expect-error TS2345
|
|
1206
1266
|
obj = replacements?.get(obj) || obj;
|
|
1207
1267
|
}
|
|
1208
1268
|
|
|
@@ -1215,6 +1275,7 @@ ${code}
|
|
|
1215
1275
|
// Directly use module.exports for wrapped assets importing themselves.
|
|
1216
1276
|
return 'module.exports';
|
|
1217
1277
|
} else {
|
|
1278
|
+
// @ts-expect-error TS2322
|
|
1218
1279
|
return obj;
|
|
1219
1280
|
}
|
|
1220
1281
|
} else if (
|
|
@@ -1229,17 +1290,21 @@ ${code}
|
|
|
1229
1290
|
if (
|
|
1230
1291
|
(!dep || kind === 'Import' || kind === 'Export') &&
|
|
1231
1292
|
exportSymbol === 'default' &&
|
|
1293
|
+
// @ts-expect-error TS2345
|
|
1232
1294
|
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
1233
1295
|
this.needsDefaultInterop(resolvedAsset)
|
|
1234
1296
|
) {
|
|
1235
1297
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
1298
|
+
// @ts-expect-error TS2731
|
|
1236
1299
|
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
1237
1300
|
} else {
|
|
1301
|
+
// @ts-expect-error TS2345
|
|
1238
1302
|
return this.getPropertyAccess(obj, exportSymbol);
|
|
1239
1303
|
}
|
|
1240
1304
|
} else if (!symbol) {
|
|
1241
1305
|
invariant(false, 'Asset was skipped or not found.');
|
|
1242
1306
|
} else {
|
|
1307
|
+
// @ts-expect-error TS2322
|
|
1243
1308
|
return replacements?.get(symbol) || symbol;
|
|
1244
1309
|
}
|
|
1245
1310
|
}
|
|
@@ -1302,8 +1367,11 @@ ${code}
|
|
|
1302
1367
|
// If there's no __esModule flag, and default is a used symbol, we need
|
|
1303
1368
|
// to insert an interop helper.
|
|
1304
1369
|
let defaultInterop =
|
|
1370
|
+
// @ts-expect-error TS2345
|
|
1305
1371
|
asset.symbols.hasExportSymbol('*') &&
|
|
1372
|
+
// @ts-expect-error TS2345
|
|
1306
1373
|
usedSymbols.has('default') &&
|
|
1374
|
+
// @ts-expect-error TS2345
|
|
1307
1375
|
!asset.symbols.hasExportSymbol('__esModule');
|
|
1308
1376
|
|
|
1309
1377
|
let usedNamespace;
|
|
@@ -1312,33 +1380,33 @@ ${code}
|
|
|
1312
1380
|
asset.meta.isConstantModule
|
|
1313
1381
|
) {
|
|
1314
1382
|
// Only set usedNamespace if there is an incoming dependency in the current bundle that uses '*'
|
|
1315
|
-
usedNamespace = this.bundleGraph
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
);
|
|
1383
|
+
usedNamespace = this.bundleGraph.getIncomingDependencies(asset).some(
|
|
1384
|
+
(dep) =>
|
|
1385
|
+
this.bundle.hasDependency(dep) &&
|
|
1386
|
+
// @ts-expect-error TS2345
|
|
1387
|
+
nullthrows(this.bundleGraph.getUsedSymbols(dep)).has('*'),
|
|
1388
|
+
);
|
|
1322
1389
|
} else {
|
|
1323
1390
|
usedNamespace =
|
|
1324
1391
|
// If the asset has * in its used symbols, we might need the exports namespace.
|
|
1325
1392
|
// The one case where this isn't true is in ESM library entries, where the only
|
|
1326
1393
|
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
1327
1394
|
// instead of the namespace object.
|
|
1395
|
+
// @ts-expect-error TS2345
|
|
1328
1396
|
(usedSymbols.has('*') &&
|
|
1329
1397
|
(this.bundle.env.outputFormat !== 'esmodule' ||
|
|
1330
1398
|
!this.bundle.env.isLibrary ||
|
|
1331
1399
|
asset !== this.bundle.getMainEntry() ||
|
|
1332
|
-
this.bundleGraph
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
(dep)
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
))) ||
|
|
1400
|
+
this.bundleGraph.getIncomingDependencies(asset).some(
|
|
1401
|
+
(dep) =>
|
|
1402
|
+
!dep.isEntry &&
|
|
1403
|
+
this.bundle.hasDependency(dep) &&
|
|
1404
|
+
// @ts-expect-error TS2345
|
|
1405
|
+
nullthrows(this.bundleGraph.getUsedSymbols(dep)).has('*'),
|
|
1406
|
+
))) ||
|
|
1340
1407
|
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
1341
1408
|
// we fallback on the namespace object.
|
|
1409
|
+
// @ts-expect-error TS2345
|
|
1342
1410
|
(asset.symbols.hasExportSymbol('*') &&
|
|
1343
1411
|
[...usedSymbols].some((s) => !asset.symbols.hasExportSymbol(s))) ||
|
|
1344
1412
|
// If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
@@ -1375,6 +1443,7 @@ ${code}
|
|
|
1375
1443
|
// Insert the __esModule interop flag for this module if it has a `default` export
|
|
1376
1444
|
// and the namespace symbol is used.
|
|
1377
1445
|
// TODO: only if required by CJS?
|
|
1446
|
+
// @ts-expect-error TS2345
|
|
1378
1447
|
if (asset.symbols.hasExportSymbol('default') && usedSymbols.has('*')) {
|
|
1379
1448
|
prepend += `\n$parcel$defineInteropFlag($${assetId}$exports);\n`;
|
|
1380
1449
|
prependLineCount += 2;
|
|
@@ -1393,6 +1462,7 @@ ${code}
|
|
|
1393
1462
|
let isWrapped = resolved && resolved.meta.shouldWrap;
|
|
1394
1463
|
|
|
1395
1464
|
for (let [imported, {local}] of dep.symbols) {
|
|
1465
|
+
// @ts-expect-error TS2367
|
|
1396
1466
|
if (imported === '*' && local === '*') {
|
|
1397
1467
|
if (!resolved) {
|
|
1398
1468
|
// Re-exporting an external module. This should have already been handled in buildReplacements.
|
|
@@ -1410,9 +1480,11 @@ ${code}
|
|
|
1410
1480
|
if (
|
|
1411
1481
|
isWrapped ||
|
|
1412
1482
|
resolved.meta.staticExports === false ||
|
|
1483
|
+
// @ts-expect-error TS2345
|
|
1413
1484
|
nullthrows(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
1414
1485
|
// an empty asset
|
|
1415
1486
|
(!resolved.meta.hasCJSExports &&
|
|
1487
|
+
// @ts-expect-error TS2345
|
|
1416
1488
|
resolved.symbols.hasExportSymbol('*'))
|
|
1417
1489
|
) {
|
|
1418
1490
|
let obj = this.getSymbolResolution(
|
|
@@ -1429,7 +1501,9 @@ ${code}
|
|
|
1429
1501
|
this.bundleGraph.getUsedSymbols(dep),
|
|
1430
1502
|
)) {
|
|
1431
1503
|
if (
|
|
1504
|
+
// @ts-expect-error TS2367
|
|
1432
1505
|
symbol === 'default' || // `export * as ...` does not include the default export
|
|
1506
|
+
// @ts-expect-error TS2367
|
|
1433
1507
|
symbol === '__esModule'
|
|
1434
1508
|
) {
|
|
1435
1509
|
continue;
|
|
@@ -1438,6 +1512,7 @@ ${code}
|
|
|
1438
1512
|
let resolvedSymbol = this.getSymbolResolution(
|
|
1439
1513
|
asset,
|
|
1440
1514
|
resolved,
|
|
1515
|
+
// @ts-expect-error TS2345
|
|
1441
1516
|
symbol,
|
|
1442
1517
|
undefined,
|
|
1443
1518
|
replacements,
|
|
@@ -1463,6 +1538,7 @@ ${code}
|
|
|
1463
1538
|
// re-exported symbols rather than only symbols declared in this asset.
|
|
1464
1539
|
let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
|
|
1465
1540
|
let usedExports = [...asset.symbols.exportSymbols()].filter((symbol) => {
|
|
1541
|
+
// @ts-expect-error TS2367
|
|
1466
1542
|
if (symbol === '*') {
|
|
1467
1543
|
return false;
|
|
1468
1544
|
}
|
|
@@ -1479,6 +1555,7 @@ ${code}
|
|
|
1479
1555
|
// No used symbols available for the asset, make sure we keep all of them
|
|
1480
1556
|
if (!symbols) return false;
|
|
1481
1557
|
|
|
1558
|
+
// @ts-expect-error TS2345
|
|
1482
1559
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
1483
1560
|
});
|
|
1484
1561
|
return !unused;
|
|
@@ -1494,6 +1571,7 @@ ${code}
|
|
|
1494
1571
|
let resolved = this.getSymbolResolution(
|
|
1495
1572
|
asset,
|
|
1496
1573
|
asset,
|
|
1574
|
+
// @ts-expect-error TS2345
|
|
1497
1575
|
exp,
|
|
1498
1576
|
undefined,
|
|
1499
1577
|
replacements,
|
|
@@ -1549,8 +1627,10 @@ ${code}
|
|
|
1549
1627
|
}
|
|
1550
1628
|
|
|
1551
1629
|
for (let helper of this.usedHelpers) {
|
|
1630
|
+
// @ts-expect-error TS7053
|
|
1552
1631
|
let currentHelper = helpers[helper];
|
|
1553
1632
|
if (typeof currentHelper === 'function') {
|
|
1633
|
+
// @ts-expect-error TS7053
|
|
1554
1634
|
currentHelper = helpers[helper](this.bundle.env);
|
|
1555
1635
|
}
|
|
1556
1636
|
res += currentHelper;
|
|
@@ -1623,7 +1703,9 @@ ${code}
|
|
|
1623
1703
|
|
|
1624
1704
|
needsDefaultInterop(asset: Asset): boolean {
|
|
1625
1705
|
if (
|
|
1706
|
+
// @ts-expect-error TS2345
|
|
1626
1707
|
asset.symbols.hasExportSymbol('*') &&
|
|
1708
|
+
// @ts-expect-error TS2345
|
|
1627
1709
|
!asset.symbols.hasExportSymbol('default')
|
|
1628
1710
|
) {
|
|
1629
1711
|
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;
|