@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/applyRuntimes.js
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = applyRuntimes;
|
|
7
|
-
function _path() {
|
|
8
|
-
const data = _interopRequireDefault(require("path"));
|
|
9
|
-
_path = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _assert() {
|
|
15
|
-
const data = _interopRequireDefault(require("assert"));
|
|
16
|
-
_assert = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _nullthrows() {
|
|
22
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
23
|
-
_nullthrows = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
var _AssetGraph = require("./AssetGraph");
|
|
29
|
-
var _BundleGraph = _interopRequireDefault(require("./public/BundleGraph"));
|
|
30
|
-
var _BundleGraph2 = _interopRequireWildcard(require("./BundleGraph"));
|
|
31
|
-
var _Bundle = require("./public/Bundle");
|
|
32
|
-
function _logger() {
|
|
33
|
-
const data = require("@atlaspack/logger");
|
|
34
|
-
_logger = function () {
|
|
35
|
-
return data;
|
|
36
|
-
};
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
function _rust() {
|
|
40
|
-
const data = require("@atlaspack/rust");
|
|
41
|
-
_rust = function () {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
return data;
|
|
45
|
-
}
|
|
46
|
-
function _diagnostic() {
|
|
47
|
-
const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
|
|
48
|
-
_diagnostic = function () {
|
|
49
|
-
return data;
|
|
50
|
-
};
|
|
51
|
-
return data;
|
|
52
|
-
}
|
|
53
|
-
var _Dependency = require("./public/Dependency");
|
|
54
|
-
var _Environment = require("./Environment");
|
|
55
|
-
var _AssetGraphRequest = _interopRequireDefault(require("./requests/AssetGraphRequest"));
|
|
56
|
-
var _DevDepRequest = require("./requests/DevDepRequest");
|
|
57
|
-
var _projectPath = require("./projectPath");
|
|
58
|
-
function _profiler() {
|
|
59
|
-
const data = require("@atlaspack/profiler");
|
|
60
|
-
_profiler = function () {
|
|
61
|
-
return data;
|
|
62
|
-
};
|
|
63
|
-
return data;
|
|
64
|
-
}
|
|
65
|
-
function _utils() {
|
|
66
|
-
const data = require("@atlaspack/utils");
|
|
67
|
-
_utils = function () {
|
|
68
|
-
return data;
|
|
69
|
-
};
|
|
70
|
-
return data;
|
|
71
|
-
}
|
|
72
|
-
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); }
|
|
73
|
-
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; }
|
|
74
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
75
|
-
function nameRuntimeBundle(bundle, siblingBundle) {
|
|
76
|
-
// We don't run custom namers on runtime bundles as the runtime assumes that they are
|
|
77
|
-
// located at the same nesting level as their owning bundle. Custom naming could
|
|
78
|
-
// be added in future as long as the custom name is validated.
|
|
79
|
-
let {
|
|
80
|
-
hashReference
|
|
81
|
-
} = bundle;
|
|
82
|
-
let name = (0, _nullthrows().default)(siblingBundle.name)
|
|
83
|
-
// Remove the existing hash from standard file patterns
|
|
84
|
-
// e.g. 'main.[hash].js' -> 'main.js' or 'main~[hash].js' -> 'main.js'
|
|
85
|
-
.replace(new RegExp(`[\\.~\\-_]?${siblingBundle.hashReference}`), '')
|
|
86
|
-
// Ensure the file ends with 'runtime.[hash].js'
|
|
87
|
-
.replace(`.${bundle.type}`, `.runtime.${hashReference}.${bundle.type}`);
|
|
88
|
-
bundle.name = name;
|
|
89
|
-
bundle.displayName = name.replace(hashReference, '[hash]');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* The applyRuntimes function is responsible for generating all the runtimes
|
|
94
|
-
* (assets created during the build that don't actually exist on disk) and then
|
|
95
|
-
* linking them into the bundle graph.
|
|
96
|
-
*
|
|
97
|
-
* Introduction of manifest bundles: https://github.com/parcel-bundler/parcel/pull/8837
|
|
98
|
-
* Introduction of reverse topology: https://github.com/parcel-bundler/parcel/pull/8981
|
|
99
|
-
*/
|
|
100
|
-
async function applyRuntimes({
|
|
101
|
-
bundleGraph,
|
|
102
|
-
config,
|
|
103
|
-
options,
|
|
104
|
-
pluginOptions,
|
|
105
|
-
api,
|
|
106
|
-
optionsRef,
|
|
107
|
-
previousDevDeps,
|
|
108
|
-
devDepRequests,
|
|
109
|
-
configs
|
|
110
|
-
}) {
|
|
111
|
-
let runtimes = await config.getRuntimes();
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Usually, the assets returned from a runtime will go in the same bundle. It is
|
|
115
|
-
* possible though, for a runtime to return an asset with a `parallel` priority,
|
|
116
|
-
* which allows it to be moved to a separate bundle. In practice, this is
|
|
117
|
-
* usually used to generate application manifest files.
|
|
118
|
-
*
|
|
119
|
-
* When adding a manifest bundle (a whole new separate bundle) during a runtime,
|
|
120
|
-
* it needs to be added to a bundle group which will be potentially referenced
|
|
121
|
-
* by another bundle group. To avoid trying to reference a manifest entry which
|
|
122
|
-
* hasn't been created yet, we process the bundles from the bottom up (topological
|
|
123
|
-
* order), so that children will always be available when parents try to reference
|
|
124
|
-
* them.
|
|
125
|
-
*/
|
|
126
|
-
let bundles = [];
|
|
127
|
-
bundleGraph.traverseBundles({
|
|
128
|
-
exit(bundle) {
|
|
129
|
-
bundles.push(bundle);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
let connectionMap = new (_utils().DefaultMap)(() => []);
|
|
133
|
-
for (let bundle of bundles) {
|
|
134
|
-
for (let runtime of runtimes) {
|
|
135
|
-
let measurement;
|
|
136
|
-
try {
|
|
137
|
-
var _configs$get;
|
|
138
|
-
const namedBundle = _Bundle.NamedBundle.get(bundle, bundleGraph, options);
|
|
139
|
-
measurement = _profiler().tracer.createMeasurement(runtime.name, 'applyRuntime', namedBundle.displayName);
|
|
140
|
-
let applied = await runtime.plugin.apply({
|
|
141
|
-
bundle: namedBundle,
|
|
142
|
-
bundleGraph: new _BundleGraph.default(bundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), options),
|
|
143
|
-
config: (_configs$get = configs.get(runtime.name)) === null || _configs$get === void 0 ? void 0 : _configs$get.result,
|
|
144
|
-
options: pluginOptions,
|
|
145
|
-
logger: new (_logger().PluginLogger)({
|
|
146
|
-
origin: runtime.name
|
|
147
|
-
}),
|
|
148
|
-
tracer: new (_profiler().PluginTracer)({
|
|
149
|
-
origin: runtime.name,
|
|
150
|
-
category: 'applyRuntime'
|
|
151
|
-
})
|
|
152
|
-
});
|
|
153
|
-
if (applied) {
|
|
154
|
-
let runtimeAssets = Array.isArray(applied) ? applied : [applied];
|
|
155
|
-
for (let {
|
|
156
|
-
code,
|
|
157
|
-
dependency,
|
|
158
|
-
filePath,
|
|
159
|
-
isEntry,
|
|
160
|
-
env,
|
|
161
|
-
priority
|
|
162
|
-
} of runtimeAssets) {
|
|
163
|
-
let sourceName = _path().default.join(_path().default.dirname(filePath), `runtime-${(0, _rust().hashString)(code)}.${bundle.type}`);
|
|
164
|
-
let assetGroup = {
|
|
165
|
-
code,
|
|
166
|
-
filePath: (0, _projectPath.toProjectPath)(options.projectRoot, sourceName),
|
|
167
|
-
env: (0, _Environment.mergeEnvironments)(options.projectRoot, bundle.env, env),
|
|
168
|
-
// Runtime assets should be considered source, as they should be
|
|
169
|
-
// e.g. compiled to run in the target environment
|
|
170
|
-
isSource: true
|
|
171
|
-
};
|
|
172
|
-
let connectionBundle = bundle;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* If a runtime asset is marked with a priority of `parallel` this
|
|
176
|
-
* means we need to create a new bundle for the asset and add it to
|
|
177
|
-
* all the same bundle groups.
|
|
178
|
-
*/
|
|
179
|
-
if (priority === 'parallel' && !bundle.needsStableName) {
|
|
180
|
-
let bundleGroups = bundleGraph.getBundleGroupsContainingBundle(bundle);
|
|
181
|
-
connectionBundle = (0, _nullthrows().default)(bundleGraph.createBundle({
|
|
182
|
-
type: bundle.type,
|
|
183
|
-
needsStableName: false,
|
|
184
|
-
env: bundle.env,
|
|
185
|
-
target: bundle.target,
|
|
186
|
-
uniqueKey: 'runtime-manifest:' + bundle.id,
|
|
187
|
-
shouldContentHash: options.shouldContentHash
|
|
188
|
-
}));
|
|
189
|
-
for (let bundleGroup of bundleGroups) {
|
|
190
|
-
bundleGraph.addBundleToBundleGroup(connectionBundle, bundleGroup);
|
|
191
|
-
}
|
|
192
|
-
bundleGraph.createBundleReference(bundle, connectionBundle);
|
|
193
|
-
|
|
194
|
-
// Ensure we name the bundle now as all other bundles have already
|
|
195
|
-
// been named as this point.
|
|
196
|
-
nameRuntimeBundle(connectionBundle, bundle);
|
|
197
|
-
}
|
|
198
|
-
connectionMap.get(connectionBundle).push({
|
|
199
|
-
bundle: connectionBundle,
|
|
200
|
-
assetGroup,
|
|
201
|
-
dependency,
|
|
202
|
-
isEntry
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
} catch (e) {
|
|
207
|
-
throw new (_diagnostic().default)({
|
|
208
|
-
diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
|
|
209
|
-
origin: runtime.name
|
|
210
|
-
})
|
|
211
|
-
});
|
|
212
|
-
} finally {
|
|
213
|
-
measurement && measurement.end();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* When merging the connections in to the bundle graph, the topological
|
|
220
|
-
* order can create module not found errors in some situations, often when HMR
|
|
221
|
-
* is enabled. To fix this, we put the connections into DFS order.
|
|
222
|
-
*
|
|
223
|
-
* Note: While DFS order seems to be the most reliable order to process the
|
|
224
|
-
* connections, this is likely due to it being close to the order that the bundles were
|
|
225
|
-
* inserted into the graph. There is a known issue where runtime assets marked
|
|
226
|
-
* as `isEntry` can create scenarios where there is no correct load order that
|
|
227
|
-
* won't error, as the entry runtime assets are added to many bundles in a
|
|
228
|
-
* single bundle group but their dependencies are not.
|
|
229
|
-
*
|
|
230
|
-
* This issue is almost exclusive to HMR scenarios as the two HMR runtime
|
|
231
|
-
* plugins (@atlaspack/runtime-browser-hmr and @atlaspack/runtime-react-refresh)
|
|
232
|
-
* are the only known cases where a runtime asset is marked as `isEntry`.
|
|
233
|
-
*/
|
|
234
|
-
let connections = [];
|
|
235
|
-
bundleGraph.traverseBundles({
|
|
236
|
-
enter(bundle) {
|
|
237
|
-
connections.push(...connectionMap.get(bundle));
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// Add dev deps for runtime plugins AFTER running them, to account for lazy require().
|
|
242
|
-
for (let runtime of runtimes) {
|
|
243
|
-
let devDepRequest = await (0, _DevDepRequest.createDevDependency)({
|
|
244
|
-
specifier: runtime.name,
|
|
245
|
-
resolveFrom: runtime.resolveFrom
|
|
246
|
-
}, previousDevDeps, options);
|
|
247
|
-
devDepRequests.set(`${devDepRequest.specifier}:${(0, _projectPath.fromProjectPathRelative)(devDepRequest.resolveFrom)}`, devDepRequest);
|
|
248
|
-
await (0, _DevDepRequest.runDevDepRequest)(api, devDepRequest);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Create a new AssetGraph from the generated runtime assets which also runs
|
|
252
|
-
// transforms and resolves all dependencies.
|
|
253
|
-
let {
|
|
254
|
-
assetGraph: runtimesAssetGraph,
|
|
255
|
-
changedAssets
|
|
256
|
-
} = await reconcileNewRuntimes(api, connections, optionsRef);
|
|
257
|
-
|
|
258
|
-
// Convert the runtime AssetGraph into a BundleGraph, this includes assigning
|
|
259
|
-
// the assets their public ids
|
|
260
|
-
let runtimesBundleGraph = _BundleGraph2.default.fromAssetGraph(runtimesAssetGraph, options.mode === 'production', bundleGraph._publicIdByAssetId, bundleGraph._assetPublicIds);
|
|
261
|
-
|
|
262
|
-
// Merge the runtimes bundle graph into the main bundle graph.
|
|
263
|
-
bundleGraph.merge(runtimesBundleGraph);
|
|
264
|
-
|
|
265
|
-
// Add the public id mappings from the runtumes bundlegraph to the main bundle graph
|
|
266
|
-
for (let [assetId, publicId] of runtimesBundleGraph._publicIdByAssetId) {
|
|
267
|
-
bundleGraph._publicIdByAssetId.set(assetId, publicId);
|
|
268
|
-
bundleGraph._assetPublicIds.add(publicId);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Connect each of the generated runtime assets to bundles in the main bundle
|
|
272
|
-
// graph. This is like a mini-bundling algorithm for runtime assets.
|
|
273
|
-
for (let {
|
|
274
|
-
bundle,
|
|
275
|
-
assetGroup,
|
|
276
|
-
dependency,
|
|
277
|
-
isEntry
|
|
278
|
-
} of connections) {
|
|
279
|
-
let assetGroupNode = (0, _AssetGraph.nodeFromAssetGroup)(assetGroup);
|
|
280
|
-
let assetGroupAssetNodeIds = runtimesAssetGraph.getNodeIdsConnectedFrom(runtimesAssetGraph.getNodeIdByContentKey(assetGroupNode.id));
|
|
281
|
-
(0, _assert().default)(assetGroupAssetNodeIds.length === 1);
|
|
282
|
-
let runtimeNodeId = assetGroupAssetNodeIds[0];
|
|
283
|
-
let runtimeNode = (0, _nullthrows().default)(runtimesAssetGraph.getNode(runtimeNodeId));
|
|
284
|
-
(0, _assert().default)(runtimeNode.type === 'asset');
|
|
285
|
-
|
|
286
|
-
// Find the asset that the runtime asset should be connected from by resolving
|
|
287
|
-
// it's dependency.
|
|
288
|
-
let resolution = dependency && bundleGraph.getResolvedAsset((0, _Dependency.dependencyToInternalDependency)(dependency), bundle);
|
|
289
|
-
|
|
290
|
-
// Walk all the dependencies of the runtime assets and check if they are
|
|
291
|
-
// already reachable from the bundle that the runtime asset is assigned to.
|
|
292
|
-
// If so, we add them to `duplicatedContentKeys` to be skipped when assigning
|
|
293
|
-
// assets to bundles.
|
|
294
|
-
let runtimesBundleGraphRuntimeNodeId = runtimesBundleGraph._graph.getNodeIdByContentKey(runtimeNode.id);
|
|
295
|
-
let duplicatedContentKeys = new Set();
|
|
296
|
-
runtimesBundleGraph._graph.traverse((nodeId, _, actions) => {
|
|
297
|
-
let node = (0, _nullthrows().default)(runtimesBundleGraph._graph.getNode(nodeId));
|
|
298
|
-
if (node.type !== 'dependency') {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
let assets = runtimesBundleGraph._graph.getNodeIdsConnectedFrom(nodeId).map(assetNodeId => {
|
|
302
|
-
let assetNode = (0, _nullthrows().default)(runtimesBundleGraph._graph.getNode(assetNodeId));
|
|
303
|
-
(0, _assert().default)(assetNode.type === 'asset');
|
|
304
|
-
return assetNode.value;
|
|
305
|
-
});
|
|
306
|
-
for (let asset of assets) {
|
|
307
|
-
if (bundleGraph.isAssetReachableFromBundle(asset, bundle) || (resolution === null || resolution === void 0 ? void 0 : resolution.id) === asset.id) {
|
|
308
|
-
duplicatedContentKeys.add(asset.id);
|
|
309
|
-
actions.skipChildren();
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}, runtimesBundleGraphRuntimeNodeId);
|
|
313
|
-
let bundleNodeId = bundleGraph._graph.getNodeIdByContentKey(bundle.id);
|
|
314
|
-
let bundleGraphRuntimeNodeId = bundleGraph._graph.getNodeIdByContentKey(runtimeNode.id); // the node id is not constant between graphs
|
|
315
|
-
|
|
316
|
-
// Assign the runtime assets and all of it's depepdencies to the bundle unless
|
|
317
|
-
// we have detected it as already being reachable from this bundle via `duplicatedContentKeys`.
|
|
318
|
-
runtimesBundleGraph._graph.traverse((nodeId, _, actions) => {
|
|
319
|
-
let node = (0, _nullthrows().default)(runtimesBundleGraph._graph.getNode(nodeId));
|
|
320
|
-
if (node.type === 'asset' || node.type === 'dependency') {
|
|
321
|
-
if (duplicatedContentKeys.has(node.id)) {
|
|
322
|
-
actions.skipChildren();
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id); // the node id is not constant between graphs
|
|
326
|
-
bundleGraph._graph.addEdge(bundleNodeId, bundleGraphNodeId, _BundleGraph2.bundleGraphEdgeTypes.contains);
|
|
327
|
-
}
|
|
328
|
-
}, runtimesBundleGraphRuntimeNodeId);
|
|
329
|
-
if (isEntry) {
|
|
330
|
-
bundleGraph._graph.addEdge(bundleNodeId, bundleGraphRuntimeNodeId);
|
|
331
|
-
bundle.entryAssetIds.unshift(runtimeNode.id);
|
|
332
|
-
}
|
|
333
|
-
if (dependency == null) {
|
|
334
|
-
// Verify this asset won't become an island
|
|
335
|
-
(0, _assert().default)(bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphRuntimeNodeId).length > 0, 'Runtime must have an inbound dependency or be an entry');
|
|
336
|
-
} else {
|
|
337
|
-
let dependencyNodeId = bundleGraph._graph.getNodeIdByContentKey(dependency.id);
|
|
338
|
-
bundleGraph._graph.addEdge(dependencyNodeId, bundleGraphRuntimeNodeId);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return changedAssets;
|
|
342
|
-
}
|
|
343
|
-
function reconcileNewRuntimes(api, connections, optionsRef) {
|
|
344
|
-
let assetGroups = connections.map(t => t.assetGroup);
|
|
345
|
-
let request = (0, _AssetGraphRequest.default)({
|
|
346
|
-
name: 'Runtimes',
|
|
347
|
-
assetGroups,
|
|
348
|
-
optionsRef
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
// rebuild the graph
|
|
352
|
-
return api.runRequest(request, {
|
|
353
|
-
force: true
|
|
354
|
-
});
|
|
355
|
-
}
|
package/lib/assetUtils.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createAsset = createAsset;
|
|
7
|
-
exports.createAssetIdFromOptions = createAssetIdFromOptions;
|
|
8
|
-
exports.generateFromAST = generateFromAST;
|
|
9
|
-
exports.getInvalidationHash = getInvalidationHash;
|
|
10
|
-
exports.getInvalidationId = getInvalidationId;
|
|
11
|
-
function _stream() {
|
|
12
|
-
const data = require("stream");
|
|
13
|
-
_stream = function () {
|
|
14
|
-
return data;
|
|
15
|
-
};
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
|
-
function _buildCache() {
|
|
19
|
-
const data = require("@atlaspack/build-cache");
|
|
20
|
-
_buildCache = function () {
|
|
21
|
-
return data;
|
|
22
|
-
};
|
|
23
|
-
return data;
|
|
24
|
-
}
|
|
25
|
-
function _logger() {
|
|
26
|
-
const data = require("@atlaspack/logger");
|
|
27
|
-
_logger = function () {
|
|
28
|
-
return data;
|
|
29
|
-
};
|
|
30
|
-
return data;
|
|
31
|
-
}
|
|
32
|
-
function _nullthrows() {
|
|
33
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
34
|
-
_nullthrows = function () {
|
|
35
|
-
return data;
|
|
36
|
-
};
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
var _CommittedAsset = _interopRequireDefault(require("./CommittedAsset"));
|
|
40
|
-
var _UncommittedAsset = _interopRequireDefault(require("./UncommittedAsset"));
|
|
41
|
-
var _loadAtlaspackPlugin = _interopRequireDefault(require("./loadAtlaspackPlugin"));
|
|
42
|
-
var _Asset = require("./public/Asset");
|
|
43
|
-
var _PluginOptions = _interopRequireDefault(require("./public/PluginOptions"));
|
|
44
|
-
function _utils() {
|
|
45
|
-
const data = require("@atlaspack/utils");
|
|
46
|
-
_utils = function () {
|
|
47
|
-
return data;
|
|
48
|
-
};
|
|
49
|
-
return data;
|
|
50
|
-
}
|
|
51
|
-
var _utils2 = require("./utils");
|
|
52
|
-
var _projectPath = require("./projectPath");
|
|
53
|
-
function _rust() {
|
|
54
|
-
const data = require("@atlaspack/rust");
|
|
55
|
-
_rust = function () {
|
|
56
|
-
return data;
|
|
57
|
-
};
|
|
58
|
-
return data;
|
|
59
|
-
}
|
|
60
|
-
var _types = require("./types");
|
|
61
|
-
function _profiler() {
|
|
62
|
-
const data = require("@atlaspack/profiler");
|
|
63
|
-
_profiler = function () {
|
|
64
|
-
return data;
|
|
65
|
-
};
|
|
66
|
-
return data;
|
|
67
|
-
}
|
|
68
|
-
var _IdentifierRegistry = require("./IdentifierRegistry");
|
|
69
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
70
|
-
function createAssetIdFromOptions(options) {
|
|
71
|
-
const data = {
|
|
72
|
-
environmentId: options.env.id,
|
|
73
|
-
filePath: options.filePath,
|
|
74
|
-
code: options.code,
|
|
75
|
-
pipeline: options.pipeline,
|
|
76
|
-
query: options.query,
|
|
77
|
-
uniqueKey: options.uniqueKey,
|
|
78
|
-
fileType: options.type
|
|
79
|
-
};
|
|
80
|
-
const id = (0, _rust().createAssetId)(data);
|
|
81
|
-
_IdentifierRegistry.identifierRegistry.addIdentifier('asset', id, data);
|
|
82
|
-
return id;
|
|
83
|
-
}
|
|
84
|
-
function createAsset(projectRoot, options) {
|
|
85
|
-
return {
|
|
86
|
-
id: options.id != null ? options.id : createAssetIdFromOptions(options),
|
|
87
|
-
committed: options.committed ?? false,
|
|
88
|
-
filePath: options.filePath,
|
|
89
|
-
query: options.query,
|
|
90
|
-
bundleBehavior: options.bundleBehavior ? _types.BundleBehavior[options.bundleBehavior] : null,
|
|
91
|
-
isBundleSplittable: options.isBundleSplittable ?? true,
|
|
92
|
-
type: options.type,
|
|
93
|
-
contentKey: options.contentKey,
|
|
94
|
-
mapKey: options.mapKey,
|
|
95
|
-
astKey: options.astKey,
|
|
96
|
-
astGenerator: options.astGenerator,
|
|
97
|
-
dependencies: options.dependencies || new Map(),
|
|
98
|
-
isSource: options.isSource,
|
|
99
|
-
outputHash: options.outputHash,
|
|
100
|
-
pipeline: options.pipeline,
|
|
101
|
-
env: options.env,
|
|
102
|
-
meta: options.meta || {},
|
|
103
|
-
stats: options.stats,
|
|
104
|
-
symbols: options.symbols && new Map([...options.symbols].map(([k, v]) => [k, {
|
|
105
|
-
local: v.local,
|
|
106
|
-
meta: v.meta,
|
|
107
|
-
loc: (0, _utils2.toInternalSourceLocation)(projectRoot, v.loc)
|
|
108
|
-
}])),
|
|
109
|
-
sideEffects: options.sideEffects ?? true,
|
|
110
|
-
uniqueKey: options.uniqueKey,
|
|
111
|
-
plugin: options.plugin,
|
|
112
|
-
configPath: options.configPath,
|
|
113
|
-
configKeyPath: options.configKeyPath
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
const generateResults = new WeakMap();
|
|
117
|
-
function generateFromAST(asset) {
|
|
118
|
-
let output = generateResults.get(asset.value);
|
|
119
|
-
if (output == null) {
|
|
120
|
-
output = _generateFromAST(asset);
|
|
121
|
-
generateResults.set(asset.value, output);
|
|
122
|
-
}
|
|
123
|
-
return output;
|
|
124
|
-
}
|
|
125
|
-
async function _generateFromAST(asset) {
|
|
126
|
-
var _plugin$generate;
|
|
127
|
-
let ast = await asset.getAST();
|
|
128
|
-
if (ast == null) {
|
|
129
|
-
throw new Error('Asset has no AST');
|
|
130
|
-
}
|
|
131
|
-
let pluginName = (0, _nullthrows().default)(asset.value.plugin);
|
|
132
|
-
let {
|
|
133
|
-
plugin
|
|
134
|
-
} = await (0, _loadAtlaspackPlugin.default)(pluginName, (0, _projectPath.fromProjectPath)(asset.options.projectRoot, (0, _nullthrows().default)(asset.value.configPath)), (0, _nullthrows().default)(asset.value.configKeyPath), asset.options);
|
|
135
|
-
let generate = (_plugin$generate = plugin.generate) === null || _plugin$generate === void 0 ? void 0 : _plugin$generate.bind(plugin);
|
|
136
|
-
if (!generate) {
|
|
137
|
-
throw new Error(`${pluginName} does not have a generate method`);
|
|
138
|
-
}
|
|
139
|
-
let {
|
|
140
|
-
content,
|
|
141
|
-
map
|
|
142
|
-
} = await generate({
|
|
143
|
-
asset: new _Asset.Asset(asset),
|
|
144
|
-
ast,
|
|
145
|
-
options: new _PluginOptions.default(asset.options),
|
|
146
|
-
logger: new (_logger().PluginLogger)({
|
|
147
|
-
origin: pluginName
|
|
148
|
-
}),
|
|
149
|
-
tracer: new (_profiler().PluginTracer)({
|
|
150
|
-
origin: pluginName,
|
|
151
|
-
category: 'asset-generate'
|
|
152
|
-
})
|
|
153
|
-
});
|
|
154
|
-
let mapBuffer = map === null || map === void 0 ? void 0 : map.toBuffer();
|
|
155
|
-
// Store the results in the cache so we can avoid generating again next time
|
|
156
|
-
await Promise.all([asset.options.cache.setStream((0, _nullthrows().default)(asset.value.contentKey), (0, _utils().blobToStream)(content)), mapBuffer != null && asset.options.cache.setBlob((0, _nullthrows().default)(asset.value.mapKey), mapBuffer)]);
|
|
157
|
-
return {
|
|
158
|
-
content: content instanceof _stream().Readable ? asset.options.cache.getStream((0, _nullthrows().default)(asset.value.contentKey)) : content,
|
|
159
|
-
map
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function getInvalidationId(invalidation) {
|
|
163
|
-
switch (invalidation.type) {
|
|
164
|
-
case 'file':
|
|
165
|
-
return 'file:' + (0, _projectPath.fromProjectPathRelative)(invalidation.filePath);
|
|
166
|
-
case 'env':
|
|
167
|
-
return 'env:' + invalidation.key;
|
|
168
|
-
case 'option':
|
|
169
|
-
return 'option:' + invalidation.key;
|
|
170
|
-
default:
|
|
171
|
-
throw new Error('Unknown invalidation type: ' + invalidation.type);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const hashCache = (0, _buildCache().createBuildCache)();
|
|
175
|
-
async function getInvalidationHash(invalidations, options) {
|
|
176
|
-
if (invalidations.length === 0) {
|
|
177
|
-
return '';
|
|
178
|
-
}
|
|
179
|
-
let sortedInvalidations = invalidations.slice().sort((a, b) => getInvalidationId(a) < getInvalidationId(b) ? -1 : 1);
|
|
180
|
-
let hashes = '';
|
|
181
|
-
for (let invalidation of sortedInvalidations) {
|
|
182
|
-
switch (invalidation.type) {
|
|
183
|
-
case 'file':
|
|
184
|
-
{
|
|
185
|
-
// Only recompute the hash of this file if we haven't seen it already during this build.
|
|
186
|
-
let fileHash = hashCache.get(invalidation.filePath);
|
|
187
|
-
if (fileHash == null) {
|
|
188
|
-
fileHash = (0, _utils().hashFile)(options.inputFS, (0, _projectPath.fromProjectPath)(options.projectRoot, invalidation.filePath));
|
|
189
|
-
hashCache.set(invalidation.filePath, fileHash);
|
|
190
|
-
}
|
|
191
|
-
hashes += await fileHash;
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
case 'env':
|
|
195
|
-
hashes += invalidation.key + ':' + (options.env[invalidation.key] || '');
|
|
196
|
-
break;
|
|
197
|
-
case 'option':
|
|
198
|
-
hashes += invalidation.key + ':' + (0, _utils2.hashFromOption)(options[invalidation.key]);
|
|
199
|
-
break;
|
|
200
|
-
default:
|
|
201
|
-
throw new Error('Unknown invalidation type: ' + invalidation.type);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return (0, _rust().hashString)(hashes);
|
|
205
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AtlaspackV3 = void 0;
|
|
7
|
-
function _rust() {
|
|
8
|
-
const data = require("@atlaspack/rust");
|
|
9
|
-
_rust = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
var _NapiWorkerPool = require("./NapiWorkerPool");
|
|
15
|
-
function _diagnostic() {
|
|
16
|
-
const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
|
|
17
|
-
_diagnostic = function () {
|
|
18
|
-
return data;
|
|
19
|
-
};
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
class AtlaspackV3 {
|
|
24
|
-
constructor({
|
|
25
|
-
fs,
|
|
26
|
-
packageManager,
|
|
27
|
-
threads,
|
|
28
|
-
lmdb,
|
|
29
|
-
napiWorkerPool = new _NapiWorkerPool.NapiWorkerPool(),
|
|
30
|
-
...options
|
|
31
|
-
}) {
|
|
32
|
-
options.logLevel = options.logLevel || 'error';
|
|
33
|
-
options.defaultTargetOptions = options.defaultTargetOptions || {};
|
|
34
|
-
// $FlowFixMe "engines" are readonly
|
|
35
|
-
options.defaultTargetOptions.engines = options.defaultTargetOptions.engines || {};
|
|
36
|
-
this._internal = _rust().AtlaspackNapi.create({
|
|
37
|
-
fs,
|
|
38
|
-
packageManager,
|
|
39
|
-
threads,
|
|
40
|
-
options,
|
|
41
|
-
napiWorkerPool
|
|
42
|
-
}, lmdb);
|
|
43
|
-
}
|
|
44
|
-
async buildAssetGraph() {
|
|
45
|
-
let [graph, error] = await this._internal.buildAssetGraph();
|
|
46
|
-
if (error !== null) {
|
|
47
|
-
throw new (_diagnostic().default)({
|
|
48
|
-
diagnostic: error
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return graph;
|
|
52
|
-
}
|
|
53
|
-
respondToFsEvents(events) {
|
|
54
|
-
return this._internal.respondToFsEvents(events);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.AtlaspackV3 = AtlaspackV3;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.NapiWorkerPool = void 0;
|
|
7
|
-
function _worker_threads() {
|
|
8
|
-
const data = require("worker_threads");
|
|
9
|
-
_worker_threads = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _path() {
|
|
15
|
-
const data = _interopRequireDefault(require("path"));
|
|
16
|
-
_path = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _process() {
|
|
22
|
-
const data = _interopRequireDefault(require("process"));
|
|
23
|
-
_process = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _rust() {
|
|
29
|
-
const data = require("@atlaspack/rust");
|
|
30
|
-
_rust = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
36
|
-
const WORKER_PATH = _path().default.join(__dirname, 'worker', 'index.js');
|
|
37
|
-
const ATLASPACK_NAPI_WORKERS = _process().default.env.ATLASPACK_NAPI_WORKERS && parseInt(_process().default.env.ATLASPACK_NAPI_WORKERS, 10);
|
|
38
|
-
class NapiWorkerPool {
|
|
39
|
-
#workers;
|
|
40
|
-
#napiWorkers;
|
|
41
|
-
#workerCount;
|
|
42
|
-
constructor({
|
|
43
|
-
workerCount
|
|
44
|
-
} = {
|
|
45
|
-
workerCount: undefined
|
|
46
|
-
}) {
|
|
47
|
-
this.#workerCount = workerCount ?? ATLASPACK_NAPI_WORKERS ?? (0, _rust().getAvailableThreads)();
|
|
48
|
-
if (!this.#workerCount) {
|
|
49
|
-
// TODO use main thread if workerCount is 0
|
|
50
|
-
}
|
|
51
|
-
this.#workers = [];
|
|
52
|
-
this.#napiWorkers = [];
|
|
53
|
-
for (let i = 0; i < this.#workerCount; i++) {
|
|
54
|
-
let worker = new (_worker_threads().Worker)(WORKER_PATH);
|
|
55
|
-
this.#workers.push(worker);
|
|
56
|
-
this.#napiWorkers.push(new Promise(res => worker.once('message', res)));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
workerCount() {
|
|
60
|
-
return this.#workerCount;
|
|
61
|
-
}
|
|
62
|
-
getWorkers() {
|
|
63
|
-
return Promise.all(this.#napiWorkers);
|
|
64
|
-
}
|
|
65
|
-
shutdown() {
|
|
66
|
-
for (const worker of this.#workers) {
|
|
67
|
-
worker.terminate();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.NapiWorkerPool = NapiWorkerPool;
|