@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.
Files changed (66) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/Atlaspack.js +5 -1
  3. package/dist/AtlaspackConfig.schema.js +9 -0
  4. package/dist/BundleGraph.js +105 -0
  5. package/dist/CommittedAsset.js +1 -1
  6. package/dist/Transformation.js +3 -2
  7. package/dist/UncommittedAsset.js +3 -3
  8. package/dist/assetUtils.js +2 -1
  9. package/dist/atlaspack-v3/AtlaspackV3.js +2 -9
  10. package/dist/atlaspack-v3/NapiWorkerPool.js +5 -1
  11. package/dist/atlaspack-v3/worker/compat/mutable-asset.js +1 -1
  12. package/dist/atlaspack-v3/worker/worker.js +1 -1
  13. package/dist/public/BundleGraph.js +12 -0
  14. package/dist/requests/AssetGraphRequestRust.js +17 -6
  15. package/dist/requests/BundleGraphRequest.js +5 -3
  16. package/dist/resolveOptions.js +1 -0
  17. package/dist/worker.js +1 -1
  18. package/lib/Atlaspack.js +5 -1
  19. package/lib/AtlaspackConfig.schema.js +9 -0
  20. package/lib/BundleGraph.js +107 -0
  21. package/lib/CommittedAsset.js +1 -1
  22. package/lib/Transformation.js +9 -4
  23. package/lib/UncommittedAsset.js +3 -3
  24. package/lib/assetUtils.js +8 -1
  25. package/lib/atlaspack-v3/AtlaspackV3.js +2 -9
  26. package/lib/atlaspack-v3/NapiWorkerPool.js +4 -1
  27. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +1 -1
  28. package/lib/atlaspack-v3/worker/worker.js +1 -1
  29. package/lib/public/BundleGraph.js +13 -0
  30. package/lib/requests/AssetGraphRequestRust.js +20 -8
  31. package/lib/requests/BundleGraphRequest.js +4 -2
  32. package/lib/resolveOptions.js +1 -0
  33. package/lib/types/AtlaspackConfig.schema.d.ts +7 -0
  34. package/lib/types/BundleGraph.d.ts +2 -0
  35. package/lib/types/CommittedAsset.d.ts +1 -1
  36. package/lib/types/PackagerRunner.d.ts +1 -1
  37. package/lib/types/UncommittedAsset.d.ts +1 -1
  38. package/lib/types/atlaspack-v3/worker/compat/mutable-asset.d.ts +1 -1
  39. package/lib/types/public/Asset.d.ts +1 -1
  40. package/lib/types/public/BundleGraph.d.ts +2 -0
  41. package/lib/types/types.d.ts +1 -0
  42. package/lib/worker.js +1 -1
  43. package/package.json +14 -14
  44. package/src/Atlaspack.ts +6 -2
  45. package/src/AtlaspackConfig.schema.ts +9 -0
  46. package/src/BundleGraph.ts +152 -0
  47. package/src/CommittedAsset.ts +1 -1
  48. package/src/PackagerRunner.ts +1 -1
  49. package/src/Transformation.ts +3 -2
  50. package/src/UncommittedAsset.ts +3 -3
  51. package/src/assetUtils.ts +2 -1
  52. package/src/atlaspack-v3/AtlaspackV3.ts +2 -13
  53. package/src/atlaspack-v3/NapiWorkerPool.ts +5 -1
  54. package/src/atlaspack-v3/worker/compat/mutable-asset.ts +1 -1
  55. package/src/atlaspack-v3/worker/worker.ts +1 -1
  56. package/src/public/Asset.ts +1 -1
  57. package/src/public/BundleGraph.ts +21 -0
  58. package/src/requests/AssetGraphRequestRust.ts +23 -11
  59. package/src/requests/BundleGraphRequest.ts +9 -7
  60. package/src/resolveOptions.ts +1 -0
  61. package/src/types.ts +1 -0
  62. package/src/worker.ts +1 -1
  63. package/test/AtlaspackConfigRequest.test.ts +1 -1
  64. package/test/requests/AssetGraphRequestRust.test.ts +278 -276
  65. package/tsconfig.json +3 -0
  66. package/tsconfig.tsbuildinfo +1 -1
@@ -72,6 +72,13 @@ function _profiler() {
72
72
  };
73
73
  return data;
74
74
  }
