@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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {BundleGraph, PluginOptions, NamedBundle} from '@atlaspack/types';
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -37,7 +36,10 @@ export class DevPackager {
|
|
|
37
36
|
this.parcelRequireName = parcelRequireName;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
async package(): Promise<{
|
|
39
|
+
async package(): Promise<{
|
|
40
|
+
contents: string;
|
|
41
|
+
map: SourceMap | null | undefined;
|
|
42
|
+
}> {
|
|
41
43
|
// Load assets
|
|
42
44
|
let queue = new PromiseQueue({maxConcurrent: 32});
|
|
43
45
|
this.bundle.traverseAssets((asset) => {
|
|
@@ -59,7 +61,13 @@ export class DevPackager {
|
|
|
59
61
|
|
|
60
62
|
let prefix = this.getPrefix();
|
|
61
63
|
let lineOffset = countLines(prefix);
|
|
62
|
-
let script:
|
|
64
|
+
let script:
|
|
65
|
+
| {
|
|
66
|
+
code: string;
|
|
67
|
+
mapBuffer: Buffer | null | undefined;
|
|
68
|
+
}
|
|
69
|
+
| null
|
|
70
|
+
| undefined = null;
|
|
63
71
|
|
|
64
72
|
this.bundle.traverse((node) => {
|
|
65
73
|
let wrapped = first ? '' : ',';
|
|
@@ -94,11 +102,12 @@ export class DevPackager {
|
|
|
94
102
|
this.bundle.env.sourceType === 'script' &&
|
|
95
103
|
asset === this.bundle.getMainEntry()
|
|
96
104
|
) {
|
|
105
|
+
// @ts-expect-error TS2322
|
|
97
106
|
script = results[i++];
|
|
98
107
|
return;
|
|
99
108
|
}
|
|
100
109
|
|
|
101
|
-
let deps = {};
|
|
110
|
+
let deps: Record<string, any> = {};
|
|
102
111
|
let dependencies = this.bundleGraph.getDependencies(asset);
|
|
103
112
|
for (let dep of dependencies) {
|
|
104
113
|
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
@@ -125,6 +134,7 @@ export class DevPackager {
|
|
|
125
134
|
}
|
|
126
135
|
}
|
|
127
136
|
|
|
137
|
+
// @ts-expect-error TS2339
|
|
128
138
|
let {code, mapBuffer} = results[i];
|
|
129
139
|
let output = code || '';
|
|
130
140
|
wrapped +=
|
|
@@ -205,6 +215,7 @@ export class DevPackager {
|
|
|
205
215
|
// runtimes with a parcelRequire call.
|
|
206
216
|
if (this.bundle.env.sourceType === 'script' && script) {
|
|
207
217
|
let entryMap;
|
|
218
|
+
// @ts-expect-error TS2339
|
|
208
219
|
let mapBuffer = script.mapBuffer;
|
|
209
220
|
if (mapBuffer) {
|
|
210
221
|
entryMap = new SourceMap(this.options.projectRoot, mapBuffer);
|
|
@@ -212,11 +223,13 @@ export class DevPackager {
|
|
|
212
223
|
contents += replaceScriptDependencies(
|
|
213
224
|
this.bundleGraph,
|
|
214
225
|
this.bundle,
|
|
226
|
+
// @ts-expect-error TS2339
|
|
215
227
|
script.code,
|
|
216
228
|
entryMap,
|
|
217
229
|
this.parcelRequireName,
|
|
218
230
|
);
|
|
219
231
|
if (this.bundle.env.sourceMap && entryMap) {
|
|
232
|
+
// @ts-expect-error TS2551
|
|
220
233
|
map.addSourceMap(entryMap, lineOffset);
|
|
221
234
|
}
|
|
222
235
|
}
|
|
@@ -228,7 +241,7 @@ export class DevPackager {
|
|
|
228
241
|
}
|
|
229
242
|
|
|
230
243
|
getPrefix(): string {
|
|
231
|
-
let interpreter:
|
|
244
|
+
let interpreter: string | null | undefined;
|
|
232
245
|
let mainEntry = this.bundle.getMainEntry();
|
|
233
246
|
if (mainEntry && this.isEntry() && !this.bundle.target.env.isBrowser()) {
|
|
234
247
|
let _interpreter = mainEntry.meta.interpreter;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {
|
|
3
2
|
ScopeHoistingPackager,
|
|
4
3
|
OutputFormat,
|
|
@@ -18,7 +17,7 @@ export class ESMOutputFormat implements OutputFormat {
|
|
|
18
17
|
for (let [source, specifiers] of this.packager.externals) {
|
|
19
18
|
let defaultSpecifier = null;
|
|
20
19
|
let namespaceSpecifier = null;
|
|
21
|
-
let namedSpecifiers = [];
|
|
20
|
+
let namedSpecifiers: Array<string> = [];
|
|
22
21
|
for (let [imported, symbol] of specifiers) {
|
|
23
22
|
if (imported === 'default' /* || isCommonJS*/) {
|
|
24
23
|
defaultSpecifier = symbol;
|
|
@@ -77,7 +76,7 @@ export class ESMOutputFormat implements OutputFormat {
|
|
|
77
76
|
buildBundlePostlude(): [string, number] {
|
|
78
77
|
let res = '';
|
|
79
78
|
let lines = 0;
|
|
80
|
-
let exportSpecifiers = [];
|
|
79
|
+
let exportSpecifiers: Array<string> = [];
|
|
81
80
|
for (let {
|
|
82
81
|
asset,
|
|
83
82
|
exportSymbol,
|