@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/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.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
6
|
+
exports.preludeOld = exports.preludeNew = exports.helpers = exports.fnExpr = exports.bundleQueuePrelude = void 0;
|
|
7
|
+
const preludeOld = parcelRequireName => `
|
|
8
8
|
var $parcel$modules = {};
|
|
9
9
|
var $parcel$inits = {};
|
|
10
10
|
|
|
@@ -37,7 +37,42 @@ if (parcelRequire == null) {
|
|
|
37
37
|
|
|
38
38
|
var parcelRegister = parcelRequire.register;
|
|
39
39
|
`;
|
|
40
|
-
exports.
|
|
40
|
+
exports.preludeOld = preludeOld;
|
|
41
|
+
const preludeNew = parcelRequireName => `
|
|
42
|
+
var $parcel$modules = {};
|
|
43
|
+
var $parcel$inits = {};
|
|
44
|
+
|
|
45
|
+
var parcelRequire = $parcel$global[${JSON.stringify(parcelRequireName)}];
|
|
46
|
+
|
|
47
|
+
if (parcelRequire == null) {
|
|
48
|
+
parcelRequire = function(id) {
|
|
49
|
+
var mod = $parcel$modules[id];
|
|
50
|
+
if (mod !== undefined) {
|
|
51
|
+
return mod.exports;
|
|
52
|
+
}
|
|
53
|
+
var init = $parcel$inits[id];
|
|
54
|
+
if (init !== undefined) {
|
|
55
|
+
delete $parcel$inits[id];
|
|
56
|
+
var module = {id: id, exports: {}};
|
|
57
|
+
$parcel$modules[id] = module;
|
|
58
|
+
init.call(module.exports, module, module.exports);
|
|
59
|
+
return module.exports;
|
|
60
|
+
}
|
|
61
|
+
var err = new Error("Cannot find module '" + id + "'");
|
|
62
|
+
err.code = 'MODULE_NOT_FOUND';
|
|
63
|
+
throw err;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
parcelRequire.register = function register(id, init) {
|
|
67
|
+
$parcel$inits[id] = init;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
$parcel$global[${JSON.stringify(parcelRequireName)}] = parcelRequire;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var parcelRegister = parcelRequire.register;
|
|
74
|
+
`;
|
|
75
|
+
exports.preludeNew = preludeNew;
|
|
41
76
|
const fnExpr = (env, params, body) => {
|
|
42
77
|
let block = `{ ${body.join(' ')} }`;
|
|
43
78
|
if (env.supports('arrow-functions')) {
|
package/lib/index.js
CHANGED
|
@@ -48,7 +48,7 @@ const CONFIG_SCHEMA = {
|
|
|
48
48
|
unstable_asyncBundleRuntime: {
|
|
49
49
|
type: 'boolean'
|
|
50
50
|
},
|
|
51
|
-
|
|
51
|
+
unstable_manualStaticBindingExports: {
|
|
52
52
|
type: 'array',
|
|
53
53
|
items: {
|
|
54
54
|
type: 'string'
|
|
@@ -70,7 +70,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
70
70
|
if (conf !== null && conf !== void 0 && conf.contents) {
|
|
71
71
|
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
72
72
|
data: conf === null || conf === void 0 ? void 0 : conf.contents,
|
|
73
|
-
source:
|
|
73
|
+
source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
|
|
74
74
|
filePath: conf.filePath,
|
|
75
75
|
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)(packageKey)}`
|
|
76
76
|
}, packageKey, `Invalid config for ${packageKey}`);
|
|
@@ -85,7 +85,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
85
85
|
return {
|
|
86
86
|
parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
|
|
87
87
|
unstable_asyncBundleRuntime: Boolean(conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime),
|
|
88
|
-
|
|
88
|
+
unstable_manualStaticBindingExports: (conf === null || conf === void 0 || (_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.unstable_manualStaticBindingExports) ?? null
|
|
89
89
|
};
|
|
90
90
|
},
|
|
91
91
|
async package({
|
|
@@ -100,6 +100,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
100
100
|
// If this is a non-module script, and there is only one asset with no dependencies,
|
|
101
101
|
// then we don't need to package at all and can pass through the original code un-wrapped.
|
|
102
102
|
let contents, map;
|
|
103
|
+
let scopeHoistingStats;
|
|
103
104
|
if (bundle.env.sourceType === 'script') {
|
|
104
105
|
let entries = bundle.getEntryAssets();
|
|
105
106
|
if (entries.length === 1 && bundleGraph.getDependencies(entries[0]).length === 0) {
|
|
@@ -108,11 +109,22 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
if (contents == null) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
if (bundle.env.shouldScopeHoist) {
|
|
113
|
+
let packager = new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName, (0, _nullthrows().default)(config).unstable_asyncBundleRuntime, (0, _nullthrows().default)(config).unstable_manualStaticBindingExports, logger);
|
|
114
|
+
let packageResult = await packager.package();
|
|
115
|
+
({
|
|
116
|
+
contents,
|
|
117
|
+
map
|
|
118
|
+
} = packageResult);
|
|
119
|
+
scopeHoistingStats = packageResult.scopeHoistingStats;
|
|
120
|
+
} else {
|
|
121
|
+
let packager = new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
|
|
122
|
+
let packageResult = await packager.package();
|
|
123
|
+
({
|
|
124
|
+
contents,
|
|
125
|
+
map
|
|
126
|
+
} = packageResult);
|
|
127
|
+
}
|
|
116
128
|
}
|
|
117
129
|
contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
|
|
118
130
|
|
|
@@ -130,7 +142,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
130
142
|
getReplacement: s => JSON.stringify(s).slice(1, -1)
|
|
131
143
|
}));
|
|
132
144
|
}
|
|
133
|
-
|
|
145
|
+
let result = await (0, _utils().replaceInlineReferences)({
|
|
134
146
|
bundle,
|
|
135
147
|
bundleGraph,
|
|
136
148
|
contents,
|
|
@@ -141,6 +153,13 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
141
153
|
getInlineBundleContents,
|
|
142
154
|
map
|
|
143
155
|
});
|
|
156
|
+
if (_utils().debugTools['scope-hoisting-stats']) {
|
|
157
|
+
return {
|
|
158
|
+
...result,
|
|
159
|
+
scopeHoistingStats
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
144
163
|
}
|
|
145
164
|
});
|
|
146
165
|
async function getSourceMapSuffix(getSourceMapReference, map) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ScopeHoistingPackager, OutputFormat } from './ScopeHoistingPackager';
|
|
2
|
+
export declare class CJSOutputFormat implements OutputFormat {
|
|
3
|
+
packager: ScopeHoistingPackager;
|
|
4
|
+
constructor(packager: ScopeHoistingPackager);
|
|
5
|
+
buildBundlePrelude(): [string, number];
|
|
6
|
+
buildBundlePostlude(): [string, number];
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BundleGraph, PluginOptions, NamedBundle } from '@atlaspack/types';
|
|
2
|
+
import SourceMap from '@atlaspack/source-map';
|
|
3
|
+
export declare class DevPackager {
|
|
4
|
+
options: PluginOptions;
|
|
5
|
+
bundleGraph: BundleGraph<NamedBundle>;
|
|
6
|
+
bundle: NamedBundle;
|
|
7
|
+
parcelRequireName: string;
|
|
8
|
+
constructor(options: PluginOptions, bundleGraph: BundleGraph<NamedBundle>, bundle: NamedBundle, parcelRequireName: string);
|
|
9
|
+
package(): Promise<{
|
|
10
|
+
contents: string;
|
|
11
|
+
map: SourceMap | null | undefined;
|
|
12
|
+
}>;
|
|
13
|
+
getPrefix(): string;
|
|
14
|
+
isEntry(): boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ScopeHoistingPackager, OutputFormat } from './ScopeHoistingPackager';
|
|
2
|
+
export declare class ESMOutputFormat implements OutputFormat {
|
|
3
|
+
packager: ScopeHoistingPackager;
|
|
4
|
+
constructor(packager: ScopeHoistingPackager);
|
|
5
|
+
buildBundlePrelude(): [string, number];
|
|
6
|
+
buildBundlePostlude(): [string, number];
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ScopeHoistingPackager, OutputFormat } from './ScopeHoistingPackager';
|
|
2
|
+
export declare class GlobalOutputFormat implements OutputFormat {
|
|
3
|
+
packager: ScopeHoistingPackager;
|
|
4
|
+
constructor(packager: ScopeHoistingPackager);
|
|
5
|
+
buildBundlePrelude(): [string, number];
|
|
6
|
+
buildBundlePostlude(): [string, number];
|
|
7
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Asset, BundleGraph, Dependency, PluginOptions, NamedBundle, PluginLogger } from '@atlaspack/types';
|
|
2
|
+
import SourceMap from '@atlaspack/source-map';
|
|
3
|
+
export interface OutputFormat {
|
|
4
|
+
buildBundlePrelude(): [string, number];
|
|
5
|
+
buildBundlePostlude(): [string, number];
|
|
6
|
+
}
|
|
7
|
+
export type PackageResult = {
|
|
8
|
+
contents: string;
|
|
9
|
+
map: SourceMap | null | undefined;
|
|
10
|
+
scopeHoistingStats?: {
|
|
11
|
+
totalAssets: number;
|
|
12
|
+
wrappedAssets: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare class ScopeHoistingPackager {
|
|
16
|
+
options: PluginOptions;
|
|
17
|
+
bundleGraph: BundleGraph<NamedBundle>;
|
|
18
|
+
bundle: NamedBundle;
|
|
19
|
+
parcelRequireName: string;
|
|
20
|
+
useAsyncBundleRuntime: boolean;
|
|
21
|
+
outputFormat: OutputFormat;
|
|
22
|
+
isAsyncBundle: boolean;
|
|
23
|
+
globalNames: ReadonlySet<string>;
|
|
24
|
+
manualStaticBindingExports: RegExp[] | null;
|
|
25
|
+
assetOutputs: Map<Asset, {
|
|
26
|
+
code: string;
|
|
27
|
+
map: Buffer | null | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
exportedSymbols: Map<string, {
|
|
30
|
+
asset: Asset;
|
|
31
|
+
exportSymbol: string;
|
|
32
|
+
local: string;
|
|
33
|
+
exportAs: Array<string>;
|
|
34
|
+
}>;
|
|
35
|
+
externals: Map<string, Map<string, string>>;
|
|
36
|
+
topLevelNames: Map<string, number>;
|
|
37
|
+
seenAssets: Set<Asset>;
|
|
38
|
+
wrappedAssets: Set<Asset>;
|
|
39
|
+
constantAssets: Set<Asset>;
|
|
40
|
+
hoistedRequires: Map<Dependency, Map<Asset, string>>;
|
|
41
|
+
seenHoistedRequires: Set<string>;
|
|
42
|
+
needsPrelude: boolean;
|
|
43
|
+
usedHelpers: Set<string>;
|
|
44
|
+
externalAssets: Set<Asset>;
|
|
45
|
+
logger: PluginLogger;
|
|
46
|
+
useBothScopeHoistingImprovements: boolean;
|
|
47
|
+
referencedAssetsCache: Map<string, Set<Asset>>;
|
|
48
|
+
constructor(options: PluginOptions, bundleGraph: BundleGraph<NamedBundle>, bundle: NamedBundle, parcelRequireName: string, useAsyncBundleRuntime: boolean, manualStaticBindingExports: string[] | null, logger: PluginLogger);
|
|
49
|
+
package(): Promise<PackageResult>;
|
|
50
|
+
shouldBundleQueue(bundle: NamedBundle): boolean;
|
|
51
|
+
runWhenReady(bundle: NamedBundle, codeToRun: string): string;
|
|
52
|
+
isAssetReferencedInBundle(bundle: NamedBundle, asset: Asset): boolean;
|
|
53
|
+
loadAssets(): Promise<void>;
|
|
54
|
+
isReExported(asset: Asset): boolean;
|
|
55
|
+
buildExportedSymbols(): void;
|
|
56
|
+
getTopLevelName(name: string): string;
|
|
57
|
+
getPropertyAccess(obj: string, property: string): string;
|
|
58
|
+
visitAsset(asset: Asset): [string, SourceMap | null | undefined, number];
|
|
59
|
+
getAssetFilePath(asset: Asset): string;
|
|
60
|
+
buildAsset(asset: Asset, code: string, map?: Buffer | null): [string, SourceMap | null | undefined, number];
|
|
61
|
+
buildReplacements(asset: Asset, deps: Array<Dependency>): [Map<string, Array<Dependency>>, Map<string, string>];
|
|
62
|
+
addExternal(dep: Dependency, replacements?: Map<string, string>, referencedBundle?: NamedBundle): void;
|
|
63
|
+
isWrapped(resolved: Asset, parentAsset: Asset): boolean;
|
|
64
|
+
getSymbolResolution(parentAsset: Asset, resolved: Asset, imported: string, dep?: Dependency, replacements?: Map<string, string>): string;
|
|
65
|
+
getHoistedParcelRequires(parentAsset: Asset, dep: Dependency, resolved: Asset): [string, number];
|
|
66
|
+
buildAssetPrelude(asset: Asset, deps: Array<Dependency>, replacements: Map<string, string>): [string, number, string];
|
|
67
|
+
buildBundlePrelude(): [string, number];
|
|
68
|
+
needsDefaultInterop(asset: Asset): boolean;
|
|
69
|
+
shouldSkipAsset(asset: Asset): boolean;
|
|
70
|
+
isScriptEntry(asset: Asset): boolean;
|
|
71
|
+
buildFunctionExpression(args: Array<string>, expr: string): string;
|
|
72
|
+
hasConditionalDependency(): boolean;
|
|
73
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Environment } from '@atlaspack/types';
|
|
2
|
+
export declare const preludeOld: (parcelRequireName: string) => string;
|
|
3
|
+
export declare const preludeNew: (parcelRequireName: string) => string;
|
|
4
|
+
export declare const fnExpr: (env: Environment, params: Array<string>, body: Array<string>) => string;
|
|
5
|
+
export declare const bundleQueuePrelude: (env: Environment) => string;
|
|
6
|
+
export declare const helpers: {
|
|
7
|
+
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";
|
|
8
|
+
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";
|
|
9
|
+
readonly $parcel$interopDefault: "\nfunction $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n";
|
|
10
|
+
readonly $parcel$global: (env: Environment) => string;
|
|
11
|
+
readonly $parcel$defineInteropFlag: "\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true, configurable: true});\n}\n";
|
|
12
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BundleGraph, Dependency, NamedBundle } from '@atlaspack/types';
|
|
2
|
+
import type SourceMap from '@atlaspack/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.350+565bab377",
|
|
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/types/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/
|
|
23
|
-
"@atlaspack/
|
|
24
|
-
"@
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.1-canary.418+565bab377",
|
|
20
|
+
"@atlaspack/feature-flags": "2.14.1-canary.418+565bab377",
|
|
21
|
+
"@atlaspack/plugin": "2.14.5-canary.350+565bab377",
|
|
22
|
+
"@atlaspack/rust": "3.2.1-canary.350+565bab377",
|
|
23
|
+
"@atlaspack/source-map": "3.2.3-canary.4129+565bab377",
|
|
24
|
+
"@atlaspack/types": "2.14.5-canary.350+565bab377",
|
|
25
|
+
"@atlaspack/utils": "2.14.5-canary.350+565bab377",
|
|
25
26
|
"globals": "^13.2.0",
|
|
26
|
-
"nullthrows": "^1.1.1"
|
|
27
|
+
"nullthrows": "^1.1.1",
|
|
28
|
+
"outdent": "^0.8.0"
|
|
27
29
|
},
|
|
28
30
|
"type": "commonjs",
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "565bab3771cc334659d873cabff4cdfac0860cc7"
|
|
35
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {BundleGraph, PluginOptions, NamedBundle} from '@atlaspack/types';
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -7,7 +6,8 @@ import {
|
|
|
7
6
|
countLines,
|
|
8
7
|
normalizeSeparators,
|
|
9
8
|
} from '@atlaspack/utils';
|
|
10
|
-
import SourceMap from '@
|
|
9
|
+
import SourceMap from '@atlaspack/source-map';
|
|
10
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
11
11
|
import invariant from 'assert';
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import fs from 'fs';
|
|
@@ -36,7 +36,10 @@ export class DevPackager {
|
|
|
36
36
|
this.parcelRequireName = parcelRequireName;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
async package(): Promise<{
|
|
39
|
+
async package(): Promise<{
|
|
40
|
+
contents: string;
|
|
41
|
+
map: SourceMap | null | undefined;
|
|
42
|
+
}> {
|
|
40
43
|
// Load assets
|
|
41
44
|
let queue = new PromiseQueue({maxConcurrent: 32});
|
|
42
45
|
this.bundle.traverseAssets((asset) => {
|
|
@@ -58,7 +61,13 @@ export class DevPackager {
|
|
|
58
61
|
|
|
59
62
|
let prefix = this.getPrefix();
|
|
60
63
|
let lineOffset = countLines(prefix);
|
|
61
|
-
let script:
|
|
64
|
+
let script:
|
|
65
|
+
| {
|
|
66
|
+
code: string;
|
|
67
|
+
mapBuffer: Buffer | null | undefined;
|
|
68
|
+
}
|
|
69
|
+
| null
|
|
70
|
+
| undefined = null;
|
|
62
71
|
|
|
63
72
|
this.bundle.traverse((node) => {
|
|
64
73
|
let wrapped = first ? '' : ',';
|
|
@@ -93,11 +102,12 @@ export class DevPackager {
|
|
|
93
102
|
this.bundle.env.sourceType === 'script' &&
|
|
94
103
|
asset === this.bundle.getMainEntry()
|
|
95
104
|
) {
|
|
105
|
+
// @ts-expect-error TS2322
|
|
96
106
|
script = results[i++];
|
|
97
107
|
return;
|
|
98
108
|
}
|
|
99
109
|
|
|
100
|
-
let deps = {};
|
|
110
|
+
let deps: Record<string, any> = {};
|
|
101
111
|
let dependencies = this.bundleGraph.getDependencies(asset);
|
|
102
112
|
for (let dep of dependencies) {
|
|
103
113
|
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
@@ -112,6 +122,19 @@ export class DevPackager {
|
|
|
112
122
|
}
|
|
113
123
|
}
|
|
114
124
|
|
|
125
|
+
if (getFeatureFlag('hmrImprovements')) {
|
|
126
|
+
// Add dependencies for parcelRequire calls added by runtimes
|
|
127
|
+
// so that the HMR runtime can correctly traverse parents.
|
|
128
|
+
let hmrDeps = asset.meta.hmrDeps;
|
|
129
|
+
if (this.options.hmrOptions && Array.isArray(hmrDeps)) {
|
|
130
|
+
for (let id of hmrDeps) {
|
|
131
|
+
invariant(typeof id === 'string');
|
|
132
|
+
deps[id] = id;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// @ts-expect-error TS2339
|
|
115
138
|
let {code, mapBuffer} = results[i];
|
|
116
139
|
let output = code || '';
|
|
117
140
|
wrapped +=
|
|
@@ -192,6 +215,7 @@ export class DevPackager {
|
|
|
192
215
|
// runtimes with a parcelRequire call.
|
|
193
216
|
if (this.bundle.env.sourceType === 'script' && script) {
|
|
194
217
|
let entryMap;
|
|
218
|
+
// @ts-expect-error TS2339
|
|
195
219
|
let mapBuffer = script.mapBuffer;
|
|
196
220
|
if (mapBuffer) {
|
|
197
221
|
entryMap = new SourceMap(this.options.projectRoot, mapBuffer);
|
|
@@ -199,6 +223,7 @@ export class DevPackager {
|
|
|
199
223
|
contents += replaceScriptDependencies(
|
|
200
224
|
this.bundleGraph,
|
|
201
225
|
this.bundle,
|
|
226
|
+
// @ts-expect-error TS2339
|
|
202
227
|
script.code,
|
|
203
228
|
entryMap,
|
|
204
229
|
this.parcelRequireName,
|
|
@@ -215,7 +240,7 @@ export class DevPackager {
|
|
|
215
240
|
}
|
|
216
241
|
|
|
217
242
|
getPrefix(): string {
|
|
218
|
-
let interpreter:
|
|
243
|
+
let interpreter: string | null | undefined;
|
|
219
244
|
let mainEntry = this.bundle.getMainEntry();
|
|
220
245
|
if (mainEntry && this.isEntry() && !this.bundle.target.env.isBrowser()) {
|
|
221
246
|
let _interpreter = mainEntry.meta.interpreter;
|
|
@@ -224,7 +249,7 @@ export class DevPackager {
|
|
|
224
249
|
}
|
|
225
250
|
|
|
226
251
|
let importScripts = '';
|
|
227
|
-
if (this.bundle.env.isWorker()) {
|
|
252
|
+
if (this.bundle.env.isWorker() || this.bundle.env.isTesseract()) {
|
|
228
253
|
let bundles = this.bundleGraph.getReferencedBundles(this.bundle);
|
|
229
254
|
for (let b of bundles) {
|
|
230
255
|
importScripts += `importScripts("${relativeBundlePath(
|
|
@@ -246,7 +271,8 @@ export class DevPackager {
|
|
|
246
271
|
return (
|
|
247
272
|
!this.bundleGraph.hasParentBundleOfType(this.bundle, 'js') ||
|
|
248
273
|
this.bundle.env.isIsolated() ||
|
|
249
|
-
this.bundle.bundleBehavior === 'isolated'
|
|
274
|
+
this.bundle.bundleBehavior === 'isolated' ||
|
|
275
|
+
this.bundle.bundleBehavior === 'inlineIsolated'
|
|
250
276
|
);
|
|
251
277
|
}
|
|
252
278
|
}
|
|
@@ -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,14 +76,14 @@ 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,
|
|
84
83
|
local,
|
|
85
84
|
exportAs,
|
|
86
85
|
} of this.packager.exportedSymbols.values()) {
|
|
87
|
-
if (this.packager.wrappedAssets.has(asset
|
|
86
|
+
if (this.packager.wrappedAssets.has(asset)) {
|
|
88
87
|
let obj = `parcelRequire("${this.packager.bundleGraph.getAssetPublicId(
|
|
89
88
|
asset,
|
|
90
89
|
)}")`;
|