75
+ function _sourceMap() {
76
+ const data = _interopRequireDefault(require("@atlaspack/source-map"));
77
+ _sourceMap = function () {
78
+ return data;
79
+ };
80
+ return data;
81
+ }
75
82
  function _featureFlags() {
76
83
  const data = require("@atlaspack/feature-flags");
77
84
  _featureFlags = function () {
@@ -343,10 +350,9 @@ class Transformation {
343
350
  // generate all assets in a large bundle during packaging.
344
351
  await Promise.all(resultingAssets.filter(asset => asset.ast != null && !(this.options.mode === 'production' && asset.value.type === 'css' && asset.value.symbols)).map(async asset => {
345
352
  if (asset.isASTDirty && asset.generate) {
346
- var _output$map;
347
353
  let output = await asset.generate();
348
354
  asset.content = output.content;
349
- asset.mapBuffer = (_output$map = output.map) === null || _output$map === void 0 ? void 0 : _output$map.toBuffer();
355
+ asset.mapBuffer = _sourceMap().default.safeToBuffer(output.map);
350
356
  }
351
357
  asset.clearAST();
352
358
  }));
@@ -453,10 +459,9 @@ class Transformation {
453
459
  logger,
454
460
  tracer
455
461
  })) && asset.generate) {
456
- var _output$map2;
457
462
  let output = await asset.generate();
458
463
  asset.content = output.content;
459
- asset.mapBuffer = (_output$map2 = output.map) === null || _output$map2 === void 0 ? void 0 : _output$map2.toBuffer();
464
+ asset.mapBuffer = _sourceMap().default.safeToBuffer(output.map);
460
465
  }
461
466
 
462
467
  // Load config for the transformer.
@@ -19,7 +19,7 @@ function _stream() {
19
19
  return data;
20
20
  }
21
21
  function _sourceMap() {
22
- const data = _interopRequireDefault(require("@parcel/source-map"));
22
+ const data = _interopRequireDefault(require("@atlaspack/source-map"));
23
23
  _sourceMap = function () {
24
24
  return data;
25
25
  };
@@ -218,7 +218,7 @@ class UncommittedAsset {
218
218
  });
219
219
  if (map) {
220
220
  this.map = map;
221
- this.mapBuffer = map.toBuffer();
221
+ this.mapBuffer = _sourceMap().default.safeToBuffer(map);
222
222
  this.setCode(code.replace(_utils().SOURCEMAP_RE, ''));
223
223
  }
224
224
  return this.map;
@@ -349,7 +349,7 @@ class UncommittedAsset {
349
349
  content,
350
350
  ast: result.ast,
351
351
  isASTDirty: result.ast === this.ast ? this.isASTDirty : true,
352
- mapBuffer: result.map ? result.map.toBuffer() : null,
352
+ mapBuffer: _sourceMap().default.safeToBuffer(result.map),
353
353
  code: this.code,
354
354
  invalidations: this.invalidations
355
355
  });
package/lib/assetUtils.js CHANGED
@@ -65,6 +65,13 @@ function _profiler() {
65
65
  }
66
66
  var _IdentifierRegistry = require("./IdentifierRegistry");
67
67
  var _EnvironmentManager = require("./EnvironmentManager");
68
+ function _sourceMap() {
69
+ const data = _interopRequireDefault(require("@atlaspack/source-map"));
70
+ _sourceMap = function () {
71
+ return data;
72
+ };
73
+ return data;
74
+ }
68
75
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69
76
  function createAssetIdFromOptions(options) {
70
77
  const data = {
@@ -150,7 +157,7 @@ async function _generateFromAST(asset) {
150
157
  category: 'asset-generate'
151
158
  })
152
159
  });
153
- let mapBuffer = map === null || map === void 0 ? void 0 : map.toBuffer();
160
+ let mapBuffer = _sourceMap().default.safeToBuffer(map);
154
161
  // Store the results in the cache so we can avoid generating again next time
155
162
  await Promise.all([asset.options.cache.setStream((0, _nullthrows().default)(asset.value.contentKey), (0, _utils().blobToStream)(content)), mapBuffer != null && asset.options.cache.setBlob((0, _nullthrows().default)(asset.value.mapKey), mapBuffer)]);
156
163
  return {
@@ -69,15 +69,8 @@ class AtlaspackV3 {
69
69
  this._napiWorkerPool.shutdown();
70
70
  }
71
71
  }
