@atlaspack/core 2.16.2-canary.372 → 2.16.2-canary.375

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.
@@ -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;
@@ -7,7 +7,6 @@ exports.AtlaspackV3 = void 0;
7
7
  const rust_1 = require("@atlaspack/rust");
8
8
  const NapiWorkerPool_1 = require("./NapiWorkerPool");
9
9
  const diagnostic_1 = __importDefault(require("@atlaspack/diagnostic"));
10
- const assert_1 = __importDefault(require("assert"));
11
10
  class AtlaspackV3 {
12
11
  constructor(atlaspack_napi, napiWorkerPool, isDefaultNapiWorkerPool) {
13
12
  this._atlaspack_napi = atlaspack_napi;
@@ -52,9 +51,9 @@ class AtlaspackV3 {
52
51
  buildAssetGraph() {
53
52
  return (0, rust_1.atlaspackNapiBuildAssetGraph)(this._atlaspack_napi);
54
53
  }
55
- loadBundleGraph({ nodes, edges, }) {
56
- (0, assert_1.default)(nodes.length > 0, 'Bundle graph must have at least one node');
57
- return (0, rust_1.atlaspackNapiLoadBundleGraph)(this._atlaspack_napi, nodes, edges);
54
+ loadBundleGraph(bundleGraph) {
55
+ const { nodesJson, edges } = bundleGraph.serializeForNative();
56
+ return (0, rust_1.atlaspackNapiLoadBundleGraph)(this._atlaspack_napi, nodesJson, edges);
58
57
  }
59
58
  package() {
60
59
  return (0, rust_1.atlaspackNapiPackage)(this._atlaspack_napi);
@@ -48,17 +48,7 @@ async function run({ input, api, options, rustAtlaspack, }) {
48
48
  }
49
49
  });
50
50
  if (hasSupportedTarget) {
51
- // In theory this could be a (somehow) null[] - but we know if we've gotten this far it probably isn't..
52
- let nodes = bundleGraph._graph.nodes;
53
- let rawEdges = [];
54
- const gen = bundleGraph._graph.getAllEdges();
55
- let next = gen.next();
56
- while (!next.done) {
57
- let edge = next.value;
58
- rawEdges.push([edge.from, edge.to, edge.type]);
59
- next = gen.next();
60
- }
61
- await rustAtlaspack.loadBundleGraph({ nodes, edges: rawEdges });
51
+ await rustAtlaspack.loadBundleGraph(bundleGraph);
62
52
  }
63
53
  }
64
54
  // @ts-expect-error TS2345
@@ -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 {
@@ -19,13 +19,6 @@ function _diagnostic() {
19
19
  };
20
20
  return data;
21
21
  }
22
- function _assert() {
23
- const data = _interopRequireDefault(require("assert"));
24
- _assert = function () {
25
- return data;
26
- };
27
- return data;
28
- }
29
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
23
  class AtlaspackV3 {
31
24
  constructor(atlaspack_napi, napiWorkerPool, isDefaultNapiWorkerPool) {
@@ -79,12 +72,12 @@ class AtlaspackV3 {
79
72
  buildAssetGraph() {
80
73
  return (0, _rust().atlaspackNapiBuildAssetGraph)(this._atlaspack_napi);
81
74
  }
82
- loadBundleGraph({
83
- nodes,
84
- edges
85
- }) {
86
- (0, _assert().default)(nodes.length > 0, 'Bundle graph must have at least one node');
87
- return (0, _rust().atlaspackNapiLoadBundleGraph)(this._atlaspack_napi, nodes, edges);
75
+ loadBundleGraph(bundleGraph) {
76
+ const {
77
+ nodesJson,
78
+ edges
79
+ } = bundleGraph.serializeForNative();
80
+ return (0, _rust().atlaspackNapiLoadBundleGraph)(this._atlaspack_napi, nodesJson, edges);
88
81
  }
89
82
  package() {
90
83
  return (0, _rust().atlaspackNapiPackage)(this._atlaspack_napi);
@@ -70,20 +70,7 @@ async function run({
70
70
  }
71
71
  });
72
72
  if (hasSupportedTarget) {
73
- // In theory this could be a (somehow) null[] - but we know if we've gotten this far it probably isn't..
74
- let nodes = bundleGraph._graph.nodes;
75
- let rawEdges = [];
76
- const gen = bundleGraph._graph.getAllEdges();
77
- let next = gen.next();
78
- while (!next.done) {
79
- let edge = next.value;
80
- rawEdges.push([edge.from, edge.to, edge.type]);
81
- next = gen.next();
82
- }
83
- await rustAtlaspack.loadBundleGraph({
84
- nodes,
85
- edges: rawEdges
86
- });
73
+ await rustAtlaspack.loadBundleGraph(bundleGraph);
87
74
  }
88
75
  }
89
76
 
@@ -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,8 +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 { BundleGraphNode } from '../types';
5
- import { BundleGraphEdgeType } from '../BundleGraph';
4
+ import type BundleGraph from '../BundleGraph';
6
5
  export type AtlaspackV3Options = {
7
6
  fs?: AtlaspackNapiOptions['fs'];
8
7
  packageManager?: AtlaspackNapiOptions['packageManager'];
@@ -24,10 +23,7 @@ export declare class AtlaspackV3 {
24
23
  static create({ fs, packageManager, threads, lmdb, napiWorkerPool, ...options }: AtlaspackV3Options): Promise<AtlaspackV3>;
25
24
  end(): void;
26
25
  buildAssetGraph(): Promise<any>;
27
- loadBundleGraph({ nodes, edges, }: {
28
- nodes: BundleGraphNode[];
29
- edges: [number, number, BundleGraphEdgeType][];
30
- }): Promise<any>;
26
+ loadBundleGraph(bundleGraph: BundleGraph): Promise<void>;
31
27
  package(): Promise<any>;
32
28
  respondToFsEvents(events: Array<Event>): Promise<boolean>;
33
29
  completeCacheSession(): Promise<CacheStats>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.16.2-canary.372+3753cb1bf",
3
+ "version": "2.16.2-canary.375+d0200834a",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,22 +22,22 @@
22
22
  "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
23
23
  },
24
24
  "dependencies": {
25
- "@atlaspack/build-cache": "2.13.3-canary.440+3753cb1bf",
26
- "@atlaspack/cache": "3.1.1-canary.372+3753cb1bf",
27
- "@atlaspack/diagnostic": "2.14.1-canary.440+3753cb1bf",
28
- "@atlaspack/events": "2.14.1-canary.440+3753cb1bf",
29
- "@atlaspack/feature-flags": "2.14.1-canary.440+3753cb1bf",
30
- "@atlaspack/fs": "2.14.5-canary.372+3753cb1bf",
31
- "@atlaspack/graph": "3.4.1-canary.440+3753cb1bf",
32
- "@atlaspack/logger": "2.14.5-canary.372+3753cb1bf",
33
- "@atlaspack/package-manager": "2.14.5-canary.372+3753cb1bf",
34
- "@atlaspack/plugin": "2.14.5-canary.372+3753cb1bf",
35
- "@atlaspack/profiler": "2.14.1-canary.440+3753cb1bf",
36
- "@atlaspack/rust": "3.2.1-canary.372+3753cb1bf",
37
- "@atlaspack/source-map": "3.2.5-canary.4151+3753cb1bf",
38
- "@atlaspack/types": "2.14.5-canary.372+3753cb1bf",
39
- "@atlaspack/utils": "2.14.5-canary.372+3753cb1bf",
40
- "@atlaspack/workers": "2.14.5-canary.372+3753cb1bf",
25
+ "@atlaspack/build-cache": "2.13.3-canary.443+d0200834a",
26
+ "@atlaspack/cache": "3.1.1-canary.375+d0200834a",
27
+ "@atlaspack/diagnostic": "2.14.1-canary.443+d0200834a",
28
+ "@atlaspack/events": "2.14.1-canary.443+d0200834a",
29
+ "@atlaspack/feature-flags": "2.14.1-canary.443+d0200834a",
30
+ "@atlaspack/fs": "2.14.5-canary.375+d0200834a",
31
+ "@atlaspack/graph": "3.4.1-canary.443+d0200834a",
32
+ "@atlaspack/logger": "2.14.5-canary.375+d0200834a",
33
+ "@atlaspack/package-manager": "2.14.5-canary.375+d0200834a",
34
+ "@atlaspack/plugin": "2.14.5-canary.375+d0200834a",
35
+ "@atlaspack/profiler": "2.14.1-canary.443+d0200834a",
36
+ "@atlaspack/rust": "3.2.1-canary.375+d0200834a",
37
+ "@atlaspack/source-map": "3.2.5-canary.4154+d0200834a",
38
+ "@atlaspack/types": "2.14.5-canary.375+d0200834a",
39
+ "@atlaspack/utils": "2.14.5-canary.375+d0200834a",
40
+ "@atlaspack/workers": "2.14.5-canary.375+d0200834a",
41
41
  "@mischnic/json-sourcemap": "^0.1.0",
42
42
  "base-x": "^3.0.8",
43
43
  "browserslist": "^4.6.6",
@@ -61,5 +61,5 @@
61
61
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
62
62
  },
63
63
  "type": "commonjs",
64
- "gitHead": "3753cb1bf9155eaf3a1a8f952886864682738647"
64
+ "gitHead": "d0200834a2dbe54b56f8b127d8c8ee8d60af27e7"
65
65
  }
@@ -46,6 +46,7 @@ import {ISOLATED_ENVS} from './public/Environment';
46
46
  import {fromProjectPath, fromProjectPathRelative} from './projectPath';
47
47
  import {HASH_REF_PREFIX} from './constants';
48
48
  import {getFeatureFlag} from '@atlaspack/feature-flags';
49
+ import logger from '@atlaspack/logger';
49
50
  import {fromEnvironmentId} from './EnvironmentManager';
50
51
  import type {EnvironmentRef} from './EnvironmentManager';
51
52
 
@@ -571,6 +572,76 @@ export default class BundleGraph {
571
572
  });
572
573
  }
573
574
 
575
+ /**
576
+ * Serialize the bundle graph for efficient transfer to native Rust code.
577
+ * Returns a JSON string of nodes and an array of edges.
578
+ */
579
+ serializeForNative(): {
580
+ nodesJson: string;
581
+ edges: [number, number, BundleGraphEdgeType][];
582
+ } {
583
+ const start = performance.now();
584
+
585
+ const nodes = this._graph.nodes as BundleGraphNode[];
586
+ const edges: [number, number, BundleGraphEdgeType][] = [];
587
+
588
+ const edgeIterator = this._graph.getAllEdges();
589
+ let next = edgeIterator.next();
590
+ while (!next.done) {
591
+ const edge = next.value;
592
+ edges.push([edge.from, edge.to, edge.type]);
593
+ next = edgeIterator.next();
594
+ }
595
+
596
+ // Optimize nodes by omitting null/undefined values to reduce JSON size
597
+ const optimizedNodes = nodes.map((node) => this._omitNulls(node));
598
+ const nodesJson = JSON.stringify(optimizedNodes);
599
+
600
+ const duration = performance.now() - start;
601
+ const sizeMB = (nodesJson.length / (1024 * 1024)).toFixed(2);
602
+ logger.verbose({
603
+ origin: '@atlaspack/core',
604
+ message: `serializeForNative: ${duration.toFixed(1)}ms, ${sizeMB}MB JSON, ${nodes.length} nodes, ${edges.length} edges`,
605
+ });
606
+
607
+ return {nodesJson, edges};
608
+ }
609
+
610
+ /**
611
+ * Remove null and undefined values from an object to reduce JSON size.
612
+ * Preserves false, 0, empty strings, and arrays.
613
+ */
614
+ private _omitNulls(obj: unknown): unknown {
615
+ if (obj === null || obj === undefined) return obj;
616
+ if (typeof obj !== 'object') return obj;
617
+ if (Array.isArray(obj)) {
618
+ return obj.map((item) => this._omitNulls(item));
619
+ }
620
+
621
+ const result: Record<string, unknown> = {};
622
+ for (const [key, value] of Object.entries(obj as Record<string, unknown>)) {
623
+ if (value === null || value === undefined) {
624
+ continue;
625
+ }
626
+ if (
627
+ typeof value === 'object' &&
628
+ !Array.isArray(value) &&
629
+ Object.keys(value as object).length === 0
630
+ ) {
631
+ continue;
632
+ }
633
+ if (typeof value === 'object') {
634
+ const processed = this._omitNulls(value);
635
+ if (processed !== undefined) {
636
+ result[key] = processed;
637
+ }
638
+ } else {
639
+ result[key] = value;
640
+ }
641
+ }
642
+ return result;
643
+ }
644
+
574
645
  createBundle(
575
646
  opts:
576
647
  | {
@@ -14,9 +14,8 @@ import {NapiWorkerPool} from './NapiWorkerPool';
14
14
  import ThrowableDiagnostic from '@atlaspack/diagnostic';
15
15
  import type {Event} from '@parcel/watcher';
16
16
  import type {NapiWorkerPool as INapiWorkerPool} from '@atlaspack/types';
17
- import {BundleGraphNode} from '../types';
18
17
  import invariant from 'assert';
19
- import {BundleGraphEdgeType} from '../BundleGraph';
18
+ import type BundleGraph from '../BundleGraph';
20
19
 
21
20
  export type AtlaspackV3Options = {
22
21
  fs?: AtlaspackNapiOptions['fs'];
@@ -102,19 +101,14 @@ export class AtlaspackV3 {
102
101
  return atlaspackNapiBuildAssetGraph(this._atlaspack_napi) as Promise<any>;
103
102
  }
104
103
 
105
- loadBundleGraph({
106
- nodes,
107
- edges,
108
- }: {
109
- nodes: BundleGraphNode[];
110
- edges: [number, number, BundleGraphEdgeType][];
111
- }): Promise<any> {
112
- invariant(nodes.length > 0, 'Bundle graph must have at least one node');
104
+ loadBundleGraph(bundleGraph: BundleGraph): Promise<void> {
105
+ const {nodesJson, edges} = bundleGraph.serializeForNative();
106
+
113
107
  return atlaspackNapiLoadBundleGraph(
114
108
  this._atlaspack_napi,
115
- nodes,
109
+ nodesJson,
116
110
  edges,
117
- ) as Promise<any>;
111
+ ) as Promise<void>;
118
112
  }
119
113
 
120
114
  package(): Promise<any> {
@@ -3,12 +3,7 @@ import type {Async} from '@atlaspack/types';
3
3
  import type {SharedReference} from '@atlaspack/workers';
4
4
 
5
5
  import type {StaticRunOpts} from '../RequestTracker';
6
- import type {
7
- Asset,
8
- AssetGroup,
9
- BundleGraphNode,
10
- PackagedBundleInfo,
11
- } from '../types';
6
+ import type {Asset, AssetGroup, PackagedBundleInfo} from '../types';
12
7
  import type BundleGraph from '../BundleGraph';
13
8
 
14
9
  import createBundleGraphRequest, {
@@ -17,7 +12,7 @@ import createBundleGraphRequest, {
17
12
  import createWriteBundlesRequest from './WriteBundlesRequest';
18
13
  import {assertSignalNotAborted} from '../utils';
19
14
  import dumpGraphToGraphViz from '../dumpGraphToGraphViz';
20
- import {BundleGraphEdgeType, bundleGraphEdgeTypes} from '../BundleGraph';
15
+ import {bundleGraphEdgeTypes} from '../BundleGraph';
21
16
  import {report} from '../ReporterRunner';
22
17
  import IBundleGraph from '../public/BundleGraph';
23
18
  import {NamedBundle} from '../public/Bundle';
@@ -107,17 +102,7 @@ async function run({
107
102
  }
108
103
  });
109
104
  if (hasSupportedTarget) {
110
- // In theory this could be a (somehow) null[] - but we know if we've gotten this far it probably isn't..
111
- let nodes = bundleGraph._graph.nodes as BundleGraphNode[];
112
- let rawEdges: [number, number, BundleGraphEdgeType][] = [];
113
- const gen = bundleGraph._graph.getAllEdges();
114
- let next = gen.next();
115
- while (!next.done) {
116
- let edge = next.value;
117
- rawEdges.push([edge.from, edge.to, edge.type]);
118
- next = gen.next();
119
- }
120
- await rustAtlaspack.loadBundleGraph({nodes, edges: rawEdges});
105
+ await rustAtlaspack.loadBundleGraph(bundleGraph);
121
106
  }
122
107
  }
123
108