@atlaspack/core 2.27.0 → 2.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +60 -0
- package/dist/Atlaspack.js +5 -1
- package/dist/AtlaspackConfig.schema.js +9 -0
- package/dist/BundleGraph.js +105 -0
- package/dist/CommittedAsset.js +1 -1
- package/dist/Transformation.js +3 -2
- package/dist/UncommittedAsset.js +3 -3
- package/dist/assetUtils.js +2 -1
- package/dist/atlaspack-v3/AtlaspackV3.js +2 -9
- package/dist/atlaspack-v3/NapiWorkerPool.js +5 -1
- package/dist/atlaspack-v3/worker/compat/mutable-asset.js +1 -1
- package/dist/atlaspack-v3/worker/worker.js +1 -1
- package/dist/public/BundleGraph.js +12 -0
- package/dist/requests/AssetGraphRequestRust.js +17 -6
- package/dist/requests/BundleGraphRequest.js +5 -3
- package/dist/resolveOptions.js +1 -0
- package/dist/worker.js +1 -1
- package/lib/Atlaspack.js +5 -1
- package/lib/AtlaspackConfig.schema.js +9 -0
- package/lib/BundleGraph.js +107 -0
- package/lib/CommittedAsset.js +1 -1
- package/lib/Transformation.js +9 -4
- package/lib/UncommittedAsset.js +3 -3
- package/lib/assetUtils.js +8 -1
- package/lib/atlaspack-v3/AtlaspackV3.js +2 -9
- package/lib/atlaspack-v3/NapiWorkerPool.js +4 -1
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +1 -1
- package/lib/atlaspack-v3/worker/worker.js +1 -1
- package/lib/public/BundleGraph.js +13 -0
- package/lib/requests/AssetGraphRequestRust.js +20 -8
- package/lib/requests/BundleGraphRequest.js +4 -2
- package/lib/resolveOptions.js +1 -0
- package/lib/types/AtlaspackConfig.schema.d.ts +7 -0
- package/lib/types/BundleGraph.d.ts +2 -0
- package/lib/types/CommittedAsset.d.ts +1 -1
- package/lib/types/PackagerRunner.d.ts +1 -1
- package/lib/types/UncommittedAsset.d.ts +1 -1
- package/lib/types/atlaspack-v3/worker/compat/mutable-asset.d.ts +1 -1
- package/lib/types/public/Asset.d.ts +1 -1
- package/lib/types/public/BundleGraph.d.ts +2 -0
- package/lib/types/types.d.ts +1 -0
- package/lib/worker.js +1 -1
- package/package.json +14 -14
- package/src/Atlaspack.ts +6 -2
- package/src/AtlaspackConfig.schema.ts +9 -0
- package/src/BundleGraph.ts +152 -0
- package/src/CommittedAsset.ts +1 -1
- package/src/PackagerRunner.ts +1 -1
- package/src/Transformation.ts +3 -2
- package/src/UncommittedAsset.ts +3 -3
- package/src/assetUtils.ts +2 -1
- package/src/atlaspack-v3/AtlaspackV3.ts +2 -13
- package/src/atlaspack-v3/NapiWorkerPool.ts +5 -1
- package/src/atlaspack-v3/worker/compat/mutable-asset.ts +1 -1
- package/src/atlaspack-v3/worker/worker.ts +1 -1
- package/src/public/Asset.ts +1 -1
- package/src/public/BundleGraph.ts +21 -0
- package/src/requests/AssetGraphRequestRust.ts +23 -11
- package/src/requests/BundleGraphRequest.ts +9 -7
- package/src/resolveOptions.ts +1 -0
- package/src/types.ts +1 -0
- package/src/worker.ts +1 -1
- package/test/AtlaspackConfigRequest.test.ts +1 -1
- package/test/requests/AssetGraphRequestRust.test.ts +278 -276
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/UncommittedAsset.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {Asset, Dependency, AtlaspackOptions, Invalidations} from './types';
|
|
|
11
11
|
|
|
12
12
|
import invariant from 'assert';
|
|
13
13
|
import {Readable} from 'stream';
|
|
14
|
-
import SourceMap from '@
|
|
14
|
+
import SourceMap from '@atlaspack/source-map';
|
|
15
15
|
import {serializeRaw} from '@atlaspack/build-cache';
|
|
16
16
|
import {
|
|
17
17
|
blobToStream,
|
|
@@ -249,7 +249,7 @@ export default class UncommittedAsset {
|
|
|
249
249
|
|
|
250
250
|
if (map) {
|
|
251
251
|
this.map = map;
|
|
252
|
-
this.mapBuffer =
|
|
252
|
+
this.mapBuffer = SourceMap.safeToBuffer(map);
|
|
253
253
|
this.setCode(code.replace(SOURCEMAP_RE, ''));
|
|
254
254
|
}
|
|
255
255
|
|
|
@@ -425,7 +425,7 @@ export default class UncommittedAsset {
|
|
|
425
425
|
content,
|
|
426
426
|
ast: result.ast,
|
|
427
427
|
isASTDirty: result.ast === this.ast ? this.isASTDirty : true,
|
|
428
|
-
mapBuffer:
|
|
428
|
+
mapBuffer: SourceMap.safeToBuffer(result.map),
|
|
429
429
|
code: this.code,
|
|
430
430
|
invalidations: this.invalidations,
|
|
431
431
|
});
|
package/src/assetUtils.ts
CHANGED
|
@@ -39,6 +39,7 @@ import {PluginTracer} from '@atlaspack/profiler';
|
|
|
39
39
|
import {identifierRegistry} from './IdentifierRegistry';
|
|
40
40
|
import type {EnvironmentRef} from './EnvironmentManager';
|
|
41
41
|
import {toEnvironmentId} from './EnvironmentManager';
|
|
42
|
+
import SourceMap from '@atlaspack/source-map';
|
|
42
43
|
|
|
43
44
|
export type AssetOptions = {
|
|
44
45
|
id?: string;
|
|
@@ -180,7 +181,7 @@ async function _generateFromAST(asset: CommittedAsset | UncommittedAsset) {
|
|
|
180
181
|
tracer: new PluginTracer({origin: pluginName, category: 'asset-generate'}),
|
|
181
182
|
});
|
|
182
183
|
|
|
183
|
-
let mapBuffer = map
|
|
184
|
+
let mapBuffer = SourceMap.safeToBuffer(map);
|
|
184
185
|
// Store the results in the cache so we can avoid generating again next time
|
|
185
186
|
await Promise.all([
|
|
186
187
|
asset.options.cache.setStream(
|
|
@@ -91,19 +91,8 @@ export class AtlaspackV3 {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
let [graph, error] = await atlaspackNapiBuildAssetGraph(
|
|
97
|
-
this._atlaspack_napi,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
if (error !== null) {
|
|
101
|
-
throw new ThrowableDiagnostic({
|
|
102
|
-
diagnostic: error,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return graph;
|
|
94
|
+
buildAssetGraph(): Promise<any> {
|
|
95
|
+
return atlaspackNapiBuildAssetGraph(this._atlaspack_napi) as Promise<any>;
|
|
107
96
|
}
|
|
108
97
|
|
|
109
98
|
async respondToFsEvents(events: Array<Event>): Promise<boolean> {
|
|
@@ -23,7 +23,11 @@ export class NapiWorkerPool implements INapiWorkerPool {
|
|
|
23
23
|
constructor({workerCount}: NapiWorkerPoolOptions = {workerCount: undefined}) {
|
|
24
24
|
// @ts-expect-error TS2322
|
|
25
25
|
this.#workerCount =
|
|
26
|
-
workerCount ??
|
|
26
|
+
workerCount ??
|
|
27
|
+
ATLASPACK_NAPI_WORKERS ??
|
|
28
|
+
// Default to a maximum of 4 workers as performance worsens beyond that
|
|
29
|
+
// point in most cases
|
|
30
|
+
Math.min(getAvailableThreads(), 4);
|
|
27
31
|
if (!this.#workerCount) {
|
|
28
32
|
// TODO use main thread if workerCount is 0
|
|
29
33
|
}
|
|
@@ -171,7 +171,7 @@ export class AtlaspackWorker {
|
|
|
171
171
|
type: 'resolved',
|
|
172
172
|
filePath: result.filePath || '',
|
|
173
173
|
canDefer: result.canDefer || false,
|
|
174
|
-
sideEffects: result.sideEffects
|
|
174
|
+
sideEffects: result.sideEffects ?? true,
|
|
175
175
|
code: result.code || undefined,
|
|
176
176
|
meta: result.meta || undefined,
|
|
177
177
|
pipeline: result.pipeline || undefined,
|
package/src/public/Asset.ts
CHANGED
|
@@ -198,6 +198,27 @@ export default class BundleGraph<TBundle extends IBundle>
|
|
|
198
198
|
);
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
+
isAssetReferencedFastCheck(bundle: IBundle, asset: IAsset): boolean | null {
|
|
202
|
+
return this.#graph.isAssetReferencedFastCheck(
|
|
203
|
+
bundleToInternalBundle(bundle),
|
|
204
|
+
assetToAssetValue(asset),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
getReferencedAssets(bundle: IBundle): Set<IAsset> {
|
|
209
|
+
let internalReferencedAssets = this.#graph.getReferencedAssets(
|
|
210
|
+
bundleToInternalBundle(bundle),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
// Convert internal assets to public assets
|
|
214
|
+
let publicReferencedAssets = new Set<IAsset>();
|
|
215
|
+
for (let internalAsset of internalReferencedAssets) {
|
|
216
|
+
publicReferencedAssets.add(assetFromValue(internalAsset, this.#options));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return publicReferencedAssets;
|
|
220
|
+
}
|
|
221
|
+
|
|
201
222
|
hasParentBundleOfType(bundle: IBundle, type: string): boolean {
|
|
202
223
|
return this.#graph.hasParentBundleOfType(
|
|
203
224
|
bundleToInternalBundle(bundle),
|
|
@@ -53,18 +53,17 @@ export function createAssetGraphRequestRust(
|
|
|
53
53
|
id: input.name,
|
|
54
54
|
run: async (input) => {
|
|
55
55
|
let options = input.options;
|
|
56
|
-
let
|
|
57
|
-
|
|
56
|
+
let {assetGraphPromise, commitPromise} =
|
|
57
|
+
await rustAtlaspack.buildAssetGraph();
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
JSON.parse(node),
|
|
62
|
-
);
|
|
59
|
+
let [serializedAssetGraph, assetGraphError] =
|
|
60
|
+
(await assetGraphPromise) as [SerializedAssetGraphDelta, Error | null];
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
if (assetGraphError) {
|
|
63
|
+
throw new ThrowableDiagnostic({
|
|
64
|
+
diagnostic: assetGraphError,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
68
67
|
|
|
69
68
|
// Don't reuse a previous asset graph result if Rust didn't have one too
|
|
70
69
|
let prevResult = null;
|
|
@@ -106,6 +105,17 @@ export function createAssetGraphRequestRust(
|
|
|
106
105
|
previousSymbolPropagationErrors: undefined,
|
|
107
106
|
};
|
|
108
107
|
|
|
108
|
+
let [_commitResult, commitError] = await commitPromise;
|
|
109
|
+
|
|
110
|
+
if (commitError) {
|
|
111
|
+
throw new ThrowableDiagnostic({
|
|
112
|
+
diagnostic: {
|
|
113
|
+
message:
|
|
114
|
+
'Error committing asset graph in Rust: ' + commitError.message,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
109
119
|
await input.api.storeResult(result);
|
|
110
120
|
input.api.invalidateOnBuild();
|
|
111
121
|
|
|
@@ -213,7 +223,7 @@ export function getAssetGraph(
|
|
|
213
223
|
|
|
214
224
|
let envId = envs.get(envKey);
|
|
215
225
|
if (envId == null) {
|
|
216
|
-
envId =
|
|
226
|
+
envId = getEnvironmentHash(env);
|
|
217
227
|
envs.set(envKey, envId);
|
|
218
228
|
}
|
|
219
229
|
|
|
@@ -242,6 +252,8 @@ export function getAssetGraph(
|
|
|
242
252
|
? serializedGraph.updates[index - nodeTypeSwitchoverIndex]
|
|
243
253
|
: serializedGraph.nodes[index];
|
|
244
254
|
|
|
255
|
+
node = JSON.parse(node);
|
|
256
|
+
|
|
245
257
|
if (node.type === 'entry') {
|
|
246
258
|
let id = 'entry:' + ++entry;
|
|
247
259
|
|
|
@@ -17,7 +17,7 @@ import fs from 'fs';
|
|
|
17
17
|
import invariant from 'assert';
|
|
18
18
|
import assert from 'assert';
|
|
19
19
|
import nullthrows from 'nullthrows';
|
|
20
|
-
import {PluginLogger} from '@atlaspack/logger';
|
|
20
|
+
import {instrumentAsync, PluginLogger} from '@atlaspack/logger';
|
|
21
21
|
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
22
22
|
import ThrowableDiagnostic, {errorToDiagnostic} from '@atlaspack/diagnostic';
|
|
23
23
|
import AssetGraph from '../AssetGraph';
|
|
@@ -155,12 +155,14 @@ export default function createBundleGraphRequest(
|
|
|
155
155
|
requestedAssetIds,
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
let {assetGraph, changedAssets, assetRequests} = await
|
|
159
|
-
request,
|
|
160
|
-
{
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
let {assetGraph, changedAssets, assetRequests} = await instrumentAsync(
|
|
159
|
+
'asset-graph-request',
|
|
160
|
+
() => {
|
|
161
|
+
return api.runRequest(request, {
|
|
162
|
+
force:
|
|
163
|
+
Boolean(input.rustAtlaspack) ||
|
|
164
|
+
(options.shouldBuildLazily && requestedAssetIds.size > 0),
|
|
165
|
+
});
|
|
164
166
|
},
|
|
165
167
|
);
|
|
166
168
|
|
package/src/resolveOptions.ts
CHANGED
|
@@ -269,6 +269,7 @@ export default async function resolveOptions(
|
|
|
269
269
|
: false,
|
|
270
270
|
shouldDisableCache: initialOptions.shouldDisableCache ?? false,
|
|
271
271
|
shouldProfile: initialOptions.shouldProfile ?? false,
|
|
272
|
+
nativeProfiler: initialOptions.nativeProfiler,
|
|
272
273
|
shouldTrace: initialOptions.shouldTrace ?? false,
|
|
273
274
|
cacheDir,
|
|
274
275
|
watchDir,
|
package/src/types.ts
CHANGED
|
@@ -335,6 +335,7 @@ export type AtlaspackOptions = {
|
|
|
335
335
|
logLevel: LogLevel;
|
|
336
336
|
projectRoot: FilePath;
|
|
337
337
|
shouldProfile: boolean;
|
|
338
|
+
nativeProfiler: 'instruments' | 'samply' | undefined;
|
|
338
339
|
shouldTrace: boolean;
|
|
339
340
|
shouldPatchConsole: boolean;
|
|
340
341
|
detailedReport?: DetailedReportOptions | null | undefined;
|
package/src/worker.ts
CHANGED
|
@@ -21,7 +21,7 @@ import Validation, {ValidationOpts} from './Validation';
|
|
|
21
21
|
import {AtlaspackConfig} from './AtlaspackConfig';
|
|
22
22
|
import {registerCoreWithSerializer} from './registerCoreWithSerializer';
|
|
23
23
|
import {clearBuildCaches} from '@atlaspack/build-cache';
|
|
24
|
-
import {init as initSourcemaps} from '@
|
|
24
|
+
import {init as initSourcemaps} from '@atlaspack/source-map';
|
|
25
25
|
// @ts-expect-error TS2305
|
|
26
26
|
import {init as initRust} from '@atlaspack/rust';
|
|
27
27
|
import WorkerFarm from '@atlaspack/workers';
|
|
@@ -133,7 +133,7 @@ describe('AtlaspackConfigRequest', () => {
|
|
|
133
133
|
(e: any) => {
|
|
134
134
|
assert.strictEqual(
|
|
135
135
|
e.diagnostics[0].codeFrames[0].codeHighlights[0].message,
|
|
136
|
-
`Possible values: "$schema", "bundler", "resolvers", "transformers", "validators", "namers", "packagers", "optimizers", "compressors", "reporters", "runtimes", "filePath", "resolveFrom"`,
|
|
136
|
+
`Possible values: "$schema", "bundler", "resolvers", "transformers", "validators", "namers", "packagers", "optimizers", "compressors", "reporters", "runtimes", "unstable\\_alias", "filePath", "resolveFrom"`,
|
|
137
137
|
);
|
|
138
138
|
return true;
|
|
139
139
|
},
|