@atlaspack/core 2.26.3-dev-compiled-hash-e5f8a1735.0 → 2.27.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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # @atlaspack/core
2
2
 
3
+ ## 2.27.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#869](https://github.com/atlassian-labs/atlaspack/pull/869) [`cfb4707`](https://github.com/atlassian-labs/atlaspack/commit/cfb4707087498e4fa4dcf10753fe984a248d196b) Thanks [@benjervis](https://github.com/benjervis)! - Adds a feature to the V3 devloop that will minimise the amount of work done if the change is only a content change.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#873](https://github.com/atlassian-labs/atlaspack/pull/873) [`ec3abe4`](https://github.com/atlassian-labs/atlaspack/commit/ec3abe4dffc98560a850fd2f71fb566577e6c99c) Thanks [@vykimnguyen](https://github.com/vykimnguyen)! - cleanup deduplicateReporters flag
12
+
13
+ - [#870](https://github.com/atlassian-labs/atlaspack/pull/870) [`33d4c26`](https://github.com/atlassian-labs/atlaspack/commit/33d4c261ceb8d585d56b0a446ed6e28cf7f1126d) Thanks [@matt-koko](https://github.com/matt-koko)! - Support Loading TypeScript Plugin Files in v3
14
+
15
+ - [#856](https://github.com/atlassian-labs/atlaspack/pull/856) [`f31b041`](https://github.com/atlassian-labs/atlaspack/commit/f31b04107e9077c9946aadb99f6f91bb69703bb7) Thanks [@matt-koko](https://github.com/matt-koko)! - Handle Directory Entry Points in v3
16
+
17
+ - [#859](https://github.com/atlassian-labs/atlaspack/pull/859) [`8180981`](https://github.com/atlassian-labs/atlaspack/commit/8180981be14c00f9570adb70d3f350bd91d6ec0a) Thanks [@benjervis](https://github.com/benjervis)! - Re-use asset graphs when building in Native, if we have one left over from a previous incremental build
18
+
19
+ - [#883](https://github.com/atlassian-labs/atlaspack/pull/883) [`119210b`](https://github.com/atlassian-labs/atlaspack/commit/119210b597eb993c50445df87a36b70bd49cd414) Thanks [@matt-koko](https://github.com/matt-koko)! - Fix bitflags rust/js interop
20
+
21
+ - Updated dependencies [[`ec3abe4`](https://github.com/atlassian-labs/atlaspack/commit/ec3abe4dffc98560a850fd2f71fb566577e6c99c), [`c7fe3f7`](https://github.com/atlassian-labs/atlaspack/commit/c7fe3f76f247e9e20299e205e2df0a16c418eaf2), [`cfb4707`](https://github.com/atlassian-labs/atlaspack/commit/cfb4707087498e4fa4dcf10753fe984a248d196b), [`1468695`](https://github.com/atlassian-labs/atlaspack/commit/1468695fc0c9d06f060a6da9e9b0e154f11dff34), [`f31b041`](https://github.com/atlassian-labs/atlaspack/commit/f31b04107e9077c9946aadb99f6f91bb69703bb7), [`8180981`](https://github.com/atlassian-labs/atlaspack/commit/8180981be14c00f9570adb70d3f350bd91d6ec0a), [`ae77e74`](https://github.com/atlassian-labs/atlaspack/commit/ae77e7452a466b43b3fa5bed24d4ba26345ed765), [`f0a496f`](https://github.com/atlassian-labs/atlaspack/commit/f0a496f70fc8652e090cf1b3f6260e8cfbb796e2), [`7d7a55d`](https://github.com/atlassian-labs/atlaspack/commit/7d7a55dd6395ec391a2e4c33b3dec0d1ea477d4c), [`540f253`](https://github.com/atlassian-labs/atlaspack/commit/540f253dfdcd1a5caebbdc0b197319d439404aae)]:
22
+ - @atlaspack/feature-flags@2.26.2
23
+ - @atlaspack/rust@3.10.0
24
+ - @atlaspack/graph@3.6.0
25
+ - @atlaspack/utils@3.1.2
26
+ - @atlaspack/cache@3.2.33
27
+ - @atlaspack/fs@2.15.33
28
+ - @atlaspack/logger@2.14.30
29
+ - @atlaspack/package-manager@2.14.38
30
+ - @atlaspack/workers@2.14.38
31
+ - @atlaspack/plugin@2.14.38
32
+ - @atlaspack/profiler@2.14.35
33
+ - @atlaspack/types@2.15.28
34
+
3
35
  ## 2.26.2
4
36
 
5
37
  ### Patch Changes
@@ -19,7 +19,6 @@ class BitFlags {
19
19
  constructor(source) {
20
20
  // @ts-expect-error TS2344
21
21
  _BitFlags_kv.set(this, void 0);
22
- // @ts-expect-error TS2344
23
22
  _BitFlags_vk.set(this, void 0);
24
23
  __classPrivateFieldSet(this, _BitFlags_kv, source, "f");
25
24
  __classPrivateFieldSet(this, _BitFlags_vk, Object.fromEntries(Object.entries(source).map((a) => a.reverse())), "f");
@@ -37,9 +36,6 @@ class BitFlags {
37
36
  }
38
37
  return this.into(key);
39
38
  }
40
- intoArray(keys) {
41
- return keys.map((key) => this.into(key));
42
- }
43
39
  from(key) {
44
40
  const found = __classPrivateFieldGet(this, _BitFlags_vk, "f")[key];
45
41
  if (found === undefined) {
@@ -53,8 +49,14 @@ class BitFlags {
53
49
  }
54
50
  return this.from(key);
55
51
  }
56
- fromArray(keys) {
57
- return keys.map((key) => this.from(key));
52
+ toArray(keys) {
53
+ let values = [];
54
+ for (let [key, value] of Object.entries(__classPrivateFieldGet(this, _BitFlags_kv, "f"))) {
55
+ if ((keys & value) !== 0) {
56
+ values.push(key);
57
+ }
58
+ }
59
+ return values;
58
60
  }
59
61
  }
60
62
  exports.BitFlags = BitFlags;
@@ -70,21 +72,23 @@ exports.dependencyPriorityMap = new BitFlags({
70
72
  lazy: 2,
71
73
  conditional: 3,
72
74
  });
75
+ // Note: The bitflags must match the bitflags in the Rust code.
76
+ // crates/atlaspack_core/src/types/package_json.rs
73
77
  exports.packageConditionsMap = new BitFlags({
74
- import: 0,
75
- require: 1,
76
- module: 2,
77
- node: 3,
78
- browser: 4,
79
- worker: 5,
80
- worklet: 6,
81
- electron: 7,
82
- development: 8,
83
- production: 9,
84
- types: 10,
85
- default: 11,
86
- style: 12,
87
- sass: 13,
78
+ import: 1 << 0,
79
+ require: 1 << 1,
80
+ module: 1 << 2,
81
+ node: 1 << 3,
82
+ browser: 1 << 4,
83
+ worker: 1 << 5,
84
+ worklet: 1 << 6,
85
+ electron: 1 << 7,
86
+ development: 1 << 8,
87
+ production: 1 << 9,
88
+ types: 1 << 10,
89
+ default: 1 << 11,
90
+ style: 1 << 12,
91
+ sass: 1 << 13,
88
92
  });
89
93
  exports.specifierTypeMap = new BitFlags({
90
94
  esm: 0,
@@ -31,7 +31,7 @@ class Dependency {
31
31
  this.isOptional = inner.isOptional;
32
32
  this.isEntry = inner.isEntry;
33
33
  this.loc = inner.loc;
34
- this.packageConditions = bitflags_1.packageConditionsMap.fromArray(inner.packageConditions || []);
34
+ this.packageConditions = bitflags_1.packageConditionsMap.toArray(inner.packageConditions || []);
35
35
  this.sourceAssetId = inner.sourceAssetId;
36
36
  this.sourcePath = inner.sourcePath;
37
37
  this.sourceAssetType = inner.sourceAssetType;
@@ -46,7 +46,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
46
46
  var __importDefault = (this && this.__importDefault) || function (mod) {
47
47
  return (mod && mod.__esModule) ? mod : { "default": mod };
48
48
  };
49
- var _AtlaspackWorker_resolvers, _AtlaspackWorker_transformers, _AtlaspackWorker_fs;
49
+ var _AtlaspackWorker_resolvers, _AtlaspackWorker_transformers, _AtlaspackWorker_fs, _AtlaspackWorker_packageManager;
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
51
  exports.AtlaspackWorker = void 0;
52
52
  const assert_1 = __importDefault(require("assert"));
@@ -63,17 +63,23 @@ class AtlaspackWorker {
63
63
  _AtlaspackWorker_resolvers.set(this, void 0);
64
64
  _AtlaspackWorker_transformers.set(this, void 0);
65
65
  _AtlaspackWorker_fs.set(this, void 0);
66
+ _AtlaspackWorker_packageManager.set(this, void 0);
66
67
  this.loadPlugin = (0, jsCallable_1.jsCallable)(async ({ kind, specifier, resolveFrom, featureFlags }) => {
67
- let customRequire = module.createRequire(resolveFrom);
68
- let resolvedPath = customRequire.resolve(specifier);
69
- let resolvedModule = await import(resolvedPath);
68
+ // Use packageManager.require() instead of dynamic import() to support TypeScript plugins
69
+ let resolvedModule = await __classPrivateFieldGet(this, _AtlaspackWorker_packageManager, "f").require(specifier, resolveFrom, { shouldAutoInstall: false });
70
70
  let instance = undefined;
71
- if (resolvedModule.default && resolvedModule.default[CONFIG]) {
71
+ // Check for CommonJS export (module.exports = new Plugin(...))
72
+ if (resolvedModule[CONFIG]) {
73
+ instance = resolvedModule[CONFIG];
74
+ }
75
+ else if (resolvedModule.default && resolvedModule.default[CONFIG]) {
76
+ // ESM default export
72
77
  instance = resolvedModule.default[CONFIG];
73
78
  }
74
79
  else if (resolvedModule.default &&
75
80
  resolvedModule.default.default &&
76
81
  resolvedModule.default.default[CONFIG]) {
82
+ // Double-wrapped default export
77
83
  instance = resolvedModule.default.default[CONFIG];
78
84
  }
79
85
  else {
@@ -287,10 +293,11 @@ class AtlaspackWorker {
287
293
  __classPrivateFieldSet(this, _AtlaspackWorker_resolvers, new Map(), "f");
288
294
  __classPrivateFieldSet(this, _AtlaspackWorker_transformers, new Map(), "f");
289
295
  __classPrivateFieldSet(this, _AtlaspackWorker_fs, new fs_1.NodeFS(), "f");
296
+ __classPrivateFieldSet(this, _AtlaspackWorker_packageManager, new package_manager_1.NodePackageManager(__classPrivateFieldGet(this, _AtlaspackWorker_fs, "f"), '/'), "f");
290
297
  }
291
298
  }
292
299
  exports.AtlaspackWorker = AtlaspackWorker;
293
- _AtlaspackWorker_resolvers = new WeakMap(), _AtlaspackWorker_transformers = new WeakMap(), _AtlaspackWorker_fs = new WeakMap();
300
+ _AtlaspackWorker_resolvers = new WeakMap(), _AtlaspackWorker_transformers = new WeakMap(), _AtlaspackWorker_fs = new WeakMap(), _AtlaspackWorker_packageManager = new WeakMap();
294
301
  // Create napi worker and send it back to main thread
295
302
  const worker = new AtlaspackWorker();
296
303
  const napiWorker = napi.newNodejsWorker(worker);
@@ -30,7 +30,7 @@ function createAssetGraphRequest(requestInput) {
30
30
  run: async (input) => {
31
31
  let prevResult = await input.api.getPreviousResult();
32
32
  let builder = new AssetGraphBuilder(input, prevResult);
33
- let assetGraphRequest = await await builder.build();
33
+ let assetGraphRequest = await builder.build();
34
34
  // early break for incremental bundling if production or flag is off;
35
35
  assetGraphRequest.assetGraph.setDisableIncrementalBundling(!input.options.shouldBundleIncrementally ||
36
36
  input.options.mode === 'production');
@@ -14,16 +14,26 @@ const RequestTracker_1 = require("../RequestTracker");
14
14
  const SymbolPropagation_1 = require("../SymbolPropagation");
15
15
  const EnvironmentManager_1 = require("../EnvironmentManager");
16
16
  const Environment_1 = require("../Environment");
17
+ const dumpGraphToGraphViz_1 = __importDefault(require("../dumpGraphToGraphViz"));
18
+ const assert_2 = __importDefault(require("assert"));
17
19
  function createAssetGraphRequestRust(rustAtlaspack) {
18
20
  return (input) => ({
19
21
  type: RequestTracker_1.requestTypes.asset_graph_request,
20
22
  id: input.name,
21
23
  run: async (input) => {
22
24
  let options = input.options;
23
- let serializedAssetGraph = await rustAtlaspack.buildAssetGraph();
24
- // @ts-expect-error TS7006
25
+ let serializedAssetGraph = (await rustAtlaspack.buildAssetGraph());
26
+ // Newly created nodes
25
27
  serializedAssetGraph.nodes = serializedAssetGraph.nodes.map((node) => JSON.parse(node));
26
- let { assetGraph, changedAssets } = (0, logger_1.instrument)('atlaspack_v3_getAssetGraph', () => getAssetGraph(serializedAssetGraph));
28
+ // Updated existing nodes
29
+ serializedAssetGraph.updates = serializedAssetGraph.updates.map((node) => JSON.parse(node));
30
+ // Don't reuse a previous asset graph result if Rust didn't have one too
31
+ let prevResult = null;
32
+ if (serializedAssetGraph.hadPreviousGraph) {
33
+ prevResult =
34
+ await input.api.getPreviousResult();
35
+ }
36
+ let { assetGraph, changedAssets } = (0, logger_1.instrument)('atlaspack_v3_getAssetGraph', () => getAssetGraph(serializedAssetGraph, prevResult?.assetGraph));
27
37
  let changedAssetsPropagation = new Set(changedAssets.keys());
28
38
  let errors = (0, SymbolPropagation_1.propagateSymbols)({
29
39
  options,
@@ -39,7 +49,8 @@ function createAssetGraphRequestRust(rustAtlaspack) {
39
49
  diagnostic: [...errors.values()][0],
40
50
  });
41
51
  }
42
- return {
52
+ await (0, dumpGraphToGraphViz_1.default)(assetGraph, 'AssetGraphV3');
53
+ let result = {
43
54
  assetGraph,
44
55
  assetRequests: [],
45
56
  assetGroupsWithRemovedParents: new Set(),
@@ -47,17 +58,57 @@ function createAssetGraphRequestRust(rustAtlaspack) {
47
58
  changedAssetsPropagation,
48
59
  previousSymbolPropagationErrors: undefined,
49
60
  };
61
+ await input.api.storeResult(result);
62
+ input.api.invalidateOnBuild();
63
+ return result;
50
64
  },
51
65
  input,
52
66
  });
53
67
  }
54
- function getAssetGraph(serializedGraph) {
55
- let graph = new AssetGraph_1.default({
56
- _contentKeyToNodeId: new Map(),
57
- _nodeIdToContentKey: new Map(),
58
- initialCapacity: serializedGraph.edges.length,
59
- });
60
- graph.safeToIncrementallyBundle = false;
68
+ function getAssetGraph(serializedGraph, prevAssetGraph) {
69
+ let graph;
70
+ let reuseEdges = false;
71
+ if (prevAssetGraph && serializedGraph.safeToSkipBundling) {
72
+ graph = new AssetGraph_1.default({
73
+ _contentKeyToNodeId: prevAssetGraph._contentKeyToNodeId,
74
+ _nodeIdToContentKey: prevAssetGraph._nodeIdToContentKey,
75
+ nodes: prevAssetGraph.nodes,
76
+ rootNodeId: prevAssetGraph.rootNodeId,
77
+ adjacencyList: prevAssetGraph.adjacencyList,
78
+ });
79
+ reuseEdges = true;
80
+ }
81
+ else if (prevAssetGraph &&
82
+ (serializedGraph.updates.length > 0 || serializedGraph.nodes.length > 0)) {
83
+ graph = new AssetGraph_1.default({
84
+ _contentKeyToNodeId: prevAssetGraph._contentKeyToNodeId,
85
+ _nodeIdToContentKey: prevAssetGraph._nodeIdToContentKey,
86
+ nodes: prevAssetGraph.nodes,
87
+ initialCapacity: serializedGraph.edges.length,
88
+ // Accomodate the root node
89
+ initialNodeCapacity: prevAssetGraph.nodes.length + 1,
90
+ rootNodeId: prevAssetGraph.rootNodeId,
91
+ });
92
+ graph.safeToIncrementallyBundle = false;
93
+ }
94
+ else {
95
+ graph = new AssetGraph_1.default({
96
+ _contentKeyToNodeId: new Map(),
97
+ _nodeIdToContentKey: new Map(),
98
+ initialCapacity: serializedGraph.edges.length,
99
+ // Accomodate the root node
100
+ initialNodeCapacity: serializedGraph.nodes.length + 1,
101
+ });
102
+ let rootNodeId = graph.addNodeByContentKey('@@root', {
103
+ id: '@@root',
104
+ type: 'root',
105
+ value: null,
106
+ });
107
+ graph.setRootNodeId(rootNodeId);
108
+ graph.safeToIncrementallyBundle = false;
109
+ }
110
+ (0, assert_1.default)(graph, 'Asset graph not initialized');
111
+ (0, assert_1.default)(graph.rootNodeId != null, 'Asset graph has no root node');
61
112
  // @ts-expect-error TS7031
62
113
  function mapSymbols({ exported, ...symbol }) {
63
114
  let jsSymbol = {
@@ -95,21 +146,29 @@ function getAssetGraph(serializedGraph) {
95
146
  ].join(':');
96
147
  let envId = envs.get(envKey);
97
148
  if (envId == null) {
98
- envId = `${envs.size}`;
149
+ envId = envs.size.toString();
99
150
  envs.set(envKey, envId);
100
151
  }
101
152
  return envId;
102
153
  };
103
- for (let node of serializedGraph.nodes) {
104
- if (node.type === 'root') {
105
- let index = graph.addNodeByContentKey('@@root', {
106
- id: '@@root',
107
- type: 'root',
108
- value: null,
109
- });
110
- graph.setRootNodeId(index);
154
+ function updateNode(newNode, isUpdateNode) {
155
+ if (isUpdateNode) {
156
+ let existingNode = graph.getNodeByContentKey(newNode.id);
157
+ (0, assert_2.default)(existingNode && existingNode.type === newNode.type);
158
+ Object.assign(existingNode, newNode);
111
159
  }
112
- else if (node.type === 'entry') {
160
+ else {
161
+ graph.addNodeByContentKey(newNode.id, newNode);
162
+ }
163
+ }
164
+ let nodeTypeSwitchoverIndex = serializedGraph.nodes.length;
165
+ let nodesCount = serializedGraph.nodes.length + serializedGraph.updates.length;
166
+ for (let index = 0; index < nodesCount; index++) {
167
+ let isUpdateNode = index >= nodeTypeSwitchoverIndex;
168
+ let node = isUpdateNode
169
+ ? serializedGraph.updates[index - nodeTypeSwitchoverIndex]
170
+ : serializedGraph.nodes[index];
171
+ if (node.type === 'entry') {
113
172
  let id = 'entry:' + ++entry;
114
173
  graph.addNodeByContentKey(id, {
115
174
  id: id,
@@ -137,14 +196,15 @@ function getAssetGraph(serializedGraph) {
137
196
  asset.symbols = new Map(asset.symbols.map(mapSymbols));
138
197
  }
139
198
  changedAssets.set(id, asset);
140
- graph.addNodeByContentKey(id, {
199
+ let assetNode = {
141
200
  id,
142
201
  type: 'asset',
143
202
  usedSymbols: new Set(),
144
203
  usedSymbolsDownDirty: true,
145
204
  usedSymbolsUpDirty: true,
146
205
  value: asset,
147
- });
206
+ };
207
+ updateNode(assetNode, isUpdateNode);
148
208
  }
149
209
  else if (node.type === 'dependency') {
150
210
  let { dependency, id } = node.value;
@@ -163,7 +223,7 @@ function getAssetGraph(serializedGraph) {
163
223
  usedSymbolsDown.add('*');
164
224
  usedSymbolsUp.set('*', undefined);
165
225
  }
166
- graph.addNodeByContentKey(id, {
226
+ let depNode = {
167
227
  id,
168
228
  type: 'dependency',
169
229
  deferred: false,
@@ -176,21 +236,24 @@ function getAssetGraph(serializedGraph) {
176
236
  usedSymbolsUpDirtyDown: true,
177
237
  usedSymbolsUpDirtyUp: true,
178
238
  value: dependency,
179
- });
239
+ };
240
+ updateNode(depNode, isUpdateNode);
180
241
  }
181
242
  }
182
- for (let i = 0; i < serializedGraph.edges.length; i += 2) {
183
- let from = serializedGraph.edges[i];
184
- let to = serializedGraph.edges[i + 1];
185
- let fromNode = graph.getNode(from);
186
- let toNode = graph.getNode(to);
187
- if (fromNode?.type === 'dependency') {
188
- (0, assert_1.default)(toNode?.type === 'asset');
189
- }
190
- if (fromNode?.type === 'asset' && toNode?.type === 'dependency') {
191
- fromNode.value.dependencies.set(toNode.value.id, toNode.value);
243
+ if (!reuseEdges) {
244
+ for (let i = 0; i < serializedGraph.edges.length; i += 2) {
245
+ let from = serializedGraph.edges[i];
246
+ let to = serializedGraph.edges[i + 1];
247
+ let fromNode = graph.getNode(from);
248
+ let toNode = graph.getNode(to);
249
+ if (fromNode?.type === 'dependency') {
250
+ (0, assert_1.default)(toNode?.type === 'asset');
251
+ }
252
+ if (fromNode?.type === 'asset' && toNode?.type === 'dependency') {
253
+ fromNode.value.dependencies.set(toNode.value.id, toNode.value);
254
+ }
255
+ graph.addEdge(from, to);
192
256
  }
193
- graph.addEdge(from, to);
194
257
  }
195
258
  return {
196
259
  assetGraph: graph,
@@ -141,27 +141,16 @@ async function resolveAtlaspackConfig(options) {
141
141
  }
142
142
  let { config, extendedFiles } = await parseAndProcessConfig(configPath, contents, options);
143
143
  if (options.additionalReporters.length > 0) {
144
- if (options.featureFlags.deduplicateReporters) {
145
- const reporterMap = new Map();
146
- options.additionalReporters.forEach(({ packageName, resolveFrom }) => {
147
- reporterMap.set(packageName, { packageName, resolveFrom });
148
- });
149
- config.reporters?.forEach((reporter) => {
150
- if (!reporterMap.has(reporter.packageName)) {
151
- reporterMap.set(reporter.packageName, reporter);
152
- }
153
- });
154
- config.reporters = Array.from(reporterMap.values());
155
- }
156
- else {
157
- config.reporters = [
158
- ...options.additionalReporters.map(({ packageName, resolveFrom }) => ({
159
- packageName,
160
- resolveFrom,
161
- })),
162
- ...(config.reporters ?? []),
163
- ];
164
- }
144
+ const reporterMap = new Map();
145
+ options.additionalReporters.forEach(({ packageName, resolveFrom }) => {
146
+ reporterMap.set(packageName, { packageName, resolveFrom });
147
+ });
148
+ config.reporters?.forEach((reporter) => {
149
+ if (!reporterMap.has(reporter.packageName)) {
150
+ reporterMap.set(reporter.packageName, reporter);
151
+ }
152
+ });
153
+ config.reporters = Array.from(reporterMap.values());
165
154
  }
166
155
  return { config, extendedFiles, usedDefault };
167
156
  }
@@ -8,7 +8,6 @@ exports.specifierTypeMap = exports.packageConditionsMap = exports.dependencyPrio
8
8
  class BitFlags {
9
9
  // @ts-expect-error TS2344
10
10
  #kv;
11
- // @ts-expect-error TS2344
12
11
  #vk;
13
12
 
14
13
  // @ts-expect-error TS2344
@@ -29,9 +28,6 @@ class BitFlags {
29
28
  }
30
29
  return this.into(key);
31
30
  }
32
- intoArray(keys) {
33
- return keys.map(key => this.into(key));
34
- }
35
31
  from(key) {
36
32
  const found = this.#vk[key];
37
33
  if (found === undefined) {
@@ -45,8 +41,14 @@ class BitFlags {
45
41
  }
46
42
  return this.from(key);
47
43
  }
48
- fromArray(keys) {
49
- return keys.map(key => this.from(key));
44
+ toArray(keys) {
45
+ let values = [];
46
+ for (let [key, value] of Object.entries(this.#kv)) {
47
+ if ((keys & value) !== 0) {
48
+ values.push(key);
49
+ }
50
+ }
51
+ return values;
50
52
  }
51
53
  }
52
54
  exports.BitFlags = BitFlags;
@@ -61,21 +63,24 @@ const dependencyPriorityMap = exports.dependencyPriorityMap = new BitFlags({
61
63
  lazy: 2,
62
64
  conditional: 3
63
65
  });
66
+
67
+ // Note: The bitflags must match the bitflags in the Rust code.
68
+ // crates/atlaspack_core/src/types/package_json.rs
64
69
  const packageConditionsMap = exports.packageConditionsMap = new BitFlags({
65
- import: 0,
66
- require: 1,
67
- module: 2,
68
- node: 3,
69
- browser: 4,
70
- worker: 5,
71
- worklet: 6,
72
- electron: 7,
73
- development: 8,
74
- production: 9,
75
- types: 10,
76
- default: 11,
77
- style: 12,
78
- sass: 13
70
+ import: 1 << 0,
71
+ require: 1 << 1,
72
+ module: 1 << 2,
73
+ node: 1 << 3,
74
+ browser: 1 << 4,
75
+ worker: 1 << 5,
76
+ worklet: 1 << 6,
77
+ electron: 1 << 7,
78
+ development: 1 << 8,
79
+ production: 1 << 9,
80
+ types: 1 << 10,
81
+ default: 1 << 11,
82
+ style: 1 << 12,
83
+ sass: 1 << 13
79
84
  });
80
85
  const specifierTypeMap = exports.specifierTypeMap = new BitFlags({
81
86
  esm: 0,
@@ -35,7 +35,7 @@ class Dependency {
35
35
  this.isOptional = inner.isOptional;
36
36
  this.isEntry = inner.isEntry;
37
37
  this.loc = inner.loc;
38
- this.packageConditions = _bitflags.packageConditionsMap.fromArray(inner.packageConditions || []);
38
+ this.packageConditions = _bitflags.packageConditionsMap.toArray(inner.packageConditions || []);
39
39
  this.sourceAssetId = inner.sourceAssetId;
40
40
  this.sourcePath = inner.sourcePath;
41
41
  this.sourceAssetType = inner.sourceAssetType;
@@ -58,10 +58,12 @@ class AtlaspackWorker {
58
58
  #resolvers;
59
59
  #transformers;
60
60
  #fs;
61
+ #packageManager;
61
62
  constructor() {
62
63
  this.#resolvers = new Map();
63
64
  this.#transformers = new Map();
64
65
  this.#fs = new (_fs().NodeFS)();
66
+ this.#packageManager = new (_packageManager().NodePackageManager)(this.#fs, '/');
65
67
  }
66
68
  loadPlugin = (0, _jsCallable.jsCallable)(async ({
67
69
  kind,
@@ -69,13 +71,19 @@ class AtlaspackWorker {
69
71
  resolveFrom,
70
72
  featureFlags
71
73
  }) => {
72
- let customRequire = _module().createRequire(resolveFrom);
73
- let resolvedPath = customRequire.resolve(specifier);
74
- let resolvedModule = await import(resolvedPath);
74
+ // Use packageManager.require() instead of dynamic import() to support TypeScript plugins
75
+ let resolvedModule = await this.#packageManager.require(specifier, resolveFrom, {
76
+ shouldAutoInstall: false
77
+ });
75
78
  let instance = undefined;
76
- if (resolvedModule.default && resolvedModule.default[CONFIG]) {
79
+ // Check for CommonJS export (module.exports = new Plugin(...))
80
+ if (resolvedModule[CONFIG]) {
81
+ instance = resolvedModule[CONFIG];
82
+ } else if (resolvedModule.default && resolvedModule.default[CONFIG]) {
83
+ // ESM default export
77
84
  instance = resolvedModule.default[CONFIG];
78
85
  } else if (resolvedModule.default && resolvedModule.default.default && resolvedModule.default.default[CONFIG]) {
86
+ // Double-wrapped default export
79
87
  instance = resolvedModule.default.default[CONFIG];
80
88
  } else {
81
89
  throw new Error(`Plugin could not be resolved\n\t${kind}\n\t${resolveFrom}\n\t${specifier}`);
@@ -73,7 +73,7 @@ function createAssetGraphRequest(requestInput) {
73
73
  run: async input => {
74
74
  let prevResult = await input.api.getPreviousResult();
75
75
  let builder = new AssetGraphBuilder(input, prevResult);
76
- let assetGraphRequest = await await builder.build();
76
+ let assetGraphRequest = await builder.build();
77
77
 
78
78
  // early break for incremental bundling if production or flag is off;
79
79
  assetGraphRequest.assetGraph.setDisableIncrementalBundling(!input.options.shouldBundleIncrementally || input.options.mode === 'production');