@atlaspack/core 2.24.1 → 2.24.2
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 +24 -0
- package/dist/AssetGraph.js +591 -0
- package/dist/Atlaspack.js +656 -0
- package/dist/AtlaspackConfig.js +324 -0
- package/dist/AtlaspackConfig.schema.js +108 -0
- package/dist/BundleGraph.js +1628 -0
- package/dist/CommittedAsset.js +142 -0
- package/dist/Dependency.js +125 -0
- package/dist/Environment.js +132 -0
- package/dist/EnvironmentManager.js +108 -0
- package/dist/IdentifierRegistry.js +38 -0
- package/dist/InternalConfig.js +37 -0
- package/dist/PackagerRunner.js +531 -0
- package/dist/ReporterRunner.js +151 -0
- package/dist/RequestTracker.js +1368 -0
- package/dist/SymbolPropagation.js +617 -0
- package/dist/TargetDescriptor.schema.js +143 -0
- package/dist/Transformation.js +487 -0
- package/dist/UncommittedAsset.js +315 -0
- package/dist/Validation.js +196 -0
- package/dist/applyRuntimes.js +305 -0
- package/dist/assetUtils.js +168 -0
- package/dist/atlaspack-v3/AtlaspackV3.js +70 -0
- package/dist/atlaspack-v3/NapiWorkerPool.js +57 -0
- package/dist/atlaspack-v3/fs.js +52 -0
- package/dist/atlaspack-v3/index.js +25 -0
- package/dist/atlaspack-v3/jsCallable.js +16 -0
- package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
- package/dist/atlaspack-v3/worker/compat/bitflags.js +94 -0
- package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
- package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
- package/dist/atlaspack-v3/worker/compat/index.js +25 -0
- package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
- package/dist/atlaspack-v3/worker/compat/plugin-config.js +76 -0
- package/dist/atlaspack-v3/worker/compat/plugin-logger.js +26 -0
- package/dist/atlaspack-v3/worker/compat/plugin-options.js +122 -0
- package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
- package/dist/atlaspack-v3/worker/compat/target.js +14 -0
- package/dist/atlaspack-v3/worker/worker.js +292 -0
- package/dist/constants.js +17 -0
- package/dist/dumpGraphToGraphViz.js +281 -0
- package/dist/index.js +62 -0
- package/dist/loadAtlaspackPlugin.js +128 -0
- package/dist/loadDotEnv.js +41 -0
- package/dist/projectPath.js +83 -0
- package/dist/public/Asset.js +279 -0
- package/dist/public/Bundle.js +224 -0
- package/dist/public/BundleGraph.js +359 -0
- package/dist/public/BundleGroup.js +53 -0
- package/dist/public/Config.js +286 -0
- package/dist/public/Dependency.js +138 -0
- package/dist/public/Environment.js +278 -0
- package/dist/public/MutableBundleGraph.js +277 -0
- package/dist/public/PluginOptions.js +80 -0
- package/dist/public/Symbols.js +248 -0
- package/dist/public/Target.js +69 -0
- package/dist/registerCoreWithSerializer.js +38 -0
- package/dist/requests/AssetGraphRequest.js +429 -0
- package/dist/requests/AssetGraphRequestRust.js +246 -0
- package/dist/requests/AssetRequest.js +130 -0
- package/dist/requests/AtlaspackBuildRequest.js +60 -0
- package/dist/requests/AtlaspackConfigRequest.js +490 -0
- package/dist/requests/BundleGraphRequest.js +441 -0
- package/dist/requests/ConfigRequest.js +222 -0
- package/dist/requests/DevDepRequest.js +204 -0
- package/dist/requests/EntryRequest.js +314 -0
- package/dist/requests/PackageRequest.js +65 -0
- package/dist/requests/PathRequest.js +349 -0
- package/dist/requests/TargetRequest.js +1310 -0
- package/dist/requests/ValidationRequest.js +49 -0
- package/dist/requests/WriteBundleRequest.js +254 -0
- package/dist/requests/WriteBundlesRequest.js +165 -0
- package/dist/requests/asset-graph-diff.js +126 -0
- package/dist/requests/asset-graph-dot.js +131 -0
- package/dist/resolveOptions.js +268 -0
- package/dist/rustWorkerThreadDylibHack.js +19 -0
- package/dist/serializerCore.browser.js +43 -0
- package/dist/summarizeRequest.js +39 -0
- package/dist/types.js +31 -0
- package/dist/utils.js +172 -0
- package/dist/worker.js +123 -0
- package/lib/AssetGraph.js +1 -0
- package/lib/SymbolPropagation.js +3 -12
- package/lib/worker.js +0 -7
- package/package.json +13 -14
- package/src/AssetGraph.ts +1 -0
- package/src/SymbolPropagation.ts +5 -9
- package/src/worker.ts +0 -8
- package/tsconfig.json +55 -2
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.propagateSymbols = propagateSymbols;
|
|
7
|
+
const assert_1 = __importDefault(require("assert"));
|
|
8
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
9
|
+
const utils_1 = require("@atlaspack/utils");
|
|
10
|
+
const logger_1 = __importDefault(require("@atlaspack/logger"));
|
|
11
|
+
const diagnostic_1 = require("@atlaspack/diagnostic");
|
|
12
|
+
const logger_2 = require("@atlaspack/logger");
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const projectPath_1 = require("./projectPath");
|
|
15
|
+
function propagateSymbols({ options, assetGraph, changedAssetsPropagation, assetGroupsWithRemovedParents, previousErrors, }) {
|
|
16
|
+
return (0, logger_2.instrument)('propagateSymbols', () => {
|
|
17
|
+
let changedAssets = new Set([...changedAssetsPropagation].map((id) => assetGraph.getNodeIdByContentKey(id)));
|
|
18
|
+
// To reorder once at the end
|
|
19
|
+
let changedDeps = new Set();
|
|
20
|
+
// For the down traversal, the nodes with `usedSymbolsDownDirty = true` are exactly
|
|
21
|
+
// `changedAssetsPropagation` (= asset and therefore potentially dependencies changed) or the
|
|
22
|
+
// asset children of `assetGroupsWithRemovedParents` (= fewer incoming dependencies causing less
|
|
23
|
+
// used symbols).
|
|
24
|
+
//
|
|
25
|
+
// The up traversal has to consider all nodes that changed in the down traversal
|
|
26
|
+
// (`useSymbolsUpDirtyDown = true`) which are listed in `changedDepsUsedSymbolsUpDirtyDown`
|
|
27
|
+
// (more or less requested symbols) and in `changedAssetsPropagation` (changing an asset might
|
|
28
|
+
// change exports).
|
|
29
|
+
// The dependencies that changed in the down traversal causing an update in the up traversal.
|
|
30
|
+
let changedDepsUsedSymbolsUpDirtyDown = new Set();
|
|
31
|
+
// Propagate the requested symbols down from the root to the leaves
|
|
32
|
+
propagateSymbolsDown(assetGraph, changedAssets, assetGroupsWithRemovedParents, (assetNode, incomingDeps, outgoingDeps) => {
|
|
33
|
+
if (assetNode.value.meta.emptyFileStarReexport &&
|
|
34
|
+
incomingDeps.every((d) => d.value.specifierType === types_1.SpecifierType.esm)) {
|
|
35
|
+
assetNode.value.symbols?.delete('*');
|
|
36
|
+
}
|
|
37
|
+
// exportSymbol -> identifier
|
|
38
|
+
let assetSymbols = assetNode.value.symbols;
|
|
39
|
+
// identifier -> exportSymbol
|
|
40
|
+
let assetSymbolsInverse;
|
|
41
|
+
if (assetSymbols) {
|
|
42
|
+
assetSymbolsInverse = new Map();
|
|
43
|
+
for (let [s, { local }] of assetSymbols) {
|
|
44
|
+
let set = assetSymbolsInverse.get(local);
|
|
45
|
+
if (!set) {
|
|
46
|
+
set = new Set();
|
|
47
|
+
assetSymbolsInverse.set(local, set);
|
|
48
|
+
}
|
|
49
|
+
set.add(s);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
let hasNamespaceOutgoingDeps = outgoingDeps.some((d) => d.value.symbols?.get('*')?.local === '*');
|
|
53
|
+
// 1) Determine what the incomingDeps requests from the asset
|
|
54
|
+
// ----------------------------------------------------------
|
|
55
|
+
let isEntry = false;
|
|
56
|
+
let addAll = false;
|
|
57
|
+
// Used symbols that are exported or reexported (symbol will be removed again later) by asset.
|
|
58
|
+
assetNode.usedSymbols = new Set();
|
|
59
|
+
// Symbols that have to be namespace reexported by outgoingDeps.
|
|
60
|
+
let namespaceReexportedSymbols = new Set();
|
|
61
|
+
if (incomingDeps.length === 0) {
|
|
62
|
+
// Root in the runtimes Graph
|
|
63
|
+
assetNode.usedSymbols.add('*');
|
|
64
|
+
namespaceReexportedSymbols.add('*');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
for (let incomingDep of incomingDeps) {
|
|
68
|
+
if (incomingDep.value.symbols == null ||
|
|
69
|
+
incomingDep.value.priority === types_1.Priority.conditional) {
|
|
70
|
+
if (incomingDep.value.sourceAssetId == null) {
|
|
71
|
+
// The root dependency on non-library builds
|
|
72
|
+
isEntry = true;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// A regular dependency with cleared symbols
|
|
76
|
+
addAll = true;
|
|
77
|
+
}
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
for (let exportSymbol of incomingDep.usedSymbolsDown) {
|
|
81
|
+
if (exportSymbol === '*') {
|
|
82
|
+
assetNode.usedSymbols.add('*');
|
|
83
|
+
namespaceReexportedSymbols.add('*');
|
|
84
|
+
}
|
|
85
|
+
if (!assetSymbols ||
|
|
86
|
+
assetSymbols.has(exportSymbol) ||
|
|
87
|
+
assetSymbols.has('*')) {
|
|
88
|
+
// An own symbol or a non-namespace reexport
|
|
89
|
+
assetNode.usedSymbols.add(exportSymbol);
|
|
90
|
+
}
|
|
91
|
+
// A namespace reexport
|
|
92
|
+
// (but only if we actually have namespace-exporting outgoing dependencies,
|
|
93
|
+
// This usually happens with a reexporting asset with many namespace exports which means that
|
|
94
|
+
// we cannot match up the correct asset with the used symbol at this level.)
|
|
95
|
+
else if (hasNamespaceOutgoingDeps && exportSymbol !== 'default') {
|
|
96
|
+
namespaceReexportedSymbols.add(exportSymbol);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Incomding dependency with cleared symbols, add everything
|
|
102
|
+
if (addAll) {
|
|
103
|
+
assetSymbols?.forEach((_, exportSymbol) => assetNode.usedSymbols.add(exportSymbol));
|
|
104
|
+
}
|
|
105
|
+
// 2) Distribute the symbols to the outgoing dependencies
|
|
106
|
+
// ----------------------------------------------------------
|
|
107
|
+
for (let dep of outgoingDeps) {
|
|
108
|
+
let depUsedSymbolsDownOld = dep.usedSymbolsDown;
|
|
109
|
+
let depUsedSymbolsDown = new Set();
|
|
110
|
+
// @ts-expect-error TS2322
|
|
111
|
+
dep.usedSymbolsDown = depUsedSymbolsDown;
|
|
112
|
+
if (assetNode.value.sideEffects ||
|
|
113
|
+
// Incoming dependency with cleared symbols
|
|
114
|
+
addAll ||
|
|
115
|
+
// For entries, we still need to add dep.value.symbols of the entry (which are "used" but not according to the symbols data)
|
|
116
|
+
isEntry ||
|
|
117
|
+
// If not a single symbol is used, we can say the entire subgraph is not used.
|
|
118
|
+
// This is e.g. needed when some symbol is imported and then used for a export which isn't used (= "semi-weak" reexport)
|
|
119
|
+
// index.js: `import {bar} from "./lib"; ...`
|
|
120
|
+
// lib/index.js: `export * from "./foo.js"; export * from "./bar.js";`
|
|
121
|
+
// lib/foo.js: `import { data } from "./bar.js"; export const foo = data + " esm2";`
|
|
122
|
+
assetNode.usedSymbols.size > 0 ||
|
|
123
|
+
namespaceReexportedSymbols.size > 0) {
|
|
124
|
+
let depSymbols = dep.value.symbols;
|
|
125
|
+
if (!depSymbols)
|
|
126
|
+
continue;
|
|
127
|
+
if (depSymbols.get('*')?.local === '*') {
|
|
128
|
+
if (addAll) {
|
|
129
|
+
depUsedSymbolsDown.add('*');
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
for (let s of namespaceReexportedSymbols) {
|
|
133
|
+
// We need to propagate the namespaceReexportedSymbols to all namespace dependencies (= even wrong ones because we don't know yet)
|
|
134
|
+
depUsedSymbolsDown.add(s);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (let [symbol, { local }] of depSymbols) {
|
|
139
|
+
// Was already handled above
|
|
140
|
+
if (local === '*')
|
|
141
|
+
continue;
|
|
142
|
+
if (!assetSymbolsInverse || !depSymbols.get(symbol)?.isWeak) {
|
|
143
|
+
// Bailout or non-weak symbol (= used in the asset itself = not a reexport)
|
|
144
|
+
depUsedSymbolsDown.add(symbol);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
let reexportedExportSymbols = assetSymbolsInverse.get(local);
|
|
148
|
+
if (reexportedExportSymbols == null) {
|
|
149
|
+
// not reexported = used in asset itself
|
|
150
|
+
depUsedSymbolsDown.add(symbol);
|
|
151
|
+
}
|
|
152
|
+
else if (assetNode.usedSymbols.has('*')) {
|
|
153
|
+
// we need everything
|
|
154
|
+
depUsedSymbolsDown.add(symbol);
|
|
155
|
+
[...reexportedExportSymbols].forEach((s) => assetNode.usedSymbols.delete(s));
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
let usedReexportedExportSymbols = [
|
|
159
|
+
...reexportedExportSymbols,
|
|
160
|
+
].filter((s) => assetNode.usedSymbols.has(s));
|
|
161
|
+
if (usedReexportedExportSymbols.length > 0) {
|
|
162
|
+
// The symbol is indeed a reexport, so it's not used from the asset itself
|
|
163
|
+
depUsedSymbolsDown.add(symbol);
|
|
164
|
+
usedReexportedExportSymbols.forEach((s) => assetNode.usedSymbols.delete(s));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
depUsedSymbolsDown.clear();
|
|
172
|
+
}
|
|
173
|
+
if (!(0, utils_1.setEqual)(depUsedSymbolsDownOld, depUsedSymbolsDown)) {
|
|
174
|
+
dep.usedSymbolsDownDirty = true;
|
|
175
|
+
dep.usedSymbolsUpDirtyDown = true;
|
|
176
|
+
changedDepsUsedSymbolsUpDirtyDown.add(dep.id);
|
|
177
|
+
}
|
|
178
|
+
if (dep.usedSymbolsUpDirtyDown) {
|
|
179
|
+
// Set on node creation
|
|
180
|
+
changedDepsUsedSymbolsUpDirtyDown.add(dep.id);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
const logFallbackNamespaceInsertion = (assetNode, symbol, depNode1, depNode2) => {
|
|
185
|
+
if (options.logLevel === 'verbose') {
|
|
186
|
+
logger_1.default.warn({
|
|
187
|
+
message: `${(0, projectPath_1.fromProjectPathRelative)(assetNode.value.filePath)} reexports "${symbol}", which could be resolved either to the dependency "${depNode1.value.specifier}" or "${depNode2.value.specifier}" at runtime. Adding a namespace object to fall back on.`,
|
|
188
|
+
origin: '@atlaspack/core',
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
// Because namespace reexports introduce ambiguity, go up the graph from the leaves to the
|
|
193
|
+
// root and remove requested symbols that aren't actually exported
|
|
194
|
+
let errors = propagateSymbolsUp(assetGraph, changedAssets, changedDepsUsedSymbolsUpDirtyDown, previousErrors, (assetNode, incomingDeps, outgoingDeps) => {
|
|
195
|
+
let assetSymbols = assetNode.value.symbols;
|
|
196
|
+
let assetSymbolsInverse = null;
|
|
197
|
+
if (assetSymbols) {
|
|
198
|
+
assetSymbolsInverse = new Map();
|
|
199
|
+
for (let [s, { local }] of assetSymbols) {
|
|
200
|
+
let set = assetSymbolsInverse.get(local);
|
|
201
|
+
if (!set) {
|
|
202
|
+
set = new Set();
|
|
203
|
+
assetSymbolsInverse.set(local, set);
|
|
204
|
+
}
|
|
205
|
+
set.add(s);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// the symbols that are reexported (not used in `asset`) -> asset they resolved to
|
|
209
|
+
let reexportedSymbols = new Map();
|
|
210
|
+
// the symbols that are reexported (not used in `asset`) -> the corresponding outgoingDep(s)
|
|
211
|
+
// To generate the diagnostic when there are multiple dependencies with non-statically
|
|
212
|
+
// analyzable exports
|
|
213
|
+
let reexportedSymbolsSource = new Map();
|
|
214
|
+
for (let outgoingDep of outgoingDeps) {
|
|
215
|
+
let outgoingDepSymbols = outgoingDep.value.symbols;
|
|
216
|
+
if (!outgoingDepSymbols)
|
|
217
|
+
continue;
|
|
218
|
+
let isExcluded = assetGraph.getNodeIdsConnectedFrom(assetGraph.getNodeIdByContentKey(outgoingDep.id)).length === 0;
|
|
219
|
+
// excluded, assume everything that is requested exists
|
|
220
|
+
if (isExcluded) {
|
|
221
|
+
outgoingDep.usedSymbolsDown.forEach((_, s) => outgoingDep.usedSymbolsUp.set(s, null));
|
|
222
|
+
}
|
|
223
|
+
if (outgoingDepSymbols.get('*')?.local === '*') {
|
|
224
|
+
outgoingDep.usedSymbolsUp.forEach((sResolved, s) => {
|
|
225
|
+
if (s === 'default') {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// If the symbol could come from multiple assets at runtime, assetNode's
|
|
229
|
+
// namespace will be needed at runtime to perform the lookup on.
|
|
230
|
+
if (reexportedSymbols.has(s)) {
|
|
231
|
+
if (!assetNode.usedSymbols.has('*')) {
|
|
232
|
+
logFallbackNamespaceInsertion(assetNode, s, (0, nullthrows_1.default)(reexportedSymbolsSource.get(s)), outgoingDep);
|
|
233
|
+
}
|
|
234
|
+
assetNode.usedSymbols.add('*');
|
|
235
|
+
reexportedSymbols.set(s, { asset: assetNode.id, symbol: s });
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
reexportedSymbols.set(s, sResolved);
|
|
239
|
+
reexportedSymbolsSource.set(s, outgoingDep);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
for (let [s, sResolved] of outgoingDep.usedSymbolsUp) {
|
|
244
|
+
if (!outgoingDep.usedSymbolsDown.has(s)) {
|
|
245
|
+
// usedSymbolsDown is a superset of usedSymbolsUp
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
let local = outgoingDepSymbols.get(s)?.local;
|
|
249
|
+
if (local == null) {
|
|
250
|
+
// Caused by '*' => '*', already handled
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
let reexported = assetSymbolsInverse?.get(local);
|
|
254
|
+
if (reexported != null) {
|
|
255
|
+
reexported.forEach((s) => {
|
|
256
|
+
// see same code above
|
|
257
|
+
if (reexportedSymbols.has(s)) {
|
|
258
|
+
if (!assetNode.usedSymbols.has('*')) {
|
|
259
|
+
logFallbackNamespaceInsertion(assetNode, s, (0, nullthrows_1.default)(reexportedSymbolsSource.get(s)), outgoingDep);
|
|
260
|
+
}
|
|
261
|
+
assetNode.usedSymbols.add('*');
|
|
262
|
+
reexportedSymbols.set(s, { asset: assetNode.id, symbol: s });
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
reexportedSymbols.set(s, sResolved);
|
|
266
|
+
reexportedSymbolsSource.set(s, outgoingDep);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
let errors = [];
|
|
273
|
+
function usedSymbolsUpAmbiguous(old, current, s, value) {
|
|
274
|
+
if (old.has(s)) {
|
|
275
|
+
let valueOld = old.get(s);
|
|
276
|
+
if (valueOld !== value &&
|
|
277
|
+
!(valueOld?.asset === value.asset &&
|
|
278
|
+
valueOld?.symbol === value.symbol)) {
|
|
279
|
+
// The dependency points to multiple assets (via an asset group).
|
|
280
|
+
current.set(s, undefined);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
current.set(s, value);
|
|
285
|
+
}
|
|
286
|
+
for (let incomingDep of incomingDeps) {
|
|
287
|
+
let incomingDepUsedSymbolsUpOld = incomingDep.usedSymbolsUp;
|
|
288
|
+
incomingDep.usedSymbolsUp = new Map();
|
|
289
|
+
let incomingDepSymbols = incomingDep.value.symbols;
|
|
290
|
+
if (!incomingDepSymbols)
|
|
291
|
+
continue;
|
|
292
|
+
let hasNamespaceReexport = incomingDepSymbols.get('*')?.local === '*';
|
|
293
|
+
for (let s of incomingDep.usedSymbolsDown) {
|
|
294
|
+
if (assetSymbols == null || // Assume everything could be provided if symbols are cleared
|
|
295
|
+
assetNode.value.bundleBehavior === types_1.BundleBehavior.isolated ||
|
|
296
|
+
assetNode.value.bundleBehavior === types_1.BundleBehavior.inline ||
|
|
297
|
+
s === '*' ||
|
|
298
|
+
assetNode.usedSymbols.has(s)) {
|
|
299
|
+
usedSymbolsUpAmbiguous(incomingDepUsedSymbolsUpOld, incomingDep.usedSymbolsUp, s, {
|
|
300
|
+
asset: assetNode.id,
|
|
301
|
+
symbol: s,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else if (reexportedSymbols.has(s)) {
|
|
305
|
+
let reexport = reexportedSymbols.get(s);
|
|
306
|
+
let v =
|
|
307
|
+
// Forward a reexport only if the current asset is side-effect free and not external
|
|
308
|
+
!assetNode.value.sideEffects && reexport != null
|
|
309
|
+
? reexport
|
|
310
|
+
: {
|
|
311
|
+
asset: assetNode.id,
|
|
312
|
+
symbol: s,
|
|
313
|
+
};
|
|
314
|
+
usedSymbolsUpAmbiguous(incomingDepUsedSymbolsUpOld, incomingDep.usedSymbolsUp, s, v);
|
|
315
|
+
}
|
|
316
|
+
else if (!hasNamespaceReexport) {
|
|
317
|
+
let loc = incomingDep.value.symbols?.get(s)?.loc;
|
|
318
|
+
let [resolutionNodeId] = assetGraph.getNodeIdsConnectedFrom(assetGraph.getNodeIdByContentKey(incomingDep.id));
|
|
319
|
+
let resolution = (0, nullthrows_1.default)(assetGraph.getNode(resolutionNodeId));
|
|
320
|
+
(0, assert_1.default)(resolution &&
|
|
321
|
+
(resolution.type === 'asset_group' ||
|
|
322
|
+
resolution.type === 'asset'));
|
|
323
|
+
errors.push({
|
|
324
|
+
message: (0, diagnostic_1.md) `${(0, projectPath_1.fromProjectPathRelative)(
|
|
325
|
+
// @ts-expect-error TS2345
|
|
326
|
+
resolution.value.filePath)} does not export '${s}'`,
|
|
327
|
+
origin: '@atlaspack/core',
|
|
328
|
+
codeFrames: loc
|
|
329
|
+
? [
|
|
330
|
+
{
|
|
331
|
+
filePath: (0, projectPath_1.fromProjectPath)(options.projectRoot, loc?.filePath) ??
|
|
332
|
+
undefined,
|
|
333
|
+
language: incomingDep.value.sourceAssetType ?? undefined,
|
|
334
|
+
codeHighlights: [(0, diagnostic_1.convertSourceLocationToHighlight)(loc)],
|
|
335
|
+
},
|
|
336
|
+
]
|
|
337
|
+
: undefined,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (!equalMap(incomingDepUsedSymbolsUpOld, incomingDep.usedSymbolsUp)) {
|
|
342
|
+
changedDeps.add(incomingDep);
|
|
343
|
+
incomingDep.usedSymbolsUpDirtyUp = true;
|
|
344
|
+
}
|
|
345
|
+
incomingDep.excluded = false;
|
|
346
|
+
if (incomingDep.value.symbols != null &&
|
|
347
|
+
incomingDep.usedSymbolsUp.size === 0) {
|
|
348
|
+
let assetGroups = assetGraph.getNodeIdsConnectedFrom(assetGraph.getNodeIdByContentKey(incomingDep.id));
|
|
349
|
+
if (assetGroups.length === 1) {
|
|
350
|
+
let [assetGroupId] = assetGroups;
|
|
351
|
+
let assetGroup = (0, nullthrows_1.default)(assetGraph.getNode(assetGroupId));
|
|
352
|
+
if (assetGroup.type === 'asset_group' &&
|
|
353
|
+
assetGroup.value.sideEffects === false) {
|
|
354
|
+
incomingDep.excluded = true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
(0, assert_1.default)(assetGroups.length === 0);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return errors;
|
|
363
|
+
});
|
|
364
|
+
// Sort usedSymbolsUp so they are a consistent order across builds.
|
|
365
|
+
// This ensures a consistent ordering of these symbols when packaging.
|
|
366
|
+
// See https://github.com/parcel-bundler/parcel/pull/8212
|
|
367
|
+
for (let dep of changedDeps) {
|
|
368
|
+
dep.usedSymbolsUp = new Map(
|
|
369
|
+
// @ts-expect-error TS2345
|
|
370
|
+
[...dep.usedSymbolsUp].sort(([a], [b]) => a.localeCompare(b)));
|
|
371
|
+
}
|
|
372
|
+
return errors;
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
function propagateSymbolsDown(assetGraph, changedAssets, assetGroupsWithRemovedParents, visit) {
|
|
376
|
+
if (changedAssets.size === 0 && assetGroupsWithRemovedParents.size === 0) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
// We care about changed assets and their changed dependencies. So start with the first changed
|
|
380
|
+
// asset or dependency and continue while the symbols change. If the queue becomes empty,
|
|
381
|
+
// continue with the next unvisited changed asset.
|
|
382
|
+
//
|
|
383
|
+
// In the end, nodes, which are neither listed in changedAssets nor in
|
|
384
|
+
// assetGroupsWithRemovedParents nor reached via a dirty flag, don't have to be visited at all.
|
|
385
|
+
//
|
|
386
|
+
// In the worst case, some nodes have to be revisited because we don't want to sort the assets
|
|
387
|
+
// into topological order. For example in a diamond graph where the join point is visited twice
|
|
388
|
+
// via each parent (the numbers signifiying the order of re/visiting, `...` being unvisited).
|
|
389
|
+
// However, this only continues as long as there are changes in the used symbols that influence
|
|
390
|
+
// child nodes.
|
|
391
|
+
//
|
|
392
|
+
// |
|
|
393
|
+
// ...
|
|
394
|
+
// / \
|
|
395
|
+
// 1 4
|
|
396
|
+
// \ /
|
|
397
|
+
// 2+5
|
|
398
|
+
// |
|
|
399
|
+
// 3+6
|
|
400
|
+
// |
|
|
401
|
+
// ...
|
|
402
|
+
// |
|
|
403
|
+
//
|
|
404
|
+
let unreachedAssets = new Set([
|
|
405
|
+
...changedAssets,
|
|
406
|
+
...assetGroupsWithRemovedParents,
|
|
407
|
+
]);
|
|
408
|
+
let queue = new Set([setPop(unreachedAssets)]);
|
|
409
|
+
while (queue.size > 0) {
|
|
410
|
+
let queuedNodeId = setPop(queue);
|
|
411
|
+
unreachedAssets.delete(queuedNodeId);
|
|
412
|
+
let outgoing = assetGraph.getNodeIdsConnectedFrom(queuedNodeId);
|
|
413
|
+
let node = (0, nullthrows_1.default)(assetGraph.getNode(queuedNodeId));
|
|
414
|
+
let wasNodeDirty = false;
|
|
415
|
+
if (node.type === 'dependency' || node.type === 'asset_group') {
|
|
416
|
+
wasNodeDirty = node.usedSymbolsDownDirty;
|
|
417
|
+
node.usedSymbolsDownDirty = false;
|
|
418
|
+
}
|
|
419
|
+
else if (node.type === 'asset' && node.usedSymbolsDownDirty) {
|
|
420
|
+
visit(node, incomingDependencyNodesFromAsset(assetGraph, node.value), dependencyNodesFromIds(assetGraph, outgoing));
|
|
421
|
+
node.usedSymbolsDownDirty = false;
|
|
422
|
+
}
|
|
423
|
+
for (let child of outgoing) {
|
|
424
|
+
let childNode = (0, nullthrows_1.default)(assetGraph.getNode(child));
|
|
425
|
+
let childDirty = false;
|
|
426
|
+
if ((childNode.type === 'asset' || childNode.type === 'asset_group') &&
|
|
427
|
+
wasNodeDirty) {
|
|
428
|
+
childNode.usedSymbolsDownDirty = true;
|
|
429
|
+
childDirty = true;
|
|
430
|
+
}
|
|
431
|
+
else if (childNode.type === 'dependency') {
|
|
432
|
+
childDirty = childNode.usedSymbolsDownDirty;
|
|
433
|
+
}
|
|
434
|
+
if (childDirty) {
|
|
435
|
+
queue.add(child);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (queue.size === 0 && unreachedAssets.size > 0) {
|
|
439
|
+
queue.add(setPop(unreachedAssets));
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function propagateSymbolsUp(assetGraph, changedAssets, changedDepsUsedSymbolsUpDirtyDown, previousErrors, visit) {
|
|
444
|
+
// For graphs in general (so with cyclic dependencies), some nodes will have to be revisited. So
|
|
445
|
+
// run a regular queue-based BFS for anything that's still dirty.
|
|
446
|
+
//
|
|
447
|
+
// (Previously, there was first a recursive post-order DFS, with the idea that all children of a
|
|
448
|
+
// node should be processed first. With a tree, this would result in a minimal amount of work by
|
|
449
|
+
// processing every asset exactly once and then the remaining cycles would have been handled
|
|
450
|
+
// with the loop. This was slightly faster for initial builds but had O(project) instead of
|
|
451
|
+
// O(changes).)
|
|
452
|
+
let errors = previousErrors
|
|
453
|
+
? // Some nodes might have been removed since the last build
|
|
454
|
+
// @ts-expect-error TS2769
|
|
455
|
+
new Map([...previousErrors].filter(([n]) => assetGraph.hasNode(n)))
|
|
456
|
+
: new Map();
|
|
457
|
+
let changedDepsUsedSymbolsUpDirtyDownAssets = new Set([
|
|
458
|
+
...[...changedDepsUsedSymbolsUpDirtyDown]
|
|
459
|
+
.reverse()
|
|
460
|
+
.flatMap((id) => getDependencyResolution(assetGraph, id)),
|
|
461
|
+
...changedAssets,
|
|
462
|
+
]);
|
|
463
|
+
// Do a more efficient full traversal (less recomputations) if more than half of the assets
|
|
464
|
+
// changed.
|
|
465
|
+
let runFullPass =
|
|
466
|
+
// If there are n nodes in the graph, then the asset count is approximately
|
|
467
|
+
// n/6 (for every asset, there are ~4 dependencies and ~1 asset_group).
|
|
468
|
+
assetGraph.nodes.length * (1 / 6) * 0.5 <
|
|
469
|
+
changedDepsUsedSymbolsUpDirtyDownAssets.size;
|
|
470
|
+
// @ts-expect-error TS7034
|
|
471
|
+
let dirtyDeps;
|
|
472
|
+
if (runFullPass) {
|
|
473
|
+
dirtyDeps = new Set();
|
|
474
|
+
let rootNodeId = (0, nullthrows_1.default)(assetGraph.rootNodeId, 'A root node is required to traverse');
|
|
475
|
+
const nodeVisitor = (nodeId) => {
|
|
476
|
+
let node = (0, nullthrows_1.default)(assetGraph.getNode(nodeId));
|
|
477
|
+
if (node.type === 'asset') {
|
|
478
|
+
let outgoing = outgoingDependencyNodesFromAsset(assetGraph, nodeId);
|
|
479
|
+
for (let child of outgoing) {
|
|
480
|
+
if (child.usedSymbolsUpDirtyUp) {
|
|
481
|
+
node.usedSymbolsUpDirty = true;
|
|
482
|
+
child.usedSymbolsUpDirtyUp = false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
let incoming = incomingDependencyNodesFromAsset(assetGraph, node.value);
|
|
486
|
+
for (let dep of incoming) {
|
|
487
|
+
if (dep.usedSymbolsUpDirtyDown) {
|
|
488
|
+
dep.usedSymbolsUpDirtyDown = false;
|
|
489
|
+
node.usedSymbolsUpDirty = true;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (node.usedSymbolsUpDirty) {
|
|
493
|
+
let e = visit(node, incoming, outgoing);
|
|
494
|
+
if (e.length > 0) {
|
|
495
|
+
node.usedSymbolsUpDirty = true;
|
|
496
|
+
errors.set(nodeId, e);
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
node.usedSymbolsUpDirty = false;
|
|
500
|
+
errors.delete(nodeId);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
if (node.type === 'dependency') {
|
|
506
|
+
if (node.usedSymbolsUpDirtyUp) {
|
|
507
|
+
// @ts-expect-error TS7005
|
|
508
|
+
dirtyDeps.add(nodeId);
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
// @ts-expect-error TS7005
|
|
512
|
+
dirtyDeps.delete(nodeId);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
// @ts-expect-error TS2345
|
|
518
|
+
assetGraph.postOrderDfsFast(nodeVisitor, rootNodeId);
|
|
519
|
+
}
|
|
520
|
+
let queue = dirtyDeps ?? changedDepsUsedSymbolsUpDirtyDownAssets;
|
|
521
|
+
while (queue.size > 0) {
|
|
522
|
+
let queuedNodeId = setPop(queue);
|
|
523
|
+
let node = (0, nullthrows_1.default)(assetGraph.getNode(queuedNodeId));
|
|
524
|
+
if (node.type === 'asset') {
|
|
525
|
+
let incoming = incomingDependencyNodesFromAsset(assetGraph, node.value);
|
|
526
|
+
for (let dep of incoming) {
|
|
527
|
+
if (dep.usedSymbolsUpDirtyDown) {
|
|
528
|
+
dep.usedSymbolsUpDirtyDown = false;
|
|
529
|
+
node.usedSymbolsUpDirty = true;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
let outgoing = outgoingDependencyNodesFromAsset(assetGraph, queuedNodeId);
|
|
533
|
+
for (let dep of outgoing) {
|
|
534
|
+
if (dep.usedSymbolsUpDirtyUp) {
|
|
535
|
+
node.usedSymbolsUpDirty = true;
|
|
536
|
+
dep.usedSymbolsUpDirtyUp = false;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
if (node.usedSymbolsUpDirty) {
|
|
540
|
+
let e = visit(node, incoming, outgoing);
|
|
541
|
+
if (e.length > 0) {
|
|
542
|
+
node.usedSymbolsUpDirty = true;
|
|
543
|
+
errors.set(queuedNodeId, e);
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
node.usedSymbolsUpDirty = false;
|
|
547
|
+
errors.delete(queuedNodeId);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
for (let i of incoming) {
|
|
551
|
+
if (i.usedSymbolsUpDirtyUp) {
|
|
552
|
+
queue.add(assetGraph.getNodeIdByContentKey(i.id));
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
let connectedNodes = assetGraph.getNodeIdsConnectedTo(queuedNodeId);
|
|
558
|
+
if (connectedNodes.length > 0) {
|
|
559
|
+
// @ts-expect-error TS2556
|
|
560
|
+
queue.add(...connectedNodes);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return errors;
|
|
565
|
+
}
|
|
566
|
+
function getDependencyResolution(graph, depId) {
|
|
567
|
+
let depNodeId = graph.getNodeIdByContentKey(depId);
|
|
568
|
+
let connected = graph.getNodeIdsConnectedFrom(depNodeId);
|
|
569
|
+
(0, assert_1.default)(connected.length <= 1);
|
|
570
|
+
let child = connected[0];
|
|
571
|
+
if (child) {
|
|
572
|
+
let childNode = (0, nullthrows_1.default)(graph.getNode(child));
|
|
573
|
+
if (childNode.type === 'asset_group') {
|
|
574
|
+
return graph.getNodeIdsConnectedFrom(child);
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
return [child];
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return [];
|
|
581
|
+
}
|
|
582
|
+
function equalMap(a, b) {
|
|
583
|
+
if (a.size !== b.size)
|
|
584
|
+
return false;
|
|
585
|
+
for (let [k, v] of a) {
|
|
586
|
+
if (!b.has(k))
|
|
587
|
+
return false;
|
|
588
|
+
let vB = b.get(k);
|
|
589
|
+
if (vB?.asset !== v?.asset || vB?.symbol !== v?.symbol)
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
594
|
+
function setPop(set) {
|
|
595
|
+
let v = (0, nullthrows_1.default)(set.values().next().value);
|
|
596
|
+
set.delete(v);
|
|
597
|
+
return v;
|
|
598
|
+
}
|
|
599
|
+
function outgoingDependencyNodesFromAsset(assetGraph, assetNode) {
|
|
600
|
+
return dependencyNodesFromIds(assetGraph, assetGraph.getNodeIdsConnectedFrom(assetNode));
|
|
601
|
+
}
|
|
602
|
+
function dependencyNodesFromIds(assetGraph, dependencyIds) {
|
|
603
|
+
return dependencyIds.map((depNodeId) => {
|
|
604
|
+
let depNode = (0, nullthrows_1.default)(assetGraph.getNode(depNodeId));
|
|
605
|
+
(0, assert_1.default)(depNode.type === 'dependency');
|
|
606
|
+
return depNode;
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
function incomingDependencyNodesFromAsset(assetGraph,
|
|
610
|
+
// @ts-expect-error TS2552
|
|
611
|
+
assetNodeValue) {
|
|
612
|
+
return assetGraph.getIncomingDependencies(assetNodeValue).map((d) => {
|
|
613
|
+
let n = assetGraph.getNodeByContentKey(d.id);
|
|
614
|
+
(0, assert_1.default)(n && n.type === 'dependency');
|
|
615
|
+
return n;
|
|
616
|
+
});
|
|
617
|
+
}
|