@atlaspack/packager-js 2.14.5-canary.27 → 2.14.5-canary.271
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 +396 -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/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
|
@@ -41,6 +41,13 @@ function _nullthrows() {
|
|
|
41
41
|
}
|
|
42
42
|
var _DevPackager = require("./DevPackager");
|
|
43
43
|
var _ScopeHoistingPackager = require("./ScopeHoistingPackager");
|
|
44
|
+
function _featureFlags() {
|
|
45
|
+
const data = require("@atlaspack/feature-flags");
|
|
46
|
+
_featureFlags = function () {
|
|
47
|
+
return data;
|
|
48
|
+
};
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
44
51
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
45
52
|
const CONFIG_SCHEMA = {
|
|
46
53
|
type: 'object',
|
|
@@ -48,7 +55,7 @@ const CONFIG_SCHEMA = {
|
|
|
48
55
|
unstable_asyncBundleRuntime: {
|
|
49
56
|
type: 'boolean'
|
|
50
57
|
},
|
|
51
|
-
|
|
58
|
+
unstable_manualStaticBindingExports: {
|
|
52
59
|
type: 'array',
|
|
53
60
|
items: {
|
|
54
61
|
type: 'string'
|
|
@@ -70,7 +77,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
70
77
|
if (conf !== null && conf !== void 0 && conf.contents) {
|
|
71
78
|
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
72
79
|
data: conf === null || conf === void 0 ? void 0 : conf.contents,
|
|
73
|
-
source: await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
80
|
+
source: (0, _featureFlags().getFeatureFlag)('schemaValidationDeferSourceLoading') ? () => options.inputFS.readFileSync(conf.filePath, 'utf8') : await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
74
81
|
filePath: conf.filePath,
|
|
75
82
|
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)(packageKey)}`
|
|
76
83
|
}, packageKey, `Invalid config for ${packageKey}`);
|
|
@@ -85,7 +92,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
85
92
|
return {
|
|
86
93
|
parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
|
|
87
94
|
unstable_asyncBundleRuntime: Boolean(conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime),
|
|
88
|
-
|
|
95
|
+
unstable_manualStaticBindingExports: (conf === null || conf === void 0 || (_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.unstable_manualStaticBindingExports) ?? null
|
|
89
96
|
};
|
|
90
97
|
},
|
|
91
98
|
async package({
|
|
@@ -100,6 +107,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
100
107
|
// If this is a non-module script, and there is only one asset with no dependencies,
|
|
101
108
|
// then we don't need to package at all and can pass through the original code un-wrapped.
|
|
102
109
|
let contents, map;
|
|
110
|
+
let scopeHoistingStats;
|
|
103
111
|
if (bundle.env.sourceType === 'script') {
|
|
104
112
|
let entries = bundle.getEntryAssets();
|
|
105
113
|
if (entries.length === 1 && bundleGraph.getDependencies(entries[0]).length === 0) {
|
|
@@ -108,11 +116,22 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
108
116
|
}
|
|
109
117
|
}
|
|
110
118
|
if (contents == null) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
if (bundle.env.shouldScopeHoist) {
|
|
120
|
+
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);
|
|
121
|
+
let packageResult = await packager.package();
|
|
122
|
+
({
|
|
123
|
+
contents,
|
|
124
|
+
map
|
|
125
|
+
} = packageResult);
|
|
126
|
+
scopeHoistingStats = packageResult.scopeHoistingStats;
|
|
127
|
+
} else {
|
|
128
|
+
let packager = new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
|
|
129
|
+
let packageResult = await packager.package();
|
|
130
|
+
({
|
|
131
|
+
contents,
|
|
132
|
+
map
|
|
133
|
+
} = packageResult);
|
|
134
|
+
}
|
|
116
135
|
}
|
|
117
136
|
contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
|
|
118
137
|
|
|
@@ -130,7 +149,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
130
149
|
getReplacement: s => JSON.stringify(s).slice(1, -1)
|
|
131
150
|
}));
|
|
132
151
|
}
|
|
133
|
-
|
|
152
|
+
let result = await (0, _utils().replaceInlineReferences)({
|
|
134
153
|
bundle,
|
|
135
154
|
bundleGraph,
|
|
136
155
|
contents,
|
|
@@ -141,6 +160,13 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
141
160
|
getInlineBundleContents,
|
|
142
161
|
map
|
|
143
162
|
});
|
|
163
|
+
if (_utils().debugTools['scope-hoisting-stats']) {
|
|
164
|
+
return {
|
|
165
|
+
...result,
|
|
166
|
+
scopeHoistingStats
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
144
170
|
}
|
|
145
171
|
});
|
|
146
172
|
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 '@parcel/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,71 @@
|
|
|
1
|
+
import type { Asset, BundleGraph, Dependency, PluginOptions, NamedBundle, PluginLogger } from '@atlaspack/types';
|
|
2
|
+
import SourceMap from '@parcel/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
|
+
constructor(options: PluginOptions, bundleGraph: BundleGraph<NamedBundle>, bundle: NamedBundle, parcelRequireName: string, useAsyncBundleRuntime: boolean, manualStaticBindingExports: string[] | null, logger: PluginLogger);
|
|
48
|
+
package(): Promise<PackageResult>;
|
|
49
|
+
shouldBundleQueue(bundle: NamedBundle): boolean;
|
|
50
|
+
runWhenReady(bundle: NamedBundle, codeToRun: string): string;
|
|
51
|
+
loadAssets(): Promise<void>;
|
|
52
|
+
isReExported(asset: Asset): boolean;
|
|
53
|
+
buildExportedSymbols(): void;
|
|
54
|
+
getTopLevelName(name: string): string;
|
|
55
|
+
getPropertyAccess(obj: string, property: string): string;
|
|
56
|
+
visitAsset(asset: Asset): [string, SourceMap | null | undefined, number];
|
|
57
|
+
getAssetFilePath(asset: Asset): string;
|
|
58
|
+
buildAsset(asset: Asset, code: string, map?: Buffer | null): [string, SourceMap | null | undefined, number];
|
|
59
|
+
buildReplacements(asset: Asset, deps: Array<Dependency>): [Map<string, Array<Dependency>>, Map<string, string>];
|
|
60
|
+
addExternal(dep: Dependency, replacements?: Map<string, string>, referencedBundle?: NamedBundle): void;
|
|
61
|
+
isWrapped(resolved: Asset, parentAsset: Asset): boolean;
|
|
62
|
+
getSymbolResolution(parentAsset: Asset, resolved: Asset, imported: string, dep?: Dependency, replacements?: Map<string, string>): string;
|
|
63
|
+
getHoistedParcelRequires(parentAsset: Asset, dep: Dependency, resolved: Asset): [string, number];
|
|
64
|
+
buildAssetPrelude(asset: Asset, deps: Array<Dependency>, replacements: Map<string, string>): [string, number, string];
|
|
65
|
+
buildBundlePrelude(): [string, number];
|
|
66
|
+
needsDefaultInterop(asset: Asset): boolean;
|
|
67
|
+
shouldSkipAsset(asset: Asset): boolean;
|
|
68
|
+
isScriptEntry(asset: Asset): boolean;
|
|
69
|
+
buildFunctionExpression(args: Array<string>, expr: string): string;
|
|
70
|
+
hasConditionalDependency(): boolean;
|
|
71
|
+
}
|
|
@@ -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 '@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.271+540f253df",
|
|
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/types": "2.14.5-canary.
|
|
23
|
-
"@atlaspack/utils": "2.14.5-canary.
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.1-canary.339+540f253df",
|
|
20
|
+
"@atlaspack/feature-flags": "2.14.1-canary.339+540f253df",
|
|
21
|
+
"@atlaspack/plugin": "2.14.5-canary.271+540f253df",
|
|
22
|
+
"@atlaspack/rust": "3.2.1-canary.271+540f253df",
|
|
23
|
+
"@atlaspack/types": "2.14.5-canary.271+540f253df",
|
|
24
|
+
"@atlaspack/utils": "2.14.5-canary.271+540f253df",
|
|
24
25
|
"@parcel/source-map": "^2.1.1",
|
|
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": "540f253dfdcd1a5caebbdc0b197319d439404aae"
|
|
35
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {BundleGraph, PluginOptions, NamedBundle} from '@atlaspack/types';
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -8,6 +7,7 @@ import {
|
|
|
8
7
|
normalizeSeparators,
|
|
9
8
|
} from '@atlaspack/utils';
|
|
10
9
|
import SourceMap from '@parcel/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,11 +223,13 @@ 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,
|
|
205
230
|
);
|
|
206
231
|
if (this.bundle.env.sourceMap && entryMap) {
|
|
232
|
+
// @ts-expect-error TS2551
|
|
207
233
|
map.addSourceMap(entryMap, lineOffset);
|
|
208
234
|
}
|
|
209
235
|
}
|
|
@@ -215,7 +241,7 @@ export class DevPackager {
|
|
|
215
241
|
}
|
|
216
242
|
|
|
217
243
|
getPrefix(): string {
|
|
218
|
-
let interpreter:
|
|
244
|
+
let interpreter: string | null | undefined;
|
|
219
245
|
let mainEntry = this.bundle.getMainEntry();
|
|
220
246
|
if (mainEntry && this.isEntry() && !this.bundle.target.env.isBrowser()) {
|
|
221
247
|
let _interpreter = mainEntry.meta.interpreter;
|
|
@@ -224,7 +250,7 @@ export class DevPackager {
|
|
|
224
250
|
}
|
|
225
251
|
|
|
226
252
|
let importScripts = '';
|
|
227
|
-
if (this.bundle.env.isWorker()) {
|
|
253
|
+
if (this.bundle.env.isWorker() || this.bundle.env.isTesseract()) {
|
|
228
254
|
let bundles = this.bundleGraph.getReferencedBundles(this.bundle);
|
|
229
255
|
for (let b of bundles) {
|
|
230
256
|
importScripts += `importScripts("${relativeBundlePath(
|
|
@@ -246,7 +272,8 @@ export class DevPackager {
|
|
|
246
272
|
return (
|
|
247
273
|
!this.bundleGraph.hasParentBundleOfType(this.bundle, 'js') ||
|
|
248
274
|
this.bundle.env.isIsolated() ||
|
|
249
|
-
this.bundle.bundleBehavior === 'isolated'
|
|
275
|
+
this.bundle.bundleBehavior === 'isolated' ||
|
|
276
|
+
this.bundle.bundleBehavior === 'inlineIsolated'
|
|
250
277
|
);
|
|
251
278
|
}
|
|
252
279
|
}
|
|
@@ -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
|
)}")`;
|