@atlaspack/core 2.13.2-dev.3689 → 2.14.0
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 +61 -0
- package/package.json +20 -20
- package/src/Atlaspack.js +3 -2
- package/src/atlaspack-v3/AtlaspackV3.js +25 -9
- package/src/requests/WriteBundlesRequest.js +31 -22
- package/LICENSE +0 -201
- package/lib/AssetGraph.js +0 -521
- package/lib/Atlaspack.js +0 -676
- package/lib/AtlaspackConfig.js +0 -298
- package/lib/AtlaspackConfig.schema.js +0 -103
- package/lib/BundleGraph.js +0 -1527
- package/lib/CommittedAsset.js +0 -155
- package/lib/Dependency.js +0 -136
- package/lib/Environment.js +0 -144
- package/lib/IdentifierRegistry.js +0 -36
- package/lib/InternalConfig.js +0 -56
- package/lib/PackagerRunner.js +0 -525
- package/lib/ReporterRunner.js +0 -151
- package/lib/RequestTracker.js +0 -1178
- package/lib/SymbolPropagation.js +0 -618
- package/lib/TargetDescriptor.schema.js +0 -118
- package/lib/Transformation.js +0 -522
- package/lib/UncommittedAsset.js +0 -348
- package/lib/Validation.js +0 -203
- package/lib/applyRuntimes.js +0 -355
- package/lib/assetUtils.js +0 -205
- package/lib/atlaspack-v3/AtlaspackV3.js +0 -57
- package/lib/atlaspack-v3/NapiWorkerPool.js +0 -71
- package/lib/atlaspack-v3/fs.js +0 -39
- package/lib/atlaspack-v3/index.js +0 -26
- package/lib/atlaspack-v3/jsCallable.js +0 -20
- package/lib/atlaspack-v3/worker/compat/asset-symbols.js +0 -197
- package/lib/atlaspack-v3/worker/compat/bitflags.js +0 -84
- package/lib/atlaspack-v3/worker/compat/dependency.js +0 -44
- package/lib/atlaspack-v3/worker/compat/environment.js +0 -57
- package/lib/atlaspack-v3/worker/compat/index.js +0 -104
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +0 -164
- package/lib/atlaspack-v3/worker/compat/plugin-config.js +0 -78
- package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
- package/lib/atlaspack-v3/worker/compat/plugin-options.js +0 -113
- package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +0 -12
- package/lib/atlaspack-v3/worker/compat/target.js +0 -17
- package/lib/atlaspack-v3/worker/index.js +0 -3
- package/lib/atlaspack-v3/worker/worker.js +0 -280
- package/lib/constants.js +0 -21
- package/lib/dumpGraphToGraphViz.js +0 -206
- package/lib/index.js +0 -70
- package/lib/loadAtlaspackPlugin.js +0 -115
- package/lib/loadDotEnv.js +0 -54
- package/lib/projectPath.js +0 -112
- package/lib/public/Asset.js +0 -259
- package/lib/public/Bundle.js +0 -236
- package/lib/public/BundleGraph.js +0 -279
- package/lib/public/BundleGroup.js +0 -50
- package/lib/public/Config.js +0 -202
- package/lib/public/Dependency.js +0 -131
- package/lib/public/Environment.js +0 -247
- package/lib/public/MutableBundleGraph.js +0 -204
- package/lib/public/PluginOptions.js +0 -71
- package/lib/public/Symbols.js +0 -247
- package/lib/public/Target.js +0 -64
- package/lib/registerCoreWithSerializer.js +0 -51
- package/lib/requests/AssetGraphRequest.js +0 -432
- package/lib/requests/AssetGraphRequestRust.js +0 -220
- package/lib/requests/AssetRequest.js +0 -132
- package/lib/requests/AtlaspackBuildRequest.js +0 -79
- package/lib/requests/AtlaspackConfigRequest.js +0 -479
- package/lib/requests/BundleGraphRequest.js +0 -485
- package/lib/requests/ConfigRequest.js +0 -203
- package/lib/requests/DevDepRequest.js +0 -193
- package/lib/requests/EntryRequest.js +0 -295
- package/lib/requests/PackageRequest.js +0 -88
- package/lib/requests/PathRequest.js +0 -357
- package/lib/requests/TargetRequest.js +0 -1179
- package/lib/requests/ValidationRequest.js +0 -66
- package/lib/requests/WriteBundleRequest.js +0 -252
- package/lib/requests/WriteBundlesRequest.js +0 -153
- package/lib/requests/asset-graph-diff.js +0 -128
- package/lib/requests/asset-graph-dot.js +0 -131
- package/lib/resolveOptions.js +0 -265
- package/lib/serializerCore.browser.js +0 -29
- package/lib/summarizeRequest.js +0 -55
- package/lib/types.js +0 -35
- package/lib/utils.js +0 -160
- package/lib/worker.js +0 -184
package/lib/PackagerRunner.js
DELETED
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
function _assert() {
|
|
8
|
-
const data = _interopRequireDefault(require("assert"));
|
|
9
|
-
_assert = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _buildCache() {
|
|
15
|
-
const data = require("@atlaspack/build-cache");
|
|
16
|
-
_buildCache = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _utils() {
|
|
22
|
-
const data = require("@atlaspack/utils");
|
|
23
|
-
_utils = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _logger() {
|
|
29
|
-
const data = require("@atlaspack/logger");
|
|
30
|
-
_logger = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
function _diagnostic() {
|
|
36
|
-
const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
|
|
37
|
-
_diagnostic = function () {
|
|
38
|
-
return data;
|
|
39
|
-
};
|
|
40
|
-
return data;
|
|
41
|
-
}
|
|
42
|
-
function _stream() {
|
|
43
|
-
const data = require("stream");
|
|
44
|
-
_stream = function () {
|
|
45
|
-
return data;
|
|
46
|
-
};
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
function _nullthrows() {
|
|
50
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
51
|
-
_nullthrows = function () {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
function _path() {
|
|
57
|
-
const data = _interopRequireDefault(require("path"));
|
|
58
|
-
_path = function () {
|
|
59
|
-
return data;
|
|
60
|
-
};
|
|
61
|
-
return data;
|
|
62
|
-
}
|
|
63
|
-
function _url() {
|
|
64
|
-
const data = _interopRequireDefault(require("url"));
|
|
65
|
-
_url = function () {
|
|
66
|
-
return data;
|
|
67
|
-
};
|
|
68
|
-
return data;
|
|
69
|
-
}
|
|
70
|
-
function _rust() {
|
|
71
|
-
const data = require("@atlaspack/rust");
|
|
72
|
-
_rust = function () {
|
|
73
|
-
return data;
|
|
74
|
-
};
|
|
75
|
-
return data;
|
|
76
|
-
}
|
|
77
|
-
var _Bundle = require("./public/Bundle");
|
|
78
|
-
var _BundleGraph = _interopRequireWildcard(require("./public/BundleGraph"));
|
|
79
|
-
var _PluginOptions = _interopRequireDefault(require("./public/PluginOptions"));
|
|
80
|
-
var _Config = _interopRequireDefault(require("./public/Config"));
|
|
81
|
-
var _constants = require("./constants");
|
|
82
|
-
var _projectPath = require("./projectPath");
|
|
83
|
-
var _InternalConfig = require("./InternalConfig");
|
|
84
|
-
var _ConfigRequest = require("./requests/ConfigRequest");
|
|
85
|
-
var _DevDepRequest = require("./requests/DevDepRequest");
|
|
86
|
-
var _assetUtils = require("./assetUtils");
|
|
87
|
-
var _utils2 = require("./utils");
|
|
88
|
-
function _profiler() {
|
|
89
|
-
const data = require("@atlaspack/profiler");
|
|
90
|
-
_profiler = function () {
|
|
91
|
-
return data;
|
|
92
|
-
};
|
|
93
|
-
return data;
|
|
94
|
-
}
|
|
95
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
96
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
97
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
98
|
-
const BOUNDARY_LENGTH = _constants.HASH_REF_PREFIX.length + 32 - 1;
|
|
99
|
-
|
|
100
|
-
// Packager/optimizer configs are not bundle-specific, so we only need to
|
|
101
|
-
// load them once per build.
|
|
102
|
-
const pluginConfigs = (0, _buildCache().createBuildCache)();
|
|
103
|
-
class PackagerRunner {
|
|
104
|
-
constructor({
|
|
105
|
-
config,
|
|
106
|
-
options,
|
|
107
|
-
report,
|
|
108
|
-
previousDevDeps,
|
|
109
|
-
previousInvalidations
|
|
110
|
-
}) {
|
|
111
|
-
this.config = config;
|
|
112
|
-
this.options = options;
|
|
113
|
-
this.report = report;
|
|
114
|
-
this.previousDevDeps = previousDevDeps;
|
|
115
|
-
this.devDepRequests = new Map();
|
|
116
|
-
this.previousInvalidations = previousInvalidations;
|
|
117
|
-
this.invalidations = new Map();
|
|
118
|
-
this.pluginOptions = new _PluginOptions.default((0, _utils2.optionsProxy)(this.options, option => {
|
|
119
|
-
let invalidation = {
|
|
120
|
-
type: 'option',
|
|
121
|
-
key: option
|
|
122
|
-
};
|
|
123
|
-
this.invalidations.set((0, _assetUtils.getInvalidationId)(invalidation), invalidation);
|
|
124
|
-
}));
|
|
125
|
-
}
|
|
126
|
-
async run(bundleGraph, bundle, invalidDevDeps) {
|
|
127
|
-
(0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, this.options, this.config);
|
|
128
|
-
let {
|
|
129
|
-
configs,
|
|
130
|
-
bundleConfigs
|
|
131
|
-
} = await this.loadConfigs(bundleGraph, bundle);
|
|
132
|
-
let bundleInfo = (await this.getBundleInfoFromCache(bundleGraph, bundle, configs, bundleConfigs)) ?? (await this.getBundleInfo(bundle, bundleGraph, configs, bundleConfigs));
|
|
133
|
-
let configRequests = (0, _ConfigRequest.getConfigRequests)([...configs.values(), ...bundleConfigs.values()]);
|
|
134
|
-
let devDepRequests = (0, _DevDepRequest.getWorkerDevDepRequests)([...this.devDepRequests.values()]);
|
|
135
|
-
return {
|
|
136
|
-
bundleInfo,
|
|
137
|
-
configRequests,
|
|
138
|
-
devDepRequests,
|
|
139
|
-
invalidations: [...this.invalidations.values()]
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
async loadConfigs(bundleGraph, bundle) {
|
|
143
|
-
let configs = new Map();
|
|
144
|
-
let bundleConfigs = new Map();
|
|
145
|
-
await this.loadConfig(bundleGraph, bundle, configs, bundleConfigs);
|
|
146
|
-
for (let inlineBundle of bundleGraph.getInlineBundles(bundle)) {
|
|
147
|
-
await this.loadConfig(bundleGraph, inlineBundle, configs, bundleConfigs);
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
configs,
|
|
151
|
-
bundleConfigs
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
async loadConfig(bundleGraph, bundle, configs, bundleConfigs) {
|
|
155
|
-
let name = (0, _nullthrows().default)(bundle.name);
|
|
156
|
-
let plugin = await this.config.getPackager(name);
|
|
157
|
-
await this.loadPluginConfig(bundleGraph, bundle, plugin, configs, bundleConfigs);
|
|
158
|
-
let optimizers = await this.config.getOptimizers(name, bundle.pipeline);
|
|
159
|
-
for (let optimizer of optimizers) {
|
|
160
|
-
await this.loadPluginConfig(bundleGraph, bundle, optimizer, configs, bundleConfigs);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
async loadPluginConfig(bundleGraph, bundle, plugin, configs, bundleConfigs) {
|
|
164
|
-
if (!configs.has(plugin.name)) {
|
|
165
|
-
// Only load config for a plugin once per build.
|
|
166
|
-
let existing = pluginConfigs.get(plugin.name);
|
|
167
|
-
if (existing != null) {
|
|
168
|
-
configs.set(plugin.name, existing);
|
|
169
|
-
} else {
|
|
170
|
-
if (plugin.plugin.loadConfig != null) {
|
|
171
|
-
let config = (0, _InternalConfig.createConfig)({
|
|
172
|
-
plugin: plugin.name,
|
|
173
|
-
searchPath: (0, _projectPath.toProjectPathUnsafe)('index')
|
|
174
|
-
});
|
|
175
|
-
await (0, _ConfigRequest.loadPluginConfig)(plugin, config, this.options);
|
|
176
|
-
for (let devDep of config.devDeps) {
|
|
177
|
-
let devDepRequest = await (0, _DevDepRequest.createDevDependency)(devDep, this.previousDevDeps, this.options);
|
|
178
|
-
let key = `${devDep.specifier}:${(0, _projectPath.fromProjectPath)(this.options.projectRoot, devDep.resolveFrom)}`;
|
|
179
|
-
this.devDepRequests.set(key, devDepRequest);
|
|
180
|
-
}
|
|
181
|
-
pluginConfigs.set(plugin.name, config);
|
|
182
|
-
configs.set(plugin.name, config);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
let loadBundleConfig = plugin.plugin.loadBundleConfig;
|
|
187
|
-
if (!bundleConfigs.has(plugin.name) && loadBundleConfig != null) {
|
|
188
|
-
let config = (0, _InternalConfig.createConfig)({
|
|
189
|
-
plugin: plugin.name,
|
|
190
|
-
searchPath: (0, _projectPath.joinProjectPath)(bundle.target.distDir, bundle.name ?? bundle.id)
|
|
191
|
-
});
|
|
192
|
-
config.result = await loadBundleConfig({
|
|
193
|
-
bundle: _Bundle.NamedBundle.get(bundle, bundleGraph, this.options),
|
|
194
|
-
bundleGraph: new _BundleGraph.default(bundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), this.options),
|
|
195
|
-
config: new _Config.default(config, this.options),
|
|
196
|
-
options: new _PluginOptions.default(this.options),
|
|
197
|
-
logger: new (_logger().PluginLogger)({
|
|
198
|
-
origin: plugin.name
|
|
199
|
-
}),
|
|
200
|
-
tracer: new (_profiler().PluginTracer)({
|
|
201
|
-
origin: plugin.name,
|
|
202
|
-
category: 'loadConfig'
|
|
203
|
-
})
|
|
204
|
-
});
|
|
205
|
-
bundleConfigs.set(plugin.name, config);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
async getBundleInfoFromCache(bundleGraph, bundle, configs, bundleConfigs) {
|
|
209
|
-
if (this.options.shouldDisableCache) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
let cacheKey = await this.getCacheKey(bundle, bundleGraph, configs, bundleConfigs, this.previousInvalidations);
|
|
213
|
-
let infoKey = PackagerRunner.getInfoKey(cacheKey);
|
|
214
|
-
return this.options.cache.get(infoKey);
|
|
215
|
-
}
|
|
216
|
-
async getBundleInfo(bundle, bundleGraph, configs, bundleConfigs) {
|
|
217
|
-
let {
|
|
218
|
-
type,
|
|
219
|
-
contents,
|
|
220
|
-
map
|
|
221
|
-
} = await this.getBundleResult(bundle, bundleGraph, configs, bundleConfigs);
|
|
222
|
-
|
|
223
|
-
// Recompute cache keys as they may have changed due to dev dependencies.
|
|
224
|
-
let cacheKey = await this.getCacheKey(bundle, bundleGraph, configs, bundleConfigs, [...this.invalidations.values()]);
|
|
225
|
-
let cacheKeys = {
|
|
226
|
-
content: PackagerRunner.getContentKey(cacheKey),
|
|
227
|
-
map: PackagerRunner.getMapKey(cacheKey),
|
|
228
|
-
info: PackagerRunner.getInfoKey(cacheKey)
|
|
229
|
-
};
|
|
230
|
-
return this.writeToCache(cacheKeys, type, contents, map);
|
|
231
|
-
}
|
|
232
|
-
async getBundleResult(bundle, bundleGraph, configs, bundleConfigs) {
|
|
233
|
-
let packaged = await this.package(bundle, bundleGraph, configs, bundleConfigs);
|
|
234
|
-
let type = packaged.type ?? bundle.type;
|
|
235
|
-
let res = await this.optimize(bundle, bundleGraph, type, packaged.contents, packaged.map, configs, bundleConfigs);
|
|
236
|
-
let map = res.map != null ? await this.generateSourceMap(bundle, res.map) : null;
|
|
237
|
-
return {
|
|
238
|
-
type: res.type ?? type,
|
|
239
|
-
contents: res.contents,
|
|
240
|
-
map
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
getSourceMapReference(bundle, map) {
|
|
244
|
-
if (map && bundle.env.sourceMap && bundle.bundleBehavior !== 'inline') {
|
|
245
|
-
if (bundle.env.sourceMap && bundle.env.sourceMap.inline) {
|
|
246
|
-
return this.generateSourceMap((0, _Bundle.bundleToInternalBundle)(bundle), map);
|
|
247
|
-
} else {
|
|
248
|
-
return _path().default.basename(bundle.name) + '.map';
|
|
249
|
-
}
|
|
250
|
-
} else {
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
async package(internalBundle, bundleGraph, configs, bundleConfigs) {
|
|
255
|
-
let bundle = _Bundle.NamedBundle.get(internalBundle, bundleGraph, this.options);
|
|
256
|
-
this.report({
|
|
257
|
-
type: 'buildProgress',
|
|
258
|
-
phase: 'packaging',
|
|
259
|
-
bundle
|
|
260
|
-
});
|
|
261
|
-
let packager = await this.config.getPackager(bundle.name);
|
|
262
|
-
let {
|
|
263
|
-
name,
|
|
264
|
-
resolveFrom,
|
|
265
|
-
plugin
|
|
266
|
-
} = packager;
|
|
267
|
-
let measurement;
|
|
268
|
-
try {
|
|
269
|
-
var _configs$get, _bundleConfigs$get;
|
|
270
|
-
measurement = _profiler().tracer.createMeasurement(name, 'packaging', bundle.name, {
|
|
271
|
-
type: bundle.type
|
|
272
|
-
});
|
|
273
|
-
return await plugin.package({
|
|
274
|
-
config: (_configs$get = configs.get(name)) === null || _configs$get === void 0 ? void 0 : _configs$get.result,
|
|
275
|
-
bundleConfig: (_bundleConfigs$get = bundleConfigs.get(name)) === null || _bundleConfigs$get === void 0 ? void 0 : _bundleConfigs$get.result,
|
|
276
|
-
bundle,
|
|
277
|
-
bundleGraph: new _BundleGraph.default(bundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), this.options),
|
|
278
|
-
getSourceMapReference: map => {
|
|
279
|
-
return this.getSourceMapReference(bundle, map);
|
|
280
|
-
},
|
|
281
|
-
options: this.pluginOptions,
|
|
282
|
-
logger: new (_logger().PluginLogger)({
|
|
283
|
-
origin: name
|
|
284
|
-
}),
|
|
285
|
-
tracer: new (_profiler().PluginTracer)({
|
|
286
|
-
origin: name,
|
|
287
|
-
category: 'package'
|
|
288
|
-
}),
|
|
289
|
-
getInlineBundleContents: async (bundle, bundleGraph) => {
|
|
290
|
-
if (bundle.bundleBehavior !== 'inline') {
|
|
291
|
-
throw new Error('Bundle is not inline and unable to retrieve contents');
|
|
292
|
-
}
|
|
293
|
-
let res = await this.getBundleResult((0, _Bundle.bundleToInternalBundle)(bundle),
|
|
294
|
-
// $FlowFixMe
|
|
295
|
-
(0, _BundleGraph.bundleGraphToInternalBundleGraph)(bundleGraph), configs, bundleConfigs);
|
|
296
|
-
return {
|
|
297
|
-
contents: res.contents
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
} catch (e) {
|
|
302
|
-
throw new (_diagnostic().default)({
|
|
303
|
-
diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
|
|
304
|
-
origin: name,
|
|
305
|
-
filePath: _path().default.join(bundle.target.distDir, bundle.name)
|
|
306
|
-
})
|
|
307
|
-
});
|
|
308
|
-
} finally {
|
|
309
|
-
measurement && measurement.end();
|
|
310
|
-
// Add dev dependency for the packager. This must be done AFTER running it due to
|
|
311
|
-
// the potential for lazy require() that aren't executed until the request runs.
|
|
312
|
-
let devDepRequest = await (0, _DevDepRequest.createDevDependency)({
|
|
313
|
-
specifier: name,
|
|
314
|
-
resolveFrom
|
|
315
|
-
}, this.previousDevDeps, this.options);
|
|
316
|
-
this.devDepRequests.set(`${name}:${(0, _projectPath.fromProjectPathRelative)(resolveFrom)}`, devDepRequest);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
async optimize(internalBundle, internalBundleGraph, type, contents, map, configs, bundleConfigs) {
|
|
320
|
-
let bundle = _Bundle.NamedBundle.get(internalBundle, internalBundleGraph, this.options);
|
|
321
|
-
let bundleGraph = new _BundleGraph.default(internalBundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), this.options);
|
|
322
|
-
let optimizers = await this.config.getOptimizers(bundle.name, internalBundle.pipeline);
|
|
323
|
-
if (!optimizers.length) {
|
|
324
|
-
return {
|
|
325
|
-
type: bundle.type,
|
|
326
|
-
contents,
|
|
327
|
-
map
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
this.report({
|
|
331
|
-
type: 'buildProgress',
|
|
332
|
-
phase: 'optimizing',
|
|
333
|
-
bundle
|
|
334
|
-
});
|
|
335
|
-
let optimized = {
|
|
336
|
-
type,
|
|
337
|
-
contents,
|
|
338
|
-
map
|
|
339
|
-
};
|
|
340
|
-
for (let optimizer of optimizers) {
|
|
341
|
-
let measurement;
|
|
342
|
-
try {
|
|
343
|
-
var _configs$get2, _bundleConfigs$get2;
|
|
344
|
-
measurement = _profiler().tracer.createMeasurement(optimizer.name, 'optimize', bundle.name);
|
|
345
|
-
let next = await optimizer.plugin.optimize({
|
|
346
|
-
config: (_configs$get2 = configs.get(optimizer.name)) === null || _configs$get2 === void 0 ? void 0 : _configs$get2.result,
|
|
347
|
-
bundleConfig: (_bundleConfigs$get2 = bundleConfigs.get(optimizer.name)) === null || _bundleConfigs$get2 === void 0 ? void 0 : _bundleConfigs$get2.result,
|
|
348
|
-
bundle,
|
|
349
|
-
bundleGraph,
|
|
350
|
-
contents: optimized.contents,
|
|
351
|
-
map: optimized.map,
|
|
352
|
-
getSourceMapReference: map => {
|
|
353
|
-
return this.getSourceMapReference(bundle, map);
|
|
354
|
-
},
|
|
355
|
-
options: this.pluginOptions,
|
|
356
|
-
logger: new (_logger().PluginLogger)({
|
|
357
|
-
origin: optimizer.name
|
|
358
|
-
}),
|
|
359
|
-
tracer: new (_profiler().PluginTracer)({
|
|
360
|
-
origin: optimizer.name,
|
|
361
|
-
category: 'optimize'
|
|
362
|
-
})
|
|
363
|
-
});
|
|
364
|
-
optimized.type = next.type ?? optimized.type;
|
|
365
|
-
optimized.contents = next.contents;
|
|
366
|
-
optimized.map = next.map;
|
|
367
|
-
} catch (e) {
|
|
368
|
-
throw new (_diagnostic().default)({
|
|
369
|
-
diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
|
|
370
|
-
origin: optimizer.name,
|
|
371
|
-
filePath: _path().default.join(bundle.target.distDir, bundle.name)
|
|
372
|
-
})
|
|
373
|
-
});
|
|
374
|
-
} finally {
|
|
375
|
-
measurement && measurement.end();
|
|
376
|
-
// Add dev dependency for the optimizer. This must be done AFTER running it due to
|
|
377
|
-
// the potential for lazy require() that aren't executed until the request runs.
|
|
378
|
-
let devDepRequest = await (0, _DevDepRequest.createDevDependency)({
|
|
379
|
-
specifier: optimizer.name,
|
|
380
|
-
resolveFrom: optimizer.resolveFrom
|
|
381
|
-
}, this.previousDevDeps, this.options);
|
|
382
|
-
this.devDepRequests.set(`${optimizer.name}:${(0, _projectPath.fromProjectPathRelative)(optimizer.resolveFrom)}`, devDepRequest);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
return optimized;
|
|
386
|
-
}
|
|
387
|
-
async generateSourceMap(bundle, map) {
|
|
388
|
-
// sourceRoot should be a relative path between outDir and rootDir for node.js targets
|
|
389
|
-
let filePath = (0, _projectPath.joinProjectPath)(bundle.target.distDir, (0, _nullthrows().default)(bundle.name));
|
|
390
|
-
let fullPath = (0, _projectPath.fromProjectPath)(this.options.projectRoot, filePath);
|
|
391
|
-
let sourceRoot = _path().default.relative(_path().default.dirname(fullPath), this.options.projectRoot);
|
|
392
|
-
let inlineSources = false;
|
|
393
|
-
if (bundle.target) {
|
|
394
|
-
if (bundle.env.sourceMap && bundle.env.sourceMap.sourceRoot !== undefined) {
|
|
395
|
-
sourceRoot = bundle.env.sourceMap.sourceRoot;
|
|
396
|
-
} else if (this.options.serveOptions && bundle.target.env.context === 'browser') {
|
|
397
|
-
sourceRoot = '/__parcel_source_root';
|
|
398
|
-
}
|
|
399
|
-
if (bundle.env.sourceMap && bundle.env.sourceMap.inlineSources !== undefined) {
|
|
400
|
-
inlineSources = bundle.env.sourceMap.inlineSources;
|
|
401
|
-
} else if (bundle.target.env.context !== 'node') {
|
|
402
|
-
// inlining should only happen in production for browser targets by default
|
|
403
|
-
inlineSources = this.options.mode === 'production';
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
let isInlineMap = bundle.env.sourceMap && bundle.env.sourceMap.inline;
|
|
407
|
-
let stringified = await map.stringify({
|
|
408
|
-
file: _path().default.basename(fullPath + '.map'),
|
|
409
|
-
// $FlowFixMe
|
|
410
|
-
fs: this.options.inputFS,
|
|
411
|
-
rootDir: this.options.projectRoot,
|
|
412
|
-
sourceRoot: !inlineSources ? _url().default.format(_url().default.parse(sourceRoot + '/')) : undefined,
|
|
413
|
-
inlineSources,
|
|
414
|
-
format: isInlineMap ? 'inline' : 'string'
|
|
415
|
-
});
|
|
416
|
-
(0, _assert().default)(typeof stringified === 'string');
|
|
417
|
-
return stringified;
|
|
418
|
-
}
|
|
419
|
-
async getCacheKey(bundle, bundleGraph, configs, bundleConfigs, invalidations) {
|
|
420
|
-
let configResults = {};
|
|
421
|
-
for (let [pluginName, config] of configs) {
|
|
422
|
-
if (config) {
|
|
423
|
-
configResults[pluginName] = await (0, _ConfigRequest.getConfigHash)(config, pluginName, this.options);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
let globalInfoResults = {};
|
|
427
|
-
for (let [pluginName, config] of bundleConfigs) {
|
|
428
|
-
if (config) {
|
|
429
|
-
globalInfoResults[pluginName] = await (0, _ConfigRequest.getConfigHash)(config, pluginName, this.options);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
let devDepHashes = await this.getDevDepHashes(bundle);
|
|
433
|
-
for (let inlineBundle of bundleGraph.getInlineBundles(bundle)) {
|
|
434
|
-
devDepHashes += await this.getDevDepHashes(inlineBundle);
|
|
435
|
-
}
|
|
436
|
-
let invalidationHash = await (0, _assetUtils.getInvalidationHash)(invalidations, this.options);
|
|
437
|
-
return (0, _rust().hashString)(_constants.ATLASPACK_VERSION + devDepHashes + invalidationHash + bundle.target.publicUrl + bundleGraph.getHash(bundle) + JSON.stringify(configResults) + JSON.stringify(globalInfoResults) + this.options.mode + (this.options.shouldBuildLazily ? 'lazy' : 'eager'));
|
|
438
|
-
}
|
|
439
|
-
async getDevDepHashes(bundle) {
|
|
440
|
-
var _this$devDepRequests$;
|
|
441
|
-
let name = (0, _nullthrows().default)(bundle.name);
|
|
442
|
-
let packager = await this.config.getPackager(name);
|
|
443
|
-
let optimizers = await this.config.getOptimizers(name);
|
|
444
|
-
let key = `${packager.name}:${(0, _projectPath.fromProjectPathRelative)(packager.resolveFrom)}`;
|
|
445
|
-
let devDepHashes = ((_this$devDepRequests$ = this.devDepRequests.get(key)) === null || _this$devDepRequests$ === void 0 ? void 0 : _this$devDepRequests$.hash) ?? this.previousDevDeps.get(key) ?? '';
|
|
446
|
-
for (let {
|
|
447
|
-
name,
|
|
448
|
-
resolveFrom
|
|
449
|
-
} of optimizers) {
|
|
450
|
-
var _this$devDepRequests$2;
|
|
451
|
-
let key = `${name}:${(0, _projectPath.fromProjectPathRelative)(resolveFrom)}`;
|
|
452
|
-
devDepHashes += ((_this$devDepRequests$2 = this.devDepRequests.get(key)) === null || _this$devDepRequests$2 === void 0 ? void 0 : _this$devDepRequests$2.hash) ?? this.previousDevDeps.get(key) ?? '';
|
|
453
|
-
}
|
|
454
|
-
return devDepHashes;
|
|
455
|
-
}
|
|
456
|
-
async readFromCache(cacheKey) {
|
|
457
|
-
let contentKey = PackagerRunner.getContentKey(cacheKey);
|
|
458
|
-
let mapKey = PackagerRunner.getMapKey(cacheKey);
|
|
459
|
-
let isLargeBlob = await this.options.cache.hasLargeBlob(contentKey);
|
|
460
|
-
let contentExists = isLargeBlob || (await this.options.cache.has(contentKey));
|
|
461
|
-
if (!contentExists) {
|
|
462
|
-
return null;
|
|
463
|
-
}
|
|
464
|
-
let mapExists = await this.options.cache.has(mapKey);
|
|
465
|
-
return {
|
|
466
|
-
contents: isLargeBlob ? this.options.cache.getStream(contentKey) : (0, _utils().blobToStream)(await this.options.cache.getBlob(contentKey)),
|
|
467
|
-
map: mapExists ? (0, _utils().blobToStream)(await this.options.cache.getBlob(mapKey)) : null
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
async writeToCache(cacheKeys, type, contents, map) {
|
|
471
|
-
let size = 0;
|
|
472
|
-
let hash;
|
|
473
|
-
let hashReferences = [];
|
|
474
|
-
let isLargeBlob = false;
|
|
475
|
-
|
|
476
|
-
// TODO: don't replace hash references in binary files??
|
|
477
|
-
if (contents instanceof _stream().Readable) {
|
|
478
|
-
isLargeBlob = true;
|
|
479
|
-
let boundaryStr = '';
|
|
480
|
-
let h = new (_rust().Hash)();
|
|
481
|
-
await this.options.cache.setStream(cacheKeys.content, (0, _utils().blobToStream)(contents).pipe(new (_utils().TapStream)(buf => {
|
|
482
|
-
let str = boundaryStr + buf.toString();
|
|
483
|
-
hashReferences = hashReferences.concat(str.match(_constants.HASH_REF_REGEX) ?? []);
|
|
484
|
-
size += buf.length;
|
|
485
|
-
h.writeBuffer(buf);
|
|
486
|
-
boundaryStr = str.slice(str.length - BOUNDARY_LENGTH);
|
|
487
|
-
})));
|
|
488
|
-
hash = h.finish();
|
|
489
|
-
} else if (typeof contents === 'string') {
|
|
490
|
-
let buffer = Buffer.from(contents);
|
|
491
|
-
size = buffer.byteLength;
|
|
492
|
-
hash = (0, _rust().hashBuffer)(buffer);
|
|
493
|
-
hashReferences = contents.match(_constants.HASH_REF_REGEX) ?? [];
|
|
494
|
-
await this.options.cache.setBlob(cacheKeys.content, buffer);
|
|
495
|
-
} else {
|
|
496
|
-
size = contents.length;
|
|
497
|
-
hash = (0, _rust().hashBuffer)(contents);
|
|
498
|
-
hashReferences = contents.toString().match(_constants.HASH_REF_REGEX) ?? [];
|
|
499
|
-
await this.options.cache.setBlob(cacheKeys.content, contents);
|
|
500
|
-
}
|
|
501
|
-
if (map != null) {
|
|
502
|
-
await this.options.cache.setBlob(cacheKeys.map, map);
|
|
503
|
-
}
|
|
504
|
-
let info = {
|
|
505
|
-
type,
|
|
506
|
-
size,
|
|
507
|
-
hash,
|
|
508
|
-
hashReferences,
|
|
509
|
-
cacheKeys,
|
|
510
|
-
isLargeBlob
|
|
511
|
-
};
|
|
512
|
-
await this.options.cache.set(cacheKeys.info, info);
|
|
513
|
-
return info;
|
|
514
|
-
}
|
|
515
|
-
static getContentKey(cacheKey) {
|
|
516
|
-
return (0, _rust().hashString)(`${cacheKey}:content`);
|
|
517
|
-
}
|
|
518
|
-
static getMapKey(cacheKey) {
|
|
519
|
-
return (0, _rust().hashString)(`${cacheKey}:map`);
|
|
520
|
-
}
|
|
521
|
-
static getInfoKey(cacheKey) {
|
|
522
|
-
return (0, _rust().hashString)(`${cacheKey}:info`);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
exports.default = PackagerRunner;
|
package/lib/ReporterRunner.js
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
exports.report = report;
|
|
8
|
-
exports.reportWorker = reportWorker;
|
|
9
|
-
function _assert() {
|
|
10
|
-
const data = _interopRequireDefault(require("assert"));
|
|
11
|
-
_assert = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
var _Bundle = require("./public/Bundle");
|
|
17
|
-
function _workers() {
|
|
18
|
-
const data = _interopRequireWildcard(require("@atlaspack/workers"));
|
|
19
|
-
_workers = function () {
|
|
20
|
-
return data;
|
|
21
|
-
};
|
|
22
|
-
return data;
|
|
23
|
-
}
|
|
24
|
-
function _logger() {
|
|
25
|
-
const data = _interopRequireWildcard(require("@atlaspack/logger"));
|
|
26
|
-
_logger = function () {
|
|
27
|
-
return data;
|
|
28
|
-
};
|
|
29
|
-
return data;
|
|
30
|
-
}
|
|
31
|
-
var _PluginOptions = _interopRequireDefault(require("./public/PluginOptions"));
|
|
32
|
-
var _BundleGraph = _interopRequireDefault(require("./BundleGraph"));
|
|
33
|
-
function _profiler() {
|
|
34
|
-
const data = require("@atlaspack/profiler");
|
|
35
|
-
_profiler = function () {
|
|
36
|
-
return data;
|
|
37
|
-
};
|
|
38
|
-
return data;
|
|
39
|
-
}
|
|
40
|
-
function _diagnostic() {
|
|
41
|
-
const data = require("@atlaspack/diagnostic");
|
|
42
|
-
_diagnostic = function () {
|
|
43
|
-
return data;
|
|
44
|
-
};
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
48
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
49
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
50
|
-
const instances = new Set();
|
|
51
|
-
class ReporterRunner {
|
|
52
|
-
constructor(opts) {
|
|
53
|
-
this.errors = [];
|
|
54
|
-
this.options = opts.options;
|
|
55
|
-
this.reporters = opts.reporters;
|
|
56
|
-
this.workerFarm = opts.workerFarm;
|
|
57
|
-
this.pluginOptions = new _PluginOptions.default(this.options);
|
|
58
|
-
_logger().default.onLog(event => this.report(event));
|
|
59
|
-
_profiler().tracer.onTrace(event => this.report(event));
|
|
60
|
-
_workers().bus.on('reporterEvent', this.eventHandler);
|
|
61
|
-
instances.add(this);
|
|
62
|
-
if (this.options.shouldPatchConsole) {
|
|
63
|
-
(0, _logger().patchConsole)();
|
|
64
|
-
} else {
|
|
65
|
-
(0, _logger().unpatchConsole)();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
eventHandler = event => {
|
|
69
|
-
if (event.type === 'buildProgress' && (event.phase === 'optimizing' || event.phase === 'packaging') && !(event.bundle instanceof _Bundle.NamedBundle)) {
|
|
70
|
-
// $FlowFixMe[prop-missing]
|
|
71
|
-
let bundleGraphRef = event.bundleGraphRef;
|
|
72
|
-
// $FlowFixMe[incompatible-exact]
|
|
73
|
-
let bundle = event.bundle;
|
|
74
|
-
// Convert any internal bundles back to their public equivalents as reporting
|
|
75
|
-
// is public api
|
|
76
|
-
let bundleGraph = this.workerFarm.workerApi.getSharedReference(
|
|
77
|
-
// $FlowFixMe
|
|
78
|
-
bundleGraphRef);
|
|
79
|
-
(0, _assert().default)(bundleGraph instanceof _BundleGraph.default);
|
|
80
|
-
// $FlowFixMe[incompatible-call]
|
|
81
|
-
this.report({
|
|
82
|
-
...event,
|
|
83
|
-
bundle: _Bundle.NamedBundle.get(bundle, bundleGraph, this.options)
|
|
84
|
-
});
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
this.report(event);
|
|
88
|
-
};
|
|
89
|
-
async report(unsanitisedEvent) {
|
|
90
|
-
let event = unsanitisedEvent;
|
|
91
|
-
if (event.diagnostics) {
|
|
92
|
-
// Sanitise input before passing to reporters
|
|
93
|
-
// $FlowFixMe too complex to narrow down by type
|
|
94
|
-
event = {
|
|
95
|
-
...event,
|
|
96
|
-
diagnostics: (0, _diagnostic().anyToDiagnostic)(event.diagnostics)
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
for (let reporter of this.reporters) {
|
|
100
|
-
let measurement;
|
|
101
|
-
try {
|
|
102
|
-
// To avoid an infinite loop we don't measure trace events, as they'll
|
|
103
|
-
// result in another trace!
|
|
104
|
-
if (event.type !== 'trace') {
|
|
105
|
-
measurement = _profiler().tracer.createMeasurement(reporter.name, 'reporter');
|
|
106
|
-
}
|
|
107
|
-
await reporter.plugin.report({
|
|
108
|
-
// $FlowFixMe
|
|
109
|
-
event,
|
|
110
|
-
options: this.pluginOptions,
|
|
111
|
-
logger: new (_logger().PluginLogger)({
|
|
112
|
-
origin: reporter.name
|
|
113
|
-
}),
|
|
114
|
-
tracer: new (_profiler().PluginTracer)({
|
|
115
|
-
origin: reporter.name,
|
|
116
|
-
category: 'reporter'
|
|
117
|
-
})
|
|
118
|
-
});
|
|
119
|
-
} catch (reportError) {
|
|
120
|
-
if (event.type !== 'buildSuccess') {
|
|
121
|
-
// This will be captured by consumers
|
|
122
|
-
_logger().INTERNAL_ORIGINAL_CONSOLE.error(reportError);
|
|
123
|
-
}
|
|
124
|
-
this.errors.push(reportError);
|
|
125
|
-
} finally {
|
|
126
|
-
measurement && measurement.end();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
dispose() {
|
|
131
|
-
_workers().bus.off('reporterEvent', this.eventHandler);
|
|
132
|
-
instances.delete(this);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.default = ReporterRunner;
|
|
136
|
-
function reportWorker(workerApi, event) {
|
|
137
|
-
if (event.type === 'buildProgress' && (event.phase === 'optimizing' || event.phase === 'packaging')) {
|
|
138
|
-
// Convert any public api bundles to their internal equivalents for
|
|
139
|
-
// easy serialization
|
|
140
|
-
_workers().bus.emit('reporterEvent', {
|
|
141
|
-
...event,
|
|
142
|
-
bundle: (0, _Bundle.bundleToInternalBundle)(event.bundle),
|
|
143
|
-
bundleGraphRef: workerApi.resolveSharedReference((0, _Bundle.bundleToInternalBundleGraph)(event.bundle))
|
|
144
|
-
});
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
_workers().bus.emit('reporterEvent', event);
|
|
148
|
-
}
|
|
149
|
-
async function report(event) {
|
|
150
|
-
await Promise.all([...instances].map(instance => instance.report(event)));
|
|
151
|
-
}
|