@atlaspack/packager-js 2.14.5-canary.138 → 2.14.5-canary.139
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/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 +15 -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
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.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.139+d2fd84977",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -9,23 +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.1-canary.
|
|
19
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
20
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
21
|
-
"@atlaspack/rust": "3.2.1-canary.
|
|
22
|
-
"@atlaspack/types": "2.14.5-canary.
|
|
23
|
-
"@atlaspack/utils": "2.14.5-canary.
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.1-canary.207+d2fd84977",
|
|
20
|
+
"@atlaspack/feature-flags": "2.14.1-canary.207+d2fd84977",
|
|
21
|
+
"@atlaspack/plugin": "2.14.5-canary.139+d2fd84977",
|
|
22
|
+
"@atlaspack/rust": "3.2.1-canary.139+d2fd84977",
|
|
23
|
+
"@atlaspack/types": "2.14.5-canary.139+d2fd84977",
|
|
24
|
+
"@atlaspack/utils": "2.14.5-canary.139+d2fd84977",
|
|
24
25
|
"@parcel/source-map": "^2.1.1",
|
|
25
26
|
"globals": "^13.2.0",
|
|
26
27
|
"nullthrows": "^1.1.1",
|
|
27
28
|
"outdent": "^0.8.0"
|
|
28
29
|
},
|
|
29
30
|
"type": "commonjs",
|
|
30
|
-
"
|
|
31
|
-
|
|
31
|
+
"scripts": {
|
|
32
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
|
|
35
|
+
}
|
|
@@ -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,
|