@atlaspack/packager-js 2.14.5-canary.35 → 2.14.5-canary.350
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 +518 -0
- package/dist/CJSOutputFormat.js +34 -0
- package/dist/DevPackager.js +201 -0
- package/dist/ESMOutputFormat.js +102 -0
- package/dist/GlobalOutputFormat.js +18 -0
- package/dist/ScopeHoistingPackager.js +1405 -0
- package/dist/helpers.js +170 -0
- package/dist/index.js +117 -0
- package/dist/utils.js +60 -0
- package/lib/DevPackager.js +28 -4
- package/lib/ESMOutputFormat.js +1 -1
- package/lib/ScopeHoistingPackager.js +307 -112
- package/lib/dev-prelude.js +6 -6
- package/lib/helpers.js +38 -3
- package/lib/index.js +28 -9
- package/lib/types/CJSOutputFormat.d.ts +7 -0
- package/lib/types/DevPackager.d.ts +15 -0
- package/lib/types/ESMOutputFormat.d.ts +7 -0
- package/lib/types/GlobalOutputFormat.d.ts +7 -0
- package/lib/types/ScopeHoistingPackager.d.ts +73 -0
- package/lib/types/helpers.d.ts +12 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/utils.d.ts +6 -0
- package/package.json +18 -13
- package/src/{CJSOutputFormat.js → CJSOutputFormat.ts} +0 -1
- package/src/{DevPackager.js → DevPackager.ts} +34 -8
- package/src/{ESMOutputFormat.js → ESMOutputFormat.ts} +3 -4
- package/src/{GlobalOutputFormat.js → GlobalOutputFormat.ts} +0 -1
- package/src/{ScopeHoistingPackager.js → ScopeHoistingPackager.ts} +482 -185
- package/src/dev-prelude.js +6 -6
- package/src/{helpers.js → helpers.ts} +37 -3
- package/src/{index.js → index.ts} +63 -39
- package/src/{utils.js → utils.ts} +2 -3
- package/tsconfig.json +30 -0
- package/tsconfig.tsbuildinfo +1 -0
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,7 +1,6 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {Environment} from '@atlaspack/types';
|
|
3
2
|
|
|
4
|
-
export const
|
|
3
|
+
export const preludeOld = (parcelRequireName: string): string => `
|
|
5
4
|
var $parcel$modules = {};
|
|
6
5
|
var $parcel$inits = {};
|
|
7
6
|
|
|
@@ -35,6 +34,41 @@ if (parcelRequire == null) {
|
|
|
35
34
|
var parcelRegister = parcelRequire.register;
|
|
36
35
|
`;
|
|
37
36
|
|
|
37
|
+
export const preludeNew = (parcelRequireName: string): string => `
|
|
38
|
+
var $parcel$modules = {};
|
|
39
|
+
var $parcel$inits = {};
|
|
40
|
+
|
|
41
|
+
var parcelRequire = $parcel$global[${JSON.stringify(parcelRequireName)}];
|
|
42
|
+
|
|
43
|
+
if (parcelRequire == null) {
|
|
44
|
+
parcelRequire = function(id) {
|
|
45
|
+
var mod = $parcel$modules[id];
|
|
46
|
+
if (mod !== undefined) {
|
|
47
|
+
return mod.exports;
|
|
48
|
+
}
|
|
49
|
+
var init = $parcel$inits[id];
|
|
50
|
+
if (init !== undefined) {
|
|
51
|
+
delete $parcel$inits[id];
|
|
52
|
+
var module = {id: id, exports: {}};
|
|
53
|
+
$parcel$modules[id] = module;
|
|
54
|
+
init.call(module.exports, module, module.exports);
|
|
55
|
+
return module.exports;
|
|
56
|
+
}
|
|
57
|
+
var err = new Error("Cannot find module '" + id + "'");
|
|
58
|
+
err.code = 'MODULE_NOT_FOUND';
|
|
59
|
+
throw err;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
parcelRequire.register = function register(id, init) {
|
|
63
|
+
$parcel$inits[id] = init;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
$parcel$global[${JSON.stringify(parcelRequireName)}] = parcelRequire;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var parcelRegister = parcelRequire.register;
|
|
70
|
+
`;
|
|
71
|
+
|
|
38
72
|
export const fnExpr = (
|
|
39
73
|
env: Environment,
|
|
40
74
|
params: Array<string>,
|
|
@@ -166,4 +200,4 @@ export const helpers = {
|
|
|
166
200
|
$parcel$interopDefault,
|
|
167
201
|
$parcel$global,
|
|
168
202
|
$parcel$defineInteropFlag,
|
|
169
|
-
};
|
|
203
|
+
} as const;
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
import type
|
|
3
|
-
import type SourceMap from '@parcel/source-map';
|
|
1
|
+
import type {Async, BundleResult} from '@atlaspack/types';
|
|
2
|
+
import type SourceMap from '@atlaspack/source-map';
|
|
4
3
|
import {Packager} from '@atlaspack/plugin';
|
|
5
4
|
import {
|
|
6
5
|
replaceInlineReferences,
|
|
7
6
|
replaceURLReferences,
|
|
8
7
|
validateSchema,
|
|
9
|
-
|
|
8
|
+
SchemaEntity,
|
|
9
|
+
debugTools,
|
|
10
10
|
} from '@atlaspack/utils';
|
|
11
11
|
import {encodeJSONKeyComponent} from '@atlaspack/diagnostic';
|
|
12
12
|
import {hashString} from '@atlaspack/rust';
|
|
13
13
|
import nullthrows from 'nullthrows';
|
|
14
14
|
import {DevPackager} from './DevPackager';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
type PackageResult as ScopeHoistingPackageResult,
|
|
17
|
+
ScopeHoistingPackager,
|
|
18
|
+
} from './ScopeHoistingPackager';
|
|
19
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
16
20
|
|
|
17
|
-
type JSPackagerConfig = {
|
|
18
|
-
parcelRequireName: string
|
|
19
|
-
unstable_asyncBundleRuntime: boolean
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
type JSPackagerConfig = {
|
|
22
|
+
parcelRequireName: string;
|
|
23
|
+
unstable_asyncBundleRuntime: boolean;
|
|
24
|
+
unstable_manualStaticBindingExports: string[] | null;
|
|
25
|
+
};
|
|
22
26
|
|
|
23
27
|
const CONFIG_SCHEMA: SchemaEntity = {
|
|
24
28
|
type: 'object',
|
|
@@ -26,7 +30,7 @@ const CONFIG_SCHEMA: SchemaEntity = {
|
|
|
26
30
|
unstable_asyncBundleRuntime: {
|
|
27
31
|
type: 'boolean',
|
|
28
32
|
},
|
|
29
|
-
|
|
33
|
+
unstable_manualStaticBindingExports: {
|
|
30
34
|
type: 'array',
|
|
31
35
|
items: {
|
|
32
36
|
type: 'string',
|
|
@@ -36,10 +40,13 @@ const CONFIG_SCHEMA: SchemaEntity = {
|
|
|
36
40
|
additionalProperties: false,
|
|
37
41
|
};
|
|
38
42
|
|
|
39
|
-
export default
|
|
43
|
+
export default new Packager({
|
|
40
44
|
async loadConfig({config, options}): Promise<JSPackagerConfig> {
|
|
41
45
|
let packageKey = '@atlaspack/packager-js';
|
|
42
|
-
let conf = await config.getConfigFrom
|
|
46
|
+
let conf = await config.getConfigFrom<{
|
|
47
|
+
unstable_asyncBundleRuntime?: boolean;
|
|
48
|
+
unstable_manualStaticBindingExports?: string[];
|
|
49
|
+
}>(options.projectRoot + '/index', [], {
|
|
43
50
|
packageKey,
|
|
44
51
|
});
|
|
45
52
|
|
|
@@ -48,7 +55,7 @@ export default (new Packager({
|
|
|
48
55
|
CONFIG_SCHEMA,
|
|
49
56
|
{
|
|
50
57
|
data: conf?.contents,
|
|
51
|
-
source:
|
|
58
|
+
source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
|
|
52
59
|
filePath: conf.filePath,
|
|
53
60
|
prependKey: `/${encodeJSONKeyComponent(packageKey)}`,
|
|
54
61
|
},
|
|
@@ -59,7 +66,7 @@ export default (new Packager({
|
|
|
59
66
|
|
|
60
67
|
// Generate a name for the global parcelRequire function that is unique to this project.
|
|
61
68
|
// This allows multiple parcel builds to coexist on the same page.
|
|
62
|
-
let packageName = await config.getConfigFrom(
|
|
69
|
+
let packageName = await config.getConfigFrom<string>(
|
|
63
70
|
options.projectRoot + '/index',
|
|
64
71
|
[],
|
|
65
72
|
{
|
|
@@ -73,8 +80,8 @@ export default (new Packager({
|
|
|
73
80
|
unstable_asyncBundleRuntime: Boolean(
|
|
74
81
|
conf?.contents?.unstable_asyncBundleRuntime,
|
|
75
82
|
),
|
|
76
|
-
|
|
77
|
-
conf?.contents?.
|
|
83
|
+
unstable_manualStaticBindingExports:
|
|
84
|
+
conf?.contents?.unstable_manualStaticBindingExports ?? null,
|
|
78
85
|
};
|
|
79
86
|
},
|
|
80
87
|
async package({
|
|
@@ -89,6 +96,8 @@ export default (new Packager({
|
|
|
89
96
|
// If this is a non-module script, and there is only one asset with no dependencies,
|
|
90
97
|
// then we don't need to package at all and can pass through the original code un-wrapped.
|
|
91
98
|
let contents, map;
|
|
99
|
+
let scopeHoistingStats: ScopeHoistingPackageResult['scopeHoistingStats'];
|
|
100
|
+
|
|
92
101
|
if (bundle.env.sourceType === 'script') {
|
|
93
102
|
let entries = bundle.getEntryAssets();
|
|
94
103
|
if (
|
|
@@ -101,24 +110,31 @@ export default (new Packager({
|
|
|
101
110
|
}
|
|
102
111
|
|
|
103
112
|
if (contents == null) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
if (bundle.env.shouldScopeHoist) {
|
|
114
|
+
let packager = new ScopeHoistingPackager(
|
|
115
|
+
options,
|
|
116
|
+
bundleGraph,
|
|
117
|
+
bundle,
|
|
118
|
+
nullthrows(config).parcelRequireName,
|
|
119
|
+
nullthrows(config).unstable_asyncBundleRuntime,
|
|
120
|
+
nullthrows(config).unstable_manualStaticBindingExports,
|
|
121
|
+
logger,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
let packageResult = await packager.package();
|
|
125
|
+
({contents, map} = packageResult);
|
|
126
|
+
scopeHoistingStats = packageResult.scopeHoistingStats;
|
|
127
|
+
} else {
|
|
128
|
+
let packager = new DevPackager(
|
|
129
|
+
options,
|
|
130
|
+
bundleGraph,
|
|
131
|
+
bundle,
|
|
132
|
+
nullthrows(config).parcelRequireName,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
let packageResult = await packager.package();
|
|
136
|
+
({contents, map} = packageResult);
|
|
137
|
+
}
|
|
122
138
|
}
|
|
123
139
|
|
|
124
140
|
contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
|
|
@@ -135,7 +151,7 @@ export default (new Packager({
|
|
|
135
151
|
}));
|
|
136
152
|
}
|
|
137
153
|
|
|
138
|
-
|
|
154
|
+
let result = await replaceInlineReferences({
|
|
139
155
|
bundle,
|
|
140
156
|
bundleGraph,
|
|
141
157
|
contents,
|
|
@@ -146,12 +162,20 @@ export default (new Packager({
|
|
|
146
162
|
getInlineBundleContents,
|
|
147
163
|
map,
|
|
148
164
|
});
|
|
165
|
+
|
|
166
|
+
if (debugTools['scope-hoisting-stats']) {
|
|
167
|
+
return {...result, scopeHoistingStats};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return result;
|
|
149
171
|
},
|
|
150
|
-
})
|
|
172
|
+
}) as Packager<unknown, unknown>;
|
|
151
173
|
|
|
152
174
|
async function getSourceMapSuffix(
|
|
153
|
-
getSourceMapReference: (
|
|
154
|
-
|
|
175
|
+
getSourceMapReference: (
|
|
176
|
+
arg1?: SourceMap | null | undefined,
|
|
177
|
+
) => Async<string | null | undefined>,
|
|
178
|
+
map?: SourceMap | null,
|
|
155
179
|
): Promise<string> {
|
|
156
180
|
let sourcemapReference = await getSourceMapReference(map);
|
|
157
181
|
if (sourcemapReference != null) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {BundleGraph, Dependency, NamedBundle} from '@atlaspack/types';
|
|
3
|
-
import type SourceMap from '@
|
|
2
|
+
import type SourceMap from '@atlaspack/source-map';
|
|
4
3
|
import nullthrows from 'nullthrows';
|
|
5
4
|
|
|
6
5
|
// This replaces __parcel__require__ references left by the transformer with
|
|
@@ -10,7 +9,7 @@ export function replaceScriptDependencies(
|
|
|
10
9
|
bundleGraph: BundleGraph<NamedBundle>,
|
|
11
10
|
bundle: NamedBundle,
|
|
12
11
|
code: string,
|
|
13
|
-
map:
|
|
12
|
+
map: SourceMap | null | undefined,
|
|
14
13
|
parcelRequireName: string,
|
|
15
14
|
): string {
|
|
16
15
|
let entry = nullthrows(bundle.getMainEntry());
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"composite": true
|
|
6
|
+
},
|
|
7
|
+
"references": [
|
|
8
|
+
{
|
|
9
|
+
"path": "../../core/diagnostic/tsconfig.json"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "../../core/feature-flags/tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "../../core/plugin/tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../../core/rust/tsconfig.json"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "../../core/types/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../core/utils/tsconfig.json"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../../core/source-map/tsconfig.json"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|