72
- async buildAssetGraph() {
73
- // @ts-expect-error TS2488
74
- let [graph, error] = await (0, _rust().atlaspackNapiBuildAssetGraph)(this._atlaspack_napi);
75
- if (error !== null) {
76
- throw new (_diagnostic().default)({
77
- diagnostic: error
78
- });
79
- }
80
- return graph;
72
+ buildAssetGraph() {
73
+ return (0, _rust().atlaspackNapiBuildAssetGraph)(this._atlaspack_napi);
81
74
  }
82
75
  async respondToFsEvents(events) {
83
76
  // @ts-expect-error TS2488
@@ -47,7 +47,10 @@ class NapiWorkerPool {
47
47
  workerCount: undefined
48
48
  }) {
49
49
  // @ts-expect-error TS2322
50
- this.#workerCount = workerCount ?? ATLASPACK_NAPI_WORKERS ?? (0, _rust().getAvailableThreads)();
50
+ this.#workerCount = workerCount ?? ATLASPACK_NAPI_WORKERS ??
51
+ // Default to a maximum of 4 workers as performance worsens beyond that
52
+ // point in most cases
53
+ Math.min((0, _rust().getAvailableThreads)(), 4);
51
54
  if (!this.#workerCount) {
52
55
  // TODO use main thread if workerCount is 0
53
56
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.MutableAsset = void 0;
7
7
  function _sourceMap() {
8
- const data = _interopRequireDefault(require("@parcel/source-map"));
8
+ const data = _interopRequireDefault(require("@atlaspack/source-map"));
9
9
  _sourceMap = function () {
10
10
  return data;
11
11
  };
@@ -183,7 +183,7 @@ class AtlaspackWorker {
183
183
  type: 'resolved',
184
184
  filePath: result.filePath || '',
185
185
  canDefer: result.canDefer || false,
186
- sideEffects: result.sideEffects || false,
186
+ sideEffects: result.sideEffects ?? true,
187
187
  code: result.code || undefined,
188
188
  meta: result.meta || undefined,
189
189
  pipeline: result.pipeline || undefined,
@@ -114,6 +114,19 @@ class BundleGraph {
114
114
  isAssetReferenced(bundle, asset) {
115
115
  return this.#graph.isAssetReferenced((0, _Bundle.bundleToInternalBundle)(bundle), (0, _Asset.assetToAssetValue)(asset));
116
116
  }
117
+ isAssetReferencedFastCheck(bundle, asset) {
118
+ return this.#graph.isAssetReferencedFastCheck((0, _Bundle.bundleToInternalBundle)(bundle), (0, _Asset.assetToAssetValue)(asset));
119
+ }
120
+ getReferencedAssets(bundle) {
121
+ let internalReferencedAssets = this.#graph.getReferencedAssets((0, _Bundle.bundleToInternalBundle)(bundle));
122
+
123
+ // Convert internal assets to public assets
124
+ let publicReferencedAssets = new Set();
125
+ for (let internalAsset of internalReferencedAssets) {
126
+ publicReferencedAssets.add((0, _Asset.assetFromValue)(internalAsset, this.#options));
127
+ }
128
+ return publicReferencedAssets;
129
+ }
117
130
  hasParentBundleOfType(bundle, type) {
118
131
  return this.#graph.hasParentBundleOfType((0, _Bundle.bundleToInternalBundle)(bundle), type);
119
132
  }
@@ -46,13 +46,16 @@ function createAssetGraphRequestRust(rustAtlaspack) {
46
46
  id: input.name,
47
47
  run: async input => {
48
48
  let options = input.options;
49
- let serializedAssetGraph = await rustAtlaspack.buildAssetGraph();
50
-
51
- // Newly created nodes
52
- serializedAssetGraph.nodes = serializedAssetGraph.nodes.map(node => JSON.parse(node));
53
-
54
- // Updated existing nodes
55
- serializedAssetGraph.updates = serializedAssetGraph.updates.map(node => JSON.parse(node));
49
+ let {
50
+ assetGraphPromise,
51
+ commitPromise
52
+ } = await rustAtlaspack.buildAssetGraph();
53
+ let [serializedAssetGraph, assetGraphError] = await assetGraphPromise;
54
+ if (assetGraphError) {
55
+ throw new (_diagnostic().default)({
56
+ diagnostic: assetGraphError
57
+ });
58
+ }
56
59
 
57
60
  // Don't reuse a previous asset graph result if Rust didn't have one too
58
61
  let prevResult = null;
@@ -91,6 +94,14 @@ function createAssetGraphRequestRust(rustAtlaspack) {
91
94
  changedAssetsPropagation,
92
95
  previousSymbolPropagationErrors: undefined
93
96
  };
97
+ let [_commitResult, commitError] = await commitPromise;
98
+ if (commitError) {
99
+ throw new (_diagnostic().default)({
100
+ diagnostic: {
101
+ message: 'Error committing asset graph in Rust: ' + commitError.message
102
+ }
103
+ });
104
+ }
94
105
  await input.api.storeResult(result);
95
106
  input.api.invalidateOnBuild();
96
107
  return result;
@@ -169,7 +180,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
169
180
  let envKey = [env.context, env.engines.atlaspack, env.engines.browsers, env.engines.electron, env.engines.node, env.includeNodeModules, env.isLibrary, env.outputFormat, env.shouldScopeHoist, env.shouldOptimize, env.sourceType].join(':');
170
181
  let envId = envs.get(envKey);
171
182
  if (envId == null) {
172
- envId = envs.size.toString();
183
+ envId = (0, _Environment.getEnvironmentHash)(env);
173
184
  envs.set(envKey, envId);
174
185
  }
175
186
  return envId;
@@ -188,6 +199,7 @@ function getAssetGraph(serializedGraph, prevAssetGraph) {
188
199
  for (let index = 0; index < nodesCount; index++) {
189
200
  let isUpdateNode = index >= nodeTypeSwitchoverIndex;
190
201
  let node = isUpdateNode ? serializedGraph.updates[index - nodeTypeSwitchoverIndex] : serializedGraph.nodes[index];
202
+ node = JSON.parse(node);
191
203
  if (node.type === 'entry') {
192
204
  let id = 'entry:' + ++entry;
193
205
  graph.addNodeByContentKey(id, {
@@ -152,8 +152,10 @@ function createBundleGraphRequest(input) {
152
152
  assetGraph,
153
153
  changedAssets,
154
154
  assetRequests
155
- } = await api.runRequest(request, {
156
- force: Boolean(input.rustAtlaspack) || options.shouldBuildLazily && requestedAssetIds.size > 0
155
+ } = await (0, _logger().instrumentAsync)('asset-graph-request', () => {
156
+ return api.runRequest(request, {
157
+ force: Boolean(input.rustAtlaspack) || options.shouldBuildLazily && requestedAssetIds.size > 0
158
+ });
157
159
  });
158
160
  if ((_input$options$featur = input.options.featureFlags) !== null && _input$options$featur !== void 0 && _input$options$featur.loadableSideEffects) {
159
161
  applySideEffectsForLoadableImports(assetGraph);
@@ -219,6 +219,7 @@ async function resolveOptions(initialOptions) {
219
219
  } : false,
220
220
  shouldDisableCache: initialOptions.shouldDisableCache ?? false,
221
221
  shouldProfile: initialOptions.shouldProfile ?? false,
222
+ nativeProfiler: initialOptions.nativeProfiler,
222
223
  shouldTrace: initialOptions.shouldTrace ?? false,
223
224
  cacheDir,
224
225
  watchDir,
@@ -34,6 +34,13 @@ declare const _default: {
34
34
  compressors: SchemaEntity;
35
35
  reporters: SchemaEntity;
36
36
  runtimes: SchemaEntity;
37
+ unstable_alias: {
38
+ type: string;
39
+ properties: {};
40
+ additionalProperties: {
41
+ type: string;
42
+ };
43
+ };
37
44
  filePath: {
38
45
  type: string;
39
46
  };
@@ -129,6 +129,8 @@ export default class BundleGraph {
129
129
  getDependencies(asset: Asset): Array<Dependency>;
130
130
  traverseAssets<TContext>(bundle: Bundle, visit: GraphVisitor<Asset, TContext>, startAsset?: Asset): TContext | null | undefined;
131
131
  isAssetReferenced(bundle: Bundle, asset: Asset): boolean;
132
+ isAssetReferencedFastCheck(bundle: Bundle, asset: Asset): boolean | null;
133
+ getReferencedAssets(bundle: Bundle): Set<Asset>;
132
134
  hasParentBundleOfType(bundle: Bundle, type: string): boolean;
133
135
  getParentBundles(bundle: Bundle): Array<Bundle>;
134
136
  isAssetReachableFromBundle(asset: Asset, bundle: Bundle): boolean;
@@ -1,6 +1,6 @@
1
1
  import { Readable } from 'stream';
2
2
  import type { AST, Blob } from '@atlaspack/types';
3
- import SourceMap from '@parcel/source-map';
3
+ import SourceMap from '@atlaspack/source-map';
4
4
  import type { Asset, Dependency, AtlaspackOptions } from './types';
5
5
  export default class CommittedAsset {
6
6
  key: string | null | undefined;
@@ -1,5 +1,5 @@
1
1
  import type { Blob, FilePath, BundleResult, Async } from '@atlaspack/types';
2
- import type SourceMap from '@parcel/source-map';
2
+ import type SourceMap from '@atlaspack/source-map';
3
3
  import type { Bundle as InternalBundle, Config, DevDepRequest, AtlaspackOptions, ReportFn, RequestInvalidation, DevDepRequestRef } from './types';
4
4
  import type { AtlaspackConfig, LoadedPlugin } from './AtlaspackConfig';
5
5
  import type InternalBundleGraph from './BundleGraph';
@@ -1,7 +1,7 @@
1
1
  import type { AST, Blob, DependencyOptions, FileCreateInvalidation, GenerateOutput, PackageName, TransformerResult } from '@atlaspack/types';
2
2
  import type { Asset, Dependency, AtlaspackOptions, Invalidations } from './types';
3
3
  import { Readable } from 'stream';
4
- import SourceMap from '@parcel/source-map';
4
+ import SourceMap from '@atlaspack/source-map';
5
5
  import { ProjectPath } from './projectPath';
6
6
  type UncommittedAssetOptions = {
7
7
  value: Asset;
@@ -1,4 +1,4 @@
1
- import SourceMap from '@parcel/source-map';
1
+ import SourceMap from '@atlaspack/source-map';
2
2
  import * as napi from '@atlaspack/rust';
3
3
  import { Readable } from 'stream';
4
4
  import type { MutableAsset as IMutableAsset, Stats, FileSystem, FilePath, Environment, Meta, BundleBehavior, ASTGenerator, AST, Dependency, DependencyOptions, FileCreateInvalidation, EnvironmentOptions } from '@atlaspack/types';
@@ -1,4 +1,4 @@
1
- import type SourceMap from '@parcel/source-map';
1
+ import type SourceMap from '@atlaspack/source-map';
2
2
  import type { Readable } from 'stream';
3
3
  import type { FileSystem } from '@atlaspack/fs';
4
4
  import type { Asset as IAsset, AST, ASTGenerator, Dependency as IDependency, DependencyOptions, Environment as IEnvironment, EnvironmentOptions, FileCreateInvalidation, FilePath, Meta, MutableAsset as IMutableAsset, Stats, MutableAssetSymbols as IMutableAssetSymbols, AssetSymbols as IAssetSymbols, BundleBehavior } from '@atlaspack/types';
@@ -30,6 +30,8 @@ export default class BundleGraph<TBundle extends IBundle> implements IBundleGrap
30
30
  getDependencies(asset: IAsset): Array<IDependency>;
31
31
  isAssetReachableFromBundle(asset: IAsset, bundle: IBundle): boolean;
32
32
  isAssetReferenced(bundle: IBundle, asset: IAsset): boolean;
33
+ isAssetReferencedFastCheck(bundle: IBundle, asset: IAsset): boolean | null;
34
+ getReferencedAssets(bundle: IBundle): Set<IAsset>;
33
35
  hasParentBundleOfType(bundle: IBundle, type: string): boolean;
34
36
  getBundlesInBundleGroup(bundleGroup: IBundleGroup, opts?: {
35
37
  includeInline: boolean;
@@ -241,6 +241,7 @@ export type AtlaspackOptions = {
241
241
  logLevel: LogLevel;
242
242
  projectRoot: FilePath;
243
243
  shouldProfile: boolean;
244
+ nativeProfiler: 'instruments' | 'samply' | undefined;
244
245
  shouldTrace: boolean;
245
246
  shouldPatchConsole: boolean;
246
247
  detailedReport?: DetailedReportOptions | null | undefined;
package/lib/worker.js CHANGED
@@ -46,7 +46,7 @@ function _buildCache() {
46
46
  return data;
47
47
  }
48
48
  function _sourceMap() {
49
- const data = require("@parcel/source-map");
49
+ const data = require("@atlaspack/source-map");
50
50
  _sourceMap = function () {
51
51
  return data;
52
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.27.0",
3
+ "version": "2.29.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -24,21 +24,21 @@
24
24
  "dependencies": {
25
25
  "@mischnic/json-sourcemap": "^0.1.0",
26
26
  "@atlaspack/build-cache": "2.13.6",
27
- "@atlaspack/cache": "3.2.33",
27
+ "@atlaspack/cache": "3.2.35",
28
28
  "@atlaspack/diagnostic": "2.14.4",
29
29
  "@atlaspack/events": "2.14.4",
30
- "@atlaspack/feature-flags": "2.26.2",
31
- "@atlaspack/fs": "2.15.33",
32
- "@atlaspack/graph": "3.6.0",
33
- "@atlaspack/logger": "2.14.30",
34
- "@atlaspack/package-manager": "2.14.38",
35
- "@atlaspack/plugin": "2.14.38",
36
- "@atlaspack/profiler": "2.14.35",
37
- "@atlaspack/rust": "3.10.0",
38
- "@atlaspack/types": "2.15.28",
39
- "@atlaspack/utils": "3.1.2",
40
- "@atlaspack/workers": "2.14.38",
41
- "@parcel/source-map": "^2.1.1",
30
+ "@atlaspack/feature-flags": "2.27.1",
31
+ "@atlaspack/fs": "2.15.35",
32
+ "@atlaspack/graph": "3.6.2",
33
+ "@atlaspack/logger": "2.14.32",
34
+ "@atlaspack/package-manager": "2.14.40",
35
+ "@atlaspack/plugin": "2.14.40",
36
+ "@atlaspack/profiler": "2.15.1",
37
+ "@atlaspack/rust": "3.12.0",
38
+ "@atlaspack/types": "2.15.30",
39
+ "@atlaspack/utils": "3.2.1",
40
+ "@atlaspack/workers": "2.14.40",
41
+ "@atlaspack/source-map": "3.1.1",
42
42
  "base-x": "^3.0.8",
43
43
  "browserslist": "^4.6.6",
44
44
  "clone": "^2.1.1",
package/src/Atlaspack.ts CHANGED
@@ -43,7 +43,7 @@ import createPathRequest from './requests/PathRequest';
43
43
  import {createEnvironment} from './Environment';
44
44
  import {createDependency} from './Dependency';
45
45
  import {Disposable} from '@atlaspack/events';
46
- import {init as initSourcemaps} from '@parcel/source-map';
46
+ import {init as initSourcemaps} from '@atlaspack/source-map';
47
47
  import {LMDBLiteCache} from '@atlaspack/cache';
48
48
  import {
49
49
  // @ts-expect-error TS2305
@@ -57,7 +57,7 @@ import {
57
57
  toProjectPath,
58
58
  fromProjectPathRelative,
59
59
  } from './projectPath';
60
- import {tracer} from '@atlaspack/profiler';
60
+ import {tracer, NativeProfiler} from '@atlaspack/profiler';
61
61
  import {setFeatureFlags, DEFAULT_FEATURE_FLAGS} from '@atlaspack/feature-flags';
62
62
  import {AtlaspackV3, FileSystemV3} from './atlaspack-v3';
63
63
  import createAssetGraphRequestJS from './requests/AssetGraphRequest';
@@ -407,6 +407,10 @@ export default class Atlaspack {
407
407
  if (options.shouldProfile) {
408
408
  await this.startProfiling();
409
409
  }
410
+ if (options.nativeProfiler) {
411
+ const nativeProfiler = new NativeProfiler();
412
+ await nativeProfiler.startProfiling(options.nativeProfiler);
413
+ }
410
414
  if (options.shouldTrace) {
411
415
  tracer.enable();
412
416
  // We need to ensure the tracer is disabled when Atlaspack is disposed as it is a module level object.
@@ -107,6 +107,15 @@ export default {
107
107
  compressors: mapPipelineSchema('compressor', 'compressors') as SchemaEntity,
108
108
  reporters: pipelineSchema('reporter', 'reporters') as SchemaEntity,
109
109
  runtimes: pipelineSchema('runtime', 'runtimes') as SchemaEntity,
110
+ // This isn't currently supported in V2, however we need to allow it to
111
+ // parse as even V3 builds need the AtlaspackConfigRequest
112
+ unstable_alias: {
113
+ type: 'object',
114
+ properties: {},
115
+ additionalProperties: {
116
+ type: 'string',
117
+ },
118
+ },
110
119
  filePath: {
111
120
  type: 'string',
112
121
  },
@@ -1435,6 +1435,158 @@ export default class BundleGraph {
1435
1435
  });
1436
1436
  }
1437
1437
 
1438
+ // New method: Fast checks only (no caching of results)
1439
+ isAssetReferencedFastCheck(bundle: Bundle, asset: Asset): boolean | null {
1440
+ // Fast Check #1: If asset is in multiple bundles in same target, it's referenced
1441
+ let bundlesWithAsset = this.getBundlesWithAsset(asset).filter(
1442
+ (b) =>
1443
+ b.target.name === bundle.target.name &&
1444
+ b.target.distDir === bundle.target.distDir,
1445
+ );
1446
+
1447
+ if (bundlesWithAsset.length > 1) {
1448
+ return true;
1449
+ }
1450
+
1451
+ // Fast Check #2: If asset is referenced by any async/conditional dependency, it's referenced
1452
+ let assetNodeId = nullthrows(this._graph.getNodeIdByContentKey(asset.id));
1453
+
1454
+ if (
1455
+ this._graph
1456
+ .getNodeIdsConnectedTo(assetNodeId, bundleGraphEdgeTypes.references)
1457
+ .map((id) => this._graph.getNode(id))
1458
+ .some(
1459
+ (node) =>
1460
+ node?.type === 'dependency' &&
1461
+ (node.value.priority === Priority.lazy ||
1462
+ node.value.priority === Priority.conditional) &&
1463
+ node.value.specifierType !== SpecifierType.url,
1464
+ )
1465
+ ) {
1466
+ return true;
1467
+ }
1468
+
1469
+ // Fast checks failed - return null to indicate expensive computation needed
1470
+ return null;
1471
+ }
1472
+
1473
+ getReferencedAssets(bundle: Bundle): Set<Asset> {
1474
+ let referencedAssets = new Set<Asset>();
1475
+
1476
+ // Build a map of all assets in this bundle with their dependencies
1477
+ // This allows us to check all assets in a single traversal
1478
+ let assetDependenciesMap = new Map<Asset, Array<Dependency>>();
1479
+
1480
+ this.traverseAssets(bundle, (asset) => {
1481
+ // Always do fast checks (no caching)
1482
+ let fastCheckResult = this.isAssetReferencedFastCheck(bundle, asset);
1483
+
1484
+ if (fastCheckResult === true) {
1485
+ referencedAssets.add(asset);
1486
+ return;
1487
+ }
1488
+
1489
+ // Fast checks failed (fastCheckResult === null), need expensive computation
1490
+ // Check if it's actually referenced via traversal
1491
+
1492
+ // Store dependencies for later batch checking
1493
+ let dependencies = this._graph
1494
+ .getNodeIdsConnectedTo(
1495
+ nullthrows(this._graph.getNodeIdByContentKey(asset.id)),
1496
+ )
1497
+ .map((id) => nullthrows(this._graph.getNode(id)))
1498
+ .filter((node) => node.type === 'dependency')
1499
+ .map((node) => {
1500
+ invariant(node.type === 'dependency');
1501
+ return node.value;
1502
+ });
1503
+
1504
+ if (dependencies.length > 0) {
1505
+ assetDependenciesMap.set(asset, dependencies);
1506
+ }
1507
+ });
1508
+
1509
+ // If no assets need the expensive check, return early
1510
+ if (assetDependenciesMap.size === 0) {
1511
+ return referencedAssets;
1512
+ }
1513
+
1514
+ // Get the assets we need to check once
1515
+ let assetsToCheck = Array.from(assetDependenciesMap.keys());
1516
+
1517
+ // Helper function to check if all assets from assetDependenciesMap are in referencedAssets
1518
+ const allAssetsReferenced = (): boolean =>
1519
+ assetsToCheck.length <= referencedAssets.size &&
1520
+ assetsToCheck.every((asset) => referencedAssets.has(asset));
1521
+
1522
+ // Do ONE traversal to check all remaining assets
1523
+ // We can share visitedBundles across all assets because we check every asset
1524
+ // against every visited bundle, which matches the original per-asset behavior
1525
+ let siblingBundles = new Set(
1526
+ this.getBundleGroupsContainingBundle(bundle).flatMap((bundleGroup) =>
1527
+ this.getBundlesInBundleGroup(bundleGroup, {includeInline: true}),
1528
+ ),
1529
+ );
1530
+
1531
+ let visitedBundles: Set<Bundle> = new Set();
1532
+
1533
+ // Single traversal from all referencers
1534
+ for (let referencer of siblingBundles) {
1535
+ this.traverseBundles((descendant, _, actions) => {
1536
+ if (descendant.id === bundle.id) {
1537
+ return;
1538
+ }
1539
+
1540
+ if (visitedBundles.has(descendant)) {
1541
+ actions.skipChildren();
1542
+ return;
1543
+ }
1544
+
1545
+ visitedBundles.add(descendant);
1546
+
1547
+ if (
1548
+ descendant.type !== bundle.type ||
1549
+ fromEnvironmentId(descendant.env).context !==
1550
+ fromEnvironmentId(bundle.env).context
1551
+ ) {
1552
+ // Don't skip children - they might be the right type!
1553
+ return;
1554
+ }
1555
+
1556
+ // Check ALL assets at once in this descendant bundle
1557
+ for (let [asset, dependencies] of assetDependenciesMap) {
1558
+ // Skip if already marked as referenced
1559
+ if (referencedAssets.has(asset)) {
1560
+ continue;
1561
+ }
1562
+
1563
+ // Check if this descendant bundle references the asset
1564
+ if (
1565
+ !this.bundleHasAsset(descendant, asset) &&
1566
+ dependencies.some((dependency) =>
1567
+ this.bundleHasDependency(descendant, dependency),
1568
+ )
1569
+ ) {
1570
+ referencedAssets.add(asset);
1571
+ }
1572
+ }
1573
+
1574
+ // If all assets from assetDependenciesMap are now marked as referenced, we can stop early
1575
+ if (allAssetsReferenced()) {
1576
+ actions.stop();
1577
+ return;
1578
+ }
1579
+ }, referencer);
1580
+
1581
+ // If all assets from assetDependenciesMap are referenced, no need to check more sibling bundles
1582
+ if (allAssetsReferenced()) {
1583
+ break;
1584
+ }
1585
+ }
1586
+
1587
+ return referencedAssets;
1588
+ }
1589
+
1438
1590
  hasParentBundleOfType(bundle: Bundle, type: string): boolean {
1439
1591
  let parents = this.getParentBundles(bundle);
1440
1592
  return (
@@ -3,7 +3,7 @@ import {Readable} from 'stream';
3
3
  import {deserializeRaw} from '@atlaspack/build-cache';
4
4
  import type {AST, Blob} from '@atlaspack/types';
5
5
  import {bufferStream, blobToStream, streamFromPromise} from '@atlaspack/utils';
6
- import SourceMap from '@parcel/source-map';
6
+ import SourceMap from '@atlaspack/source-map';
7
7
 
8
8
  import {generateFromAST} from './assetUtils';
9
9
  import type {Asset, Dependency, AtlaspackOptions} from './types';
@@ -7,7 +7,7 @@ import type {
7
7
  NamedBundle as NamedBundleType,
8
8
  Async,
9
9
  } from '@atlaspack/types';
10
- import type SourceMap from '@parcel/source-map';
10
+ import type SourceMap from '@atlaspack/source-map';
11
11
  import type {
12
12
  Bundle as InternalBundle,
13
13
  Config,
@@ -69,6 +69,7 @@ import {
69
69
  import {invalidateOnFileCreateToInternal, createInvalidations} from './utils';
70
70
  import invariant from 'assert';
71
71
  import {tracer, PluginTracer} from '@atlaspack/profiler';
72
+ import SourceMap from '@atlaspack/source-map';
72
73
  import {getFeatureFlag} from '@atlaspack/feature-flags';
73
74
 
74
75
  type GenerateFunc = (input: UncommittedAsset) => Promise<GenerateOutput>;
@@ -460,7 +461,7 @@ export default class Transformation {
460
461
  if (asset.isASTDirty && asset.generate) {
461
462
  let output = await asset.generate();
462
463
  asset.content = output.content;
463
- asset.mapBuffer = output.map?.toBuffer();
464
+ asset.mapBuffer = SourceMap.safeToBuffer(output.map);
464
465
  }
465
466
 
466
467
  asset.clearAST();
@@ -634,7 +635,7 @@ export default class Transformation {
634
635
  ) {
635
636
  let output = await asset.generate();
636
637
  asset.content = output.content;
637
- asset.mapBuffer = output.map?.toBuffer();
638
+ asset.mapBuffer = SourceMap.safeToBuffer(output.map);
638
639
  }
639
640
 
640
641
  // Load config for the transformer.