@atlaspack/core 2.12.1-dev.3401 → 2.12.1-dev.3450
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 +247 -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 +300 -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
|
@@ -1,14 +1,312 @@
|
|
|
1
1
|
// @flow
|
|
2
|
+
import assert from 'assert';
|
|
2
3
|
import * as napi from '@atlaspack/rust';
|
|
4
|
+
import {NodeFS} from '@atlaspack/fs';
|
|
5
|
+
import {NodePackageManager} from '@atlaspack/package-manager';
|
|
6
|
+
import type {
|
|
7
|
+
Resolver,
|
|
8
|
+
Transformer,
|
|
9
|
+
PluginOptions,
|
|
10
|
+
Dependency,
|
|
11
|
+
FilePath,
|
|
12
|
+
FileSystem,
|
|
13
|
+
ConfigResultWithFilePath,
|
|
14
|
+
PackageJSON,
|
|
15
|
+
} from '@atlaspack/types';
|
|
3
16
|
import {workerData} from 'worker_threads';
|
|
4
|
-
import
|
|
17
|
+
import * as module from 'module';
|
|
18
|
+
|
|
19
|
+
import {AssetCompat} from './compat';
|
|
20
|
+
import type {InnerAsset} from './compat';
|
|
21
|
+
import {jsCallable} from '../jsCallable';
|
|
22
|
+
import type {JsCallable} from '../jsCallable';
|
|
23
|
+
import Environment from '../../public/Environment';
|
|
24
|
+
|
|
25
|
+
const CONFIG = Symbol.for('parcel-plugin-config');
|
|
5
26
|
|
|
6
27
|
export class AtlaspackWorker {
|
|
7
|
-
#resolvers: Map<string,
|
|
28
|
+
#resolvers: Map<string, ResolverState<any>>;
|
|
29
|
+
#fs: FileSystem;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
this.#resolvers = new Map();
|
|
33
|
+
this.#fs = new NodeFS();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
loadPlugin: JsCallable<[LoadPluginOptions], Promise<void>> = jsCallable(
|
|
37
|
+
async ({kind, specifier, resolveFrom}) => {
|
|
38
|
+
let customRequire = module.createRequire(resolveFrom);
|
|
39
|
+
let resolvedPath = customRequire.resolve(specifier);
|
|
40
|
+
// $FlowFixMe
|
|
41
|
+
let resolvedModule = await import(resolvedPath);
|
|
42
|
+
|
|
43
|
+
let instance = undefined;
|
|
44
|
+
if (resolvedModule.default && resolvedModule.default[CONFIG]) {
|
|
45
|
+
instance = resolvedModule.default[CONFIG];
|
|
46
|
+
} else if (
|
|
47
|
+
resolvedModule.default &&
|
|
48
|
+
resolvedModule.default.default &&
|
|
49
|
+
resolvedModule.default.default[CONFIG]
|
|
50
|
+
) {
|
|
51
|
+
instance = resolvedModule.default.default[CONFIG];
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Plugin could not be resolved\n\t${kind}\n\t${resolveFrom}\n\t${specifier}`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
switch (kind) {
|
|
59
|
+
case 'resolver':
|
|
60
|
+
this.#resolvers.set(specifier, {resolver: instance});
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
runResolverResolve: JsCallable<
|
|
67
|
+
[RunResolverResolveOptions],
|
|
68
|
+
Promise<RunResolverResolveResult>,
|
|
69
|
+
> = jsCallable(
|
|
70
|
+
async ({key, dependency, specifier, pipeline, projectRoot}) => {
|
|
71
|
+
const state = this.#resolvers.get(key);
|
|
72
|
+
if (!state) {
|
|
73
|
+
throw new Error(`Resolver not found: ${key}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let packageManager = state.packageManager;
|
|
77
|
+
if (!packageManager) {
|
|
78
|
+
packageManager = new NodePackageManager(this.#fs, projectRoot);
|
|
79
|
+
state.packageManager = packageManager;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const defaultOptions = {
|
|
83
|
+
get logger() {
|
|
84
|
+
// $FlowFixMe
|
|
85
|
+
return globalThis.console;
|
|
86
|
+
},
|
|
87
|
+
tracer: {
|
|
88
|
+
enabled: false,
|
|
89
|
+
createMeasurement: () => null,
|
|
90
|
+
},
|
|
91
|
+
options: {
|
|
92
|
+
get mode() {
|
|
93
|
+
throw new Error('Resolver.resolve.options.mode');
|
|
94
|
+
},
|
|
95
|
+
parcelVersion: 'TODO',
|
|
96
|
+
packageManager,
|
|
97
|
+
env: process.env,
|
|
98
|
+
get hmrOptions() {
|
|
99
|
+
throw new Error('Resolver.resolve.options.hmrOptions');
|
|
100
|
+
},
|
|
101
|
+
get serveOptions() {
|
|
102
|
+
throw new Error('Resolver.resolve.options.serveOptions');
|
|
103
|
+
},
|
|
104
|
+
get shouldBuildLazily() {
|
|
105
|
+
throw new Error('Resolver.resolve.options.shouldBuildLazily');
|
|
106
|
+
},
|
|
107
|
+
shouldAutoInstall: false,
|
|
108
|
+
get logLevel() {
|
|
109
|
+
throw new Error('Resolver.resolve.options.logLevel');
|
|
110
|
+
},
|
|
111
|
+
projectRoot,
|
|
112
|
+
get cacheDir() {
|
|
113
|
+
throw new Error('Resolver.resolve.options.cacheDir');
|
|
114
|
+
},
|
|
115
|
+
inputFS: this.#fs,
|
|
116
|
+
outputFS: this.#fs,
|
|
117
|
+
get instanceId() {
|
|
118
|
+
throw new Error('Resolver.resolve.options.instanceId');
|
|
119
|
+
},
|
|
120
|
+
get detailedReport() {
|
|
121
|
+
throw new Error('Resolver.resolve.options.detailedReport');
|
|
122
|
+
},
|
|
123
|
+
get featureFlags() {
|
|
124
|
+
throw new Error('Resolver.resolve.options.featureFlags');
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
if (!('config' in state)) {
|
|
130
|
+
state.config = await state.resolver.loadConfig?.({
|
|
131
|
+
config: {
|
|
132
|
+
isSource: true,
|
|
133
|
+
searchPath: '',
|
|
134
|
+
// $FlowFixMe This isn't correct to flow but is enough to satisfy the runtime checks
|
|
135
|
+
env: new Environment(dependency.env, {
|
|
136
|
+
projectRoot,
|
|
137
|
+
hmrOptions: undefined,
|
|
138
|
+
}),
|
|
139
|
+
invalidateOnFileChange(): void {},
|
|
140
|
+
invalidateOnFileCreate(): void {},
|
|
141
|
+
invalidateOnEnvChange(): void {},
|
|
142
|
+
invalidateOnStartup(): void {},
|
|
143
|
+
invalidateOnBuild(): void {},
|
|
144
|
+
addDevDependency(): void {},
|
|
145
|
+
setCacheKey(): void {},
|
|
146
|
+
getConfig<T>(): Promise<?ConfigResultWithFilePath<T>> {
|
|
147
|
+
throw new Error('Resolver.loadConfig.config.getConfig');
|
|
148
|
+
},
|
|
149
|
+
getConfigFrom<T>(): Promise<?ConfigResultWithFilePath<T>> {
|
|
150
|
+
throw new Error('Resolver.loadConfig.config.getConfigFrom');
|
|
151
|
+
},
|
|
152
|
+
getPackage(): Promise<?PackageJSON> {
|
|
153
|
+
throw new Error('Resolver.loadConfig.config.getPackage');
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
...defaultOptions,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const result = await state.resolver.resolve({
|
|
161
|
+
specifier,
|
|
162
|
+
dependency,
|
|
163
|
+
pipeline,
|
|
164
|
+
config: state.config,
|
|
165
|
+
...defaultOptions,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (!result) {
|
|
169
|
+
return {
|
|
170
|
+
invalidations: [],
|
|
171
|
+
resolution: {type: 'unresolved'},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
invalidations: [],
|
|
177
|
+
resolution: {
|
|
178
|
+
type: 'resolved',
|
|
179
|
+
filePath: result.filePath || '',
|
|
180
|
+
canDefer: result.canDefer || false,
|
|
181
|
+
sideEffects: result.sideEffects || false,
|
|
182
|
+
code: result.code || undefined,
|
|
183
|
+
meta: result.meta || undefined,
|
|
184
|
+
pipeline: result.pipeline || undefined,
|
|
185
|
+
priority: result.priority && PriorityMap[result.priority],
|
|
186
|
+
query: result.query && result.query.toString(),
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
);
|
|
8
191
|
|
|
9
192
|
ping() {
|
|
10
193
|
// console.log('Hi');
|
|
11
194
|
}
|
|
195
|
+
|
|
196
|
+
async runTransformer({
|
|
197
|
+
resolveFrom,
|
|
198
|
+
specifier,
|
|
199
|
+
options,
|
|
200
|
+
asset,
|
|
201
|
+
}: {|
|
|
202
|
+
resolveFrom: string,
|
|
203
|
+
specifier: string,
|
|
204
|
+
options: PluginOptions,
|
|
205
|
+
asset: InnerAsset,
|
|
206
|
+
|}): any {
|
|
207
|
+
const customRequire = module.createRequire(resolveFrom);
|
|
208
|
+
const resolvedPath = customRequire.resolve(specifier);
|
|
209
|
+
// $FlowFixMe
|
|
210
|
+
const transformerModule = await import(resolvedPath);
|
|
211
|
+
const transformer: Transformer<*> =
|
|
212
|
+
transformerModule.default.default[CONFIG];
|
|
213
|
+
|
|
214
|
+
let assetCompat = new AssetCompat(asset, options);
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
if (transformer.parse) {
|
|
218
|
+
// $FlowFixMe
|
|
219
|
+
const ast = await transformer.parse({asset: assetCompat}); // missing "config"
|
|
220
|
+
// $FlowFixMe
|
|
221
|
+
assetCompat.setAST(ast);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// $FlowFixMe
|
|
225
|
+
const result = await transformer.transform({
|
|
226
|
+
// $FlowFixMe
|
|
227
|
+
asset: assetCompat,
|
|
228
|
+
options,
|
|
229
|
+
config: null,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
if (transformer.generate) {
|
|
233
|
+
// $FlowFixMe
|
|
234
|
+
let output = await transformer.generate({
|
|
235
|
+
// $FlowFixMe
|
|
236
|
+
asset: assetCompat,
|
|
237
|
+
// $FlowFixMe
|
|
238
|
+
ast: assetCompat.getAST(),
|
|
239
|
+
});
|
|
240
|
+
// $FlowFixMe
|
|
241
|
+
assetCompat.setCode(output.content);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
assert(
|
|
245
|
+
result.length === 1,
|
|
246
|
+
'[V3] Unimplemented: Multiple asset return from Node transformer',
|
|
247
|
+
);
|
|
248
|
+
assert(
|
|
249
|
+
result[0] === assetCompat,
|
|
250
|
+
'[V3] Unimplemented: New asset returned from Node transformer',
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
asset,
|
|
255
|
+
dependencies: assetCompat._dependencies,
|
|
256
|
+
};
|
|
257
|
+
} catch (e) {
|
|
258
|
+
// TODO: Improve error logging from JS plugins. Without this you currently
|
|
259
|
+
// only see the error message, no stack trace.
|
|
260
|
+
// eslint-disable-next-line no-console
|
|
261
|
+
console.error(e);
|
|
262
|
+
throw e;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
12
265
|
}
|
|
13
266
|
|
|
14
267
|
napi.registerWorker(workerData.tx_worker, new AtlaspackWorker());
|
|
268
|
+
|
|
269
|
+
type ResolverState<T> = {|
|
|
270
|
+
resolver: Resolver<T>,
|
|
271
|
+
config?: T,
|
|
272
|
+
packageManager?: NodePackageManager,
|
|
273
|
+
|};
|
|
274
|
+
|
|
275
|
+
type LoadPluginOptions = {|
|
|
276
|
+
kind: 'resolver',
|
|
277
|
+
specifier: string,
|
|
278
|
+
resolveFrom: string,
|
|
279
|
+
|};
|
|
280
|
+
|
|
281
|
+
type RunResolverResolveOptions = {|
|
|
282
|
+
key: string,
|
|
283
|
+
dependency: Dependency,
|
|
284
|
+
specifier: FilePath,
|
|
285
|
+
pipeline: ?string,
|
|
286
|
+
projectRoot: string,
|
|
287
|
+
|};
|
|
288
|
+
|
|
289
|
+
type RunResolverResolveResult = {|
|
|
290
|
+
invalidations: Array<*>,
|
|
291
|
+
resolution:
|
|
292
|
+
| {|type: 'unresolved'|}
|
|
293
|
+
| {|type: 'excluded'|}
|
|
294
|
+
| {|
|
|
295
|
+
type: 'resolved',
|
|
296
|
+
canDefer: boolean,
|
|
297
|
+
filePath: string,
|
|
298
|
+
sideEffects: boolean,
|
|
299
|
+
code?: string,
|
|
300
|
+
meta?: mixed,
|
|
301
|
+
pipeline?: string,
|
|
302
|
+
priority?: number,
|
|
303
|
+
query?: string,
|
|
304
|
+
|},
|
|
305
|
+
|};
|
|
306
|
+
|
|
307
|
+
const PriorityMap = {
|
|
308
|
+
sync: 0,
|
|
309
|
+
parallel: 1,
|
|
310
|
+
lazy: 2,
|
|
311
|
+
conditional: 3,
|
|
312
|
+
};
|
|
@@ -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
|
|