@atlaspack/core 2.29.2 → 2.30.1-dev-40d0e250f.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 +20 -0
- package/LICENSE +201 -0
- package/dist/applyRuntimes.js +79 -1
- package/dist/requests/AssetGraphRequest.js +32 -22
- package/dist/requests/BundleGraphRequest.js +2 -2
- package/lib/applyRuntimes.js +87 -3
- package/lib/requests/AssetGraphRequest.js +32 -22
- package/lib/requests/BundleGraphRequest.js +2 -2
- package/lib/types/requests/AssetGraphRequest.d.ts +2 -0
- package/lib/types/types.d.ts +2 -1
- package/package.json +22 -21
- package/src/applyRuntimes.ts +98 -0
- package/src/requests/AssetGraphRequest.ts +46 -32
- package/src/requests/BundleGraphRequest.ts +13 -11
- package/src/types.ts +2 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlaspack/core
|
|
2
2
|
|
|
3
|
+
## 2.30.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#925](https://github.com/atlassian-labs/atlaspack/pull/925) [`00fa643`](https://github.com/atlassian-labs/atlaspack/commit/00fa6433202bfd3311479f6314c9ec878a789f2c) Thanks [@benjervis](https://github.com/benjervis)! - Save propagating symbols for runtimes by requiring symbol and dependency data be returned at the time the assets are injected.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies []:
|
|
12
|
+
- @atlaspack/fs@2.15.38
|
|
13
|
+
- @atlaspack/graph@3.6.5
|
|
14
|
+
- @atlaspack/logger@2.14.35
|
|
15
|
+
- @atlaspack/plugin@2.14.43
|
|
16
|
+
- @atlaspack/profiler@2.15.4
|
|
17
|
+
- @atlaspack/types@2.15.33
|
|
18
|
+
- @atlaspack/utils@3.2.4
|
|
19
|
+
- @atlaspack/workers@2.14.43
|
|
20
|
+
- @atlaspack/cache@3.2.38
|
|
21
|
+
- @atlaspack/package-manager@2.14.43
|
|
22
|
+
|
|
3
23
|
## 2.29.2
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright (c) 2024 Atlassian US., Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/applyRuntimes.js
CHANGED
|
@@ -56,6 +56,7 @@ const projectPath_1 = require("./projectPath");
|
|
|
56
56
|
const profiler_1 = require("@atlaspack/profiler");
|
|
57
57
|
const utils_1 = require("@atlaspack/utils");
|
|
58
58
|
const EnvironmentManager_1 = require("./EnvironmentManager");
|
|
59
|
+
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
59
60
|
function nameRuntimeBundle(bundle, siblingBundle) {
|
|
60
61
|
// We don't run custom namers on runtime bundles as the runtime assumes that they are
|
|
61
62
|
// located at the same nesting level as their owning bundle. Custom naming could
|
|
@@ -121,7 +122,7 @@ async function applyRuntimes({ bundleGraph, config, options, pluginOptions, api,
|
|
|
121
122
|
});
|
|
122
123
|
if (applied) {
|
|
123
124
|
let runtimeAssets = Array.isArray(applied) ? applied : [applied];
|
|
124
|
-
for (let { code, dependency, filePath, isEntry, env, runtimeAssetRequiringExecutionOnLoad, priority, } of runtimeAssets) {
|
|
125
|
+
for (let { code, dependency, filePath, isEntry, env, runtimeAssetRequiringExecutionOnLoad, priority, symbolData, } of runtimeAssets) {
|
|
125
126
|
let sourceName = path_1.default.join(path_1.default.dirname(filePath), `runtime-${(0, rust_1.hashString)(code)}.${bundle.type}`);
|
|
126
127
|
let assetGroup = {
|
|
127
128
|
code,
|
|
@@ -131,6 +132,7 @@ async function applyRuntimes({ bundleGraph, config, options, pluginOptions, api,
|
|
|
131
132
|
// Runtime assets should be considered source, as they should be
|
|
132
133
|
// e.g. compiled to run in the target environment
|
|
133
134
|
isSource: true,
|
|
135
|
+
symbolData,
|
|
134
136
|
};
|
|
135
137
|
let connectionBundle = bundle;
|
|
136
138
|
/**
|
|
@@ -213,6 +215,10 @@ async function applyRuntimes({ bundleGraph, config, options, pluginOptions, api,
|
|
|
213
215
|
// Create a new AssetGraph from the generated runtime assets which also runs
|
|
214
216
|
// transforms and resolves all dependencies.
|
|
215
217
|
let { assetGraph: runtimesAssetGraph, changedAssets } = await reconcileNewRuntimes(api, connections, optionsRef);
|
|
218
|
+
if ((0, feature_flags_1.getFeatureFlag)('skipRuntimeSymbolProp')) {
|
|
219
|
+
// Apply pre-computed symbol data from runtime assets to skip symbol propagation
|
|
220
|
+
applyRuntimeSymbolData(runtimesAssetGraph, connections);
|
|
221
|
+
}
|
|
216
222
|
// Convert the runtime AssetGraph into a BundleGraph, this includes assigning
|
|
217
223
|
// the assets their public ids
|
|
218
224
|
let runtimesBundleGraph = BundleGraph_2.default.fromAssetGraph(runtimesAssetGraph, options.mode === 'production', bundleGraph._publicIdByAssetId, bundleGraph._assetPublicIds);
|
|
@@ -293,12 +299,84 @@ async function applyRuntimes({ bundleGraph, config, options, pluginOptions, api,
|
|
|
293
299
|
}
|
|
294
300
|
return changedAssets;
|
|
295
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Apply pre-computed symbol data from runtime assets to the asset graph
|
|
304
|
+
* to avoid running symbol propagation on runtime code we control.
|
|
305
|
+
*/
|
|
306
|
+
function applyRuntimeSymbolData(assetGraph, connections) {
|
|
307
|
+
for (let { assetGroup } of connections) {
|
|
308
|
+
let assetGroupNode = (0, AssetGraph_1.nodeFromAssetGroup)(assetGroup);
|
|
309
|
+
let assetGroupAssetNodeIds = assetGraph.getNodeIdsConnectedFrom(assetGraph.getNodeIdByContentKey(assetGroupNode.id));
|
|
310
|
+
if (assetGroupAssetNodeIds.length !== 1) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
let runtimeAssetNodeId = assetGroupAssetNodeIds[0];
|
|
314
|
+
let runtimeAssetNode = assetGraph.getNode(runtimeAssetNodeId);
|
|
315
|
+
if (!runtimeAssetNode || runtimeAssetNode.type !== 'asset') {
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
let symbolData = assetGroup.symbolData;
|
|
319
|
+
if (!symbolData) {
|
|
320
|
+
// We completely skip symbol propagation for runtime assets, so symbolData
|
|
321
|
+
// is required
|
|
322
|
+
throw new Error('Runtime asset is missing symbol data');
|
|
323
|
+
}
|
|
324
|
+
if (symbolData.symbols) {
|
|
325
|
+
// Convert from SymbolData format to internal Asset.symbols format
|
|
326
|
+
let internalSymbols = new Map();
|
|
327
|
+
for (let [symbol, data] of symbolData.symbols) {
|
|
328
|
+
internalSymbols.set(symbol, {
|
|
329
|
+
local: data.local,
|
|
330
|
+
loc: data.loc || null,
|
|
331
|
+
meta: data.meta,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
runtimeAssetNode.value.symbols = internalSymbols;
|
|
335
|
+
}
|
|
336
|
+
if (symbolData.dependencies && symbolData.dependencies.length > 0) {
|
|
337
|
+
let outgoingDeps = assetGraph
|
|
338
|
+
.getNodeIdsConnectedFrom(runtimeAssetNodeId)
|
|
339
|
+
.map((id) => assetGraph.getNode(id))
|
|
340
|
+
.filter((node) => node?.type === 'dependency')
|
|
341
|
+
.map((node) => node);
|
|
342
|
+
for (let depSymbolData of symbolData.dependencies) {
|
|
343
|
+
let matchingDep = outgoingDeps.find((depNode) => depNode.value.specifier === depSymbolData.specifier);
|
|
344
|
+
if (matchingDep) {
|
|
345
|
+
if (depSymbolData.symbols) {
|
|
346
|
+
let internalDepSymbols = new Map();
|
|
347
|
+
for (let [symbol, data] of depSymbolData.symbols) {
|
|
348
|
+
internalDepSymbols.set(symbol, {
|
|
349
|
+
local: data.local,
|
|
350
|
+
loc: data.loc || null,
|
|
351
|
+
isWeak: data.isWeak,
|
|
352
|
+
meta: data.meta,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
matchingDep.value.symbols = internalDepSymbols;
|
|
356
|
+
}
|
|
357
|
+
if (depSymbolData.usedSymbols) {
|
|
358
|
+
matchingDep.usedSymbolsDown = new Set(depSymbolData.usedSymbols);
|
|
359
|
+
// For runtime assets, usedSymbolsUp will be the same as usedSymbolsDown
|
|
360
|
+
// since we know exactly what we're using
|
|
361
|
+
let usedSymbolsUp = new Map();
|
|
362
|
+
for (let symbol of depSymbolData.usedSymbols) {
|
|
363
|
+
// Mark as resolved to external (null) since runtime deps are typically external
|
|
364
|
+
usedSymbolsUp.set(symbol, null);
|
|
365
|
+
}
|
|
366
|
+
matchingDep.usedSymbolsUp = usedSymbolsUp;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
296
373
|
function reconcileNewRuntimes(api, connections, optionsRef) {
|
|
297
374
|
let assetGroups = connections.map((t) => t.assetGroup);
|
|
298
375
|
let request = (0, AssetGraphRequest_1.default)({
|
|
299
376
|
name: 'Runtimes',
|
|
300
377
|
assetGroups,
|
|
301
378
|
optionsRef,
|
|
379
|
+
skipSymbolProp: (0, feature_flags_1.getFeatureFlag)('skipRuntimeSymbolProp'),
|
|
302
380
|
});
|
|
303
381
|
// rebuild the graph
|
|
304
382
|
return api.runRequest(request, { force: true });
|
|
@@ -76,6 +76,7 @@ class AssetGraphBuilder {
|
|
|
76
76
|
this.shouldBuildLazily = shouldBuildLazily ?? false;
|
|
77
77
|
this.lazyIncludes = lazyIncludes ?? [];
|
|
78
78
|
this.lazyExcludes = lazyExcludes ?? [];
|
|
79
|
+
this.skipSymbolProp = input.skipSymbolProp ?? false;
|
|
79
80
|
if ((0, feature_flags_1.getFeatureFlag)('cachePerformanceImprovements')) {
|
|
80
81
|
const key = (0, rust_1.hashString)(`${constants_1.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
|
|
81
82
|
this.cacheKey = `AssetGraph/${constants_1.ATLASPACK_VERSION}/${options.mode}/${key}`;
|
|
@@ -172,34 +173,43 @@ class AssetGraphBuilder {
|
|
|
172
173
|
}
|
|
173
174
|
if (this.assetGraph.nodes.length > 1) {
|
|
174
175
|
await (0, dumpGraphToGraphViz_1.default)(this.assetGraph, 'AssetGraph_' + this.name + '_before_prop');
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
assetGroupsWithRemovedParents: this.assetGroupsWithRemovedParents,
|
|
181
|
-
previousErrors: this.previousSymbolPropagationErrors,
|
|
176
|
+
// Skip symbol propagation for runtime assets - they have pre-computed symbol data
|
|
177
|
+
if (this.skipSymbolProp) {
|
|
178
|
+
logger_1.default.verbose({
|
|
179
|
+
origin: '@atlaspack/core',
|
|
180
|
+
message: 'Skipping symbol propagation for runtime asset graph',
|
|
182
181
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
try {
|
|
185
|
+
let errors = (0, SymbolPropagation_1.propagateSymbols)({
|
|
186
|
+
options: this.options,
|
|
186
187
|
assetGraph: this.assetGraph,
|
|
187
|
-
changedAssets: this.changedAssets,
|
|
188
188
|
changedAssetsPropagation: this.changedAssetsPropagation,
|
|
189
189
|
assetGroupsWithRemovedParents: this.assetGroupsWithRemovedParents,
|
|
190
|
-
|
|
191
|
-
assetRequests: [],
|
|
192
|
-
}, this.cacheKey);
|
|
193
|
-
// Just throw the first error. Since errors can bubble (e.g. reexporting a reexported symbol also fails),
|
|
194
|
-
// determining which failing export is the root cause is nontrivial (because of circular dependencies).
|
|
195
|
-
throw new diagnostic_1.default({
|
|
196
|
-
diagnostic: [...errors.values()][0],
|
|
190
|
+
previousErrors: this.previousSymbolPropagationErrors,
|
|
197
191
|
});
|
|
192
|
+
this.changedAssetsPropagation.clear();
|
|
193
|
+
if (errors.size > 0) {
|
|
194
|
+
this.api.storeResult({
|
|
195
|
+
assetGraph: this.assetGraph,
|
|
196
|
+
changedAssets: this.changedAssets,
|
|
197
|
+
changedAssetsPropagation: this.changedAssetsPropagation,
|
|
198
|
+
assetGroupsWithRemovedParents: this.assetGroupsWithRemovedParents,
|
|
199
|
+
previousSymbolPropagationErrors: errors,
|
|
200
|
+
assetRequests: [],
|
|
201
|
+
}, this.cacheKey);
|
|
202
|
+
// Just throw the first error. Since errors can bubble (e.g. reexporting a reexported symbol also fails),
|
|
203
|
+
// determining which failing export is the root cause is nontrivial (because of circular dependencies).
|
|
204
|
+
throw new diagnostic_1.default({
|
|
205
|
+
diagnostic: [...errors.values()][0],
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
await (0, dumpGraphToGraphViz_1.default)(this.assetGraph, 'AssetGraph_' + this.name + '_failed');
|
|
211
|
+
throw e;
|
|
198
212
|
}
|
|
199
|
-
}
|
|
200
|
-
catch (e) {
|
|
201
|
-
await (0, dumpGraphToGraphViz_1.default)(this.assetGraph, 'AssetGraph_' + this.name + '_failed');
|
|
202
|
-
throw e;
|
|
203
213
|
}
|
|
204
214
|
}
|
|
205
215
|
await (0, dumpGraphToGraphViz_1.default)(this.assetGraph, 'AssetGraph_' + this.name);
|
|
@@ -360,7 +360,7 @@ class BundlerRunner {
|
|
|
360
360
|
// can match them to the correct packager/optimizer plugins.
|
|
361
361
|
let bundles = internalBundleGraph.getBundles({ includeInline: true });
|
|
362
362
|
await Promise.all(bundles.map((bundle) => this.nameBundle(namers, bundle, internalBundleGraph)));
|
|
363
|
-
changedRuntimes = await (0, applyRuntimes_1.default)({
|
|
363
|
+
changedRuntimes = await (0, logger_1.instrumentAsync)('applyRuntimes', () => (0, applyRuntimes_1.default)({
|
|
364
364
|
bundleGraph: internalBundleGraph,
|
|
365
365
|
api: this.api,
|
|
366
366
|
config: this.config,
|
|
@@ -370,7 +370,7 @@ class BundlerRunner {
|
|
|
370
370
|
previousDevDeps: this.previousDevDeps,
|
|
371
371
|
devDepRequests: this.devDepRequests,
|
|
372
372
|
configs: this.configs,
|
|
373
|
-
});
|
|
373
|
+
}));
|
|
374
374
|
// Add dev deps for namers, AFTER running them to account for lazy require().
|
|
375
375
|
for (let namer of namers) {
|
|
376
376
|
let devDepRequest = await (0, DevDepRequest_1.createDevDependency)({
|
package/lib/applyRuntimes.js
CHANGED
|
@@ -70,6 +70,13 @@ function _utils() {
|
|
|
70
70
|
return data;
|
|
71
71
|
}
|
|
72
72
|
var _EnvironmentManager = require("./EnvironmentManager");
|
|
73
|
+
function _featureFlags() {
|
|
74
|
+
const data = require("@atlaspack/feature-flags");
|
|
75
|
+
_featureFlags = function () {
|
|
76
|
+
return data;
|
|
77
|
+
};
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
73
80
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
74
81
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
75
82
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -162,7 +169,8 @@ async function applyRuntimes({
|
|
|
162
169
|
isEntry,
|
|
163
170
|
env,
|
|
164
171
|
runtimeAssetRequiringExecutionOnLoad,
|
|
165
|
-
priority
|
|
172
|
+
priority,
|
|
173
|
+
symbolData
|
|
166
174
|
} of runtimeAssets) {
|
|
167
175
|
let sourceName = _path().default.join(_path().default.dirname(filePath), `runtime-${(0, _rust().hashString)(code)}.${bundle.type}`);
|
|
168
176
|
let assetGroup = {
|
|
@@ -172,7 +180,8 @@ async function applyRuntimes({
|
|
|
172
180
|
env: (0, _Environment.mergeEnvironments)(options.projectRoot, (0, _EnvironmentManager.fromEnvironmentId)(bundle.env), env),
|
|
173
181
|
// Runtime assets should be considered source, as they should be
|
|
174
182
|
// e.g. compiled to run in the target environment
|
|
175
|
-
isSource: true
|
|
183
|
+
isSource: true,
|
|
184
|
+
symbolData
|
|
176
185
|
};
|
|
177
186
|
let connectionBundle = bundle;
|
|
178
187
|
|
|
@@ -262,6 +271,10 @@ async function applyRuntimes({
|
|
|
262
271
|
assetGraph: runtimesAssetGraph,
|
|
263
272
|
changedAssets
|
|
264
273
|
} = await reconcileNewRuntimes(api, connections, optionsRef);
|
|
274
|
+
if ((0, _featureFlags().getFeatureFlag)('skipRuntimeSymbolProp')) {
|
|
275
|
+
// Apply pre-computed symbol data from runtime assets to skip symbol propagation
|
|
276
|
+
applyRuntimeSymbolData(runtimesAssetGraph, connections);
|
|
277
|
+
}
|
|
265
278
|
|
|
266
279
|
// Convert the runtime AssetGraph into a BundleGraph, this includes assigning
|
|
267
280
|
// the assets their public ids
|
|
@@ -348,12 +361,83 @@ async function applyRuntimes({
|
|
|
348
361
|
}
|
|
349
362
|
return changedAssets;
|
|
350
363
|
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Apply pre-computed symbol data from runtime assets to the asset graph
|
|
367
|
+
* to avoid running symbol propagation on runtime code we control.
|
|
368
|
+
*/
|
|
369
|
+
function applyRuntimeSymbolData(assetGraph, connections) {
|
|
370
|
+
for (let {
|
|
371
|
+
assetGroup
|
|
372
|
+
} of connections) {
|
|
373
|
+
let assetGroupNode = (0, _AssetGraph.nodeFromAssetGroup)(assetGroup);
|
|
374
|
+
let assetGroupAssetNodeIds = assetGraph.getNodeIdsConnectedFrom(assetGraph.getNodeIdByContentKey(assetGroupNode.id));
|
|
375
|
+
if (assetGroupAssetNodeIds.length !== 1) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
let runtimeAssetNodeId = assetGroupAssetNodeIds[0];
|
|
379
|
+
let runtimeAssetNode = assetGraph.getNode(runtimeAssetNodeId);
|
|
380
|
+
if (!runtimeAssetNode || runtimeAssetNode.type !== 'asset') {
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
let symbolData = assetGroup.symbolData;
|
|
384
|
+
if (!symbolData) {
|
|
385
|
+
// We completely skip symbol propagation for runtime assets, so symbolData
|
|
386
|
+
// is required
|
|
387
|
+
throw new Error('Runtime asset is missing symbol data');
|
|
388
|
+
}
|
|
389
|
+
if (symbolData.symbols) {
|
|
390
|
+
// Convert from SymbolData format to internal Asset.symbols format
|
|
391
|
+
let internalSymbols = new Map();
|
|
392
|
+
for (let [symbol, data] of symbolData.symbols) {
|
|
393
|
+
internalSymbols.set(symbol, {
|
|
394
|
+
local: data.local,
|
|
395
|
+
loc: data.loc || null,
|
|
396
|
+
meta: data.meta
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
runtimeAssetNode.value.symbols = internalSymbols;
|
|
400
|
+
}
|
|
401
|
+
if (symbolData.dependencies && symbolData.dependencies.length > 0) {
|
|
402
|
+
let outgoingDeps = assetGraph.getNodeIdsConnectedFrom(runtimeAssetNodeId).map(id => assetGraph.getNode(id)).filter(node => (node === null || node === void 0 ? void 0 : node.type) === 'dependency').map(node => node);
|
|
403
|
+
for (let depSymbolData of symbolData.dependencies) {
|
|
404
|
+
let matchingDep = outgoingDeps.find(depNode => depNode.value.specifier === depSymbolData.specifier);
|
|
405
|
+
if (matchingDep) {
|
|
406
|
+
if (depSymbolData.symbols) {
|
|
407
|
+
let internalDepSymbols = new Map();
|
|
408
|
+
for (let [symbol, data] of depSymbolData.symbols) {
|
|
409
|
+
internalDepSymbols.set(symbol, {
|
|
410
|
+
local: data.local,
|
|
411
|
+
loc: data.loc || null,
|
|
412
|
+
isWeak: data.isWeak,
|
|
413
|
+
meta: data.meta
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
matchingDep.value.symbols = internalDepSymbols;
|
|
417
|
+
}
|
|
418
|
+
if (depSymbolData.usedSymbols) {
|
|
419
|
+
matchingDep.usedSymbolsDown = new Set(depSymbolData.usedSymbols);
|
|
420
|
+
// For runtime assets, usedSymbolsUp will be the same as usedSymbolsDown
|
|
421
|
+
// since we know exactly what we're using
|
|
422
|
+
let usedSymbolsUp = new Map();
|
|
423
|
+
for (let symbol of depSymbolData.usedSymbols) {
|
|
424
|
+
// Mark as resolved to external (null) since runtime deps are typically external
|
|
425
|
+
usedSymbolsUp.set(symbol, null);
|
|
426
|
+
}
|
|
427
|
+
matchingDep.usedSymbolsUp = usedSymbolsUp;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
351
434
|
function reconcileNewRuntimes(api, connections, optionsRef) {
|
|
352
435
|
let assetGroups = connections.map(t => t.assetGroup);
|
|
353
436
|
let request = (0, _AssetGraphRequest.default)({
|
|
354
437
|
name: 'Runtimes',
|
|
355
438
|
assetGroups,
|
|
356
|
-
optionsRef
|
|
439
|
+
optionsRef,
|
|
440
|
+
skipSymbolProp: (0, _featureFlags().getFeatureFlag)('skipRuntimeSymbolProp')
|
|
357
441
|
});
|
|
358
442
|
|
|
359
443
|
// rebuild the graph
|
|
@@ -124,6 +124,7 @@ class AssetGraphBuilder {
|
|
|
124
124
|
this.shouldBuildLazily = shouldBuildLazily ?? false;
|
|
125
125
|
this.lazyIncludes = lazyIncludes ?? [];
|
|
126
126
|
this.lazyExcludes = lazyExcludes ?? [];
|
|
127
|
+
this.skipSymbolProp = input.skipSymbolProp ?? false;
|
|
127
128
|
if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
|
128
129
|
const key = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}${name}${JSON.stringify(entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`);
|
|
129
130
|
this.cacheKey = `AssetGraph/${_constants.ATLASPACK_VERSION}/${options.mode}/${key}`;
|
|
@@ -216,34 +217,43 @@ class AssetGraphBuilder {
|
|
|
216
217
|
}
|
|
217
218
|
if (this.assetGraph.nodes.length > 1) {
|
|
218
219
|
await (0, _dumpGraphToGraphViz.default)(this.assetGraph, 'AssetGraph_' + this.name + '_before_prop');
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
previousErrors: this.previousSymbolPropagationErrors
|
|
220
|
+
|
|
221
|
+
// Skip symbol propagation for runtime assets - they have pre-computed symbol data
|
|
222
|
+
if (this.skipSymbolProp) {
|
|
223
|
+
_logger().default.verbose({
|
|
224
|
+
origin: '@atlaspack/core',
|
|
225
|
+
message: 'Skipping symbol propagation for runtime asset graph'
|
|
226
226
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
} else {
|
|
228
|
+
try {
|
|
229
|
+
let errors = (0, _SymbolPropagation.propagateSymbols)({
|
|
230
|
+
options: this.options,
|
|
230
231
|
assetGraph: this.assetGraph,
|
|
231
|
-
changedAssets: this.changedAssets,
|
|
232
232
|
changedAssetsPropagation: this.changedAssetsPropagation,
|
|
233
233
|
assetGroupsWithRemovedParents: this.assetGroupsWithRemovedParents,
|
|
234
|
-
|
|
235
|
-
assetRequests: []
|
|
236
|
-
}, this.cacheKey);
|
|
237
|
-
|
|
238
|
-
// Just throw the first error. Since errors can bubble (e.g. reexporting a reexported symbol also fails),
|
|
239
|
-
// determining which failing export is the root cause is nontrivial (because of circular dependencies).
|
|
240
|
-
throw new (_diagnostic().default)({
|
|
241
|
-
diagnostic: [...errors.values()][0]
|
|
234
|
+
previousErrors: this.previousSymbolPropagationErrors
|
|
242
235
|
});
|
|
236
|
+
this.changedAssetsPropagation.clear();
|
|
237
|
+
if (errors.size > 0) {
|
|
238
|
+
this.api.storeResult({
|
|
239
|
+
assetGraph: this.assetGraph,
|
|
240
|
+
changedAssets: this.changedAssets,
|
|
241
|
+
changedAssetsPropagation: this.changedAssetsPropagation,
|
|
242
|
+
assetGroupsWithRemovedParents: this.assetGroupsWithRemovedParents,
|
|
243
|
+
previousSymbolPropagationErrors: errors,
|
|
244
|
+
assetRequests: []
|
|
245
|
+
}, this.cacheKey);
|
|
246
|
+
|
|
247
|
+
// Just throw the first error. Since errors can bubble (e.g. reexporting a reexported symbol also fails),
|
|
248
|
+
// determining which failing export is the root cause is nontrivial (because of circular dependencies).
|
|
249
|
+
throw new (_diagnostic().default)({
|
|
250
|
+
diagnostic: [...errors.values()][0]
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
} catch (e) {
|
|
254
|
+
await (0, _dumpGraphToGraphViz.default)(this.assetGraph, 'AssetGraph_' + this.name + '_failed');
|
|
255
|
+
throw e;
|
|
243
256
|
}
|
|
244
|
-
} catch (e) {
|
|
245
|
-
await (0, _dumpGraphToGraphViz.default)(this.assetGraph, 'AssetGraph_' + this.name + '_failed');
|
|
246
|
-
throw e;
|
|
247
257
|
}
|
|
248
258
|
}
|
|
249
259
|
await (0, _dumpGraphToGraphViz.default)(this.assetGraph, 'AssetGraph_' + this.name);
|
|
@@ -412,7 +412,7 @@ class BundlerRunner {
|
|
|
412
412
|
includeInline: true
|
|
413
413
|
});
|
|
414
414
|
await Promise.all(bundles.map(bundle => this.nameBundle(namers, bundle, internalBundleGraph)));
|
|
415
|
-
changedRuntimes = await (0, _applyRuntimes.default)({
|
|
415
|
+
changedRuntimes = await (0, _logger().instrumentAsync)('applyRuntimes', () => (0, _applyRuntimes.default)({
|
|
416
416
|
bundleGraph: internalBundleGraph,
|
|
417
417
|
api: this.api,
|
|
418
418
|
config: this.config,
|
|
@@ -422,7 +422,7 @@ class BundlerRunner {
|
|
|
422
422
|
previousDevDeps: this.previousDevDeps,
|
|
423
423
|
devDepRequests: this.devDepRequests,
|
|
424
424
|
configs: this.configs
|
|
425
|
-
});
|
|
425
|
+
}));
|
|
426
426
|
|
|
427
427
|
// Add dev deps for namers, AFTER running them to account for lazy require().
|
|
428
428
|
for (let namer of namers) {
|