@atlaspack/core 2.12.1-dev.3450 → 2.12.1-dev.3466
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/CommittedAsset.js +11 -5
- package/lib/Dependency.js +1 -1
- package/lib/PackagerRunner.js +53 -5
- package/lib/RequestTracker.js +10 -4
- package/lib/SymbolPropagation.js +25 -36
- package/lib/UncommittedAsset.js +8 -2
- package/lib/assetUtils.js +9 -3
- 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 +115 -127
- package/lib/index.js +0 -43
- package/lib/projectPath.js +12 -4
- package/lib/registerCoreWithSerializer.js +11 -5
- package/lib/requests/AtlaspackConfigRequest.js +8 -2
- package/lib/requests/ConfigRequest.js +9 -4
- package/lib/requests/DevDepRequest.js +9 -3
- package/lib/requests/PathRequest.js +8 -2
- package/lib/requests/WriteBundleRequest.js +15 -15
- package/lib/worker.js +8 -2
- package/package.json +24 -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 +5 -3
- package/src/Dependency.js +1 -1
- package/src/PackagerRunner.js +57 -9
- package/src/ReporterRunner.js +4 -4
- package/src/RequestTracker.js +19 -19
- package/src/SymbolPropagation.js +40 -52
- package/src/Transformation.js +12 -12
- package/src/UncommittedAsset.js +3 -3
- package/src/Validation.js +5 -5
- package/src/applyRuntimes.js +2 -2
- package/src/assetUtils.js +2 -2
- 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 +148 -134
- package/src/dumpGraphToGraphViz.js +1 -1
- package/src/index.js +0 -10
- 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/registerCoreWithSerializer.js +7 -4
- 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 +6 -4
- package/src/requests/BundleGraphRequest.js +6 -6
- package/src/requests/ConfigRequest.js +5 -6
- package/src/requests/DevDepRequest.js +8 -8
- package/src/requests/EntryRequest.js +2 -2
- package/src/requests/PathRequest.js +1 -1
- 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/serializerCore.browser.js +3 -2
- package/src/utils.js +2 -2
- package/src/worker.js +1 -1
- 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/lib/buildCache.js +0 -18
- package/lib/serializer.js +0 -216
- package/lib/serializerCore.js +0 -16
- package/src/atlaspack-v3/worker/compat.js +0 -82
- package/src/buildCache.js +0 -15
- package/src/serializer.js +0 -255
- package/src/serializerCore.js +0 -5
- package/test/requests/WriteBundleRequest.test.js +0 -132
- package/test/serializer.test.js +0 -302
|
@@ -1,35 +1,41 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import assert from 'assert';
|
|
3
3
|
import * as napi from '@atlaspack/rust';
|
|
4
|
+
import type {JsCallable} from '@atlaspack/rust';
|
|
4
5
|
import {NodeFS} from '@atlaspack/fs';
|
|
5
6
|
import {NodePackageManager} from '@atlaspack/package-manager';
|
|
6
7
|
import type {
|
|
7
8
|
Resolver,
|
|
8
9
|
Transformer,
|
|
9
|
-
PluginOptions,
|
|
10
|
-
Dependency,
|
|
11
10
|
FilePath,
|
|
12
11
|
FileSystem,
|
|
13
|
-
ConfigResultWithFilePath,
|
|
14
|
-
PackageJSON,
|
|
15
12
|
} from '@atlaspack/types';
|
|
16
13
|
import {workerData} from 'worker_threads';
|
|
17
14
|
import * as module from 'module';
|
|
18
15
|
|
|
19
|
-
import {
|
|
20
|
-
|
|
16
|
+
import {
|
|
17
|
+
Environment,
|
|
18
|
+
Dependency,
|
|
19
|
+
PluginConfig,
|
|
20
|
+
PluginLogger,
|
|
21
|
+
PluginTracer,
|
|
22
|
+
PluginOptions,
|
|
23
|
+
MutableAsset,
|
|
24
|
+
bundleBehaviorMap,
|
|
25
|
+
dependencyPriorityMap,
|
|
26
|
+
} from './compat';
|
|
21
27
|
import {jsCallable} from '../jsCallable';
|
|
22
|
-
import type {JsCallable} from '../jsCallable';
|
|
23
|
-
import Environment from '../../public/Environment';
|
|
24
28
|
|
|
25
29
|
const CONFIG = Symbol.for('parcel-plugin-config');
|
|
26
30
|
|
|
27
31
|
export class AtlaspackWorker {
|
|
28
32
|
#resolvers: Map<string, ResolverState<any>>;
|
|
33
|
+
#transformers: Map<string, TransformerState<any>>;
|
|
29
34
|
#fs: FileSystem;
|
|
30
35
|
|
|
31
36
|
constructor() {
|
|
32
37
|
this.#resolvers = new Map();
|
|
38
|
+
this.#transformers = new Map();
|
|
33
39
|
this.#fs = new NodeFS();
|
|
34
40
|
}
|
|
35
41
|
|
|
@@ -59,6 +65,9 @@ export class AtlaspackWorker {
|
|
|
59
65
|
case 'resolver':
|
|
60
66
|
this.#resolvers.set(specifier, {resolver: instance});
|
|
61
67
|
break;
|
|
68
|
+
case 'transformer':
|
|
69
|
+
this.#transformers.set(specifier, {transformer: instance});
|
|
70
|
+
break;
|
|
62
71
|
}
|
|
63
72
|
},
|
|
64
73
|
);
|
|
@@ -67,7 +76,13 @@ export class AtlaspackWorker {
|
|
|
67
76
|
[RunResolverResolveOptions],
|
|
68
77
|
Promise<RunResolverResolveResult>,
|
|
69
78
|
> = jsCallable(
|
|
70
|
-
async ({
|
|
79
|
+
async ({
|
|
80
|
+
key,
|
|
81
|
+
dependency: napiDependency,
|
|
82
|
+
specifier,
|
|
83
|
+
pipeline,
|
|
84
|
+
projectRoot,
|
|
85
|
+
}) => {
|
|
71
86
|
const state = this.#resolvers.get(key);
|
|
72
87
|
if (!state) {
|
|
73
88
|
throw new Error(`Resolver not found: ${key}`);
|
|
@@ -79,80 +94,28 @@ export class AtlaspackWorker {
|
|
|
79
94
|
state.packageManager = packageManager;
|
|
80
95
|
}
|
|
81
96
|
|
|
97
|
+
const env = new Environment(napiDependency.env);
|
|
98
|
+
const dependency = new Dependency(napiDependency, env);
|
|
99
|
+
|
|
82
100
|
const defaultOptions = {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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',
|
|
101
|
+
logger: new PluginLogger(),
|
|
102
|
+
tracer: new PluginTracer(),
|
|
103
|
+
options: new PluginOptions({
|
|
96
104
|
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
105
|
shouldAutoInstall: false,
|
|
108
|
-
get logLevel() {
|
|
109
|
-
throw new Error('Resolver.resolve.options.logLevel');
|
|
110
|
-
},
|
|
111
106
|
projectRoot,
|
|
112
|
-
get cacheDir() {
|
|
113
|
-
throw new Error('Resolver.resolve.options.cacheDir');
|
|
114
|
-
},
|
|
115
107
|
inputFS: this.#fs,
|
|
116
108
|
outputFS: this.#fs,
|
|
117
|
-
|
|
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
|
-
},
|
|
109
|
+
}),
|
|
127
110
|
};
|
|
128
111
|
|
|
129
112
|
if (!('config' in state)) {
|
|
130
113
|
state.config = await state.resolver.loadConfig?.({
|
|
131
|
-
config: {
|
|
114
|
+
config: new PluginConfig({
|
|
115
|
+
env,
|
|
132
116
|
isSource: true,
|
|
133
117
|
searchPath: '',
|
|
134
|
-
|
|
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
|
-
},
|
|
118
|
+
}),
|
|
156
119
|
...defaultOptions,
|
|
157
120
|
});
|
|
158
121
|
}
|
|
@@ -182,86 +145,128 @@ export class AtlaspackWorker {
|
|
|
182
145
|
code: result.code || undefined,
|
|
183
146
|
meta: result.meta || undefined,
|
|
184
147
|
pipeline: result.pipeline || undefined,
|
|
185
|
-
priority:
|
|
148
|
+
priority: dependencyPriorityMap.intoNullable(result.priority),
|
|
186
149
|
query: result.query && result.query.toString(),
|
|
187
150
|
},
|
|
188
151
|
};
|
|
189
152
|
},
|
|
190
153
|
);
|
|
191
154
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
+
});
|
|
195
194
|
|
|
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
195
|
if (transformer.parse) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
}
|
|
222
207
|
}
|
|
223
208
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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,
|
|
230
216
|
});
|
|
231
217
|
|
|
232
218
|
if (transformer.generate) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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,
|
|
239
228
|
});
|
|
240
|
-
|
|
241
|
-
|
|
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
|
+
}
|
|
242
237
|
}
|
|
243
238
|
|
|
244
239
|
assert(
|
|
245
240
|
result.length === 1,
|
|
246
241
|
'[V3] Unimplemented: Multiple asset return from Node transformer',
|
|
247
242
|
);
|
|
243
|
+
|
|
248
244
|
assert(
|
|
249
|
-
result[0] ===
|
|
245
|
+
result[0] === mutableAsset,
|
|
250
246
|
'[V3] Unimplemented: New asset returned from Node transformer',
|
|
251
247
|
);
|
|
252
248
|
|
|
253
249
|
return {
|
|
254
|
-
asset
|
|
255
|
-
|
|
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
|
+
},
|
|
256
267
|
};
|
|
257
|
-
}
|
|
258
|
-
|
|
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
|
-
}
|
|
268
|
+
},
|
|
269
|
+
);
|
|
265
270
|
}
|
|
266
271
|
|
|
267
272
|
napi.registerWorker(workerData.tx_worker, new AtlaspackWorker());
|
|
@@ -272,15 +277,20 @@ type ResolverState<T> = {|
|
|
|
272
277
|
packageManager?: NodePackageManager,
|
|
273
278
|
|};
|
|
274
279
|
|
|
280
|
+
type TransformerState<T> = {|
|
|
281
|
+
packageManager?: NodePackageManager,
|
|
282
|
+
transformer: Transformer<T>,
|
|
283
|
+
|};
|
|
284
|
+
|
|
275
285
|
type LoadPluginOptions = {|
|
|
276
|
-
kind: 'resolver',
|
|
286
|
+
kind: 'resolver' | 'transformer',
|
|
277
287
|
specifier: string,
|
|
278
288
|
resolveFrom: string,
|
|
279
289
|
|};
|
|
280
290
|
|
|
281
291
|
type RunResolverResolveOptions = {|
|
|
282
292
|
key: string,
|
|
283
|
-
dependency: Dependency,
|
|
293
|
+
dependency: napi.Dependency,
|
|
284
294
|
specifier: FilePath,
|
|
285
295
|
pipeline: ?string,
|
|
286
296
|
projectRoot: string,
|
|
@@ -299,14 +309,18 @@ type RunResolverResolveResult = {|
|
|
|
299
309
|
code?: string,
|
|
300
310
|
meta?: mixed,
|
|
301
311
|
pipeline?: string,
|
|
302
|
-
priority?: number,
|
|
312
|
+
priority?: ?number,
|
|
303
313
|
query?: string,
|
|
304
314
|
|},
|
|
305
315
|
|};
|
|
306
316
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
};
|
|
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/index.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
-
// Needs to be exported first because of circular imports
|
|
4
|
-
export {
|
|
5
|
-
registerSerializableClass,
|
|
6
|
-
unregisterSerializableClass,
|
|
7
|
-
prepareForSerialization,
|
|
8
|
-
restoreDeserializedObject,
|
|
9
|
-
serialize,
|
|
10
|
-
deserialize,
|
|
11
|
-
} from './serializer';
|
|
12
|
-
|
|
13
3
|
export {
|
|
14
4
|
default,
|
|
15
5
|
default as Atlaspack,
|
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
|
})),
|