@atlaspack/packager-js 2.14.5-canary.26 → 2.14.5-canary.262
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 +407 -0
- package/dist/CJSOutputFormat.js +34 -0
- package/dist/DevPackager.js +202 -0
- package/dist/ESMOutputFormat.js +102 -0
- package/dist/GlobalOutputFormat.js +18 -0
- package/dist/ScopeHoistingPackager.js +1369 -0
- package/dist/helpers.js +170 -0
- package/dist/index.js +120 -0
- package/dist/utils.js +60 -0
- package/lib/DevPackager.js +28 -3
- package/lib/ESMOutputFormat.js +1 -1
- package/lib/ScopeHoistingPackager.js +265 -107
- package/lib/dev-prelude.js +6 -6
- package/lib/helpers.js +38 -3
- package/lib/index.js +35 -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 +71 -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 +17 -12
- package/src/{CJSOutputFormat.js → CJSOutputFormat.ts} +0 -1
- package/src/{DevPackager.js → DevPackager.ts} +34 -7
- package/src/{ESMOutputFormat.js → ESMOutputFormat.ts} +3 -4
- package/src/{GlobalOutputFormat.js → GlobalOutputFormat.ts} +0 -1
- package/src/{ScopeHoistingPackager.js → ScopeHoistingPackager.ts} +427 -180
- package/src/dev-prelude.js +6 -6
- package/src/{helpers.js → helpers.ts} +37 -3
- package/src/{index.js → index.ts} +64 -38
- package/src/{utils.js → utils.ts} +1 -2
- package/tsconfig.json +27 -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 {Async} from '@atlaspack/types';
|
|
1
|
+
import type {Async, BundleResult} from '@atlaspack/types';
|
|
3
2
|
import type SourceMap from '@parcel/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,9 @@ export default (new Packager({
|
|
|
48
55
|
CONFIG_SCHEMA,
|
|
49
56
|
{
|
|
50
57
|
data: conf?.contents,
|
|
51
|
-
source:
|
|
58
|
+
source: getFeatureFlag('schemaValidationDeferSourceLoading')
|
|
59
|
+
? () => options.inputFS.readFileSync(conf.filePath, 'utf8')
|
|
60
|
+
: await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
52
61
|
filePath: conf.filePath,
|
|
53
62
|
prependKey: `/${encodeJSONKeyComponent(packageKey)}`,
|
|
54
63
|
},
|
|
@@ -59,7 +68,7 @@ export default (new Packager({
|
|
|
59
68
|
|
|
60
69
|
// Generate a name for the global parcelRequire function that is unique to this project.
|
|
61
70
|
// This allows multiple parcel builds to coexist on the same page.
|
|
62
|
-
let packageName = await config.getConfigFrom(
|
|
71
|
+
let packageName = await config.getConfigFrom<string>(
|
|
63
72
|
options.projectRoot + '/index',
|
|
64
73
|
[],
|
|
65
74
|
{
|
|
@@ -73,8 +82,8 @@ export default (new Packager({
|
|
|
73
82
|
unstable_asyncBundleRuntime: Boolean(
|
|
74
83
|
conf?.contents?.unstable_asyncBundleRuntime,
|
|
75
84
|
),
|
|
76
|
-
|
|
77
|
-
conf?.contents?.
|
|
85
|
+
unstable_manualStaticBindingExports:
|
|
86
|
+
conf?.contents?.unstable_manualStaticBindingExports ?? null,
|
|
78
87
|
};
|
|
79
88
|
},
|
|
80
89
|
async package({
|
|
@@ -89,6 +98,8 @@ export default (new Packager({
|
|
|
89
98
|
// If this is a non-module script, and there is only one asset with no dependencies,
|
|
90
99
|
// then we don't need to package at all and can pass through the original code un-wrapped.
|
|
91
100
|
let contents, map;
|
|
101
|
+
let scopeHoistingStats: ScopeHoistingPackageResult['scopeHoistingStats'];
|
|
102
|
+
|
|
92
103
|
if (bundle.env.sourceType === 'script') {
|
|
93
104
|
let entries = bundle.getEntryAssets();
|
|
94
105
|
if (
|
|
@@ -101,24 +112,31 @@ export default (new Packager({
|
|
|
101
112
|
}
|
|
102
113
|
|
|
103
114
|
if (contents == null) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
if (bundle.env.shouldScopeHoist) {
|
|
116
|
+
let packager = new ScopeHoistingPackager(
|
|
117
|
+
options,
|
|
118
|
+
bundleGraph,
|
|
119
|
+
bundle,
|
|
120
|
+
nullthrows(config).parcelRequireName,
|
|
121
|
+
nullthrows(config).unstable_asyncBundleRuntime,
|
|
122
|
+
nullthrows(config).unstable_manualStaticBindingExports,
|
|
123
|
+
logger,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
let packageResult = await packager.package();
|
|
127
|
+
({contents, map} = packageResult);
|
|
128
|
+
scopeHoistingStats = packageResult.scopeHoistingStats;
|
|
129
|
+
} else {
|
|
130
|
+
let packager = new DevPackager(
|
|
131
|
+
options,
|
|
132
|
+
bundleGraph,
|
|
133
|
+
bundle,
|
|
134
|
+
nullthrows(config).parcelRequireName,
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
let packageResult = await packager.package();
|
|
138
|
+
({contents, map} = packageResult);
|
|
139
|
+
}
|
|
122
140
|
}
|
|
123
141
|
|
|
124
142
|
contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
|
|
@@ -135,7 +153,7 @@ export default (new Packager({
|
|
|
135
153
|
}));
|
|
136
154
|
}
|
|
137
155
|
|
|
138
|
-
|
|
156
|
+
let result = await replaceInlineReferences({
|
|
139
157
|
bundle,
|
|
140
158
|
bundleGraph,
|
|
141
159
|
contents,
|
|
@@ -146,12 +164,20 @@ export default (new Packager({
|
|
|
146
164
|
getInlineBundleContents,
|
|
147
165
|
map,
|
|
148
166
|
});
|
|
167
|
+
|
|
168
|
+
if (debugTools['scope-hoisting-stats']) {
|
|
169
|
+
return {...result, scopeHoistingStats};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return result;
|
|
149
173
|
},
|
|
150
|
-
})
|
|
174
|
+
}) as Packager<unknown, unknown>;
|
|
151
175
|
|
|
152
176
|
async function getSourceMapSuffix(
|
|
153
|
-
getSourceMapReference: (
|
|
154
|
-
|
|
177
|
+
getSourceMapReference: (
|
|
178
|
+
arg1?: SourceMap | null | undefined,
|
|
179
|
+
) => Async<string | null | undefined>,
|
|
180
|
+
map?: SourceMap | null,
|
|
155
181
|
): Promise<string> {
|
|
156
182
|
let sourcemapReference = await getSourceMapReference(map);
|
|
157
183
|
if (sourcemapReference != null) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type {BundleGraph, Dependency, NamedBundle} from '@atlaspack/types';
|
|
3
2
|
import type SourceMap from '@parcel/source-map';
|
|
4
3
|
import nullthrows from 'nullthrows';
|
|
@@ -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,27 @@
|
|
|
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
|
+
}
|