@atlaspack/core 2.31.2 → 2.32.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 +48 -0
- package/dist/Atlaspack.js +4 -3
- package/dist/BundleGraph.js +61 -0
- package/dist/atlaspack-v3/AtlaspackV3.js +7 -0
- package/dist/requests/AtlaspackBuildRequest.js +17 -0
- package/dist/requests/BundleGraphRequest.js +1 -1
- package/dist/requests/PackageRequest.js +11 -1
- package/dist/resolveOptions.js +1 -1
- package/lib/Atlaspack.js +3 -3
- package/lib/BundleGraph.js +68 -0
- package/lib/atlaspack-v3/AtlaspackV3.js +10 -0
- package/lib/requests/AtlaspackBuildRequest.js +20 -0
- package/lib/requests/BundleGraphRequest.js +1 -1
- package/lib/requests/PackageRequest.js +14 -1
- package/lib/resolveOptions.js +1 -1
- package/lib/types/BundleGraph.d.ts +13 -0
- package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +3 -0
- package/package.json +15 -15
- package/src/Atlaspack.ts +11 -4
- package/src/BundleGraph.ts +71 -0
- package/src/atlaspack-v3/AtlaspackV3.ts +18 -0
- package/src/requests/AtlaspackBuildRequest.ts +23 -0
- package/src/requests/BundleGraphRequest.ts +4 -3
- package/src/requests/PackageRequest.ts +15 -1
- package/src/resolveOptions.ts +2 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# @atlaspack/core
|
|
2
2
|
|
|
3
|
+
## 2.32.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#976](https://github.com/atlassian-labs/atlaspack/pull/976) [`e8ea59b`](https://github.com/atlassian-labs/atlaspack/commit/e8ea59beabb4b4fef647dc9ebea3519b6d56d7b5) Thanks [@marcins](https://github.com/marcins)! - Initial implementation of loadBundleGraph to deserialise JS -> Rust BundleGraph.
|
|
8
|
+
|
|
9
|
+
- [#970](https://github.com/atlassian-labs/atlaspack/pull/970) [`8826fd0`](https://github.com/atlassian-labs/atlaspack/commit/8826fd02c29c9c67cf0c80da41f424257fbdef93) Thanks [@marcins](https://github.com/marcins)! - Add initial plumbing for native packaging to core and Atlaspack V3 code
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#984](https://github.com/atlassian-labs/atlaspack/pull/984) [`dbcaabb`](https://github.com/atlassian-labs/atlaspack/commit/dbcaabbf15d4fbc8ecd9c0be58cf7b2317eebfc4) Thanks [@marcins](https://github.com/marcins)! - Serialise to JSON on the JS side before sending bundle graph nodes to Rust for performance.
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`e8ea59b`](https://github.com/atlassian-labs/atlaspack/commit/e8ea59beabb4b4fef647dc9ebea3519b6d56d7b5), [`3753cb1`](https://github.com/atlassian-labs/atlaspack/commit/3753cb1bf9155eaf3a1a8f952886864682738647), [`8826fd0`](https://github.com/atlassian-labs/atlaspack/commit/8826fd02c29c9c67cf0c80da41f424257fbdef93), [`225683f`](https://github.com/atlassian-labs/atlaspack/commit/225683f7c59355da53b7004d2b8596701ce3af41), [`43adda0`](https://github.com/atlassian-labs/atlaspack/commit/43adda06bf3b6a404b54f8ba2a3b810d92e61d75), [`dbcaabb`](https://github.com/atlassian-labs/atlaspack/commit/dbcaabbf15d4fbc8ecd9c0be58cf7b2317eebfc4)]:
|
|
16
|
+
- @atlaspack/rust@3.20.0
|
|
17
|
+
- @atlaspack/feature-flags@2.28.0
|
|
18
|
+
- @atlaspack/cache@3.2.45
|
|
19
|
+
- @atlaspack/fs@2.15.45
|
|
20
|
+
- @atlaspack/logger@2.14.42
|
|
21
|
+
- @atlaspack/source-map@3.2.5
|
|
22
|
+
- @atlaspack/utils@3.3.2
|
|
23
|
+
- @atlaspack/build-cache@2.13.9
|
|
24
|
+
- @atlaspack/graph@3.6.12
|
|
25
|
+
- @atlaspack/package-manager@2.14.50
|
|
26
|
+
- @atlaspack/profiler@2.15.11
|
|
27
|
+
- @atlaspack/workers@2.14.50
|
|
28
|
+
- @atlaspack/plugin@2.14.50
|
|
29
|
+
- @atlaspack/types@2.15.40
|
|
30
|
+
|
|
31
|
+
## 2.31.3
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- Updated dependencies [[`fc3adc0`](https://github.com/atlassian-labs/atlaspack/commit/fc3adc098f583e40d6d7687412cac6dde7cbb3f3), [`f33f9c4`](https://github.com/atlassian-labs/atlaspack/commit/f33f9c48dd24b319df352d197e4a83cbb1b053bc), [`e15fb6c`](https://github.com/atlassian-labs/atlaspack/commit/e15fb6c885c6354c6c02283de35ce18abc8c9e18), [`53da216`](https://github.com/atlassian-labs/atlaspack/commit/53da216320e19c9b71b001386eb420d05f111db8)]:
|
|
36
|
+
- @atlaspack/rust@3.19.0
|
|
37
|
+
- @atlaspack/feature-flags@2.27.7
|
|
38
|
+
- @atlaspack/cache@3.2.44
|
|
39
|
+
- @atlaspack/fs@2.15.44
|
|
40
|
+
- @atlaspack/logger@2.14.41
|
|
41
|
+
- @atlaspack/source-map@3.2.4
|
|
42
|
+
- @atlaspack/utils@3.3.1
|
|
43
|
+
- @atlaspack/build-cache@2.13.8
|
|
44
|
+
- @atlaspack/graph@3.6.11
|
|
45
|
+
- @atlaspack/package-manager@2.14.49
|
|
46
|
+
- @atlaspack/profiler@2.15.10
|
|
47
|
+
- @atlaspack/workers@2.14.49
|
|
48
|
+
- @atlaspack/plugin@2.14.49
|
|
49
|
+
- @atlaspack/types@2.15.39
|
|
50
|
+
|
|
3
51
|
## 2.31.2
|
|
4
52
|
|
|
5
53
|
### Patch Changes
|
package/dist/Atlaspack.js
CHANGED
|
@@ -157,7 +157,8 @@ class Atlaspack {
|
|
|
157
157
|
});
|
|
158
158
|
__classPrivateFieldSet(this, _Atlaspack_resolvedOptions, resolvedOptions, "f");
|
|
159
159
|
let rustAtlaspack;
|
|
160
|
-
if (resolvedOptions.featureFlags.atlaspackV3
|
|
160
|
+
if (resolvedOptions.featureFlags.atlaspackV3 ||
|
|
161
|
+
resolvedOptions.featureFlags.nativePackager) {
|
|
161
162
|
// eslint-disable-next-line no-unused-vars
|
|
162
163
|
let { entries, inputFS, outputFS, ...options } = __classPrivateFieldGet(this, _Atlaspack_initialOptions, "f");
|
|
163
164
|
if (!(resolvedOptions.cache instanceof cache_1.LMDBLiteCache)) {
|
|
@@ -487,7 +488,7 @@ class Atlaspack {
|
|
|
487
488
|
message: `File watch event emitted with ${events.length} events. Sample event: [${events[0]?.type}] ${events[0]?.path}`,
|
|
488
489
|
});
|
|
489
490
|
let nativeInvalid = false;
|
|
490
|
-
if (this.rustAtlaspack) {
|
|
491
|
+
if ((0, feature_flags_1.getFeatureFlag)('atlaspackV3') && this.rustAtlaspack) {
|
|
491
492
|
nativeInvalid = await this.rustAtlaspack.respondToFsEvents(events);
|
|
492
493
|
}
|
|
493
494
|
let { didInvalidate: isInvalid } = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").respondToFSEvents(events, Number.POSITIVE_INFINITY);
|
|
@@ -555,7 +556,7 @@ class Atlaspack {
|
|
|
555
556
|
requestedAssetIds: __classPrivateFieldGet(this, _Atlaspack_requestedAssetIds, "f"),
|
|
556
557
|
};
|
|
557
558
|
const start = Date.now();
|
|
558
|
-
const result = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").runRequest(this.rustAtlaspack != null
|
|
559
|
+
const result = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").runRequest((0, feature_flags_1.getFeatureFlag)('atlaspackV3') && this.rustAtlaspack != null
|
|
559
560
|
? // @ts-expect-error TS2345
|
|
560
561
|
(0, AssetGraphRequestRust_1.createAssetGraphRequestRust)(this.rustAtlaspack)(input)
|
|
561
562
|
: // @ts-expect-error TS2345
|
package/dist/BundleGraph.js
CHANGED
|
@@ -16,6 +16,7 @@ const Environment_1 = require("./public/Environment");
|
|
|
16
16
|
const projectPath_1 = require("./projectPath");
|
|
17
17
|
const constants_1 = require("./constants");
|
|
18
18
|
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
19
|
+
const logger_1 = __importDefault(require("@atlaspack/logger"));
|
|
19
20
|
const EnvironmentManager_1 = require("./EnvironmentManager");
|
|
20
21
|
exports.bundleGraphEdgeTypes = {
|
|
21
22
|
// A lack of an edge type indicates to follow the edge while traversing
|
|
@@ -380,6 +381,66 @@ class BundleGraph {
|
|
|
380
381
|
conditions: serialized.conditions,
|
|
381
382
|
});
|
|
382
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Serialize the bundle graph for efficient transfer to native Rust code.
|
|
386
|
+
* Returns a JSON string of nodes and an array of edges.
|
|
387
|
+
*/
|
|
388
|
+
serializeForNative() {
|
|
389
|
+
const start = performance.now();
|
|
390
|
+
const nodes = this._graph.nodes;
|
|
391
|
+
const edges = [];
|
|
392
|
+
const edgeIterator = this._graph.getAllEdges();
|
|
393
|
+
let next = edgeIterator.next();
|
|
394
|
+
while (!next.done) {
|
|
395
|
+
const edge = next.value;
|
|
396
|
+
edges.push([edge.from, edge.to, edge.type]);
|
|
397
|
+
next = edgeIterator.next();
|
|
398
|
+
}
|
|
399
|
+
// Optimize nodes by omitting null/undefined values to reduce JSON size
|
|
400
|
+
const optimizedNodes = nodes.map((node) => this._omitNulls(node));
|
|
401
|
+
const nodesJson = JSON.stringify(optimizedNodes);
|
|
402
|
+
const duration = performance.now() - start;
|
|
403
|
+
const sizeMB = (nodesJson.length / (1024 * 1024)).toFixed(2);
|
|
404
|
+
logger_1.default.verbose({
|
|
405
|
+
origin: '@atlaspack/core',
|
|
406
|
+
message: `serializeForNative: ${duration.toFixed(1)}ms, ${sizeMB}MB JSON, ${nodes.length} nodes, ${edges.length} edges`,
|
|
407
|
+
});
|
|
408
|
+
return { nodesJson, edges };
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Remove null and undefined values from an object to reduce JSON size.
|
|
412
|
+
* Preserves false, 0, empty strings, and arrays.
|
|
413
|
+
*/
|
|
414
|
+
_omitNulls(obj) {
|
|
415
|
+
if (obj === null || obj === undefined)
|
|
416
|
+
return obj;
|
|
417
|
+
if (typeof obj !== 'object')
|
|
418
|
+
return obj;
|
|
419
|
+
if (Array.isArray(obj)) {
|
|
420
|
+
return obj.map((item) => this._omitNulls(item));
|
|
421
|
+
}
|
|
422
|
+
const result = {};
|
|
423
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
424
|
+
if (value === null || value === undefined) {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
if (typeof value === 'object' &&
|
|
428
|
+
!Array.isArray(value) &&
|
|
429
|
+
Object.keys(value).length === 0) {
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
if (typeof value === 'object') {
|
|
433
|
+
const processed = this._omitNulls(value);
|
|
434
|
+
if (processed !== undefined) {
|
|
435
|
+
result[key] = processed;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
result[key] = value;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return result;
|
|
443
|
+
}
|
|
383
444
|
createBundle(opts) {
|
|
384
445
|
// @ts-expect-error TS2339
|
|
385
446
|
let { entryAsset, target } = opts;
|
|
@@ -51,6 +51,13 @@ class AtlaspackV3 {
|
|
|
51
51
|
buildAssetGraph() {
|
|
52
52
|
return (0, rust_1.atlaspackNapiBuildAssetGraph)(this._atlaspack_napi);
|
|
53
53
|
}
|
|
54
|
+
loadBundleGraph(bundleGraph) {
|
|
55
|
+
const { nodesJson, edges } = bundleGraph.serializeForNative();
|
|
56
|
+
return (0, rust_1.atlaspackNapiLoadBundleGraph)(this._atlaspack_napi, nodesJson, edges);
|
|
57
|
+
}
|
|
58
|
+
package() {
|
|
59
|
+
return (0, rust_1.atlaspackNapiPackage)(this._atlaspack_napi);
|
|
60
|
+
}
|
|
54
61
|
async respondToFsEvents(events) {
|
|
55
62
|
// @ts-expect-error TS2488
|
|
56
63
|
let [needsRebuild, error] = await (0, rust_1.atlaspackNapiRespondToFsEvents)(this._atlaspack_napi, events);
|
|
@@ -15,6 +15,8 @@ const Bundle_1 = require("../public/Bundle");
|
|
|
15
15
|
const Asset_1 = require("../public/Asset");
|
|
16
16
|
const profiler_1 = require("@atlaspack/profiler");
|
|
17
17
|
const RequestTracker_1 = require("../RequestTracker");
|
|
18
|
+
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
19
|
+
const EnvironmentManager_1 = require("../EnvironmentManager");
|
|
18
20
|
function createAtlaspackBuildRequest(input) {
|
|
19
21
|
return {
|
|
20
22
|
type: RequestTracker_1.requestTypes.atlaspack_build_request,
|
|
@@ -34,6 +36,21 @@ async function run({ input, api, options, rustAtlaspack, }) {
|
|
|
34
36
|
force: Boolean(rustAtlaspack) ||
|
|
35
37
|
(options.shouldBuildLazily && requestedAssetIds.size > 0),
|
|
36
38
|
});
|
|
39
|
+
if ((0, feature_flags_1.getFeatureFlag)('nativePackager') &&
|
|
40
|
+
(0, feature_flags_1.getFeatureFlag)('nativePackagerSSRDev') &&
|
|
41
|
+
rustAtlaspack) {
|
|
42
|
+
let hasSupportedTarget = false;
|
|
43
|
+
bundleGraph.traverseBundles((bundle, ctx, actions) => {
|
|
44
|
+
if ((0, EnvironmentManager_1.fromEnvironmentId)(bundle.env).context === 'tesseract' &&
|
|
45
|
+
bundle.type === 'js') {
|
|
46
|
+
hasSupportedTarget = true;
|
|
47
|
+
actions.stop();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (hasSupportedTarget) {
|
|
51
|
+
await rustAtlaspack.loadBundleGraph(bundleGraph);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
37
54
|
// @ts-expect-error TS2345
|
|
38
55
|
(0, dumpGraphToGraphViz_1.default)(bundleGraph._graph, 'BundleGraph', BundleGraph_1.bundleGraphEdgeTypes);
|
|
39
56
|
await (0, ReporterRunner_1.report)({
|
|
@@ -104,7 +104,7 @@ function createBundleGraphRequest(input) {
|
|
|
104
104
|
let { options, api, invalidateReason } = input;
|
|
105
105
|
let { optionsRef, requestedAssetIds, signal } = input.input;
|
|
106
106
|
let measurement = profiler_1.tracer.createMeasurement('building');
|
|
107
|
-
let createAssetGraphRequest = input.rustAtlaspack
|
|
107
|
+
let createAssetGraphRequest = (0, feature_flags_1.getFeatureFlag)('atlaspackV3') && input.rustAtlaspack
|
|
108
108
|
? (0, AssetGraphRequestRust_1.createAssetGraphRequestRust)(input.rustAtlaspack)
|
|
109
109
|
: AssetGraphRequest_1.default;
|
|
110
110
|
let request = createAssetGraphRequest({
|
|
@@ -9,6 +9,8 @@ const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
|
9
9
|
const ConfigRequest_1 = require("./ConfigRequest");
|
|
10
10
|
const DevDepRequest_1 = require("./DevDepRequest");
|
|
11
11
|
const AtlaspackConfigRequest_1 = __importDefault(require("./AtlaspackConfigRequest"));
|
|
12
|
+
const EnvironmentManager_1 = require("../EnvironmentManager");
|
|
13
|
+
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
12
14
|
function createPackageRequest(input) {
|
|
13
15
|
return {
|
|
14
16
|
type: RequestTracker_1.requestTypes.package_request,
|
|
@@ -17,12 +19,20 @@ function createPackageRequest(input) {
|
|
|
17
19
|
input,
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
|
-
async function run({ input, api, farm }) {
|
|
22
|
+
async function run({ input, api, farm, rustAtlaspack }) {
|
|
21
23
|
let { bundleGraphReference, optionsRef, bundle, useMainThread } = input;
|
|
22
24
|
let runPackage = farm.createHandle('runPackage', useMainThread);
|
|
23
25
|
let start = Date.now();
|
|
24
26
|
let { devDeps, invalidDevDeps } = await (0, DevDepRequest_1.getDevDepRequests)(api);
|
|
25
27
|
let { cachePath } = (0, nullthrows_1.default)(await api.runRequest((0, AtlaspackConfigRequest_1.default)()));
|
|
28
|
+
if ((0, feature_flags_1.getFeatureFlag)('nativePackager') &&
|
|
29
|
+
(0, feature_flags_1.getFeatureFlag)('nativePackagerSSRDev') &&
|
|
30
|
+
rustAtlaspack &&
|
|
31
|
+
(0, EnvironmentManager_1.fromEnvironmentId)(bundle.env).context === 'tesseract' &&
|
|
32
|
+
bundle.type === 'js') {
|
|
33
|
+
// Once this actually does something, the code below will be in an `else` block (i.e. we'll only run one or the other)
|
|
34
|
+
await rustAtlaspack.package();
|
|
35
|
+
}
|
|
26
36
|
let { devDepRequests, configRequests, bundleInfo, invalidations } = (await runPackage({
|
|
27
37
|
bundle,
|
|
28
38
|
bundleGraphReference,
|
package/dist/resolveOptions.js
CHANGED
|
@@ -132,7 +132,7 @@ async function resolveOptions(initialOptions) {
|
|
|
132
132
|
if (initialOptions.cache) {
|
|
133
133
|
return initialOptions.cache;
|
|
134
134
|
}
|
|
135
|
-
const needsRustLmdbCache = (0, feature_flags_1.getFeatureFlag)('atlaspackV3');
|
|
135
|
+
const needsRustLmdbCache = (0, feature_flags_1.getFeatureFlag)('atlaspackV3') || (0, feature_flags_1.getFeatureFlag)('nativePackager');
|
|
136
136
|
if (!(0, feature_flags_1.getFeatureFlag)('cachePerformanceImprovements')) {
|
|
137
137
|
if (!needsRustLmdbCache && !(outputFS instanceof fs_1.NodeFS)) {
|
|
138
138
|
return new cache_1.FSCache(outputFS, cacheDir);
|
package/lib/Atlaspack.js
CHANGED
|
@@ -197,7 +197,7 @@ class Atlaspack {
|
|
|
197
197
|
});
|
|
198
198
|
this.#resolvedOptions = resolvedOptions;
|
|
199
199
|
let rustAtlaspack;
|
|
200
|
-
if (resolvedOptions.featureFlags.atlaspackV3) {
|
|
200
|
+
if (resolvedOptions.featureFlags.atlaspackV3 || resolvedOptions.featureFlags.nativePackager) {
|
|
201
201
|
// eslint-disable-next-line no-unused-vars
|
|
202
202
|
let {
|
|
203
203
|
entries,
|
|
@@ -553,7 +553,7 @@ class Atlaspack {
|
|
|
553
553
|
message: `File watch event emitted with ${events.length} events. Sample event: [${(_events$ = events[0]) === null || _events$ === void 0 ? void 0 : _events$.type}] ${(_events$2 = events[0]) === null || _events$2 === void 0 ? void 0 : _events$2.path}`
|
|
554
554
|
});
|
|
555
555
|
let nativeInvalid = false;
|
|
556
|
-
if (this.rustAtlaspack) {
|
|
556
|
+
if ((0, _featureFlags().getFeatureFlag)('atlaspackV3') && this.rustAtlaspack) {
|
|
557
557
|
nativeInvalid = await this.rustAtlaspack.respondToFsEvents(events);
|
|
558
558
|
}
|
|
559
559
|
let {
|
|
@@ -634,7 +634,7 @@ class Atlaspack {
|
|
|
634
634
|
requestedAssetIds: this.#requestedAssetIds
|
|
635
635
|
};
|
|
636
636
|
const start = Date.now();
|
|
637
|
-
const result = await this.#requestTracker.runRequest(this.rustAtlaspack != null ?
|
|
637
|
+
const result = await this.#requestTracker.runRequest((0, _featureFlags().getFeatureFlag)('atlaspackV3') && this.rustAtlaspack != null ?
|
|
638
638
|
// @ts-expect-error TS2345
|
|
639
639
|
(0, _AssetGraphRequestRust.createAssetGraphRequestRust)(this.rustAtlaspack)(input) :
|
|
640
640
|
// @ts-expect-error TS2345
|
package/lib/BundleGraph.js
CHANGED
|
@@ -51,6 +51,13 @@ function _featureFlags() {
|
|
|
51
51
|
};
|
|
52
52
|
return data;
|
|
53
53
|
}
|
|
54
|
+
function _logger() {
|
|
55
|
+
const data = _interopRequireDefault(require("@atlaspack/logger"));
|
|
56
|
+
_logger = function () {
|
|
57
|
+
return data;
|
|
58
|
+
};
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
54
61
|
var _EnvironmentManager = require("./EnvironmentManager");
|
|
55
62
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
56
63
|
const bundleGraphEdgeTypes = exports.bundleGraphEdgeTypes = {
|
|
@@ -428,6 +435,67 @@ class BundleGraph {
|
|
|
428
435
|
conditions: serialized.conditions
|
|
429
436
|
});
|
|
430
437
|
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Serialize the bundle graph for efficient transfer to native Rust code.
|
|
441
|
+
* Returns a JSON string of nodes and an array of edges.
|
|
442
|
+
*/
|
|
443
|
+
serializeForNative() {
|
|
444
|
+
const start = performance.now();
|
|
445
|
+
const nodes = this._graph.nodes;
|
|
446
|
+
const edges = [];
|
|
447
|
+
const edgeIterator = this._graph.getAllEdges();
|
|
448
|
+
let next = edgeIterator.next();
|
|
449
|
+
while (!next.done) {
|
|
450
|
+
const edge = next.value;
|
|
451
|
+
edges.push([edge.from, edge.to, edge.type]);
|
|
452
|
+
next = edgeIterator.next();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Optimize nodes by omitting null/undefined values to reduce JSON size
|
|
456
|
+
const optimizedNodes = nodes.map(node => this._omitNulls(node));
|
|
457
|
+
const nodesJson = JSON.stringify(optimizedNodes);
|
|
458
|
+
const duration = performance.now() - start;
|
|
459
|
+
const sizeMB = (nodesJson.length / (1024 * 1024)).toFixed(2);
|
|
460
|
+
_logger().default.verbose({
|
|
461
|
+
origin: '@atlaspack/core',
|
|
462
|
+
message: `serializeForNative: ${duration.toFixed(1)}ms, ${sizeMB}MB JSON, ${nodes.length} nodes, ${edges.length} edges`
|
|
463
|
+
});
|
|
464
|
+
return {
|
|
465
|
+
nodesJson,
|
|
466
|
+
edges
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Remove null and undefined values from an object to reduce JSON size.
|
|
472
|
+
* Preserves false, 0, empty strings, and arrays.
|
|
473
|
+
*/
|
|
474
|
+
_omitNulls(obj) {
|
|
475
|
+
if (obj === null || obj === undefined) return obj;
|
|
476
|
+
if (typeof obj !== 'object') return obj;
|
|
477
|
+
if (Array.isArray(obj)) {
|
|
478
|
+
return obj.map(item => this._omitNulls(item));
|
|
479
|
+
}
|
|
480
|
+
const result = {};
|
|
481
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
482
|
+
if (value === null || value === undefined) {
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0) {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if (typeof value === 'object') {
|
|
489
|
+
const processed = this._omitNulls(value);
|
|
490
|
+
if (processed !== undefined) {
|
|
491
|
+
result[key] = processed;
|
|
492
|
+
}
|
|
493
|
+
} else {
|
|
494
|
+
result[key] = value;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return result;
|
|
498
|
+
}
|
|
431
499
|
createBundle(opts) {
|
|
432
500
|
// @ts-expect-error TS2339
|
|
433
501
|
let {
|
|
@@ -72,6 +72,16 @@ class AtlaspackV3 {
|
|
|
72
72
|
buildAssetGraph() {
|
|
73
73
|
return (0, _rust().atlaspackNapiBuildAssetGraph)(this._atlaspack_napi);
|
|
74
74
|
}
|
|
75
|
+
loadBundleGraph(bundleGraph) {
|
|
76
|
+
const {
|
|
77
|
+
nodesJson,
|
|
78
|
+
edges
|
|
79
|
+
} = bundleGraph.serializeForNative();
|
|
80
|
+
return (0, _rust().atlaspackNapiLoadBundleGraph)(this._atlaspack_napi, nodesJson, edges);
|
|
81
|
+
}
|
|
82
|
+
package() {
|
|
83
|
+
return (0, _rust().atlaspackNapiPackage)(this._atlaspack_napi);
|
|
84
|
+
}
|
|
75
85
|
async respondToFsEvents(events) {
|
|
76
86
|
// @ts-expect-error TS2488
|
|
77
87
|
let [needsRebuild, error] = await (0, _rust().atlaspackNapiRespondToFsEvents)(this._atlaspack_napi, events);
|
|
@@ -21,6 +21,14 @@ function _profiler() {
|
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
23
|
var _RequestTracker = require("../RequestTracker");
|
|
24
|
+
function _featureFlags() {
|
|
25
|
+
const data = require("@atlaspack/feature-flags");
|
|
26
|
+
_featureFlags = function () {
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
var _EnvironmentManager = require("../EnvironmentManager");
|
|
24
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
33
|
function createAtlaspackBuildRequest(input) {
|
|
26
34
|
return {
|
|
@@ -53,6 +61,18 @@ async function run({
|
|
|
53
61
|
} = await api.runRequest(bundleGraphRequest, {
|
|
54
62
|
force: Boolean(rustAtlaspack) || options.shouldBuildLazily && requestedAssetIds.size > 0
|
|
55
63
|
});
|
|
64
|
+
if ((0, _featureFlags().getFeatureFlag)('nativePackager') && (0, _featureFlags().getFeatureFlag)('nativePackagerSSRDev') && rustAtlaspack) {
|
|
65
|
+
let hasSupportedTarget = false;
|
|
66
|
+
bundleGraph.traverseBundles((bundle, ctx, actions) => {
|
|
67
|
+
if ((0, _EnvironmentManager.fromEnvironmentId)(bundle.env).context === 'tesseract' && bundle.type === 'js') {
|
|
68
|
+
hasSupportedTarget = true;
|
|
69
|
+
actions.stop();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (hasSupportedTarget) {
|
|
73
|
+
await rustAtlaspack.loadBundleGraph(bundleGraph);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
56
76
|
|
|
57
77
|
// @ts-expect-error TS2345
|
|
58
78
|
(0, _dumpGraphToGraphViz.default)(bundleGraph._graph, 'BundleGraph', _BundleGraph.bundleGraphEdgeTypes);
|
|
@@ -138,7 +138,7 @@ function createBundleGraphRequest(input) {
|
|
|
138
138
|
signal
|
|
139
139
|
} = input.input;
|
|
140
140
|
let measurement = _profiler().tracer.createMeasurement('building');
|
|
141
|
-
let createAssetGraphRequest = input.rustAtlaspack ? (0, _AssetGraphRequestRust.createAssetGraphRequestRust)(input.rustAtlaspack) : _AssetGraphRequest.default;
|
|
141
|
+
let createAssetGraphRequest = (0, _featureFlags().getFeatureFlag)('atlaspackV3') && input.rustAtlaspack ? (0, _AssetGraphRequestRust.createAssetGraphRequestRust)(input.rustAtlaspack) : _AssetGraphRequest.default;
|
|
142
142
|
let request = createAssetGraphRequest({
|
|
143
143
|
name: 'Main',
|
|
144
144
|
entries: options.entries,
|
|
@@ -15,6 +15,14 @@ function _nullthrows() {
|
|
|
15
15
|
var _ConfigRequest = require("./ConfigRequest");
|
|
16
16
|
var _DevDepRequest = require("./DevDepRequest");
|
|
17
17
|
var _AtlaspackConfigRequest = _interopRequireDefault(require("./AtlaspackConfigRequest"));
|
|
18
|
+
var _EnvironmentManager = require("../EnvironmentManager");
|
|
19
|
+
function _featureFlags() {
|
|
20
|
+
const data = require("@atlaspack/feature-flags");
|
|
21
|
+
_featureFlags = function () {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
18
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
27
|
function createPackageRequest(input) {
|
|
20
28
|
return {
|
|
@@ -27,7 +35,8 @@ function createPackageRequest(input) {
|
|
|
27
35
|
async function run({
|
|
28
36
|
input,
|
|
29
37
|
api,
|
|
30
|
-
farm
|
|
38
|
+
farm,
|
|
39
|
+
rustAtlaspack
|
|
31
40
|
}) {
|
|
32
41
|
let {
|
|
33
42
|
bundleGraphReference,
|
|
@@ -44,6 +53,10 @@ async function run({
|
|
|
44
53
|
let {
|
|
45
54
|
cachePath
|
|
46
55
|
} = (0, _nullthrows().default)(await api.runRequest((0, _AtlaspackConfigRequest.default)()));
|
|
56
|
+
if ((0, _featureFlags().getFeatureFlag)('nativePackager') && (0, _featureFlags().getFeatureFlag)('nativePackagerSSRDev') && rustAtlaspack && (0, _EnvironmentManager.fromEnvironmentId)(bundle.env).context === 'tesseract' && bundle.type === 'js') {
|
|
57
|
+
// Once this actually does something, the code below will be in an `else` block (i.e. we'll only run one or the other)
|
|
58
|
+
await rustAtlaspack.package();
|
|
59
|
+
}
|
|
47
60
|
let {
|
|
48
61
|
devDepRequests,
|
|
49
62
|
configRequests,
|
package/lib/resolveOptions.js
CHANGED
|
@@ -166,7 +166,7 @@ async function resolveOptions(initialOptions) {
|
|
|
166
166
|
if (initialOptions.cache) {
|
|
167
167
|
return initialOptions.cache;
|
|
168
168
|
}
|
|
169
|
-
const needsRustLmdbCache = (0, _featureFlags().getFeatureFlag)('atlaspackV3');
|
|
169
|
+
const needsRustLmdbCache = (0, _featureFlags().getFeatureFlag)('atlaspackV3') || (0, _featureFlags().getFeatureFlag)('nativePackager');
|
|
170
170
|
if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
171
171
|
if (!needsRustLmdbCache && !(outputFS instanceof _fs().NodeFS)) {
|
|
172
172
|
return new (_cache().FSCache)(outputFS, cacheDir);
|
|
@@ -77,6 +77,19 @@ export default class BundleGraph {
|
|
|
77
77
|
static fromAssetGraph(assetGraph: AssetGraph, isProduction: boolean, publicIdByAssetId?: Map<string, string>, assetPublicIds?: Set<string>): BundleGraph;
|
|
78
78
|
serialize(): SerializedBundleGraph;
|
|
79
79
|
static deserialize(serialized: BundleGraphOpts): BundleGraph;
|
|
80
|
+
/**
|
|
81
|
+
* Serialize the bundle graph for efficient transfer to native Rust code.
|
|
82
|
+
* Returns a JSON string of nodes and an array of edges.
|
|
83
|
+
*/
|
|
84
|
+
serializeForNative(): {
|
|
85
|
+
nodesJson: string;
|
|
86
|
+
edges: [number, number, BundleGraphEdgeType][];
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Remove null and undefined values from an object to reduce JSON size.
|
|
90
|
+
* Preserves false, 0, empty strings, and arrays.
|
|
91
|
+
*/
|
|
92
|
+
private _omitNulls;
|
|
80
93
|
createBundle(opts: {
|
|
81
94
|
readonly entryAsset: Asset;
|
|
82
95
|
readonly bundleRoots?: Array<Asset>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AtlaspackNapi, Lmdb, AtlaspackNapiOptions, CacheStats } from '@atlaspack/rust';
|
|
2
2
|
import type { Event } from '@parcel/watcher';
|
|
3
3
|
import type { NapiWorkerPool as INapiWorkerPool } from '@atlaspack/types';
|
|
4
|
+
import type BundleGraph from '../BundleGraph';
|
|
4
5
|
export type AtlaspackV3Options = {
|
|
5
6
|
fs?: AtlaspackNapiOptions['fs'];
|
|
6
7
|
packageManager?: AtlaspackNapiOptions['packageManager'];
|
|
@@ -22,6 +23,8 @@ export declare class AtlaspackV3 {
|
|
|
22
23
|
static create({ fs, packageManager, threads, lmdb, napiWorkerPool, ...options }: AtlaspackV3Options): Promise<AtlaspackV3>;
|
|
23
24
|
end(): void;
|
|
24
25
|
buildAssetGraph(): Promise<any>;
|
|
26
|
+
loadBundleGraph(bundleGraph: BundleGraph): Promise<void>;
|
|
27
|
+
package(): Promise<any>;
|
|
25
28
|
respondToFsEvents(events: Array<Event>): Promise<boolean>;
|
|
26
29
|
completeCacheSession(): Promise<CacheStats>;
|
|
27
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.32.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -23,22 +23,22 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@mischnic/json-sourcemap": "^0.1.0",
|
|
26
|
-
"@atlaspack/build-cache": "2.13.
|
|
27
|
-
"@atlaspack/cache": "3.2.
|
|
26
|
+
"@atlaspack/build-cache": "2.13.9",
|
|
27
|
+
"@atlaspack/cache": "3.2.45",
|
|
28
28
|
"@atlaspack/diagnostic": "2.14.4",
|
|
29
29
|
"@atlaspack/events": "2.14.4",
|
|
30
|
-
"@atlaspack/feature-flags": "2.
|
|
31
|
-
"@atlaspack/fs": "2.15.
|
|
32
|
-
"@atlaspack/graph": "3.6.
|
|
33
|
-
"@atlaspack/logger": "2.14.
|
|
34
|
-
"@atlaspack/package-manager": "2.14.
|
|
35
|
-
"@atlaspack/plugin": "2.14.
|
|
36
|
-
"@atlaspack/profiler": "2.15.
|
|
37
|
-
"@atlaspack/rust": "3.
|
|
38
|
-
"@atlaspack/types": "2.15.
|
|
39
|
-
"@atlaspack/utils": "3.3.
|
|
40
|
-
"@atlaspack/workers": "2.14.
|
|
41
|
-
"@atlaspack/source-map": "3.2.
|
|
30
|
+
"@atlaspack/feature-flags": "2.28.0",
|
|
31
|
+
"@atlaspack/fs": "2.15.45",
|
|
32
|
+
"@atlaspack/graph": "3.6.12",
|
|
33
|
+
"@atlaspack/logger": "2.14.42",
|
|
34
|
+
"@atlaspack/package-manager": "2.14.50",
|
|
35
|
+
"@atlaspack/plugin": "2.14.50",
|
|
36
|
+
"@atlaspack/profiler": "2.15.11",
|
|
37
|
+
"@atlaspack/rust": "3.20.0",
|
|
38
|
+
"@atlaspack/types": "2.15.40",
|
|
39
|
+
"@atlaspack/utils": "3.3.2",
|
|
40
|
+
"@atlaspack/workers": "2.14.50",
|
|
41
|
+
"@atlaspack/source-map": "3.2.5",
|
|
42
42
|
"base-x": "^3.0.8",
|
|
43
43
|
"browserslist": "^4.6.6",
|
|
44
44
|
"clone": "^2.1.1",
|
package/src/Atlaspack.ts
CHANGED
|
@@ -58,7 +58,11 @@ import {
|
|
|
58
58
|
fromProjectPathRelative,
|
|
59
59
|
} from './projectPath';
|
|
60
60
|
import {tracer, NativeProfiler} from '@atlaspack/profiler';
|
|
61
|
-
import {
|
|
61
|
+
import {
|
|
62
|
+
setFeatureFlags,
|
|
63
|
+
DEFAULT_FEATURE_FLAGS,
|
|
64
|
+
getFeatureFlag,
|
|
65
|
+
} from '@atlaspack/feature-flags';
|
|
62
66
|
import {AtlaspackV3, FileSystemV3} from './atlaspack-v3';
|
|
63
67
|
import createAssetGraphRequestJS from './requests/AssetGraphRequest';
|
|
64
68
|
import {createAssetGraphRequestRust} from './requests/AssetGraphRequestRust';
|
|
@@ -165,7 +169,10 @@ export default class Atlaspack {
|
|
|
165
169
|
this.#resolvedOptions = resolvedOptions;
|
|
166
170
|
|
|
167
171
|
let rustAtlaspack: AtlaspackV3;
|
|
168
|
-
if (
|
|
172
|
+
if (
|
|
173
|
+
resolvedOptions.featureFlags.atlaspackV3 ||
|
|
174
|
+
resolvedOptions.featureFlags.nativePackager
|
|
175
|
+
) {
|
|
169
176
|
// eslint-disable-next-line no-unused-vars
|
|
170
177
|
let {entries, inputFS, outputFS, ...options} = this.#initialOptions;
|
|
171
178
|
|
|
@@ -585,7 +592,7 @@ export default class Atlaspack {
|
|
|
585
592
|
});
|
|
586
593
|
|
|
587
594
|
let nativeInvalid = false;
|
|
588
|
-
if (this.rustAtlaspack) {
|
|
595
|
+
if (getFeatureFlag('atlaspackV3') && this.rustAtlaspack) {
|
|
589
596
|
nativeInvalid = await this.rustAtlaspack.respondToFsEvents(events);
|
|
590
597
|
}
|
|
591
598
|
|
|
@@ -681,7 +688,7 @@ export default class Atlaspack {
|
|
|
681
688
|
|
|
682
689
|
const start = Date.now();
|
|
683
690
|
const result = await this.#requestTracker.runRequest(
|
|
684
|
-
this.rustAtlaspack != null
|
|
691
|
+
getFeatureFlag('atlaspackV3') && this.rustAtlaspack != null
|
|
685
692
|
? // @ts-expect-error TS2345
|
|
686
693
|
createAssetGraphRequestRust(this.rustAtlaspack)(input)
|
|
687
694
|
: // @ts-expect-error TS2345
|