@atlaspack/core 2.26.3-dev-compiled-hash-e5f8a1735.0 → 2.28.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 +61 -0
- package/dist/Atlaspack.js +5 -1
- package/dist/BundleGraph.js +105 -0
- package/dist/CommittedAsset.js +1 -1
- package/dist/Transformation.js +3 -2
- package/dist/UncommittedAsset.js +3 -3
- package/dist/assetUtils.js +2 -1
- package/dist/atlaspack-v3/worker/compat/bitflags.js +24 -20
- package/dist/atlaspack-v3/worker/compat/dependency.js +1 -1
- package/dist/atlaspack-v3/worker/compat/mutable-asset.js +1 -1
- package/dist/atlaspack-v3/worker/worker.js +14 -7
- package/dist/public/BundleGraph.js +12 -0
- package/dist/requests/AssetGraphRequest.js +1 -1
- package/dist/requests/AssetGraphRequestRust.js +99 -36
- package/dist/requests/AtlaspackConfigRequest.js +10 -21
- package/dist/requests/BundleGraphRequest.js +5 -3
- package/dist/resolveOptions.js +1 -0
- package/dist/worker.js +1 -1
- package/lib/Atlaspack.js +5 -1
- package/lib/BundleGraph.js +107 -0
- package/lib/CommittedAsset.js +1 -1
- package/lib/Transformation.js +9 -4
- package/lib/UncommittedAsset.js +3 -3
- package/lib/assetUtils.js +8 -1
- package/lib/atlaspack-v3/worker/compat/bitflags.js +25 -20
- package/lib/atlaspack-v3/worker/compat/dependency.js +1 -1
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +1 -1
- package/lib/atlaspack-v3/worker/worker.js +13 -5
- package/lib/public/BundleGraph.js +13 -0
- package/lib/requests/AssetGraphRequest.js +1 -1
- package/lib/requests/AssetGraphRequestRust.js +96 -35
- package/lib/requests/AtlaspackConfigRequest.js +14 -24
- package/lib/requests/BundleGraphRequest.js +4 -2
- package/lib/resolveOptions.js +1 -0
- package/lib/types/BundleGraph.d.ts +2 -0
- package/lib/types/CommittedAsset.d.ts +1 -1
- package/lib/types/PackagerRunner.d.ts +1 -1
- package/lib/types/UncommittedAsset.d.ts +1 -1
- package/lib/types/atlaspack-v3/worker/compat/bitflags.d.ts +11 -12
- package/lib/types/atlaspack-v3/worker/compat/mutable-asset.d.ts +1 -1
- package/lib/types/public/Asset.d.ts +1 -1
- package/lib/types/public/BundleGraph.d.ts +2 -0
- package/lib/types/requests/AssetGraphRequestRust.d.ts +1 -1
- package/lib/types/types.d.ts +1 -0
- package/lib/worker.js +1 -1
- package/package.json +21 -22
- package/src/Atlaspack.ts +6 -2
- package/src/BundleGraph.ts +152 -0
- package/src/CommittedAsset.ts +1 -1
- package/src/PackagerRunner.ts +1 -1
- package/src/Transformation.ts +3 -2
- package/src/UncommittedAsset.ts +3 -3
- package/src/assetUtils.ts +2 -1
- package/src/atlaspack-v3/worker/compat/bitflags.ts +44 -41
- package/src/atlaspack-v3/worker/compat/dependency.ts +1 -1
- package/src/atlaspack-v3/worker/compat/mutable-asset.ts +1 -1
- package/src/atlaspack-v3/worker/worker.ts +15 -5
- package/src/public/Asset.ts +1 -1
- package/src/public/BundleGraph.ts +21 -0
- package/src/requests/AssetGraphRequest.ts +1 -1
- package/src/requests/AssetGraphRequestRust.ts +138 -40
- package/src/requests/AtlaspackConfigRequest.ts +10 -20
- package/src/requests/BundleGraphRequest.ts +9 -7
- package/src/resolveOptions.ts +1 -0
- package/src/types.ts +1 -0
- package/src/worker.ts +1 -1
- package/test/requests/AssetGraphRequestRust.test.ts +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/LICENSE +0 -201
|
@@ -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
|
-
//
|
|
25
|
+
let serializedAssetGraph = (await rustAtlaspack.buildAssetGraph());
|
|
26
|
+
// Newly created nodes
|
|
25
27
|
serializedAssetGraph.nodes = serializedAssetGraph.nodes.map((node) => JSON.parse(node));
|
|
26
|
-
|
|
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
|
-
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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 =
|
|
149
|
+
envId = envs.size.toString();
|
|
99
150
|
envs.set(envKey, envId);
|
|
100
151
|
}
|
|
101
152
|
return envId;
|
|
102
153
|
};
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
let
|
|
106
|
-
|
|
107
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
-
let
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
fromNode
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
}
|
|
@@ -116,9 +116,11 @@ function createBundleGraphRequest(input) {
|
|
|
116
116
|
lazyExcludes: options.lazyExcludes,
|
|
117
117
|
requestedAssetIds,
|
|
118
118
|
});
|
|
119
|
-
let { assetGraph, changedAssets, assetRequests } = await
|
|
120
|
-
|
|
121
|
-
(
|
|
119
|
+
let { assetGraph, changedAssets, assetRequests } = await (0, logger_1.instrumentAsync)('asset-graph-request', () => {
|
|
120
|
+
return api.runRequest(request, {
|
|
121
|
+
force: Boolean(input.rustAtlaspack) ||
|
|
122
|
+
(options.shouldBuildLazily && requestedAssetIds.size > 0),
|
|
123
|
+
});
|
|
122
124
|
});
|
|
123
125
|
if (input.options.featureFlags?.loadableSideEffects) {
|
|
124
126
|
applySideEffectsForLoadableImports(assetGraph);
|
package/dist/resolveOptions.js
CHANGED
|
@@ -190,6 +190,7 @@ async function resolveOptions(initialOptions) {
|
|
|
190
190
|
: false,
|
|
191
191
|
shouldDisableCache: initialOptions.shouldDisableCache ?? false,
|
|
192
192
|
shouldProfile: initialOptions.shouldProfile ?? false,
|
|
193
|
+
nativeProfiler: initialOptions.nativeProfiler,
|
|
193
194
|
shouldTrace: initialOptions.shouldTrace ?? false,
|
|
194
195
|
cacheDir,
|
|
195
196
|
watchDir,
|
package/dist/worker.js
CHANGED
|
@@ -21,7 +21,7 @@ const Validation_1 = __importDefault(require("./Validation"));
|
|
|
21
21
|
const AtlaspackConfig_1 = require("./AtlaspackConfig");
|
|
22
22
|
const registerCoreWithSerializer_1 = require("./registerCoreWithSerializer");
|
|
23
23
|
const build_cache_1 = require("@atlaspack/build-cache");
|
|
24
|
-
const source_map_1 = require("@
|
|
24
|
+
const source_map_1 = require("@atlaspack/source-map");
|
|
25
25
|
// @ts-expect-error TS2305
|
|
26
26
|
const rust_1 = require("@atlaspack/rust");
|
|
27
27
|
const workers_1 = __importDefault(require("@atlaspack/workers"));
|
package/lib/Atlaspack.js
CHANGED
|
@@ -80,7 +80,7 @@ var _PathRequest = _interopRequireDefault(require("./requests/PathRequest"));
|
|
|
80
80
|
var _Environment = require("./Environment");
|
|
81
81
|
var _Dependency = require("./Dependency");
|
|
82
82
|
function _sourceMap() {
|
|
83
|
-
const data = require("@
|
|
83
|
+
const data = require("@atlaspack/source-map");
|
|
84
84
|
_sourceMap = function () {
|
|
85
85
|
return data;
|
|
86
86
|
};
|
|
@@ -410,6 +410,10 @@ class Atlaspack {
|
|
|
410
410
|
if (options.shouldProfile) {
|
|
411
411
|
await this.startProfiling();
|
|
412
412
|
}
|
|
413
|
+
if (options.nativeProfiler) {
|
|
414
|
+
const nativeProfiler = new (_profiler().NativeProfiler)();
|
|
415
|
+
await nativeProfiler.startProfiling(options.nativeProfiler);
|
|
416
|
+
}
|
|
413
417
|
if (options.shouldTrace) {
|
|
414
418
|
_profiler().tracer.enable();
|
|
415
419
|
// We need to ensure the tracer is disabled when Atlaspack is disposed as it is a module level object.
|
package/lib/BundleGraph.js
CHANGED
|
@@ -914,6 +914,113 @@ class BundleGraph {
|
|
|
914
914
|
return isReferenced;
|
|
915
915
|
});
|
|
916
916
|
}
|
|
917
|
+
|
|
918
|
+
// New method: Fast checks only (no caching of results)
|
|
919
|
+
isAssetReferencedFastCheck(bundle, asset) {
|
|
920
|
+
// Fast Check #1: If asset is in multiple bundles in same target, it's referenced
|
|
921
|
+
let bundlesWithAsset = this.getBundlesWithAsset(asset).filter(b => b.target.name === bundle.target.name && b.target.distDir === bundle.target.distDir);
|
|
922
|
+
if (bundlesWithAsset.length > 1) {
|
|
923
|
+
return true;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// Fast Check #2: If asset is referenced by any async/conditional dependency, it's referenced
|
|
927
|
+
let assetNodeId = (0, _nullthrows().default)(this._graph.getNodeIdByContentKey(asset.id));
|
|
928
|
+
if (this._graph.getNodeIdsConnectedTo(assetNodeId, bundleGraphEdgeTypes.references).map(id => this._graph.getNode(id)).some(node => (node === null || node === void 0 ? void 0 : node.type) === 'dependency' && (node.value.priority === _types.Priority.lazy || node.value.priority === _types.Priority.conditional) && node.value.specifierType !== _types.SpecifierType.url)) {
|
|
929
|
+
return true;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// Fast checks failed - return null to indicate expensive computation needed
|
|
933
|
+
return null;
|
|
934
|
+
}
|
|
935
|
+
getReferencedAssets(bundle) {
|
|
936
|
+
let referencedAssets = new Set();
|
|
937
|
+
|
|
938
|
+
// Build a map of all assets in this bundle with their dependencies
|
|
939
|
+
// This allows us to check all assets in a single traversal
|
|
940
|
+
let assetDependenciesMap = new Map();
|
|
941
|
+
this.traverseAssets(bundle, asset => {
|
|
942
|
+
// Always do fast checks (no caching)
|
|
943
|
+
let fastCheckResult = this.isAssetReferencedFastCheck(bundle, asset);
|
|
944
|
+
if (fastCheckResult === true) {
|
|
945
|
+
referencedAssets.add(asset);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// Fast checks failed (fastCheckResult === null), need expensive computation
|
|
950
|
+
// Check if it's actually referenced via traversal
|
|
951
|
+
|
|
952
|
+
// Store dependencies for later batch checking
|
|
953
|
+
let dependencies = this._graph.getNodeIdsConnectedTo((0, _nullthrows().default)(this._graph.getNodeIdByContentKey(asset.id))).map(id => (0, _nullthrows().default)(this._graph.getNode(id))).filter(node => node.type === 'dependency').map(node => {
|
|
954
|
+
(0, _assert().default)(node.type === 'dependency');
|
|
955
|
+
return node.value;
|
|
956
|
+
});
|
|
957
|
+
if (dependencies.length > 0) {
|
|
958
|
+
assetDependenciesMap.set(asset, dependencies);
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
// If no assets need the expensive check, return early
|
|
963
|
+
if (assetDependenciesMap.size === 0) {
|
|
964
|
+
return referencedAssets;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// Get the assets we need to check once
|
|
968
|
+
let assetsToCheck = Array.from(assetDependenciesMap.keys());
|
|
969
|
+
|
|
970
|
+
// Helper function to check if all assets from assetDependenciesMap are in referencedAssets
|
|
971
|
+
const allAssetsReferenced = () => assetsToCheck.length <= referencedAssets.size && assetsToCheck.every(asset => referencedAssets.has(asset));
|
|
972
|
+
|
|
973
|
+
// Do ONE traversal to check all remaining assets
|
|
974
|
+
// We can share visitedBundles across all assets because we check every asset
|
|
975
|
+
// against every visited bundle, which matches the original per-asset behavior
|
|
976
|
+
let siblingBundles = new Set(this.getBundleGroupsContainingBundle(bundle).flatMap(bundleGroup => this.getBundlesInBundleGroup(bundleGroup, {
|
|
977
|
+
includeInline: true
|
|
978
|
+
})));
|
|
979
|
+
let visitedBundles = new Set();
|
|
980
|
+
|
|
981
|
+
// Single traversal from all referencers
|
|
982
|
+
for (let referencer of siblingBundles) {
|
|
983
|
+
this.traverseBundles((descendant, _, actions) => {
|
|
984
|
+
if (descendant.id === bundle.id) {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (visitedBundles.has(descendant)) {
|
|
988
|
+
actions.skipChildren();
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
visitedBundles.add(descendant);
|
|
992
|
+
if (descendant.type !== bundle.type || (0, _EnvironmentManager.fromEnvironmentId)(descendant.env).context !== (0, _EnvironmentManager.fromEnvironmentId)(bundle.env).context) {
|
|
993
|
+
// Don't skip children - they might be the right type!
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
// Check ALL assets at once in this descendant bundle
|
|
998
|
+
for (let [asset, dependencies] of assetDependenciesMap) {
|
|
999
|
+
// Skip if already marked as referenced
|
|
1000
|
+
if (referencedAssets.has(asset)) {
|
|
1001
|
+
continue;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// Check if this descendant bundle references the asset
|
|
1005
|
+
if (!this.bundleHasAsset(descendant, asset) && dependencies.some(dependency => this.bundleHasDependency(descendant, dependency))) {
|
|
1006
|
+
referencedAssets.add(asset);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// If all assets from assetDependenciesMap are now marked as referenced, we can stop early
|
|
1011
|
+
if (allAssetsReferenced()) {
|
|
1012
|
+
actions.stop();
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
}, referencer);
|
|
1016
|
+
|
|
1017
|
+
// If all assets from assetDependenciesMap are referenced, no need to check more sibling bundles
|
|
1018
|
+
if (allAssetsReferenced()) {
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return referencedAssets;
|
|
1023
|
+
}
|
|
917
1024
|
hasParentBundleOfType(bundle, type) {
|
|
918
1025
|
let parents = this.getParentBundles(bundle);
|
|
919
1026
|
return parents.length > 0 && parents.every(parent => parent.type === type);
|
package/lib/CommittedAsset.js
CHANGED
|
@@ -26,7 +26,7 @@ function _utils() {
|
|
|
26
26
|
return data;
|
|
27
27
|
}
|
|
28
28
|
function _sourceMap() {
|
|
29
|
-
const data = _interopRequireDefault(require("@
|
|
29
|
+
const data = _interopRequireDefault(require("@atlaspack/source-map"));
|
|
30
30
|
_sourceMap = function () {
|
|
31
31
|
return data;
|
|
32
32
|
};
|
package/lib/Transformation.js
CHANGED
|
@@ -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 = (
|
|
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 = (
|
|
464
|
+
asset.mapBuffer = _sourceMap().default.safeToBuffer(output.map);
|
|
460
465
|
}
|
|
461
466
|
|
|
462
467
|
// Load config for the transformer.
|
package/lib/UncommittedAsset.js
CHANGED
|
@@ -19,7 +19,7 @@ function _stream() {
|
|
|
19
19
|
return data;
|
|
20
20
|
}
|
|
21
21
|
function _sourceMap() {
|
|
22
|
-
const data = _interopRequireDefault(require("@
|
|
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 =
|
|
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:
|
|
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 =
|
|
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 {
|
|
@@ -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
|
-
|
|
49
|
-
|
|
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.
|
|
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;
|
|
@@ -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("@
|
|
8
|
+
const data = _interopRequireDefault(require("@atlaspack/source-map"));
|
|
9
9
|
_sourceMap = function () {
|
|
10
10
|
return data;
|
|
11
11
|
};
|
|
@@ -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
|
-
|
|
73
|
-
let
|
|
74
|
-
|
|
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
|
-
|
|
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}`);
|
|
@@ -175,7 +183,7 @@ class AtlaspackWorker {
|
|
|
175
183
|
type: 'resolved',
|
|
176
184
|
filePath: result.filePath || '',
|
|
177
185
|
canDefer: result.canDefer || false,
|
|
178
|
-
sideEffects: result.sideEffects
|
|
186
|
+
sideEffects: result.sideEffects ?? true,
|
|
179
187
|
code: result.code || undefined,
|
|
180
188
|
meta: result.meta || undefined,
|
|
181
189
|
pipeline: result.pipeline || undefined,
|