@atlaspack/core 2.12.1-dev.3401 → 2.12.1-dev.3443
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/lib/AssetGraph.js +1 -2
- package/lib/Atlaspack.js +25 -3
- package/lib/AtlaspackConfig.schema.js +10 -36
- package/lib/BundleGraph.js +59 -5
- package/lib/Dependency.js +46 -1
- package/lib/Environment.js +12 -2
- package/lib/PackagerRunner.js +3 -45
- package/lib/RequestTracker.js +112 -30
- package/lib/SymbolPropagation.js +1 -1
- package/lib/Transformation.js +1 -15
- package/lib/UncommittedAsset.js +4 -4
- package/lib/Validation.js +1 -13
- package/lib/applyRuntimes.js +96 -20
- package/lib/assetUtils.js +9 -3
- package/lib/atlaspack-v3/AtlaspackV3.js +6 -8
- package/lib/atlaspack-v3/fs.js +8 -1
- package/lib/atlaspack-v3/worker/compat.js +57 -0
- package/lib/atlaspack-v3/worker/worker.js +156 -1
- package/lib/public/BundleGraph.js +68 -0
- package/lib/requests/AssetGraphRequestRust.js +79 -12
- package/lib/requests/BundleGraphRequest.js +19 -0
- package/lib/requests/WriteBundleRequest.js +15 -15
- package/lib/requests/asset-graph-diff.js +128 -0
- package/lib/resolveOptions.js +15 -8
- package/lib/types.js +2 -1
- package/package.json +19 -17
- package/src/AssetGraph.js +1 -1
- package/src/Atlaspack.js +28 -6
- package/src/AtlaspackConfig.schema.js +13 -36
- package/src/BundleGraph.js +77 -1
- package/src/CommittedAsset.js +1 -1
- package/src/Dependency.js +50 -12
- package/src/Environment.js +13 -15
- package/src/PackagerRunner.js +5 -53
- package/src/RequestTracker.js +144 -38
- package/src/SymbolPropagation.js +5 -2
- package/src/Transformation.js +1 -9
- package/src/UncommittedAsset.js +6 -6
- package/src/Validation.js +1 -7
- package/src/applyRuntimes.js +86 -22
- package/src/assetUtils.js +12 -19
- package/src/atlaspack-v3/AtlaspackV3.js +8 -11
- package/src/atlaspack-v3/fs.js +8 -3
- package/src/atlaspack-v3/jsCallable.js +4 -0
- package/src/atlaspack-v3/worker/compat.js +82 -0
- package/src/atlaspack-v3/worker/worker.js +209 -2
- package/src/public/BundleGraph.js +106 -0
- package/src/requests/AssetGraphRequestRust.js +105 -17
- package/src/requests/BundleGraphRequest.js +18 -0
- package/src/requests/WriteBundleRequest.js +17 -23
- package/src/requests/asset-graph-diff.js +145 -0
- package/src/resolveOptions.js +12 -2
- package/src/types.js +10 -0
- package/test/AssetGraph.test.js +23 -9
- package/test/AtlaspackConfigRequest.test.js +0 -161
- package/test/BundleGraph.test.js +8 -3
- package/test/Dependency.test.js +21 -0
- package/test/Environment.test.js +16 -5
- package/test/InternalAsset.test.js +8 -2
- package/test/PublicAsset.test.js +6 -2
- package/test/PublicBundle.test.js +1 -0
- package/test/PublicMutableBundleGraph.test.js +9 -4
- package/test/RequestTracker.test.js +139 -2
- package/test/SymbolPropagation.test.js +1 -0
- package/test/TargetRequest.test.js +25 -25
- package/test/requests/WriteBundleRequest.test.js +132 -0
- package/lib/atlaspack-v3/plugins/Resolver.js +0 -12
- package/lib/atlaspack-v3/plugins/index.js +0 -16
- package/src/atlaspack-v3/plugins/Resolver.js +0 -9
- package/src/atlaspack-v3/plugins/index.js +0 -3
|
@@ -332,4 +332,110 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
332
332
|
targetToInternalTarget(target),
|
|
333
333
|
);
|
|
334
334
|
}
|
|
335
|
+
|
|
336
|
+
// Given a set of dependencies, return any conditions where those dependencies are either
|
|
337
|
+
// the true or false dependency for those conditions. This is currently used to work out which
|
|
338
|
+
// conditions belong to a bundle in packaging.
|
|
339
|
+
getConditionsForDependencies(deps: Array<IDependency>): Set<{|
|
|
340
|
+
publicId: string,
|
|
341
|
+
key: string,
|
|
342
|
+
ifTrueDependency: IDependency,
|
|
343
|
+
ifFalseDependency: IDependency,
|
|
344
|
+
ifTrueAssetId: string,
|
|
345
|
+
ifFalseAssetId: string,
|
|
346
|
+
|}> {
|
|
347
|
+
const conditions = new Set();
|
|
348
|
+
const depIds = deps.map(dep => dep.id);
|
|
349
|
+
for (const condition of this.#graph._conditions.values()) {
|
|
350
|
+
if (
|
|
351
|
+
depIds.includes(condition.ifTrueDependency.id) ||
|
|
352
|
+
depIds.includes(condition.ifFalseDependency.id)
|
|
353
|
+
) {
|
|
354
|
+
const [trueAsset, falseAsset] = [
|
|
355
|
+
condition.ifTrueDependency,
|
|
356
|
+
condition.ifFalseDependency,
|
|
357
|
+
].map(dep => {
|
|
358
|
+
const resolved = nullthrows(this.#graph.resolveAsyncDependency(dep));
|
|
359
|
+
if (resolved.type === 'asset') {
|
|
360
|
+
return resolved.value;
|
|
361
|
+
} else {
|
|
362
|
+
return this.#graph.getAssetById(resolved.value.entryAssetId);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
conditions.add({
|
|
367
|
+
publicId: condition.publicId,
|
|
368
|
+
key: condition.key,
|
|
369
|
+
ifTrueDependency: nullthrows(
|
|
370
|
+
deps.find(dep => dep.id === condition.ifTrueDependency.id),
|
|
371
|
+
'ifTrueDependency was null',
|
|
372
|
+
),
|
|
373
|
+
ifFalseDependency: nullthrows(
|
|
374
|
+
deps.find(dep => dep.id === condition.ifFalseDependency.id),
|
|
375
|
+
'ifFalseDependency was null',
|
|
376
|
+
),
|
|
377
|
+
ifTrueAssetId: this.#graph.getAssetPublicId(trueAsset),
|
|
378
|
+
ifFalseAssetId: this.#graph.getAssetPublicId(falseAsset),
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return conditions;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// This is used to generate information for building a manifest that can
|
|
387
|
+
// be used by a webserver to understand which conditions are used by which bundles,
|
|
388
|
+
// and which bundles those conditions require depending on what they evaluate to.
|
|
389
|
+
getConditionalBundleMapping(): Map<
|
|
390
|
+
TBundle,
|
|
391
|
+
Map<
|
|
392
|
+
string,
|
|
393
|
+
{|
|
|
394
|
+
ifTrueBundles: Array<TBundle>,
|
|
395
|
+
ifFalseBundles: Array<TBundle>,
|
|
396
|
+
|},
|
|
397
|
+
>,
|
|
398
|
+
> {
|
|
399
|
+
let bundleConditions = new Map();
|
|
400
|
+
|
|
401
|
+
// Convert the internal references in conditions to public API references
|
|
402
|
+
for (const cond of this.#graph._conditions.values()) {
|
|
403
|
+
let assets = Array.from(cond.assets).map(asset =>
|
|
404
|
+
nullthrows(this.getAssetById(asset.id)),
|
|
405
|
+
);
|
|
406
|
+
let bundles = new Set<TBundle>();
|
|
407
|
+
let ifTrueBundles = [];
|
|
408
|
+
let ifFalseBundles = [];
|
|
409
|
+
for (const asset of assets) {
|
|
410
|
+
const bundlesWithAsset = this.getBundlesWithAsset(asset);
|
|
411
|
+
for (const bundle of bundlesWithAsset) {
|
|
412
|
+
bundles.add(bundle);
|
|
413
|
+
}
|
|
414
|
+
const assetDeps = this.getDependencies(asset);
|
|
415
|
+
const depToBundles = dep => {
|
|
416
|
+
const publicDep = nullthrows(
|
|
417
|
+
assetDeps.find(assetDep => dep.id === assetDep.id),
|
|
418
|
+
);
|
|
419
|
+
const resolved = nullthrows(this.resolveAsyncDependency(publicDep));
|
|
420
|
+
invariant(resolved.type === 'bundle_group');
|
|
421
|
+
return this.getBundlesInBundleGroup(resolved.value);
|
|
422
|
+
};
|
|
423
|
+
ifTrueBundles.push(...depToBundles(cond.ifTrueDependency));
|
|
424
|
+
ifFalseBundles.push(...depToBundles(cond.ifFalseDependency));
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
for (let bundle of bundles) {
|
|
428
|
+
const conditions = bundleConditions.get(bundle) ?? new Map();
|
|
429
|
+
|
|
430
|
+
conditions.set(cond.key, {
|
|
431
|
+
ifTrueBundles,
|
|
432
|
+
ifFalseBundles,
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
bundleConditions.set(bundle, conditions);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return bundleConditions;
|
|
440
|
+
}
|
|
335
441
|
}
|
|
@@ -10,6 +10,7 @@ import type {AtlaspackV3} from '../atlaspack-v3';
|
|
|
10
10
|
import {toProjectPath} from '../projectPath';
|
|
11
11
|
import {requestTypes, type StaticRunOpts} from '../RequestTracker';
|
|
12
12
|
import {propagateSymbols} from '../SymbolPropagation';
|
|
13
|
+
import type {Environment} from '../types';
|
|
13
14
|
|
|
14
15
|
import type {
|
|
15
16
|
AssetGraphRequestInput,
|
|
@@ -95,9 +96,58 @@ function getAssetGraph(serializedGraph, options) {
|
|
|
95
96
|
|
|
96
97
|
graph.safeToIncrementallyBundle = false;
|
|
97
98
|
|
|
99
|
+
function mapSymbols({exported, ...symbol}) {
|
|
100
|
+
let jsSymbol = {
|
|
101
|
+
local: symbol.local ?? undefined,
|
|
102
|
+
loc: symbol.loc ?? undefined,
|
|
103
|
+
meta: undefined,
|
|
104
|
+
isWeak: symbol.isWeak,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
if (symbol.exported) {
|
|
108
|
+
// $FlowFixMe
|
|
109
|
+
jsSymbol.exported = symbol.exported;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (symbol.isEsmExport) {
|
|
113
|
+
// $FlowFixMe
|
|
114
|
+
jsSymbol.meta = {
|
|
115
|
+
isEsm: true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return [exported, jsSymbol];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// See crates/atlaspack_core/src/types/environment.rs
|
|
98
122
|
let cachedAssets = new Map();
|
|
99
123
|
let changedAssets = new Map();
|
|
100
124
|
let entry = 0;
|
|
125
|
+
|
|
126
|
+
let envs = new Map();
|
|
127
|
+
let getEnvId = (env: Environment) => {
|
|
128
|
+
let envKey = [
|
|
129
|
+
env.context,
|
|
130
|
+
env.engines.atlaspack,
|
|
131
|
+
env.engines.browsers,
|
|
132
|
+
env.engines.electron,
|
|
133
|
+
env.engines.node,
|
|
134
|
+
env.includeNodeModules,
|
|
135
|
+
env.isLibrary,
|
|
136
|
+
env.outputFormat,
|
|
137
|
+
env.shouldScopeHoist,
|
|
138
|
+
env.shouldOptimize,
|
|
139
|
+
env.sourceType,
|
|
140
|
+
].join(':');
|
|
141
|
+
|
|
142
|
+
let envId = envs.get(envKey);
|
|
143
|
+
if (envId == null) {
|
|
144
|
+
envId = envs.size;
|
|
145
|
+
envs.set(envKey, envId);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return envId;
|
|
149
|
+
};
|
|
150
|
+
|
|
101
151
|
for (let node of serializedGraph.nodes) {
|
|
102
152
|
if (node.type === 'root') {
|
|
103
153
|
let index = graph.addNodeByContentKey('@@root', {
|
|
@@ -116,20 +166,38 @@ function getAssetGraph(serializedGraph, options) {
|
|
|
116
166
|
value: null,
|
|
117
167
|
});
|
|
118
168
|
} else if (node.type === 'asset') {
|
|
119
|
-
let
|
|
120
|
-
let
|
|
169
|
+
let asset = node.value;
|
|
170
|
+
let id = asset.id;
|
|
171
|
+
|
|
172
|
+
asset.meta.id = id;
|
|
121
173
|
|
|
122
174
|
asset = {
|
|
123
175
|
...asset,
|
|
124
|
-
|
|
176
|
+
uniqueKey: asset.uniqueKey ?? undefined,
|
|
177
|
+
pipeline: asset.pipeline ?? undefined,
|
|
178
|
+
range: asset.range ?? undefined,
|
|
179
|
+
resolveFrom: asset.resolveFrom ?? undefined,
|
|
180
|
+
target: asset.target ?? undefined,
|
|
181
|
+
plugin: asset.plugin ?? undefined,
|
|
182
|
+
query: asset.query ?? undefined,
|
|
183
|
+
configPath: asset.configPath ?? undefined,
|
|
184
|
+
configKeyPath: asset.configKeyPath ?? undefined,
|
|
185
|
+
isLargeBlob: asset.isLargeBlob ?? false,
|
|
186
|
+
isSource: asset.isSource ?? false,
|
|
187
|
+
sourcePath: asset.sourcePath ?? undefined,
|
|
188
|
+
env: {
|
|
189
|
+
...asset.env,
|
|
190
|
+
loc: asset.env.loc ?? undefined,
|
|
191
|
+
id: getEnvId(asset.env),
|
|
192
|
+
sourceType: asset.env.sourceType,
|
|
193
|
+
},
|
|
194
|
+
bundleBehavior:
|
|
195
|
+
asset.bundleBehavior === 255 ? null : asset.bundleBehavior,
|
|
125
196
|
committed: true,
|
|
126
197
|
contentKey: id,
|
|
127
198
|
filePath: toProjectPath(options.projectRoot, asset.filePath),
|
|
128
|
-
symbols:
|
|
129
|
-
? new Map(
|
|
130
|
-
asset.symbols.map(({exported, ...symbol}) => [exported, symbol]),
|
|
131
|
-
)
|
|
132
|
-
: null,
|
|
199
|
+
symbols:
|
|
200
|
+
asset.symbols != null ? new Map(asset.symbols.map(mapSymbols)) : null,
|
|
133
201
|
};
|
|
134
202
|
|
|
135
203
|
cachedAssets.set(id, asset.code);
|
|
@@ -150,18 +218,38 @@ function getAssetGraph(serializedGraph, options) {
|
|
|
150
218
|
dependency = {
|
|
151
219
|
...dependency,
|
|
152
220
|
id,
|
|
221
|
+
env: {
|
|
222
|
+
...dependency.env,
|
|
223
|
+
id: getEnvId(dependency.env),
|
|
224
|
+
sourceType: dependency.env.sourceType,
|
|
225
|
+
loc: dependency.env.loc ?? undefined,
|
|
226
|
+
},
|
|
227
|
+
pipeline: dependency.pipeline ?? undefined,
|
|
228
|
+
range: dependency.range ?? undefined,
|
|
229
|
+
resolveFrom: dependency.resolveFrom ?? undefined,
|
|
230
|
+
target: dependency.target ?? undefined,
|
|
231
|
+
bundleBehavior:
|
|
232
|
+
dependency.bundleBehavior === 255 ? null : dependency.bundleBehavior,
|
|
153
233
|
contentKey: id,
|
|
234
|
+
loc: dependency.loc
|
|
235
|
+
? {
|
|
236
|
+
...dependency.loc,
|
|
237
|
+
filePath: toProjectPath(
|
|
238
|
+
options.projectRoot,
|
|
239
|
+
dependency.loc.filePath,
|
|
240
|
+
),
|
|
241
|
+
}
|
|
242
|
+
: undefined,
|
|
154
243
|
sourcePath: dependency.sourcePath
|
|
155
244
|
? toProjectPath(options.projectRoot, dependency.sourcePath)
|
|
156
|
-
:
|
|
157
|
-
symbols:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
: null,
|
|
245
|
+
: undefined,
|
|
246
|
+
symbols:
|
|
247
|
+
// Dependency.symbols are always set to an empty map when scope hoisting
|
|
248
|
+
// is enabled. Some tests will fail if this is not the case. We should
|
|
249
|
+
// make this consistant when we re-visit packaging.
|
|
250
|
+
dependency.symbols != null || dependency.env.shouldScopeHoist
|
|
251
|
+
? new Map(dependency.symbols?.map(mapSymbols))
|
|
252
|
+
: undefined,
|
|
165
253
|
};
|
|
166
254
|
let usedSymbolsDown = new Set();
|
|
167
255
|
let usedSymbolsUp = new Map();
|
|
@@ -118,6 +118,24 @@ export default function createBundleGraphRequest(
|
|
|
118
118
|
},
|
|
119
119
|
);
|
|
120
120
|
|
|
121
|
+
// if (input.rustAtlaspack && process.env.NATIVE_COMPARE === 'true') {
|
|
122
|
+
// let {assetGraph: jsAssetGraph} = await api.runRequest(
|
|
123
|
+
// createAssetGraphRequestJS({
|
|
124
|
+
// name: 'Main',
|
|
125
|
+
// entries: options.entries,
|
|
126
|
+
// optionsRef,
|
|
127
|
+
// shouldBuildLazily: options.shouldBuildLazily,
|
|
128
|
+
// lazyIncludes: options.lazyIncludes,
|
|
129
|
+
// lazyExcludes: options.lazyExcludes,
|
|
130
|
+
// requestedAssetIds,
|
|
131
|
+
// }),
|
|
132
|
+
// {
|
|
133
|
+
// force: true,
|
|
134
|
+
// },
|
|
135
|
+
// );
|
|
136
|
+
// require('./asset-graph-diff.js')(jsAssetGraph, assetGraph);
|
|
137
|
+
// }
|
|
138
|
+
|
|
121
139
|
measurement && measurement.end();
|
|
122
140
|
assertSignalNotAborted(signal);
|
|
123
141
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type {FileSystem, FileOptions} from '@atlaspack/fs';
|
|
4
4
|
import type {ContentKey} from '@atlaspack/graph';
|
|
5
5
|
import type {Async, FilePath, Compressor} from '@atlaspack/types';
|
|
6
|
+
import {replaceHashReferences} from '@atlaspack/rust';
|
|
6
7
|
|
|
7
8
|
import type {RunAPI, StaticRunOpts} from '../RequestTracker';
|
|
8
9
|
import type {Bundle, PackagedBundleInfo, AtlaspackOptions} from '../types';
|
|
@@ -16,7 +17,7 @@ import {HASH_REF_HASH_LEN, HASH_REF_PREFIX} from '../constants';
|
|
|
16
17
|
import nullthrows from 'nullthrows';
|
|
17
18
|
import path from 'path';
|
|
18
19
|
import {NamedBundle} from '../public/Bundle';
|
|
19
|
-
import {blobToStream
|
|
20
|
+
import {blobToStream} from '@atlaspack/utils';
|
|
20
21
|
import {Readable, Transform, pipeline} from 'stream';
|
|
21
22
|
import {
|
|
22
23
|
fromProjectPath,
|
|
@@ -129,20 +130,8 @@ async function run({input, options, api}) {
|
|
|
129
130
|
: {
|
|
130
131
|
mode: (await inputFS.stat(mainEntry.filePath)).mode,
|
|
131
132
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
contentStream = options.cache.getStream(cacheKeys.content);
|
|
135
|
-
} else {
|
|
136
|
-
contentStream = blobToStream(
|
|
137
|
-
await options.cache.getBlob(cacheKeys.content),
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
let size = 0;
|
|
141
|
-
contentStream = contentStream.pipe(
|
|
142
|
-
new TapStream(buf => {
|
|
143
|
-
size += buf.length;
|
|
144
|
-
}),
|
|
145
|
-
);
|
|
133
|
+
const contents: Buffer = await options.cache.getBlob(cacheKeys.content);
|
|
134
|
+
const size = contents.byteLength;
|
|
146
135
|
|
|
147
136
|
let configResult = nullthrows(
|
|
148
137
|
await api.runRequest<null, ConfigAndCachePath>(
|
|
@@ -155,7 +144,7 @@ async function run({input, options, api}) {
|
|
|
155
144
|
invalidateDevDeps(invalidDevDeps, options, config);
|
|
156
145
|
|
|
157
146
|
await writeFiles(
|
|
158
|
-
|
|
147
|
+
contents,
|
|
159
148
|
info,
|
|
160
149
|
hashRefToNameHash,
|
|
161
150
|
options,
|
|
@@ -174,7 +163,7 @@ async function run({input, options, api}) {
|
|
|
174
163
|
(await options.cache.has(mapKey))
|
|
175
164
|
) {
|
|
176
165
|
await writeFiles(
|
|
177
|
-
|
|
166
|
+
await options.cache.getBlob(mapKey),
|
|
178
167
|
info,
|
|
179
168
|
hashRefToNameHash,
|
|
180
169
|
options,
|
|
@@ -201,7 +190,7 @@ async function run({input, options, api}) {
|
|
|
201
190
|
}
|
|
202
191
|
|
|
203
192
|
async function writeFiles(
|
|
204
|
-
|
|
193
|
+
contents: Buffer,
|
|
205
194
|
info: BundleInfo,
|
|
206
195
|
hashRefToNameHash: Map<string, string>,
|
|
207
196
|
options: AtlaspackOptions,
|
|
@@ -217,16 +206,19 @@ async function writeFiles(
|
|
|
217
206
|
);
|
|
218
207
|
let fullPath = fromProjectPath(options.projectRoot, filePath);
|
|
219
208
|
|
|
220
|
-
|
|
221
|
-
?
|
|
222
|
-
|
|
209
|
+
const stream = info.hashReferences.length
|
|
210
|
+
? replaceHashReferences(
|
|
211
|
+
contents,
|
|
212
|
+
Object.fromEntries(hashRefToNameHash.entries()),
|
|
213
|
+
)
|
|
214
|
+
: contents;
|
|
223
215
|
|
|
224
216
|
let promises = [];
|
|
225
217
|
for (let compressor of compressors) {
|
|
226
218
|
promises.push(
|
|
227
219
|
runCompressor(
|
|
228
220
|
compressor,
|
|
229
|
-
|
|
221
|
+
blobToStream(stream),
|
|
230
222
|
options,
|
|
231
223
|
outputFS,
|
|
232
224
|
fullPath,
|
|
@@ -300,7 +292,9 @@ async function runCompressor(
|
|
|
300
292
|
}
|
|
301
293
|
}
|
|
302
294
|
|
|
303
|
-
function replaceStream(
|
|
295
|
+
export function replaceStream(
|
|
296
|
+
hashRefToNameHash: Map<string, string>,
|
|
297
|
+
): Transform {
|
|
304
298
|
let boundaryStr = Buffer.alloc(0);
|
|
305
299
|
let replaced = Buffer.alloc(0);
|
|
306
300
|
return new Transform({
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
// @flow strict-local
|
|
3
|
+
|
|
4
|
+
// $FlowFixMe
|
|
5
|
+
import deepClone from 'rfdc/default';
|
|
6
|
+
// $FlowFixMe
|
|
7
|
+
import {diff} from 'jest-diff';
|
|
8
|
+
import AssetGraph from '../AssetGraph';
|
|
9
|
+
import type {AssetGraphNode} from '../types';
|
|
10
|
+
import {fromProjectPathRelative, toProjectPath} from '../projectPath';
|
|
11
|
+
|
|
12
|
+
function filterNode(node) {
|
|
13
|
+
let clone = deepClone(node);
|
|
14
|
+
|
|
15
|
+
// Clean up anything you don't want to see in the diff
|
|
16
|
+
// delete clone.id;
|
|
17
|
+
delete clone.value.id;
|
|
18
|
+
delete clone.value.meta.id;
|
|
19
|
+
delete clone.value.sourceAssetId;
|
|
20
|
+
delete clone.value.env.id;
|
|
21
|
+
delete clone.value.isEsm;
|
|
22
|
+
delete clone.value.shouldWrap;
|
|
23
|
+
delete clone.value.contentKey;
|
|
24
|
+
delete clone.value.placeholder;
|
|
25
|
+
delete clone.value.code;
|
|
26
|
+
delete clone.value.hasCjsExports;
|
|
27
|
+
delete clone.value.staticExports;
|
|
28
|
+
delete clone.value.isConstantModule;
|
|
29
|
+
delete clone.value.hasNodeReplacements;
|
|
30
|
+
delete clone.value.stats;
|
|
31
|
+
delete clone.value.astKey;
|
|
32
|
+
delete clone.value.astGenerator;
|
|
33
|
+
delete clone.value.dependencies;
|
|
34
|
+
|
|
35
|
+
return clone;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function compactDeep(
|
|
39
|
+
obj: mixed,
|
|
40
|
+
ignoredPatterns: Array<string> = [],
|
|
41
|
+
currentPath: string = '$',
|
|
42
|
+
) {
|
|
43
|
+
if (obj instanceof Map) {
|
|
44
|
+
const copy = {};
|
|
45
|
+
Array.from(obj.entries()).forEach(([k, v]) => {
|
|
46
|
+
if (v != null) {
|
|
47
|
+
copy[k] = compactDeep(v, ignoredPatterns, `${currentPath}.${k}`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return copy;
|
|
51
|
+
} else if (Array.isArray(obj)) {
|
|
52
|
+
return obj.map(v => compactDeep(v, ignoredPatterns, `${currentPath}[]`));
|
|
53
|
+
} else if (typeof obj === 'object') {
|
|
54
|
+
const copy = {};
|
|
55
|
+
Object.entries(obj ?? {}).forEach(([key, value]) => {
|
|
56
|
+
const path = `${currentPath}.${key}`;
|
|
57
|
+
if (ignoredPatterns.some(pattern => path.includes(pattern))) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Equivalent false == null
|
|
61
|
+
if (key === 'isWeak' && value === false) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (value != null) {
|
|
66
|
+
copy[key] = compactDeep(value, ignoredPatterns, path);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return copy;
|
|
70
|
+
} else if (obj != null) {
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function assetGraphDiff(jsAssetGraph: AssetGraph, rustAssetGraph: AssetGraph) {
|
|
76
|
+
const getNodes = graph => {
|
|
77
|
+
let nodes = {};
|
|
78
|
+
|
|
79
|
+
graph.traverse(nodeId => {
|
|
80
|
+
let node: AssetGraphNode | null = graph.getNode(nodeId) ?? null;
|
|
81
|
+
if (!node) return;
|
|
82
|
+
|
|
83
|
+
if (node.type === 'dependency') {
|
|
84
|
+
let sourcePath = node.value.sourcePath ?? toProjectPath('', 'entry');
|
|
85
|
+
nodes[
|
|
86
|
+
`dep:${fromProjectPathRelative(sourcePath)}:${node.value.specifier}`
|
|
87
|
+
] = filterNode(node);
|
|
88
|
+
} else if (node.type === 'asset') {
|
|
89
|
+
nodes[`asset:${fromProjectPathRelative(node.value.filePath)}`] =
|
|
90
|
+
filterNode(node);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return nodes;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const jsNodes = getNodes(jsAssetGraph);
|
|
98
|
+
const rustNodes = getNodes(rustAssetGraph);
|
|
99
|
+
|
|
100
|
+
const all = new Set([...Object.keys(jsNodes), ...Object.keys(rustNodes)]);
|
|
101
|
+
const missing = [];
|
|
102
|
+
const extra = [];
|
|
103
|
+
|
|
104
|
+
for (const key of all.keys()) {
|
|
105
|
+
if (process.env.NATIVE_COMPARE !== 'true') {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
let jsNode = jsNodes[key];
|
|
109
|
+
let rustNode = rustNodes[key];
|
|
110
|
+
|
|
111
|
+
if (!rustNode) {
|
|
112
|
+
missing.push(key);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!jsNode) {
|
|
116
|
+
extra.push(key);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log(key);
|
|
121
|
+
const ignoredPatterns = [
|
|
122
|
+
// ignored because we don't copy the environment ID back from rust
|
|
123
|
+
// in the target value
|
|
124
|
+
'$.value.target.env.id',
|
|
125
|
+
// ignore asset.mapKey because we don't do persistence on rust yet
|
|
126
|
+
'$.value.mapKey',
|
|
127
|
+
// ignore this because it's just the output hash. We don't need to compute
|
|
128
|
+
// this yet
|
|
129
|
+
'$.value.outputHash',
|
|
130
|
+
// ignore correspondingRequest from all nodes
|
|
131
|
+
'$.correspondingRequest',
|
|
132
|
+
];
|
|
133
|
+
console.log(
|
|
134
|
+
diff(
|
|
135
|
+
compactDeep(rustNode, ignoredPatterns),
|
|
136
|
+
compactDeep(jsNode, ignoredPatterns),
|
|
137
|
+
),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log('Missing', missing);
|
|
142
|
+
console.log('Extra', extra);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = assetGraphDiff;
|
package/src/resolveOptions.js
CHANGED
|
@@ -12,7 +12,8 @@ import type {AtlaspackOptions} from './types';
|
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import {hashString} from '@atlaspack/rust';
|
|
14
14
|
import {NodeFS} from '@atlaspack/fs';
|
|
15
|
-
import {LMDBCache, FSCache} from '@atlaspack/cache';
|
|
15
|
+
import {LMDBCache, LMDBLiteCache, FSCache} from '@atlaspack/cache';
|
|
16
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
16
17
|
import {NodePackageManager} from '@atlaspack/package-manager';
|
|
17
18
|
import {
|
|
18
19
|
getRootDir,
|
|
@@ -108,10 +109,17 @@ export default async function resolveOptions(
|
|
|
108
109
|
? path.resolve(initialOptions.watchDir)
|
|
109
110
|
: projectRoot;
|
|
110
111
|
|
|
112
|
+
const makeLMDBCache = () => {
|
|
113
|
+
if (getFeatureFlag('useLmdbJsLite')) {
|
|
114
|
+
return new LMDBLiteCache(cacheDir);
|
|
115
|
+
}
|
|
116
|
+
return new LMDBCache(cacheDir);
|
|
117
|
+
};
|
|
118
|
+
|
|
111
119
|
let cache =
|
|
112
120
|
initialOptions.cache ??
|
|
113
121
|
(outputFS instanceof NodeFS
|
|
114
|
-
?
|
|
122
|
+
? makeLMDBCache()
|
|
115
123
|
: new FSCache(outputFS, cacheDir));
|
|
116
124
|
|
|
117
125
|
let mode = initialOptions.mode ?? 'development';
|
|
@@ -223,6 +231,8 @@ export default async function resolveOptions(
|
|
|
223
231
|
outputFormat: initialOptions?.defaultTargetOptions?.outputFormat,
|
|
224
232
|
isLibrary: initialOptions?.defaultTargetOptions?.isLibrary,
|
|
225
233
|
},
|
|
234
|
+
// unused, feature-flags are set above this to allow this function to use
|
|
235
|
+
// feature-flags
|
|
226
236
|
featureFlags: {...DEFAULT_FEATURE_FLAGS, ...initialOptions?.featureFlags},
|
|
227
237
|
parcelVersion: ATLASPACK_VERSION,
|
|
228
238
|
};
|
package/src/types.js
CHANGED
|
@@ -115,6 +115,7 @@ export const Priority = {
|
|
|
115
115
|
sync: 0,
|
|
116
116
|
parallel: 1,
|
|
117
117
|
lazy: 2,
|
|
118
|
+
conditional: 3,
|
|
118
119
|
};
|
|
119
120
|
|
|
120
121
|
// Must match package_json.rs in node-resolver-rs.
|
|
@@ -542,6 +543,7 @@ export type Bundle = {|
|
|
|
542
543
|
displayName: ?string,
|
|
543
544
|
pipeline: ?string,
|
|
544
545
|
manualSharedBundle?: ?string,
|
|
546
|
+
conditions?: Map<string, string>,
|
|
545
547
|
|};
|
|
546
548
|
|
|
547
549
|
export type BundleNode = {|
|
|
@@ -580,3 +582,11 @@ export type ValidationOpts = {|
|
|
|
580
582
|
|};
|
|
581
583
|
|
|
582
584
|
export type ReportFn = (event: ReporterEvent) => void | Promise<void>;
|
|
585
|
+
|
|
586
|
+
export type Condition = {|
|
|
587
|
+
publicId: string,
|
|
588
|
+
assets: Set<Asset>,
|
|
589
|
+
key: string,
|
|
590
|
+
ifTrueDependency: Dependency,
|
|
591
|
+
ifFalseDependency: Dependency,
|
|
592
|
+
|};
|