@atlaspack/core 2.12.1-dev.3443 → 2.12.1-dev.3460
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 +5 -1
- package/lib/Atlaspack.js +2 -2
- package/lib/Dependency.js +1 -1
- package/lib/PackagerRunner.js +45 -3
- package/lib/SymbolPropagation.js +25 -36
- package/lib/assetUtils.js +1 -1
- package/lib/atlaspack-v3/fs.js +31 -29
- package/lib/atlaspack-v3/index.js +2 -2
- package/lib/atlaspack-v3/jsCallable.js +9 -4
- package/lib/atlaspack-v3/worker/compat/asset-symbols.js +192 -0
- package/lib/atlaspack-v3/worker/compat/bitflags.js +84 -0
- package/lib/atlaspack-v3/worker/compat/dependency.js +44 -0
- package/lib/atlaspack-v3/worker/compat/environment.js +68 -0
- package/lib/atlaspack-v3/worker/compat/index.js +104 -0
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +144 -0
- package/lib/atlaspack-v3/worker/compat/plugin-config.js +58 -0
- package/lib/atlaspack-v3/worker/compat/plugin-logger.js +29 -0
- package/lib/atlaspack-v3/worker/compat/plugin-options.js +113 -0
- package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +12 -0
- package/lib/atlaspack-v3/worker/compat/target.js +17 -0
- package/lib/atlaspack-v3/worker/worker.js +162 -83
- package/lib/projectPath.js +12 -4
- package/lib/requests/ConfigRequest.js +1 -1
- package/lib/requests/WriteBundleRequest.js +15 -15
- package/package.json +23 -16
- package/src/AssetGraph.js +15 -13
- package/src/Atlaspack.js +5 -6
- package/src/AtlaspackConfig.js +11 -9
- package/src/AtlaspackConfig.schema.js +1 -1
- package/src/BundleGraph.js +83 -79
- package/src/CommittedAsset.js +1 -1
- package/src/Dependency.js +1 -1
- package/src/PackagerRunner.js +56 -8
- package/src/ReporterRunner.js +4 -4
- package/src/RequestTracker.js +18 -18
- package/src/SymbolPropagation.js +40 -52
- package/src/Transformation.js +12 -12
- package/src/UncommittedAsset.js +2 -2
- package/src/Validation.js +5 -5
- package/src/applyRuntimes.js +2 -2
- package/src/assetUtils.js +1 -1
- package/src/atlaspack-v3/AtlaspackV3.js +1 -1
- package/src/atlaspack-v3/fs.js +39 -25
- package/src/atlaspack-v3/index.js +1 -1
- package/src/atlaspack-v3/jsCallable.js +11 -10
- package/src/atlaspack-v3/worker/compat/asset-symbols.js +225 -0
- package/src/atlaspack-v3/worker/compat/bitflags.js +100 -0
- package/src/atlaspack-v3/worker/compat/dependency.js +83 -0
- package/src/atlaspack-v3/worker/compat/environment.js +92 -0
- package/src/atlaspack-v3/worker/compat/index.js +10 -0
- package/src/atlaspack-v3/worker/compat/mutable-asset.js +184 -0
- package/src/atlaspack-v3/worker/compat/plugin-config.js +94 -0
- package/src/atlaspack-v3/worker/compat/plugin-logger.js +47 -0
- package/src/atlaspack-v3/worker/compat/plugin-options.js +137 -0
- package/src/atlaspack-v3/worker/compat/plugin-tracer.js +11 -0
- package/src/atlaspack-v3/worker/compat/target.js +27 -0
- package/src/atlaspack-v3/worker/worker.js +218 -113
- package/src/dumpGraphToGraphViz.js +1 -1
- package/src/loadDotEnv.js +1 -1
- package/src/projectPath.js +12 -4
- package/src/public/Asset.js +1 -1
- package/src/public/Bundle.js +3 -3
- package/src/public/BundleGraph.js +20 -20
- package/src/public/Config.js +1 -1
- package/src/public/MutableBundleGraph.js +8 -8
- package/src/requests/AssetGraphRequest.js +10 -10
- package/src/requests/AssetGraphRequestRust.js +3 -3
- package/src/requests/AssetRequest.js +3 -3
- package/src/requests/AtlaspackConfigRequest.js +5 -3
- package/src/requests/BundleGraphRequest.js +6 -6
- package/src/requests/ConfigRequest.js +5 -5
- package/src/requests/DevDepRequest.js +7 -7
- package/src/requests/EntryRequest.js +2 -2
- package/src/requests/TargetRequest.js +9 -8
- package/src/requests/ValidationRequest.js +2 -2
- package/src/requests/WriteBundleRequest.js +26 -20
- package/src/requests/WriteBundlesRequest.js +6 -6
- package/src/requests/asset-graph-diff.js +4 -4
- package/src/resolveOptions.js +3 -3
- package/src/serializer.js +2 -2
- package/src/serializerCore.browser.js +3 -2
- package/src/serializerCore.js +2 -2
- package/src/utils.js +2 -2
- package/test/AtlaspackConfigRequest.test.js +1 -1
- package/test/BundleGraph.test.js +3 -3
- package/test/Dependency.test.js +28 -0
- package/test/PublicMutableBundleGraph.test.js +2 -2
- package/test/RequestTracker.test.js +7 -6
- package/test/SymbolPropagation.test.js +9 -9
- package/test/requests/ConfigRequest.test.js +3 -6
- package/test/utils.test.js +1 -1
- package/lib/atlaspack-v3/worker/compat.js +0 -57
- package/src/atlaspack-v3/worker/compat.js +0 -82
- package/test/requests/WriteBundleRequest.test.js +0 -132
|
@@ -1,28 +1,42 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import assert from 'assert';
|
|
3
3
|
import * as napi from '@atlaspack/rust';
|
|
4
|
+
import type {JsCallable} from '@atlaspack/rust';
|
|
5
|
+
import {NodeFS} from '@atlaspack/fs';
|
|
6
|
+
import {NodePackageManager} from '@atlaspack/package-manager';
|
|
4
7
|
import type {
|
|
5
8
|
Resolver,
|
|
6
9
|
Transformer,
|
|
7
|
-
PluginOptions,
|
|
8
|
-
Dependency,
|
|
9
10
|
FilePath,
|
|
11
|
+
FileSystem,
|
|
10
12
|
} from '@atlaspack/types';
|
|
11
13
|
import {workerData} from 'worker_threads';
|
|
12
14
|
import * as module from 'module';
|
|
13
15
|
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
+
import {
|
|
17
|
+
Environment,
|
|
18
|
+
Dependency,
|
|
19
|
+
PluginConfig,
|
|
20
|
+
PluginLogger,
|
|
21
|
+
PluginTracer,
|
|
22
|
+
PluginOptions,
|
|
23
|
+
MutableAsset,
|
|
24
|
+
bundleBehaviorMap,
|
|
25
|
+
dependencyPriorityMap,
|
|
26
|
+
} from './compat';
|
|
16
27
|
import {jsCallable} from '../jsCallable';
|
|
17
|
-
import type {JsCallable} from '../jsCallable';
|
|
18
28
|
|
|
19
29
|
const CONFIG = Symbol.for('parcel-plugin-config');
|
|
20
30
|
|
|
21
31
|
export class AtlaspackWorker {
|
|
22
|
-
#resolvers: Map<string,
|
|
32
|
+
#resolvers: Map<string, ResolverState<any>>;
|
|
33
|
+
#transformers: Map<string, TransformerState<any>>;
|
|
34
|
+
#fs: FileSystem;
|
|
23
35
|
|
|
24
36
|
constructor() {
|
|
25
37
|
this.#resolvers = new Map();
|
|
38
|
+
this.#transformers = new Map();
|
|
39
|
+
this.#fs = new NodeFS();
|
|
26
40
|
}
|
|
27
41
|
|
|
28
42
|
loadPlugin: JsCallable<[LoadPluginOptions], Promise<void>> = jsCallable(
|
|
@@ -37,6 +51,7 @@ export class AtlaspackWorker {
|
|
|
37
51
|
instance = resolvedModule.default[CONFIG];
|
|
38
52
|
} else if (
|
|
39
53
|
resolvedModule.default &&
|
|
54
|
+
resolvedModule.default.default &&
|
|
40
55
|
resolvedModule.default.default[CONFIG]
|
|
41
56
|
) {
|
|
42
57
|
instance = resolvedModule.default.default[CONFIG];
|
|
@@ -48,7 +63,10 @@ export class AtlaspackWorker {
|
|
|
48
63
|
|
|
49
64
|
switch (kind) {
|
|
50
65
|
case 'resolver':
|
|
51
|
-
this.#resolvers.set(specifier, instance);
|
|
66
|
+
this.#resolvers.set(specifier, {resolver: instance});
|
|
67
|
+
break;
|
|
68
|
+
case 'transformer':
|
|
69
|
+
this.#transformers.set(specifier, {transformer: instance});
|
|
52
70
|
break;
|
|
53
71
|
}
|
|
54
72
|
},
|
|
@@ -57,142 +75,225 @@ export class AtlaspackWorker {
|
|
|
57
75
|
runResolverResolve: JsCallable<
|
|
58
76
|
[RunResolverResolveOptions],
|
|
59
77
|
Promise<RunResolverResolveResult>,
|
|
60
|
-
> = jsCallable(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const result = await resolver.resolve({
|
|
78
|
+
> = jsCallable(
|
|
79
|
+
async ({
|
|
80
|
+
key,
|
|
81
|
+
dependency: napiDependency,
|
|
67
82
|
specifier,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
throw new Error(
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
pipeline,
|
|
84
|
+
projectRoot,
|
|
85
|
+
}) => {
|
|
86
|
+
const state = this.#resolvers.get(key);
|
|
87
|
+
if (!state) {
|
|
88
|
+
throw new Error(`Resolver not found: ${key}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let packageManager = state.packageManager;
|
|
92
|
+
if (!packageManager) {
|
|
93
|
+
packageManager = new NodePackageManager(this.#fs, projectRoot);
|
|
94
|
+
state.packageManager = packageManager;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const env = new Environment(napiDependency.env);
|
|
98
|
+
const dependency = new Dependency(napiDependency, env);
|
|
99
|
+
|
|
100
|
+
const defaultOptions = {
|
|
101
|
+
logger: new PluginLogger(),
|
|
102
|
+
tracer: new PluginTracer(),
|
|
103
|
+
options: new PluginOptions({
|
|
104
|
+
packageManager,
|
|
105
|
+
shouldAutoInstall: false,
|
|
106
|
+
projectRoot,
|
|
107
|
+
inputFS: this.#fs,
|
|
108
|
+
outputFS: this.#fs,
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
if (!('config' in state)) {
|
|
113
|
+
state.config = await state.resolver.loadConfig?.({
|
|
114
|
+
config: new PluginConfig({
|
|
115
|
+
env,
|
|
116
|
+
isSource: true,
|
|
117
|
+
searchPath: '',
|
|
118
|
+
}),
|
|
119
|
+
...defaultOptions,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const result = await state.resolver.resolve({
|
|
124
|
+
specifier,
|
|
125
|
+
dependency,
|
|
126
|
+
pipeline,
|
|
127
|
+
config: state.config,
|
|
128
|
+
...defaultOptions,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (!result) {
|
|
132
|
+
return {
|
|
133
|
+
invalidations: [],
|
|
134
|
+
resolution: {type: 'unresolved'},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
87
138
|
return {
|
|
88
139
|
invalidations: [],
|
|
89
|
-
resolution: {
|
|
140
|
+
resolution: {
|
|
141
|
+
type: 'resolved',
|
|
142
|
+
filePath: result.filePath || '',
|
|
143
|
+
canDefer: result.canDefer || false,
|
|
144
|
+
sideEffects: result.sideEffects || false,
|
|
145
|
+
code: result.code || undefined,
|
|
146
|
+
meta: result.meta || undefined,
|
|
147
|
+
pipeline: result.pipeline || undefined,
|
|
148
|
+
priority: dependencyPriorityMap.intoNullable(result.priority),
|
|
149
|
+
query: result.query && result.query.toString(),
|
|
150
|
+
},
|
|
90
151
|
};
|
|
91
|
-
}
|
|
152
|
+
},
|
|
153
|
+
);
|
|
92
154
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
155
|
+
runTransformerTransform: JsCallable<
|
|
156
|
+
[RunTransformerTransformOptions],
|
|
157
|
+
Promise<RunTransformerTransformResult>,
|
|
158
|
+
> = jsCallable(
|
|
159
|
+
async ({key, env: napiEnv, projectRoot, asset: innerAsset}) => {
|
|
160
|
+
const state = this.#transformers.get(key);
|
|
161
|
+
if (!state) {
|
|
162
|
+
throw new Error(`Transformer not found: ${key}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let packageManager = state.packageManager;
|
|
166
|
+
if (!packageManager) {
|
|
167
|
+
packageManager = new NodePackageManager(this.#fs, projectRoot);
|
|
168
|
+
state.packageManager = packageManager;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const transformer: Transformer<any> = state.transformer;
|
|
172
|
+
const env = new Environment(napiEnv);
|
|
173
|
+
const mutableAsset = new MutableAsset(innerAsset, this.#fs, env);
|
|
174
|
+
const defaultOptions = {
|
|
175
|
+
logger: new PluginLogger(),
|
|
176
|
+
tracer: new PluginTracer(),
|
|
177
|
+
options: new PluginOptions({
|
|
178
|
+
packageManager,
|
|
179
|
+
shouldAutoInstall: false,
|
|
180
|
+
projectRoot,
|
|
181
|
+
inputFS: this.#fs,
|
|
182
|
+
outputFS: this.#fs,
|
|
183
|
+
}),
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const config = await transformer.loadConfig?.({
|
|
187
|
+
config: new PluginConfig({
|
|
188
|
+
env,
|
|
189
|
+
isSource: true,
|
|
190
|
+
searchPath: '',
|
|
191
|
+
}),
|
|
192
|
+
...defaultOptions,
|
|
193
|
+
});
|
|
112
194
|
|
|
113
|
-
async runTransformer({
|
|
114
|
-
resolveFrom,
|
|
115
|
-
specifier,
|
|
116
|
-
options,
|
|
117
|
-
asset,
|
|
118
|
-
}: {|
|
|
119
|
-
resolveFrom: string,
|
|
120
|
-
specifier: string,
|
|
121
|
-
options: PluginOptions,
|
|
122
|
-
asset: InnerAsset,
|
|
123
|
-
|}): any {
|
|
124
|
-
const customRequire = module.createRequire(resolveFrom);
|
|
125
|
-
const resolvedPath = customRequire.resolve(specifier);
|
|
126
|
-
// $FlowFixMe
|
|
127
|
-
const transformerModule = await import(resolvedPath);
|
|
128
|
-
const transformer: Transformer<*> =
|
|
129
|
-
transformerModule.default.default[CONFIG];
|
|
130
|
-
|
|
131
|
-
let assetCompat = new AssetCompat(asset, options);
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
195
|
if (transformer.parse) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
196
|
+
const ast = await transformer.parse({
|
|
197
|
+
asset: mutableAsset,
|
|
198
|
+
config,
|
|
199
|
+
get resolve() {
|
|
200
|
+
throw new Error('Transformer.parse.resolve()');
|
|
201
|
+
},
|
|
202
|
+
...defaultOptions,
|
|
203
|
+
});
|
|
204
|
+
if (ast) {
|
|
205
|
+
mutableAsset.setAST(ast);
|
|
206
|
+
}
|
|
139
207
|
}
|
|
140
208
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
209
|
+
const result = await state.transformer.transform({
|
|
210
|
+
asset: mutableAsset,
|
|
211
|
+
config,
|
|
212
|
+
get resolve() {
|
|
213
|
+
throw new Error('Transformer.transform.resolve()');
|
|
214
|
+
},
|
|
215
|
+
...defaultOptions,
|
|
147
216
|
});
|
|
148
217
|
|
|
149
218
|
if (transformer.generate) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
219
|
+
const ast = await mutableAsset.getAST();
|
|
220
|
+
if (!ast) {
|
|
221
|
+
throw new Error('Transformer.generate.ast');
|
|
222
|
+
}
|
|
223
|
+
// $FlowFixMe "Cannot call `transformer.generate` because undefined [1] is not a function." 🤷♀️
|
|
224
|
+
const output = await transformer.generate({
|
|
225
|
+
asset: mutableAsset,
|
|
226
|
+
ast,
|
|
227
|
+
...defaultOptions,
|
|
156
228
|
});
|
|
157
|
-
|
|
158
|
-
|
|
229
|
+
|
|
230
|
+
if (typeof output.content === 'string') {
|
|
231
|
+
mutableAsset.setCode(output.content);
|
|
232
|
+
} else if (output.content instanceof Buffer) {
|
|
233
|
+
mutableAsset.setBuffer(output.content);
|
|
234
|
+
} else {
|
|
235
|
+
mutableAsset.setStream(output.content);
|
|
236
|
+
}
|
|
159
237
|
}
|
|
160
238
|
|
|
161
239
|
assert(
|
|
162
240
|
result.length === 1,
|
|
163
241
|
'[V3] Unimplemented: Multiple asset return from Node transformer',
|
|
164
242
|
);
|
|
243
|
+
|
|
165
244
|
assert(
|
|
166
|
-
result[0] ===
|
|
245
|
+
result[0] === mutableAsset,
|
|
167
246
|
'[V3] Unimplemented: New asset returned from Node transformer',
|
|
168
247
|
);
|
|
169
248
|
|
|
170
249
|
return {
|
|
171
|
-
asset
|
|
172
|
-
|
|
250
|
+
asset: {
|
|
251
|
+
id: mutableAsset.id,
|
|
252
|
+
bundleBehavior: bundleBehaviorMap.intoNullable(
|
|
253
|
+
mutableAsset.bundleBehavior,
|
|
254
|
+
),
|
|
255
|
+
filePath: mutableAsset.filePath,
|
|
256
|
+
type: mutableAsset.type,
|
|
257
|
+
code: Array.from(await mutableAsset.getBuffer()),
|
|
258
|
+
meta: mutableAsset.meta,
|
|
259
|
+
pipeline: mutableAsset.pipeline,
|
|
260
|
+
query: mutableAsset.query.toString(),
|
|
261
|
+
symbols: mutableAsset.symbols.intoNapi(),
|
|
262
|
+
uniqueKey: mutableAsset.uniqueKey,
|
|
263
|
+
sideEffects: mutableAsset.sideEffects,
|
|
264
|
+
isBundleSplittable: mutableAsset.isBundleSplittable,
|
|
265
|
+
isSource: mutableAsset.isSource,
|
|
266
|
+
},
|
|
173
267
|
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// only see the error message, no stack trace.
|
|
177
|
-
// eslint-disable-next-line no-console
|
|
178
|
-
console.error(e);
|
|
179
|
-
throw e;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
268
|
+
},
|
|
269
|
+
);
|
|
182
270
|
}
|
|
183
271
|
|
|
184
272
|
napi.registerWorker(workerData.tx_worker, new AtlaspackWorker());
|
|
185
273
|
|
|
274
|
+
type ResolverState<T> = {|
|
|
275
|
+
resolver: Resolver<T>,
|
|
276
|
+
config?: T,
|
|
277
|
+
packageManager?: NodePackageManager,
|
|
278
|
+
|};
|
|
279
|
+
|
|
280
|
+
type TransformerState<T> = {|
|
|
281
|
+
packageManager?: NodePackageManager,
|
|
282
|
+
transformer: Transformer<T>,
|
|
283
|
+
|};
|
|
284
|
+
|
|
186
285
|
type LoadPluginOptions = {|
|
|
187
|
-
kind: 'resolver',
|
|
286
|
+
kind: 'resolver' | 'transformer',
|
|
188
287
|
specifier: string,
|
|
189
288
|
resolveFrom: string,
|
|
190
289
|
|};
|
|
191
290
|
|
|
192
291
|
type RunResolverResolveOptions = {|
|
|
193
292
|
key: string,
|
|
194
|
-
dependency: Dependency,
|
|
293
|
+
dependency: napi.Dependency,
|
|
195
294
|
specifier: FilePath,
|
|
295
|
+
pipeline: ?string,
|
|
296
|
+
projectRoot: string,
|
|
196
297
|
|};
|
|
197
298
|
|
|
198
299
|
type RunResolverResolveResult = {|
|
|
@@ -208,14 +309,18 @@ type RunResolverResolveResult = {|
|
|
|
208
309
|
code?: string,
|
|
209
310
|
meta?: mixed,
|
|
210
311
|
pipeline?: string,
|
|
211
|
-
priority?: number,
|
|
312
|
+
priority?: ?number,
|
|
212
313
|
query?: string,
|
|
213
314
|
|},
|
|
214
315
|
|};
|
|
215
316
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
};
|
|
317
|
+
type RunTransformerTransformOptions = {|
|
|
318
|
+
key: string,
|
|
319
|
+
env: napi.Environment,
|
|
320
|
+
projectRoot: string,
|
|
321
|
+
asset: napi.Asset,
|
|
322
|
+
|};
|
|
323
|
+
|
|
324
|
+
type RunTransformerTransformResult = {|
|
|
325
|
+
asset: napi.RpcAssetResult,
|
|
326
|
+
|};
|
|
@@ -82,7 +82,7 @@ export default async function dumpGraphToGraphViz(
|
|
|
82
82
|
label = node;
|
|
83
83
|
} else if (node.assets) {
|
|
84
84
|
label = `(${nodeId(id)}), (assetIds: ${[...node.assets]
|
|
85
|
-
.map(a => {
|
|
85
|
+
.map((a) => {
|
|
86
86
|
let arr = a.filePath.split('/');
|
|
87
87
|
return arr[arr.length - 1];
|
|
88
88
|
})
|
package/src/loadDotEnv.js
CHANGED
package/src/projectPath.js
CHANGED
|
@@ -9,14 +9,22 @@ import {relativePath, normalizeSeparators} from '@atlaspack/utils';
|
|
|
9
9
|
export opaque type ProjectPath = string;
|
|
10
10
|
|
|
11
11
|
function toProjectPath_(projectRoot: FilePath, p: FilePath): ProjectPath {
|
|
12
|
+
// If the file path is not provided, then treat it as though it is already from the project root
|
|
12
13
|
if (p == null) {
|
|
13
14
|
return p;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
// If the file is
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
17
|
+
// If the file path is already relative and it does not begin with . then treat the path as if it
|
|
18
|
+
// is already from the project root. This prevents relative paths from being processed twice,
|
|
19
|
+
// most often within `toInternalSourceLocation` when handling loc types from symbols and asset
|
|
20
|
+
// dependencies.
|
|
21
|
+
if (p[0] !== '.' && !path.isAbsolute(p)) {
|
|
22
|
+
return p;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// If the file is outside the project root, store an absolute path rather than a relative one.
|
|
26
|
+
// This way if the project root is moved, the file references still work. Accessing files outside
|
|
27
|
+
// the project root is not portable anyway.
|
|
20
28
|
let relative = relativePath(projectRoot, p, false);
|
|
21
29
|
if (relative.startsWith('..')) {
|
|
22
30
|
return process.platform === 'win32' ? normalizeSeparators(p) : p;
|
package/src/public/Asset.js
CHANGED
|
@@ -162,7 +162,7 @@ class BaseAsset {
|
|
|
162
162
|
getDependencies(): $ReadOnlyArray<IDependency> {
|
|
163
163
|
return this.#asset
|
|
164
164
|
.getDependencies()
|
|
165
|
-
.map(dep => getPublicDependency(dep, this.#asset.options));
|
|
165
|
+
.map((dep) => getPublicDependency(dep, this.#asset.options));
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
getCode(): Promise<string> {
|
package/src/public/Bundle.js
CHANGED
|
@@ -155,7 +155,7 @@ export class Bundle implements IBundle {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
getEntryAssets(): Array<IAsset> {
|
|
158
|
-
return this.#bundle.entryAssetIds.map(id => {
|
|
158
|
+
return this.#bundle.entryAssetIds.map((id) => {
|
|
159
159
|
let assetNode = this.#bundleGraph._graph.getNodeByContentKey(id);
|
|
160
160
|
invariant(assetNode != null && assetNode.type === 'asset');
|
|
161
161
|
return assetFromValue(assetNode.value, this.#options);
|
|
@@ -177,7 +177,7 @@ export class Bundle implements IBundle {
|
|
|
177
177
|
): ?TContext {
|
|
178
178
|
return this.#bundleGraph.traverseBundle(
|
|
179
179
|
this.#bundle,
|
|
180
|
-
mapVisitor(node => {
|
|
180
|
+
mapVisitor((node) => {
|
|
181
181
|
if (node.type === 'asset') {
|
|
182
182
|
return {
|
|
183
183
|
type: 'asset',
|
|
@@ -199,7 +199,7 @@ export class Bundle implements IBundle {
|
|
|
199
199
|
): ?TContext {
|
|
200
200
|
return this.#bundleGraph.traverseAssets(
|
|
201
201
|
this.#bundle,
|
|
202
|
-
mapVisitor(asset => assetFromValue(asset, this.#options), visit),
|
|
202
|
+
mapVisitor((asset) => assetFromValue(asset, this.#options), visit),
|
|
203
203
|
startAsset ? assetToAssetValue(startAsset) : undefined,
|
|
204
204
|
);
|
|
205
205
|
}
|
|
@@ -93,7 +93,7 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
93
93
|
getIncomingDependencies(asset: IAsset): Array<IDependency> {
|
|
94
94
|
return this.#graph
|
|
95
95
|
.getIncomingDependencies(assetToAssetValue(asset))
|
|
96
|
-
.map(dep => getPublicDependency(dep, this.#options));
|
|
96
|
+
.map((dep) => getPublicDependency(dep, this.#options));
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
getAssetWithDependency(dep: IDependency): ?IAsset {
|
|
@@ -108,7 +108,7 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
108
108
|
getBundleGroupsContainingBundle(bundle: IBundle): Array<IBundleGroup> {
|
|
109
109
|
return this.#graph
|
|
110
110
|
.getBundleGroupsContainingBundle(bundleToInternalBundle(bundle))
|
|
111
|
-
.map(bundleGroup => new BundleGroup(bundleGroup, this.#options));
|
|
111
|
+
.map((bundleGroup) => new BundleGroup(bundleGroup, this.#options));
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
getReferencedBundles(
|
|
@@ -117,13 +117,13 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
117
117
|
): Array<TBundle> {
|
|
118
118
|
return this.#graph
|
|
119
119
|
.getReferencedBundles(bundleToInternalBundle(bundle), opts)
|
|
120
|
-
.map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
|
|
120
|
+
.map((bundle) => this.#createBundle(bundle, this.#graph, this.#options));
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
getReferencingBundles(bundle: IBundle): Array<TBundle> {
|
|
124
124
|
return this.#graph
|
|
125
125
|
.getReferencingBundles(bundleToInternalBundle(bundle))
|
|
126
|
-
.map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
|
|
126
|
+
.map((bundle) => this.#createBundle(bundle, this.#graph, this.#options));
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
resolveAsyncDependency(
|
|
@@ -167,7 +167,7 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
167
167
|
getDependencies(asset: IAsset): Array<IDependency> {
|
|
168
168
|
return this.#graph
|
|
169
169
|
.getDependencies(assetToAssetValue(asset))
|
|
170
|
-
.map(dep => getPublicDependency(dep, this.#options));
|
|
170
|
+
.map((dep) => getPublicDependency(dep, this.#options));
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
isAssetReachableFromBundle(asset: IAsset, bundle: IBundle): boolean {
|
|
@@ -200,13 +200,13 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
200
200
|
bundleGroupToInternalBundleGroup(bundleGroup),
|
|
201
201
|
opts,
|
|
202
202
|
)
|
|
203
|
-
.map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
|
|
203
|
+
.map((bundle) => this.#createBundle(bundle, this.#graph, this.#options));
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
getBundles(opts?: {|includeInline: boolean|}): Array<TBundle> {
|
|
207
207
|
return this.#graph
|
|
208
208
|
.getBundles(opts)
|
|
209
|
-
.map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
|
|
209
|
+
.map((bundle) => this.#createBundle(bundle, this.#graph, this.#options));
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
isEntryBundleGroup(bundleGroup: IBundleGroup): boolean {
|
|
@@ -218,13 +218,13 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
218
218
|
getChildBundles(bundle: IBundle): Array<TBundle> {
|
|
219
219
|
return this.#graph
|
|
220
220
|
.getChildBundles(bundleToInternalBundle(bundle))
|
|
221
|
-
.map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
|
|
221
|
+
.map((bundle) => this.#createBundle(bundle, this.#graph, this.#options));
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
getParentBundles(bundle: IBundle): Array<TBundle> {
|
|
225
225
|
return this.#graph
|
|
226
226
|
.getParentBundles(bundleToInternalBundle(bundle))
|
|
227
|
-
.map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
|
|
227
|
+
.map((bundle) => this.#createBundle(bundle, this.#graph, this.#options));
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
getSymbolResolution(
|
|
@@ -253,7 +253,7 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
253
253
|
assetToAssetValue(asset),
|
|
254
254
|
boundary ? bundleToInternalBundle(boundary) : null,
|
|
255
255
|
);
|
|
256
|
-
return res.map(e => ({
|
|
256
|
+
return res.map((e) => ({
|
|
257
257
|
asset: assetFromValue(e.asset, this.#options),
|
|
258
258
|
exportSymbol: e.exportSymbol,
|
|
259
259
|
symbol: e.symbol,
|
|
@@ -296,7 +296,7 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
296
296
|
): ?TContext {
|
|
297
297
|
return this.#graph.traverseBundles(
|
|
298
298
|
mapVisitor(
|
|
299
|
-
bundle => this.#createBundle(bundle, this.#graph, this.#options),
|
|
299
|
+
(bundle) => this.#createBundle(bundle, this.#graph, this.#options),
|
|
300
300
|
visit,
|
|
301
301
|
),
|
|
302
302
|
startBundle == null ? undefined : bundleToInternalBundle(startBundle),
|
|
@@ -306,13 +306,13 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
306
306
|
getBundlesWithAsset(asset: IAsset): Array<TBundle> {
|
|
307
307
|
return this.#graph
|
|
308
308
|
.getBundlesWithAsset(assetToAssetValue(asset))
|
|
309
|
-
.map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
|
|
309
|
+
.map((bundle) => this.#createBundle(bundle, this.#graph, this.#options));
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
getBundlesWithDependency(dependency: IDependency): Array<TBundle> {
|
|
313
313
|
return this.#graph
|
|
314
314
|
.getBundlesWithDependency(dependencyToInternalDependency(dependency))
|
|
315
|
-
.map(bundle => this.#createBundle(bundle, this.#graph, this.#options));
|
|
315
|
+
.map((bundle) => this.#createBundle(bundle, this.#graph, this.#options));
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
getUsedSymbols(v: IAsset | IDependency): ?$ReadOnlySet<Symbol> {
|
|
@@ -345,7 +345,7 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
345
345
|
ifFalseAssetId: string,
|
|
346
346
|
|}> {
|
|
347
347
|
const conditions = new Set();
|
|
348
|
-
const depIds = deps.map(dep => dep.id);
|
|
348
|
+
const depIds = deps.map((dep) => dep.id);
|
|
349
349
|
for (const condition of this.#graph._conditions.values()) {
|
|
350
350
|
if (
|
|
351
351
|
depIds.includes(condition.ifTrueDependency.id) ||
|
|
@@ -354,7 +354,7 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
354
354
|
const [trueAsset, falseAsset] = [
|
|
355
355
|
condition.ifTrueDependency,
|
|
356
356
|
condition.ifFalseDependency,
|
|
357
|
-
].map(dep => {
|
|
357
|
+
].map((dep) => {
|
|
358
358
|
const resolved = nullthrows(this.#graph.resolveAsyncDependency(dep));
|
|
359
359
|
if (resolved.type === 'asset') {
|
|
360
360
|
return resolved.value;
|
|
@@ -367,11 +367,11 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
367
367
|
publicId: condition.publicId,
|
|
368
368
|
key: condition.key,
|
|
369
369
|
ifTrueDependency: nullthrows(
|
|
370
|
-
deps.find(dep => dep.id === condition.ifTrueDependency.id),
|
|
370
|
+
deps.find((dep) => dep.id === condition.ifTrueDependency.id),
|
|
371
371
|
'ifTrueDependency was null',
|
|
372
372
|
),
|
|
373
373
|
ifFalseDependency: nullthrows(
|
|
374
|
-
deps.find(dep => dep.id === condition.ifFalseDependency.id),
|
|
374
|
+
deps.find((dep) => dep.id === condition.ifFalseDependency.id),
|
|
375
375
|
'ifFalseDependency was null',
|
|
376
376
|
),
|
|
377
377
|
ifTrueAssetId: this.#graph.getAssetPublicId(trueAsset),
|
|
@@ -400,7 +400,7 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
400
400
|
|
|
401
401
|
// Convert the internal references in conditions to public API references
|
|
402
402
|
for (const cond of this.#graph._conditions.values()) {
|
|
403
|
-
let assets = Array.from(cond.assets).map(asset =>
|
|
403
|
+
let assets = Array.from(cond.assets).map((asset) =>
|
|
404
404
|
nullthrows(this.getAssetById(asset.id)),
|
|
405
405
|
);
|
|
406
406
|
let bundles = new Set<TBundle>();
|
|
@@ -412,9 +412,9 @@ export default class BundleGraph<TBundle: IBundle>
|
|
|
412
412
|
bundles.add(bundle);
|
|
413
413
|
}
|
|
414
414
|
const assetDeps = this.getDependencies(asset);
|
|
415
|
-
const depToBundles = dep => {
|
|
415
|
+
const depToBundles = (dep) => {
|
|
416
416
|
const publicDep = nullthrows(
|
|
417
|
-
assetDeps.find(assetDep => dep.id === assetDep.id),
|
|
417
|
+
assetDeps.find((assetDep) => dep.id === assetDep.id),
|
|
418
418
|
);
|
|
419
419
|
const resolved = nullthrows(this.resolveAsyncDependency(publicDep));
|
|
420
420
|
invariant(resolved.type === 'bundle_group');
|
package/src/public/Config.js
CHANGED
|
@@ -86,7 +86,7 @@ export default class PublicConfig implements IConfig {
|
|
|
86
86
|
this.#config.devDeps.push({
|
|
87
87
|
...devDep,
|
|
88
88
|
resolveFrom: toProjectPath(this.#options.projectRoot, devDep.resolveFrom),
|
|
89
|
-
additionalInvalidations: devDep.additionalInvalidations?.map(i => ({
|
|
89
|
+
additionalInvalidations: devDep.additionalInvalidations?.map((i) => ({
|
|
90
90
|
...i,
|
|
91
91
|
resolveFrom: toProjectPath(this.#options.projectRoot, i.resolveFrom),
|
|
92
92
|
})),
|