@atlaspack/packager-js 2.19.0 → 2.19.1-typescript-5ad950d33.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
|
@@ -77,7 +77,6 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
77
77
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
78
78
|
// General regex used to replace imports with the resolved code, references with resolutions,
|
|
79
79
|
// and count the number of newlines in the file for source maps.
|
|
80
|
-
//
|
|
81
80
|
// For conditional bundling the only difference in this regex is adding `importCond` where we have `importAsync` etc..
|
|
82
81
|
const REPLACEMENT_RE_CONDITIONAL = /\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;
|
|
83
82
|
const REPLACEMENT_RE = /\n|import\s+"([0-9a-f]{16,20}:.+?)";|(?:\$[0-9a-f]{16,20}\$exports)|(?:\$[0-9a-f]{16,20}\$(?:import|importAsync|require)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
@@ -97,6 +96,8 @@ const OUTPUT_FORMATS = {
|
|
|
97
96
|
global: _GlobalOutputFormat.GlobalOutputFormat
|
|
98
97
|
};
|
|
99
98
|
class ScopeHoistingPackager {
|
|
99
|
+
// @ts-expect-error TS2564
|
|
100
|
+
|
|
100
101
|
exportedSymbols = new Map();
|
|
101
102
|
externals = new Map();
|
|
102
103
|
topLevelNames = new Map();
|
|
@@ -140,9 +141,11 @@ class ScopeHoistingPackager {
|
|
|
140
141
|
}
|
|
141
142
|
let res = '';
|
|
142
143
|
let lineCount = 0;
|
|
144
|
+
// @ts-expect-error TS7034
|
|
143
145
|
let sourceMap = null;
|
|
144
146
|
let processAsset = asset => {
|
|
145
147
|
let [content, map, lines] = this.visitAsset(asset);
|
|
148
|
+
// @ts-expect-error TS7005
|
|
146
149
|
if (sourceMap && map) {
|
|
147
150
|
sourceMap.addSourceMap(map, lineCount);
|
|
148
151
|
} else if (this.bundle.env.sourceMap) {
|
|
@@ -181,6 +184,7 @@ class ScopeHoistingPackager {
|
|
|
181
184
|
let [prelude, preludeLines] = this.buildBundlePrelude();
|
|
182
185
|
res = prelude + res;
|
|
183
186
|
lineCount += preludeLines;
|
|
187
|
+
// @ts-expect-error TS2339
|
|
184
188
|
(_sourceMap = sourceMap) === null || _sourceMap === void 0 || _sourceMap.offsetLines(1, preludeLines);
|
|
185
189
|
let entries = this.bundle.getEntryAssets();
|
|
186
190
|
let mainEntry = this.bundle.getMainEntry();
|
|
@@ -204,9 +208,14 @@ class ScopeHoistingPackager {
|
|
|
204
208
|
if (this.wrappedAssets.has(entry.id) && !this.isScriptEntry(entry)) {
|
|
205
209
|
var _entry$symbols$get;
|
|
206
210
|
let parcelRequire = `parcelRequire(${JSON.stringify(this.bundleGraph.getAssetPublicId(entry))});\n`;
|
|
211
|
+
|
|
212
|
+
// @ts-expect-error TS2345
|
|
207
213
|
let entryExports = (_entry$symbols$get = entry.symbols.get('*')) === null || _entry$symbols$get === void 0 ? void 0 : _entry$symbols$get.local;
|
|
208
|
-
if (entryExports && entry === mainEntry &&
|
|
214
|
+
if (entryExports && entry === mainEntry &&
|
|
215
|
+
// @ts-expect-error TS2345
|
|
216
|
+
this.exportedSymbols.has(entryExports)) {
|
|
209
217
|
(0, _assert().default)(!needsBundleQueue, 'Entry exports are not yet compaitble with async bundles');
|
|
218
|
+
// @ts-expect-error TS2731
|
|
210
219
|
res += `\nvar ${entryExports} = ${parcelRequire}`;
|
|
211
220
|
} else {
|
|
212
221
|
if (needsBundleQueue) {
|
|
@@ -238,6 +247,7 @@ class ScopeHoistingPackager {
|
|
|
238
247
|
}
|
|
239
248
|
res += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, code, map, this.parcelRequireName);
|
|
240
249
|
if (sourceMap && map) {
|
|
250
|
+
// @ts-expect-error TS2339
|
|
241
251
|
sourceMap.addSourceMap(map, lineCount);
|
|
242
252
|
}
|
|
243
253
|
}
|
|
@@ -342,6 +352,8 @@ class ScopeHoistingPackager {
|
|
|
342
352
|
}, wrappedAssetRoot);
|
|
343
353
|
}
|
|
344
354
|
}
|
|
355
|
+
|
|
356
|
+
// @ts-expect-error TS2769
|
|
345
357
|
this.assetOutputs = new Map(await queue.run());
|
|
346
358
|
return {
|
|
347
359
|
wrapped,
|
|
@@ -366,6 +378,7 @@ class ScopeHoistingPackager {
|
|
|
366
378
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
367
379
|
let entry = this.bundle.getMainEntry();
|
|
368
380
|
if (entry && !this.wrappedAssets.has(entry.id)) {
|
|
381
|
+
// @ts-expect-error TS2345
|
|
369
382
|
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
370
383
|
for (let {
|
|
371
384
|
asset,
|
|
@@ -381,11 +394,14 @@ class ScopeHoistingPackager {
|
|
|
381
394
|
if (hasNamespace && this.isAsyncBundle && exportAs !== '*') {
|
|
382
395
|
continue;
|
|
383
396
|
}
|
|
384
|
-
let symbols = (_this$exportedSymbols = this.exportedSymbols.get(
|
|
397
|
+
let symbols = (_this$exportedSymbols = this.exportedSymbols.get(
|
|
398
|
+
// @ts-expect-error TS2345
|
|
399
|
+
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;
|
|
385
400
|
if (!symbols) {
|
|
386
401
|
symbols = [];
|
|
387
402
|
this.exportedSymbols.set(symbol, {
|
|
388
403
|
asset,
|
|
404
|
+
// @ts-expect-error TS2322
|
|
389
405
|
exportSymbol,
|
|
390
406
|
local: symbol,
|
|
391
407
|
exportAs: symbols
|
|
@@ -394,6 +410,8 @@ class ScopeHoistingPackager {
|
|
|
394
410
|
if (exportAs === '*') {
|
|
395
411
|
exportAs = 'default';
|
|
396
412
|
}
|
|
413
|
+
|
|
414
|
+
// @ts-expect-error TS2345
|
|
397
415
|
symbols.push(exportAs);
|
|
398
416
|
} else if (symbol === null) {
|
|
399
417
|
// TODO `meta.exportsIdentifier[exportSymbol]` should be exported
|
|
@@ -470,6 +488,7 @@ class ScopeHoistingPackager {
|
|
|
470
488
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
471
489
|
depCode += code + '\n';
|
|
472
490
|
if (sourceMap && map) {
|
|
491
|
+
// @ts-expect-error TS2551
|
|
473
492
|
sourceMap.addSourceMap(map, lineCount);
|
|
474
493
|
}
|
|
475
494
|
lineCount += lines + 1;
|
|
@@ -495,6 +514,7 @@ class ScopeHoistingPackager {
|
|
|
495
514
|
}
|
|
496
515
|
code += append;
|
|
497
516
|
let lineCount = 0;
|
|
517
|
+
// @ts-expect-error TS2552
|
|
498
518
|
let depContent = [];
|
|
499
519
|
if (depMap.size === 0 && replacements.size === 0) {
|
|
500
520
|
// If there are no dependencies or replacements, use a simple function to count the number of lines.
|
|
@@ -576,6 +596,7 @@ class ScopeHoistingPackager {
|
|
|
576
596
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
577
597
|
}
|
|
578
598
|
if (map) {
|
|
599
|
+
// @ts-expect-error TS2551
|
|
579
600
|
sourceMap.addSourceMap(map, lineCount);
|
|
580
601
|
}
|
|
581
602
|
}
|
|
@@ -620,6 +641,7 @@ ${code}
|
|
|
620
641
|
if (!depCode) continue;
|
|
621
642
|
code += depCode + '\n';
|
|
622
643
|
if (sourceMap && map) {
|
|
644
|
+
// @ts-expect-error TS2551
|
|
623
645
|
sourceMap.addSourceMap(map, lineCount);
|
|
624
646
|
}
|
|
625
647
|
lineCount += lines + 1;
|
|
@@ -666,9 +688,12 @@ ${code}
|
|
|
666
688
|
for (let [imported, {
|
|
667
689
|
local
|
|
668
690
|
}] of dep.symbols) {
|
|
691
|
+
// @ts-expect-error TS2367
|
|
669
692
|
if (local === '*') {
|
|
670
693
|
continue;
|
|
671
694
|
}
|
|
695
|
+
|
|
696
|
+
// @ts-expect-error TS2345
|
|
672
697
|
let symbol = this.getSymbolResolution(asset, resolved, imported, dep);
|
|
673
698
|
replacements.set(local,
|
|
674
699
|
// If this was an internalized async asset, wrap in a Promise.resolve.
|
|
@@ -690,6 +715,7 @@ ${code}
|
|
|
690
715
|
// which will be provided to us by the wrapper.
|
|
691
716
|
if (this.wrappedAssets.has(asset.id) || this.bundle.env.outputFormat === 'commonjs' && asset === this.bundle.getMainEntry()) {
|
|
692
717
|
var _asset$symbols$get;
|
|
718
|
+
// @ts-expect-error TS2345
|
|
693
719
|
let exportsName = ((_asset$symbols$get = asset.symbols.get('*')) === null || _asset$symbols$get === void 0 ? void 0 : _asset$symbols$get.local) || `$${assetId}$exports`;
|
|
694
720
|
replacements.set(exportsName, 'module.exports');
|
|
695
721
|
}
|
|
@@ -722,8 +748,11 @@ ${code}
|
|
|
722
748
|
local
|
|
723
749
|
}] of dep.symbols) {
|
|
724
750
|
// If already imported, just add the already renamed variable to the mapping.
|
|
751
|
+
// @ts-expect-error TS2345
|
|
725
752
|
let renamed = external.get(imported);
|
|
753
|
+
// @ts-expect-error TS2367
|
|
726
754
|
if (renamed && local !== '*' && replacements) {
|
|
755
|
+
// @ts-expect-error TS2345
|
|
727
756
|
replacements.set(local, renamed);
|
|
728
757
|
continue;
|
|
729
758
|
}
|
|
@@ -736,16 +765,25 @@ ${code}
|
|
|
736
765
|
if (referencedBundle) {
|
|
737
766
|
var _entry$symbols$get3;
|
|
738
767
|
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
739
|
-
|
|
768
|
+
// @ts-expect-error TS2322
|
|
769
|
+
renamed =
|
|
770
|
+
// @ts-expect-error TS2345
|
|
771
|
+
((_entry$symbols$get3 = entry.symbols.get('*')) === null || _entry$symbols$get3 === void 0 ? void 0 : _entry$symbols$get3.local) ?? `$${String(entry.meta.id)}$exports`;
|
|
740
772
|
} else {
|
|
741
773
|
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${specifier}`);
|
|
742
774
|
}
|
|
775
|
+
|
|
776
|
+
// @ts-expect-error TS2345
|
|
743
777
|
external.set('*', renamed);
|
|
744
778
|
}
|
|
779
|
+
|
|
780
|
+
// @ts-expect-error TS2367
|
|
745
781
|
if (local !== '*' && replacements) {
|
|
746
782
|
let replacement;
|
|
783
|
+
// @ts-expect-error TS2367
|
|
747
784
|
if (imported === '*') {
|
|
748
785
|
replacement = renamed;
|
|
786
|
+
// @ts-expect-error TS2367
|
|
749
787
|
} else if (imported === 'default') {
|
|
750
788
|
let needsDefaultInterop = true;
|
|
751
789
|
if (referencedBundle) {
|
|
@@ -759,32 +797,41 @@ ${code}
|
|
|
759
797
|
replacement = `${renamed}.default`;
|
|
760
798
|
}
|
|
761
799
|
} else {
|
|
800
|
+
// @ts-expect-error TS2345
|
|
762
801
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
763
802
|
}
|
|
803
|
+
|
|
804
|
+
// @ts-expect-error TS2345
|
|
764
805
|
replacements.set(local, replacement);
|
|
765
806
|
}
|
|
766
807
|
} else {
|
|
767
808
|
let property;
|
|
768
809
|
if (referencedBundle) {
|
|
769
810
|
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
811
|
+
// @ts-expect-error TS2345
|
|
770
812
|
if (entry.symbols.hasExportSymbol('*')) {
|
|
771
813
|
// If importing * and the referenced module has a * export (e.g. CJS), use default instead.
|
|
772
814
|
// This mirrors the logic in buildExportedSymbols.
|
|
773
815
|
property = imported;
|
|
816
|
+
// @ts-expect-error TS2322
|
|
774
817
|
imported = (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.env.outputFormat) === 'esmodule' ? 'default' : '*';
|
|
775
818
|
} else {
|
|
819
|
+
// @ts-expect-error TS2367
|
|
776
820
|
if (imported === '*') {
|
|
777
821
|
let exportedSymbols = this.bundleGraph.getExportedSymbols(entry);
|
|
822
|
+
// @ts-expect-error TS2367
|
|
778
823
|
if (local === '*') {
|
|
779
824
|
// Re-export all symbols.
|
|
780
825
|
for (let exported of exportedSymbols) {
|
|
781
826
|
if (exported.symbol) {
|
|
827
|
+
// @ts-expect-error TS2345
|
|
782
828
|
external.set(exported.exportSymbol, exported.symbol);
|
|
783
829
|
}
|
|
784
830
|
}
|
|
785
831
|
continue;
|
|
786
832
|
}
|
|
787
833
|
}
|
|
834
|
+
// @ts-expect-error TS2322
|
|
788
835
|
renamed = this.bundleGraph.getSymbolResolution(entry, imported, this.bundle).symbol;
|
|
789
836
|
}
|
|
790
837
|
}
|
|
@@ -793,25 +840,37 @@ ${code}
|
|
|
793
840
|
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
794
841
|
// local variables do not shadow it.
|
|
795
842
|
if (!renamed) {
|
|
843
|
+
// @ts-expect-error TS2345
|
|
796
844
|
if (this.exportedSymbols.has(local)) {
|
|
845
|
+
// @ts-expect-error TS2322
|
|
797
846
|
renamed = local;
|
|
847
|
+
// @ts-expect-error TS2367
|
|
798
848
|
} else if (imported === 'default' || imported === '*') {
|
|
799
849
|
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${specifier}`);
|
|
800
850
|
} else {
|
|
801
|
-
renamed = this.getTopLevelName(
|
|
851
|
+
renamed = this.getTopLevelName(
|
|
852
|
+
// @ts-expect-error TS2731
|
|
853
|
+
`$${this.bundle.publicId}$${imported}`);
|
|
802
854
|
}
|
|
803
855
|
}
|
|
856
|
+
|
|
857
|
+
// @ts-expect-error TS2345
|
|
804
858
|
external.set(imported, renamed);
|
|
859
|
+
// @ts-expect-error TS2367
|
|
805
860
|
if (local !== '*' && replacements) {
|
|
806
861
|
let replacement = renamed;
|
|
862
|
+
// @ts-expect-error TS2367
|
|
807
863
|
if (property === '*') {
|
|
808
864
|
replacement = renamed;
|
|
865
|
+
// @ts-expect-error TS2367
|
|
809
866
|
} else if (property === 'default') {
|
|
810
867
|
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
811
868
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
812
869
|
} else if (property) {
|
|
870
|
+
// @ts-expect-error TS2345
|
|
813
871
|
replacement = this.getPropertyAccess(renamed, property);
|
|
814
872
|
}
|
|
873
|
+
// @ts-expect-error TS2345
|
|
815
874
|
replacements.set(local, replacement);
|
|
816
875
|
}
|
|
817
876
|
}
|
|
@@ -833,6 +892,7 @@ ${code}
|
|
|
833
892
|
asset: resolvedAsset,
|
|
834
893
|
exportSymbol,
|
|
835
894
|
symbol
|
|
895
|
+
// @ts-expect-error TS2345
|
|
836
896
|
} = this.bundleGraph.getSymbolResolution(resolved, imported, this.bundle);
|
|
837
897
|
if (resolvedAsset.type !== 'js' || dep && this.bundleGraph.isDependencySkipped(dep)) {
|
|
838
898
|
// Graceful fallback for non-js imports or when trying to resolve a symbol
|
|
@@ -866,7 +926,13 @@ ${code}
|
|
|
866
926
|
|
|
867
927
|
// If this is an ESM default import of a CJS module with a `default` symbol,
|
|
868
928
|
// and no __esModule flag, we need to resolve to the namespace instead.
|
|
869
|
-
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && ((dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' || (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Export') &&
|
|
929
|
+
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && ((dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' || (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Export') &&
|
|
930
|
+
// @ts-expect-error TS2345
|
|
931
|
+
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
932
|
+
// @ts-expect-error TS2345
|
|
933
|
+
resolvedAsset.symbols.hasExportSymbol('default') &&
|
|
934
|
+
// @ts-expect-error TS2345
|
|
935
|
+
!resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
870
936
|
|
|
871
937
|
// Find the namespace object for the resolved module. If wrapped and this
|
|
872
938
|
// is an inline require (not top-level), use a parcelRequire call, otherwise
|
|
@@ -882,7 +948,9 @@ ${code}
|
|
|
882
948
|
obj = `$${publicId}`;
|
|
883
949
|
} else {
|
|
884
950
|
var _resolvedAsset$symbol;
|
|
951
|
+
// @ts-expect-error TS2345
|
|
885
952
|
obj = ((_resolvedAsset$symbol = resolvedAsset.symbols.get('*')) === null || _resolvedAsset$symbol === void 0 ? void 0 : _resolvedAsset$symbol.local) || `$${assetId}$exports`;
|
|
953
|
+
// @ts-expect-error TS2345
|
|
886
954
|
obj = (replacements === null || replacements === void 0 ? void 0 : replacements.get(obj)) || obj;
|
|
887
955
|
}
|
|
888
956
|
if (imported === '*' || exportSymbol === '*' || isDefaultInterop) {
|
|
@@ -891,6 +959,7 @@ ${code}
|
|
|
891
959
|
// Directly use module.exports for wrapped assets importing themselves.
|
|
892
960
|
return 'module.exports';
|
|
893
961
|
} else {
|
|
962
|
+
// @ts-expect-error TS2322
|
|
894
963
|
return obj;
|
|
895
964
|
}
|
|
896
965
|
} else if ((!staticExports || isWrapped || !symbol || isExternalCommonJS) && resolvedAsset !== parentAsset) {
|
|
@@ -899,15 +968,20 @@ ${code}
|
|
|
899
968
|
// than a direct reference. If importing default from a CJS module,
|
|
900
969
|
// use a helper to check the __esModule flag at runtime.
|
|
901
970
|
let kind = dep === null || dep === void 0 ? void 0 : dep.meta.kind;
|
|
902
|
-
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' &&
|
|
971
|
+
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' &&
|
|
972
|
+
// @ts-expect-error TS2345
|
|
973
|
+
resolvedAsset.symbols.hasExportSymbol('*') && this.needsDefaultInterop(resolvedAsset)) {
|
|
903
974
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
975
|
+
// @ts-expect-error TS2731
|
|
904
976
|
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
905
977
|
} else {
|
|
978
|
+
// @ts-expect-error TS2345
|
|
906
979
|
return this.getPropertyAccess(obj, exportSymbol);
|
|
907
980
|
}
|
|
908
981
|
} else if (!symbol) {
|
|
909
982
|
(0, _assert().default)(false, 'Asset was skipped or not found.');
|
|
910
983
|
} else {
|
|
984
|
+
// @ts-expect-error TS2322
|
|
911
985
|
return (replacements === null || replacements === void 0 ? void 0 : replacements.get(symbol)) || symbol;
|
|
912
986
|
}
|
|
913
987
|
}
|
|
@@ -947,20 +1021,32 @@ ${code}
|
|
|
947
1021
|
// If the asset has a namespace export symbol, it is CommonJS.
|
|
948
1022
|
// If there's no __esModule flag, and default is a used symbol, we need
|
|
949
1023
|
// to insert an interop helper.
|
|
950
|
-
let defaultInterop =
|
|
1024
|
+
let defaultInterop =
|
|
1025
|
+
// @ts-expect-error TS2345
|
|
1026
|
+
asset.symbols.hasExportSymbol('*') &&
|
|
1027
|
+
// @ts-expect-error TS2345
|
|
1028
|
+
usedSymbols.has('default') &&
|
|
1029
|
+
// @ts-expect-error TS2345
|
|
1030
|
+
!asset.symbols.hasExportSymbol('__esModule');
|
|
951
1031
|
let usedNamespace;
|
|
952
1032
|
if ((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') && asset.meta.isConstantModule) {
|
|
953
1033
|
// Only set usedNamespace if there is an incoming dependency in the current bundle that uses '*'
|
|
954
|
-
usedNamespace = this.bundleGraph.getIncomingDependencies(asset).some(dep => this.bundle.hasDependency(dep) &&
|
|
1034
|
+
usedNamespace = this.bundleGraph.getIncomingDependencies(asset).some(dep => this.bundle.hasDependency(dep) &&
|
|
1035
|
+
// @ts-expect-error TS2345
|
|
1036
|
+
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'));
|
|
955
1037
|
} else {
|
|
956
1038
|
usedNamespace =
|
|
957
1039
|
// If the asset has * in its used symbols, we might need the exports namespace.
|
|
958
1040
|
// The one case where this isn't true is in ESM library entries, where the only
|
|
959
1041
|
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
960
1042
|
// instead of the namespace object.
|
|
961
|
-
|
|
1043
|
+
// @ts-expect-error TS2345
|
|
1044
|
+
usedSymbols.has('*') && (this.bundle.env.outputFormat !== 'esmodule' || !this.bundle.env.isLibrary || asset !== this.bundle.getMainEntry() || this.bundleGraph.getIncomingDependencies(asset).some(dep => !dep.isEntry && this.bundle.hasDependency(dep) &&
|
|
1045
|
+
// @ts-expect-error TS2345
|
|
1046
|
+
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'))) ||
|
|
962
1047
|
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
963
1048
|
// we fallback on the namespace object.
|
|
1049
|
+
// @ts-expect-error TS2345
|
|
964
1050
|
asset.symbols.hasExportSymbol('*') && [...usedSymbols].some(s => !asset.symbols.hasExportSymbol(s)) ||
|
|
965
1051
|
// If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
966
1052
|
// include the namespace object for the default export.
|
|
@@ -985,6 +1071,7 @@ ${code}
|
|
|
985
1071
|
// Insert the __esModule interop flag for this module if it has a `default` export
|
|
986
1072
|
// and the namespace symbol is used.
|
|
987
1073
|
// TODO: only if required by CJS?
|
|
1074
|
+
// @ts-expect-error TS2345
|
|
988
1075
|
if (asset.symbols.hasExportSymbol('default') && usedSymbols.has('*')) {
|
|
989
1076
|
prepend += `\n$parcel$defineInteropFlag($${assetId}$exports);\n`;
|
|
990
1077
|
prependLineCount += 2;
|
|
@@ -1003,6 +1090,7 @@ ${code}
|
|
|
1003
1090
|
for (let [imported, {
|
|
1004
1091
|
local
|
|
1005
1092
|
}] of dep.symbols) {
|
|
1093
|
+
// @ts-expect-error TS2367
|
|
1006
1094
|
if (imported === '*' && local === '*') {
|
|
1007
1095
|
if (!resolved) {
|
|
1008
1096
|
// Re-exporting an external module. This should have already been handled in buildReplacements.
|
|
@@ -1015,20 +1103,29 @@ ${code}
|
|
|
1015
1103
|
// If the resolved asset has an exports object, use the $parcel$exportWildcard helper
|
|
1016
1104
|
// to re-export all symbols. Otherwise, if there's no namespace object available, add
|
|
1017
1105
|
// $parcel$export calls for each used symbol of the dependency.
|
|
1018
|
-
if (isWrapped || resolved.meta.staticExports === false ||
|
|
1106
|
+
if (isWrapped || resolved.meta.staticExports === false ||
|
|
1107
|
+
// @ts-expect-error TS2345
|
|
1108
|
+
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
1019
1109
|
// an empty asset
|
|
1020
|
-
!resolved.meta.hasCJSExports &&
|
|
1110
|
+
!resolved.meta.hasCJSExports &&
|
|
1111
|
+
// @ts-expect-error TS2345
|
|
1112
|
+
resolved.symbols.hasExportSymbol('*')) {
|
|
1021
1113
|
let obj = this.getSymbolResolution(asset, resolved, '*', dep, replacements);
|
|
1022
1114
|
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
1023
1115
|
this.usedHelpers.add('$parcel$exportWildcard');
|
|
1024
1116
|
} else {
|
|
1025
1117
|
for (let symbol of (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep))) {
|
|
1026
|
-
if (
|
|
1118
|
+
if (
|
|
1119
|
+
// @ts-expect-error TS2367
|
|
1120
|
+
symbol === 'default' ||
|
|
1027
1121
|
// `export * as ...` does not include the default export
|
|
1122
|
+
// @ts-expect-error TS2367
|
|
1028
1123
|
symbol === '__esModule') {
|
|
1029
1124
|
continue;
|
|
1030
1125
|
}
|
|
1031
|
-
let resolvedSymbol = this.getSymbolResolution(asset, resolved,
|
|
1126
|
+
let resolvedSymbol = this.getSymbolResolution(asset, resolved,
|
|
1127
|
+
// @ts-expect-error TS2345
|
|
1128
|
+
symbol, undefined, replacements);
|
|
1032
1129
|
let get = this.buildFunctionExpression([], resolvedSymbol);
|
|
1033
1130
|
let set = asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolvedSymbol} = v`) : '';
|
|
1034
1131
|
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(symbol)}, ${get}${set});\n`;
|
|
@@ -1045,6 +1142,7 @@ ${code}
|
|
|
1045
1142
|
// re-exported symbols rather than only symbols declared in this asset.
|
|
1046
1143
|
let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
|
|
1047
1144
|
let usedExports = [...asset.symbols.exportSymbols()].filter(symbol => {
|
|
1145
|
+
// @ts-expect-error TS2367
|
|
1048
1146
|
if (symbol === '*') {
|
|
1049
1147
|
return false;
|
|
1050
1148
|
}
|
|
@@ -1059,6 +1157,8 @@ ${code}
|
|
|
1059
1157
|
|
|
1060
1158
|
// No used symbols available for the asset, make sure we keep all of them
|
|
1061
1159
|
if (!symbols) return false;
|
|
1160
|
+
|
|
1161
|
+
// @ts-expect-error TS2345
|
|
1062
1162
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
1063
1163
|
});
|
|
1064
1164
|
return !unused;
|
|
@@ -1070,7 +1170,9 @@ ${code}
|
|
|
1070
1170
|
// additional assignments after each mutation of the original binding.
|
|
1071
1171
|
prepend += `\n${usedExports.map(exp => {
|
|
1072
1172
|
var _asset$symbols$get2;
|
|
1073
|
-
let resolved = this.getSymbolResolution(asset, asset,
|
|
1173
|
+
let resolved = this.getSymbolResolution(asset, asset,
|
|
1174
|
+
// @ts-expect-error TS2345
|
|
1175
|
+
exp, undefined, replacements);
|
|
1074
1176
|
let get = this.buildFunctionExpression([], resolved);
|
|
1075
1177
|
let isEsmExport = !!((_asset$symbols$get2 = asset.symbols.get(exp)) !== null && _asset$symbols$get2 !== void 0 && (_asset$symbols$get2 = _asset$symbols$get2.meta) !== null && _asset$symbols$get2 !== void 0 && _asset$symbols$get2.isEsm);
|
|
1076
1178
|
let set = !isEsmExport && asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`) : '';
|
|
@@ -1108,8 +1210,10 @@ ${code}
|
|
|
1108
1210
|
this.usedHelpers.add('$parcel$global');
|
|
1109
1211
|
}
|
|
1110
1212
|
for (let helper of this.usedHelpers) {
|
|
1213
|
+
// @ts-expect-error TS7053
|
|
1111
1214
|
let currentHelper = _helpers.helpers[helper];
|
|
1112
1215
|
if (typeof currentHelper === 'function') {
|
|
1216
|
+
// @ts-expect-error TS7053
|
|
1113
1217
|
currentHelper = _helpers.helpers[helper](this.bundle.env);
|
|
1114
1218
|
}
|
|
1115
1219
|
res += currentHelper;
|
|
@@ -1165,7 +1269,11 @@ ${code}
|
|
|
1165
1269
|
return [res, lines];
|
|
1166
1270
|
}
|
|
1167
1271
|
needsDefaultInterop(asset) {
|
|
1168
|
-
if (
|
|
1272
|
+
if (
|
|
1273
|
+
// @ts-expect-error TS2345
|
|
1274
|
+
asset.symbols.hasExportSymbol('*') &&
|
|
1275
|
+
// @ts-expect-error TS2345
|
|
1276
|
+
!asset.symbols.hasExportSymbol('default')) {
|
|
1169
1277
|
return true;
|
|
1170
1278
|
}
|
|
1171
1279
|
return false;
|
package/lib/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
|
package/lib/helpers.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Environment } from '@atlaspack/types';
|
|
2
|
+
export declare const prelude: (parcelRequireName: string) => string;
|
|
3
|
+
export declare const fnExpr: (env: Environment, params: Array<string>, body: Array<string>) => string;
|
|
4
|
+
export declare const bundleQueuePrelude: (env: Environment) => string;
|
|
5
|
+
export declare const helpers: {
|
|
6
|
+
readonly $parcel$export: "\nfunction $parcel$export(e, n, v, s) {\n Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});\n}\n";
|
|
7
|
+
readonly $parcel$exportWildcard: "\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n }\n });\n });\n\n return dest;\n}\n";
|
|
8
|
+
readonly $parcel$interopDefault: "\nfunction $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n";
|
|
9
|
+
readonly $parcel$global: (env: Environment) => string;
|
|
10
|
+
readonly $parcel$defineInteropFlag: "\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true, configurable: true});\n}\n";
|
|
11
|
+
};
|
package/lib/index.d.ts
ADDED
package/lib/index.js
CHANGED
|
@@ -77,8 +77,10 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
77
77
|
});
|
|
78
78
|
let name = (packageName === null || packageName === void 0 ? void 0 : packageName.contents) ?? '';
|
|
79
79
|
return {
|
|
80
|
+
// @ts-expect-error TS2345
|
|
80
81
|
parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
|
|
81
|
-
unstable_asyncBundleRuntime: Boolean(
|
|
82
|
+
unstable_asyncBundleRuntime: Boolean( // @ts-expect-error TS2339
|
|
83
|
+
conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime)
|
|
82
84
|
};
|
|
83
85
|
},
|
|
84
86
|
async package({
|
|
@@ -101,15 +103,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
if (contents == null) {
|
|
104
|
-
let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle,
|
|
105
|
-
// $FlowFixMe
|
|
106
|
-
// $FlowFixMe
|
|
107
|
-
(0, _nullthrows().default)(config).parcelRequireName,
|
|
108
|
-
// $FlowFixMe
|
|
109
|
-
(0, _nullthrows().default)(config).unstable_asyncBundleRuntime, logger) : new _DevPackager.DevPackager(options, bundleGraph, bundle,
|
|
110
|
-
// $FlowFixMe
|
|
111
|
-
// $FlowFixMe
|
|
112
|
-
(0, _nullthrows().default)(config).parcelRequireName);
|
|
106
|
+
let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName, (0, _nullthrows().default)(config).unstable_asyncBundleRuntime, logger) : new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
|
|
113
107
|
({
|
|
114
108
|
contents,
|
|
115
109
|
map
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BundleGraph, Dependency, NamedBundle } from '@atlaspack/types';
|
|
2
|
+
import type SourceMap from '@parcel/source-map';
|
|
3
|
+
export declare function replaceScriptDependencies(bundleGraph: BundleGraph<NamedBundle>, bundle: NamedBundle, code: string, map: SourceMap | null | undefined, parcelRequireName: string): string;
|
|
4
|
+
export declare function getSpecifier(dep: Dependency): string;
|
|
5
|
+
export declare function isValidIdentifier(id: string): boolean;
|
|
6
|
+
export declare function makeValidIdentifier(name: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.19.0",
|
|
3
|
+
"version": "2.19.1-typescript-5ad950d33.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -9,22 +9,27 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
11
|
},
|
|
12
|
-
"main": "lib/index.js",
|
|
13
|
-
"source": "src/index.
|
|
12
|
+
"main": "./lib/index.js",
|
|
13
|
+
"source": "./src/index.ts",
|
|
14
|
+
"types": "./lib/index.d.ts",
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">= 16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@atlaspack/diagnostic": "2.14.
|
|
19
|
-
"@atlaspack/feature-flags": "2.20.0",
|
|
20
|
-
"@atlaspack/plugin": "2.14.
|
|
21
|
-
"@atlaspack/rust": "3.4.
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.2-typescript-5ad950d33.0",
|
|
20
|
+
"@atlaspack/feature-flags": "2.20.1-typescript-5ad950d33.0",
|
|
21
|
+
"@atlaspack/plugin": "2.14.22-typescript-5ad950d33.0",
|
|
22
|
+
"@atlaspack/rust": "3.4.2-typescript-5ad950d33.0",
|
|
23
|
+
"@atlaspack/types": "2.15.12-typescript-5ad950d33.0",
|
|
24
|
+
"@atlaspack/utils": "2.17.4-typescript-5ad950d33.0",
|
|
22
25
|
"@parcel/source-map": "^2.1.1",
|
|
23
|
-
"@atlaspack/types": "2.15.11",
|
|
24
|
-
"@atlaspack/utils": "2.17.3",
|
|
25
26
|
"globals": "^13.2.0",
|
|
26
27
|
"nullthrows": "^1.1.1",
|
|
27
28
|
"outdent": "^0.8.0"
|
|
28
29
|
},
|
|
29
|
-
"type": "commonjs"
|
|
30
|
-
|
|
30
|
+
"type": "commonjs",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "5ad950d33a5f2255ebeb10c04a2e84c346e2de85"
|
|
35
|
+
}
|