@atlaspack/core 2.12.1-canary.3354

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/LICENSE +201 -0
  2. package/index.d.ts +22 -0
  3. package/lib/AssetGraph.js +518 -0
  4. package/lib/Atlaspack.js +587 -0
  5. package/lib/AtlaspackConfig.js +298 -0
  6. package/lib/AtlaspackConfig.schema.js +125 -0
  7. package/lib/BundleGraph.js +1445 -0
  8. package/lib/CommittedAsset.js +133 -0
  9. package/lib/Dependency.js +88 -0
  10. package/lib/Environment.js +128 -0
  11. package/lib/InternalConfig.js +48 -0
  12. package/lib/PackagerRunner.js +519 -0
  13. package/lib/ReporterRunner.js +151 -0
  14. package/lib/RequestTracker.js +1089 -0
  15. package/lib/SymbolPropagation.js +625 -0
  16. package/lib/TargetDescriptor.schema.js +115 -0
  17. package/lib/Transformation.js +536 -0
  18. package/lib/UncommittedAsset.js +342 -0
  19. package/lib/Validation.js +215 -0
  20. package/lib/applyRuntimes.js +279 -0
  21. package/lib/assetUtils.js +189 -0
  22. package/lib/atlaspack-v3/AtlaspackV3.js +74 -0
  23. package/lib/atlaspack-v3/fs.js +30 -0
  24. package/lib/atlaspack-v3/index.js +19 -0
  25. package/lib/atlaspack-v3/jsCallable.js +15 -0
  26. package/lib/atlaspack-v3/plugins/Resolver.js +12 -0
  27. package/lib/atlaspack-v3/plugins/index.js +16 -0
  28. package/lib/atlaspack-v3/worker/index.js +3 -0
  29. package/lib/atlaspack-v3/worker/worker.js +30 -0
  30. package/lib/buildCache.js +18 -0
  31. package/lib/constants.js +21 -0
  32. package/lib/dumpGraphToGraphViz.js +206 -0
  33. package/lib/index.js +106 -0
  34. package/lib/loadAtlaspackPlugin.js +148 -0
  35. package/lib/loadDotEnv.js +54 -0
  36. package/lib/projectPath.js +86 -0
  37. package/lib/public/Asset.js +259 -0
  38. package/lib/public/Bundle.js +231 -0
  39. package/lib/public/BundleGraph.js +193 -0
  40. package/lib/public/BundleGroup.js +44 -0
  41. package/lib/public/Config.js +202 -0
  42. package/lib/public/Dependency.js +131 -0
  43. package/lib/public/Environment.js +244 -0
  44. package/lib/public/MutableBundleGraph.js +184 -0
  45. package/lib/public/PluginOptions.js +71 -0
  46. package/lib/public/Symbols.js +247 -0
  47. package/lib/public/Target.js +64 -0
  48. package/lib/registerCoreWithSerializer.js +45 -0
  49. package/lib/requests/AssetGraphRequest.js +427 -0
  50. package/lib/requests/AssetGraphRequestRust.js +187 -0
  51. package/lib/requests/AssetRequest.js +137 -0
  52. package/lib/requests/AtlaspackBuildRequest.js +78 -0
  53. package/lib/requests/AtlaspackConfigRequest.js +473 -0
  54. package/lib/requests/BundleGraphRequest.js +419 -0
  55. package/lib/requests/ConfigRequest.js +198 -0
  56. package/lib/requests/DevDepRequest.js +166 -0
  57. package/lib/requests/EntryRequest.js +295 -0
  58. package/lib/requests/PackageRequest.js +88 -0
  59. package/lib/requests/PathRequest.js +349 -0
  60. package/lib/requests/TargetRequest.js +1177 -0
  61. package/lib/requests/ValidationRequest.js +66 -0
  62. package/lib/requests/WriteBundleRequest.js +252 -0
  63. package/lib/requests/WriteBundlesRequest.js +153 -0
  64. package/lib/resolveOptions.js +234 -0
  65. package/lib/serializer.js +216 -0
  66. package/lib/serializerCore.browser.js +29 -0
  67. package/lib/serializerCore.js +16 -0
  68. package/lib/summarizeRequest.js +55 -0
  69. package/lib/types.js +35 -0
  70. package/lib/utils.js +160 -0
  71. package/lib/worker.js +170 -0
  72. package/package.json +59 -0
  73. package/src/AssetGraph.js +646 -0
  74. package/src/Atlaspack.js +632 -0
  75. package/src/AtlaspackConfig.js +490 -0
  76. package/src/AtlaspackConfig.schema.js +141 -0
  77. package/src/BundleGraph.js +2193 -0
  78. package/src/CommittedAsset.js +143 -0
  79. package/src/Dependency.js +142 -0
  80. package/src/Environment.js +151 -0
  81. package/src/InternalConfig.js +72 -0
  82. package/src/PackagerRunner.js +790 -0
  83. package/src/ReporterRunner.js +158 -0
  84. package/src/RequestTracker.js +1697 -0
  85. package/src/SymbolPropagation.js +794 -0
  86. package/src/TargetDescriptor.schema.js +136 -0
  87. package/src/Transformation.js +752 -0
  88. package/src/UncommittedAsset.js +426 -0
  89. package/src/Validation.js +223 -0
  90. package/src/applyRuntimes.js +341 -0
  91. package/src/assetUtils.js +254 -0
  92. package/src/atlaspack-v3/AtlaspackV3.js +73 -0
  93. package/src/atlaspack-v3/fs.js +36 -0
  94. package/src/atlaspack-v3/index.js +5 -0
  95. package/src/atlaspack-v3/jsCallable.js +13 -0
  96. package/src/atlaspack-v3/plugins/Resolver.js +9 -0
  97. package/src/atlaspack-v3/plugins/index.js +3 -0
  98. package/src/atlaspack-v3/worker/index.js +8 -0
  99. package/src/atlaspack-v3/worker/worker.js +14 -0
  100. package/src/buildCache.js +15 -0
  101. package/src/constants.js +22 -0
  102. package/src/dumpGraphToGraphViz.js +244 -0
  103. package/src/index.js +22 -0
  104. package/src/loadAtlaspackPlugin.js +239 -0
  105. package/src/loadDotEnv.js +56 -0
  106. package/src/projectPath.js +87 -0
  107. package/src/public/Asset.js +359 -0
  108. package/src/public/Bundle.js +337 -0
  109. package/src/public/BundleGraph.js +335 -0
  110. package/src/public/BundleGroup.js +55 -0
  111. package/src/public/Config.js +261 -0
  112. package/src/public/Dependency.js +176 -0
  113. package/src/public/Environment.js +316 -0
  114. package/src/public/MutableBundleGraph.js +320 -0
  115. package/src/public/PluginOptions.js +99 -0
  116. package/src/public/Symbols.js +315 -0
  117. package/src/public/Target.js +71 -0
  118. package/src/registerCoreWithSerializer.js +34 -0
  119. package/src/requests/AssetGraphRequest.js +577 -0
  120. package/src/requests/AssetGraphRequestRust.js +222 -0
  121. package/src/requests/AssetRequest.js +179 -0
  122. package/src/requests/AtlaspackBuildRequest.js +109 -0
  123. package/src/requests/AtlaspackConfigRequest.js +709 -0
  124. package/src/requests/BundleGraphRequest.js +547 -0
  125. package/src/requests/ConfigRequest.js +287 -0
  126. package/src/requests/DevDepRequest.js +246 -0
  127. package/src/requests/EntryRequest.js +385 -0
  128. package/src/requests/PackageRequest.js +105 -0
  129. package/src/requests/PathRequest.js +454 -0
  130. package/src/requests/TargetRequest.js +1632 -0
  131. package/src/requests/ValidationRequest.js +79 -0
  132. package/src/requests/WriteBundleRequest.js +362 -0
  133. package/src/requests/WriteBundlesRequest.js +209 -0
  134. package/src/resolveOptions.js +278 -0
  135. package/src/serializer.js +255 -0
  136. package/src/serializerCore.browser.js +8 -0
  137. package/src/serializerCore.js +5 -0
  138. package/src/summarizeRequest.js +47 -0
  139. package/src/types.js +581 -0
  140. package/src/utils.js +211 -0
  141. package/src/worker.js +189 -0
  142. package/test/AssetGraph.test.js +679 -0
  143. package/test/Atlaspack.test.js +142 -0
  144. package/test/AtlaspackConfig.test.js +405 -0
  145. package/test/AtlaspackConfigRequest.test.js +993 -0
  146. package/test/BundleGraph.test.js +121 -0
  147. package/test/EntryRequest.test.js +215 -0
  148. package/test/Environment.test.js +99 -0
  149. package/test/InternalAsset.test.js +76 -0
  150. package/test/PackagerRunner.test.js +27 -0
  151. package/test/PublicAsset.test.js +40 -0
  152. package/test/PublicBundle.test.js +68 -0
  153. package/test/PublicDependency.test.js +22 -0
  154. package/test/PublicEnvironment.test.js +27 -0
  155. package/test/PublicMutableBundleGraph.test.js +192 -0
  156. package/test/RequestTracker.test.js +448 -0
  157. package/test/SymbolPropagation.test.js +716 -0
  158. package/test/TargetRequest.test.js +1715 -0
  159. package/test/fixtures/application-targets/package.json +3 -0
  160. package/test/fixtures/atlaspack/index.js +1 -0
  161. package/test/fixtures/atlaspack/other.js +3 -0
  162. package/test/fixtures/atlaspack/package.json +1 -0
  163. package/test/fixtures/atlaspack/yarn.lock +0 -0
  164. package/test/fixtures/bundle.js +10 -0
  165. package/test/fixtures/common-targets/package.json +24 -0
  166. package/test/fixtures/common-targets-ignore/package.json +13 -0
  167. package/test/fixtures/config/.atlaspackrc +6 -0
  168. package/test/fixtures/config/subfolder/.atlaspackrc +6 -0
  169. package/test/fixtures/config-extends-not-found/.atlaspackrc +3 -0
  170. package/test/fixtures/config-extends-not-found/.atlaspackrc-json5 +3 -0
  171. package/test/fixtures/config-extends-not-found/.atlaspackrc-multiple +3 -0
  172. package/test/fixtures/config-extends-not-found/.atlaspackrc-node-modules +3 -0
  173. package/test/fixtures/config-malformed/.atlaspackrc +3 -0
  174. package/test/fixtures/config-node-pipeline/.atlaspackrc +6 -0
  175. package/test/fixtures/config-plugin-not-found/.atlaspackrc +6 -0
  176. package/test/fixtures/context/package.json +8 -0
  177. package/test/fixtures/custom-format-infer-ext/package.json +6 -0
  178. package/test/fixtures/custom-format-infer-type/package.json +7 -0
  179. package/test/fixtures/custom-format-mismatch/package.json +8 -0
  180. package/test/fixtures/custom-targets/package.json +20 -0
  181. package/test/fixtures/custom-targets-distdir/package.json +11 -0
  182. package/test/fixtures/duplicate-targets/package.json +4 -0
  183. package/test/fixtures/glob-like/[entry].js +0 -0
  184. package/test/fixtures/invalid-distpath/package.json +11 -0
  185. package/test/fixtures/invalid-engines/package.json +12 -0
  186. package/test/fixtures/invalid-source-missing/package.json +5 -0
  187. package/test/fixtures/invalid-source-not-file/package.json +5 -0
  188. package/test/fixtures/invalid-source-not-file/src/index.js +1 -0
  189. package/test/fixtures/invalid-target-source-missing/package.json +9 -0
  190. package/test/fixtures/invalid-target-source-not-file/package.json +9 -0
  191. package/test/fixtures/invalid-target-source-not-file/src/index.js +1 -0
  192. package/test/fixtures/invalid-targets/package.json +19 -0
  193. package/test/fixtures/library-custom-scopehoist/package.json +9 -0
  194. package/test/fixtures/library-scopehoist/package.json +8 -0
  195. package/test/fixtures/local-plugin-config-pkg/.atlaspackrc +3 -0
  196. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/index.json +8 -0
  197. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/local-plugin.js +7 -0
  198. package/test/fixtures/local-plugin-config-pkg/node_modules/atlaspack-config-local/package.json +7 -0
  199. package/test/fixtures/main-format-mismatch/package.json +8 -0
  200. package/test/fixtures/main-global/package.json +8 -0
  201. package/test/fixtures/main-mjs/package.json +8 -0
  202. package/test/fixtures/module-a.js +1 -0
  203. package/test/fixtures/module-b.js +1 -0
  204. package/test/fixtures/plugins/local-plugin.js +7 -0
  205. package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/index.js +7 -0
  206. package/test/fixtures/plugins/node_modules/atlaspack-transformer-bad-engines/package.json +7 -0
  207. package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/index.js +7 -0
  208. package/test/fixtures/plugins/node_modules/atlaspack-transformer-no-engines/package.json +4 -0
  209. package/test/fixtures/targets-default-distdir-none/package.json +5 -0
  210. package/test/fixtures/targets-default-distdir-one/package.json +8 -0
  211. package/test/fixtures/targets-default-distdir-two/package.json +18 -0
  212. package/test/requests/ConfigRequest.test.js +254 -0
  213. package/test/serializer.test.js +302 -0
  214. package/test/test-utils.js +80 -0
  215. package/test/utils.test.js +43 -0
@@ -0,0 +1,222 @@
1
+ // @flow strict-local
2
+
3
+ import invariant from 'assert';
4
+
5
+ import ThrowableDiagnostic from '@atlaspack/diagnostic';
6
+ import type {Async} from '@atlaspack/types';
7
+
8
+ import AssetGraph, {nodeFromAssetGroup} from '../AssetGraph';
9
+ import type {AtlaspackV3} from '../atlaspack-v3';
10
+ import {toProjectPath} from '../projectPath';
11
+ import {requestTypes, type StaticRunOpts} from '../RequestTracker';
12
+ import {propagateSymbols} from '../SymbolPropagation';
13
+
14
+ import type {
15
+ AssetGraphRequestInput,
16
+ AssetGraphRequestResult,
17
+ } from './AssetGraphRequest';
18
+
19
+ type RunInput = {|
20
+ input: AssetGraphRequestInput,
21
+ ...StaticRunOpts<AssetGraphRequestResult>,
22
+ |};
23
+
24
+ type AssetGraphRequest = {|
25
+ id: string,
26
+ +type: typeof requestTypes.asset_graph_request,
27
+ run: RunInput => Async<AssetGraphRequestResult>,
28
+ input: AssetGraphRequestInput,
29
+ |};
30
+
31
+ export function createAssetGraphRequestRust(
32
+ rustAtlaspack: AtlaspackV3,
33
+ ): (input: AssetGraphRequestInput) => AssetGraphRequest {
34
+ return input => ({
35
+ type: requestTypes.asset_graph_request,
36
+ id: input.name,
37
+ run: async input => {
38
+ let options = input.options;
39
+ let serializedAssetGraph;
40
+ try {
41
+ serializedAssetGraph = await rustAtlaspack.buildAssetGraph();
42
+ } catch (err) {
43
+ throw new ThrowableDiagnostic({
44
+ diagnostic: err,
45
+ });
46
+ }
47
+
48
+ let {assetGraph, cachedAssets, changedAssets} = getAssetGraph(
49
+ serializedAssetGraph,
50
+ options,
51
+ );
52
+
53
+ // TODO: Make it a bulk transaction
54
+ await Promise.all(
55
+ Array.from(cachedAssets.entries(), ([id, code]) =>
56
+ options.cache.setBlob(id, Buffer.from(code)),
57
+ ),
58
+ );
59
+
60
+ let changedAssetsPropagation = new Set(changedAssets.keys());
61
+ let errors = propagateSymbols({
62
+ options,
63
+ assetGraph,
64
+ changedAssetsPropagation,
65
+ assetGroupsWithRemovedParents: new Set(),
66
+ previousErrors: new Map(), //this.previousSymbolPropagationErrors,
67
+ });
68
+
69
+ if (errors.size > 0) {
70
+ // Just throw the first error. Since errors can bubble (e.g. reexporting a reexported symbol also fails),
71
+ // determining which failing export is the root cause is nontrivial (because of circular dependencies).
72
+ throw new ThrowableDiagnostic({
73
+ diagnostic: [...errors.values()][0],
74
+ });
75
+ }
76
+
77
+ return {
78
+ assetGraph,
79
+ assetRequests: [],
80
+ assetGroupsWithRemovedParents: new Set(),
81
+ changedAssets,
82
+ changedAssetsPropagation,
83
+ previousSymbolPropagationErrors: undefined,
84
+ };
85
+ },
86
+ input,
87
+ });
88
+ }
89
+
90
+ function getAssetGraph(serializedGraph, options) {
91
+ let graph = new AssetGraph({
92
+ _contentKeyToNodeId: new Map(),
93
+ _nodeIdToContentKey: new Map(),
94
+ });
95
+
96
+ graph.safeToIncrementallyBundle = false;
97
+
98
+ let cachedAssets = new Map();
99
+ let changedAssets = new Map();
100
+ let entry = 0;
101
+ for (let node of serializedGraph.nodes) {
102
+ if (node.type === 'root') {
103
+ let index = graph.addNodeByContentKey('@@root', {
104
+ id: '@@root',
105
+ type: 'root',
106
+ value: null,
107
+ });
108
+
109
+ graph.setRootNodeId(index);
110
+ } else if (node.type === 'entry') {
111
+ let id = 'entry:' + ++entry;
112
+
113
+ graph.addNodeByContentKey(id, {
114
+ id: id,
115
+ type: 'root',
116
+ value: null,
117
+ });
118
+ } else if (node.type === 'asset') {
119
+ let id = node.value.id;
120
+ let asset = node.value.asset;
121
+
122
+ asset = {
123
+ ...asset,
124
+ id,
125
+ committed: true,
126
+ contentKey: id,
127
+ filePath: toProjectPath(options.projectRoot, asset.filePath),
128
+ symbols: asset.hasSymbols
129
+ ? new Map(
130
+ asset.symbols.map(({exported, ...symbol}) => [exported, symbol]),
131
+ )
132
+ : null,
133
+ };
134
+
135
+ cachedAssets.set(id, asset.code);
136
+ changedAssets.set(id, asset);
137
+
138
+ graph.addNodeByContentKey(id, {
139
+ id,
140
+ type: 'asset',
141
+ usedSymbols: new Set(),
142
+ usedSymbolsDownDirty: true,
143
+ usedSymbolsUpDirty: true,
144
+ value: asset,
145
+ });
146
+ } else if (node.type === 'dependency') {
147
+ let id = node.value.id;
148
+ let dependency = node.value.dependency;
149
+
150
+ dependency = {
151
+ ...dependency,
152
+ id,
153
+ contentKey: id,
154
+ sourcePath: dependency.sourcePath
155
+ ? toProjectPath(options.projectRoot, dependency.sourcePath)
156
+ : null,
157
+ symbols: dependency.hasSymbols
158
+ ? new Map(
159
+ dependency.symbols.map(({exported, ...symbol}) => [
160
+ exported,
161
+ symbol,
162
+ ]),
163
+ )
164
+ : null,
165
+ };
166
+ let usedSymbolsDown = new Set();
167
+ let usedSymbolsUp = new Map();
168
+ if (dependency.isEntry && dependency.isLibrary) {
169
+ usedSymbolsDown.add('*');
170
+ usedSymbolsUp.set('*', undefined);
171
+ }
172
+
173
+ graph.addNodeByContentKey(id, {
174
+ id,
175
+ type: 'dependency',
176
+ deferred: false,
177
+ excluded: false,
178
+ hasDeferred: node.has_deferred,
179
+ usedSymbolsDown,
180
+ usedSymbolsDownDirty: true,
181
+ usedSymbolsUp,
182
+ usedSymbolsUpDirtyDown: true,
183
+ usedSymbolsUpDirtyUp: true,
184
+ value: dependency,
185
+ });
186
+ }
187
+ }
188
+
189
+ for (let i = 0; i < serializedGraph.edges.length; i += 2) {
190
+ let from = serializedGraph.edges[i];
191
+ let to = serializedGraph.edges[i + 1];
192
+ let fromNode = graph.getNode(from);
193
+ if (fromNode?.type === 'dependency') {
194
+ let toNode = graph.getNode(to);
195
+ invariant(toNode?.type === 'asset');
196
+
197
+ // For backwards compatibility, create asset group node if needed.
198
+ let assetGroupNode = nodeFromAssetGroup({
199
+ filePath: toNode.value.filePath,
200
+ env: fromNode.value.env,
201
+ pipeline: toNode.value.pipeline,
202
+ sideEffects: Boolean(toNode.value.sideEffects),
203
+ });
204
+
205
+ let index = graph.addNodeByContentKeyIfNeeded(
206
+ assetGroupNode.id,
207
+ assetGroupNode,
208
+ );
209
+
210
+ graph.addEdge(from, index);
211
+ graph.addEdge(index, to);
212
+ } else {
213
+ graph.addEdge(from, to);
214
+ }
215
+ }
216
+
217
+ return {
218
+ assetGraph: graph,
219
+ cachedAssets,
220
+ changedAssets,
221
+ };
222
+ }
@@ -0,0 +1,179 @@
1
+ // @flow strict-local
2
+
3
+ import type {ContentKey} from '@atlaspack/graph';
4
+ import type {Async} from '@atlaspack/types';
5
+ import type {StaticRunOpts} from '../RequestTracker';
6
+ import type {
7
+ AssetRequestInput,
8
+ AssetRequestResult,
9
+ TransformationRequest,
10
+ } from '../types';
11
+ import type {ConfigAndCachePath} from './AtlaspackConfigRequest';
12
+ import type {TransformationResult} from '../Transformation';
13
+
14
+ import nullthrows from 'nullthrows';
15
+ import ThrowableDiagnostic from '@atlaspack/diagnostic';
16
+ import {hashString} from '@atlaspack/rust';
17
+ import createAtlaspackConfigRequest from './AtlaspackConfigRequest';
18
+ import {runDevDepRequest} from './DevDepRequest';
19
+ import {runConfigRequest} from './ConfigRequest';
20
+ import {fromProjectPath, fromProjectPathRelative} from '../projectPath';
21
+ import {report} from '../ReporterRunner';
22
+ import {requestTypes} from '../RequestTracker';
23
+ import type {DevDepRequestResult} from './DevDepRequest';
24
+
25
+ type RunInput<TResult> = {|
26
+ input: AssetRequestInput,
27
+ ...StaticRunOpts<TResult>,
28
+ |};
29
+
30
+ export type AssetRequest = {|
31
+ id: ContentKey,
32
+ +type: typeof requestTypes.asset_request,
33
+ run: (RunInput<AssetRequestResult>) => Async<AssetRequestResult>,
34
+ input: AssetRequestInput,
35
+ |};
36
+
37
+ export default function createAssetRequest(
38
+ input: AssetRequestInput,
39
+ ): AssetRequest {
40
+ return {
41
+ type: requestTypes.asset_request,
42
+ id: getId(input),
43
+ run,
44
+ input,
45
+ };
46
+ }
47
+
48
+ const type = 'asset_request';
49
+
50
+ function getId(input: AssetRequestInput) {
51
+ // eslint-disable-next-line no-unused-vars
52
+ let {optionsRef, ...hashInput} = input;
53
+ return hashString(
54
+ type +
55
+ fromProjectPathRelative(input.filePath) +
56
+ input.env.id +
57
+ String(input.isSource) +
58
+ String(input.sideEffects) +
59
+ (input.code ?? '') +
60
+ ':' +
61
+ (input.pipeline ?? '') +
62
+ ':' +
63
+ (input.query ?? ''),
64
+ );
65
+ }
66
+
67
+ async function run({input, api, farm, invalidateReason, options}) {
68
+ report({
69
+ type: 'buildProgress',
70
+ phase: 'transforming',
71
+ filePath: fromProjectPath(options.projectRoot, input.filePath),
72
+ });
73
+
74
+ api.invalidateOnFileUpdate(input.filePath);
75
+ let start = Date.now();
76
+ let {optionsRef, ...rest} = input;
77
+ let {cachePath} = nullthrows(
78
+ await api.runRequest<null, ConfigAndCachePath>(
79
+ createAtlaspackConfigRequest(),
80
+ ),
81
+ );
82
+
83
+ let previousDevDepRequests: Map<string, DevDepRequestResult> = new Map(
84
+ await Promise.all(
85
+ api
86
+ .getSubRequests()
87
+ .filter(req => req.requestType === requestTypes.dev_dep_request)
88
+ .map(async req => [
89
+ req.id,
90
+ nullthrows(await api.getRequestResult<DevDepRequestResult>(req.id)),
91
+ ]),
92
+ ),
93
+ );
94
+
95
+ let request: TransformationRequest = {
96
+ ...rest,
97
+ invalidateReason,
98
+ devDeps: new Map(
99
+ [...previousDevDepRequests.entries()]
100
+ .filter(([id]) => api.canSkipSubrequest(id))
101
+ .map(([, req]: [string, DevDepRequestResult]) => [
102
+ `${req.specifier}:${fromProjectPathRelative(req.resolveFrom)}`,
103
+ req.hash,
104
+ ]),
105
+ ),
106
+ invalidDevDeps: await Promise.all(
107
+ [...previousDevDepRequests.entries()]
108
+ .filter(([id]) => !api.canSkipSubrequest(id))
109
+ .flatMap(([, req]: [string, DevDepRequestResult]) => {
110
+ return [
111
+ {
112
+ specifier: req.specifier,
113
+ resolveFrom: req.resolveFrom,
114
+ },
115
+ ...(req.additionalInvalidations ?? []).map(i => ({
116
+ specifier: i.specifier,
117
+ resolveFrom: i.resolveFrom,
118
+ })),
119
+ ];
120
+ }),
121
+ ),
122
+ };
123
+
124
+ let {assets, configRequests, error, invalidations, devDepRequests} =
125
+ (await farm.createHandle(
126
+ 'runTransform',
127
+ input.isSingleChangeRebuild,
128
+ )({
129
+ configCachePath: cachePath,
130
+ optionsRef,
131
+ request,
132
+ }): TransformationResult);
133
+
134
+ let time = Date.now() - start;
135
+ if (assets) {
136
+ for (let asset of assets) {
137
+ asset.stats.time = time;
138
+ }
139
+ }
140
+
141
+ for (let filePath of invalidations.invalidateOnFileChange) {
142
+ api.invalidateOnFileUpdate(filePath);
143
+ api.invalidateOnFileDelete(filePath);
144
+ }
145
+
146
+ for (let invalidation of invalidations.invalidateOnFileCreate) {
147
+ api.invalidateOnFileCreate(invalidation);
148
+ }
149
+
150
+ for (let env of invalidations.invalidateOnEnvChange) {
151
+ api.invalidateOnEnvChange(env);
152
+ }
153
+
154
+ for (let option of invalidations.invalidateOnOptionChange) {
155
+ api.invalidateOnOptionChange(option);
156
+ }
157
+
158
+ if (invalidations.invalidateOnStartup) {
159
+ api.invalidateOnStartup();
160
+ }
161
+
162
+ if (invalidations.invalidateOnBuild) {
163
+ api.invalidateOnBuild();
164
+ }
165
+
166
+ for (let devDepRequest of devDepRequests) {
167
+ await runDevDepRequest(api, devDepRequest);
168
+ }
169
+
170
+ for (let configRequest of configRequests) {
171
+ await runConfigRequest(api, configRequest);
172
+ }
173
+
174
+ if (error != null) {
175
+ throw new ThrowableDiagnostic({diagnostic: error});
176
+ } else {
177
+ return nullthrows(assets);
178
+ }
179
+ }
@@ -0,0 +1,109 @@
1
+ // @flow strict-local
2
+
3
+ import type {ContentKey} from '@atlaspack/graph';
4
+ import type {Async} from '@atlaspack/types';
5
+ import type {SharedReference} from '@atlaspack/workers';
6
+
7
+ import type {StaticRunOpts} from '../RequestTracker';
8
+ import type {Asset, AssetGroup, PackagedBundleInfo} from '../types';
9
+ import type BundleGraph from '../BundleGraph';
10
+
11
+ import createBundleGraphRequest, {
12
+ type BundleGraphResult,
13
+ } from './BundleGraphRequest';
14
+ import createWriteBundlesRequest from './WriteBundlesRequest';
15
+ import {assertSignalNotAborted} from '../utils';
16
+ import dumpGraphToGraphViz from '../dumpGraphToGraphViz';
17
+ import {bundleGraphEdgeTypes} from '../BundleGraph';
18
+ import {report} from '../ReporterRunner';
19
+ import IBundleGraph from '../public/BundleGraph';
20
+ import {NamedBundle} from '../public/Bundle';
21
+ import {assetFromValue} from '../public/Asset';
22
+
23
+ import {tracer} from '@atlaspack/profiler';
24
+ import {requestTypes} from '../RequestTracker';
25
+
26
+ type AtlaspackBuildRequestInput = {|
27
+ optionsRef: SharedReference,
28
+ requestedAssetIds: Set<string>,
29
+ signal?: AbortSignal,
30
+ |};
31
+
32
+ export type AtlaspackBuildRequestResult = {|
33
+ bundleGraph: BundleGraph,
34
+ bundleInfo: Map<string, PackagedBundleInfo>,
35
+ changedAssets: Map<string, Asset>,
36
+ assetRequests: Array<AssetGroup>,
37
+ |};
38
+
39
+ type RunInput<TResult> = {|
40
+ input: AtlaspackBuildRequestInput,
41
+ ...StaticRunOpts<TResult>,
42
+ |};
43
+
44
+ export type AtlaspackBuildRequest = {|
45
+ id: ContentKey,
46
+ +type: typeof requestTypes.atlaspack_build_request,
47
+ run: (
48
+ RunInput<AtlaspackBuildRequestResult>,
49
+ ) => Async<AtlaspackBuildRequestResult>,
50
+ input: AtlaspackBuildRequestInput,
51
+ |};
52
+
53
+ export default function createAtlaspackBuildRequest(
54
+ input: AtlaspackBuildRequestInput,
55
+ ): AtlaspackBuildRequest {
56
+ return {
57
+ type: requestTypes.atlaspack_build_request,
58
+ id: 'atlaspack_build_request',
59
+ run,
60
+ input,
61
+ };
62
+ }
63
+
64
+ async function run({input, api, options}) {
65
+ let {optionsRef, requestedAssetIds, signal} = input;
66
+
67
+ let bundleGraphRequest = createBundleGraphRequest({
68
+ optionsRef,
69
+ requestedAssetIds,
70
+ signal,
71
+ });
72
+
73
+ let {bundleGraph, changedAssets, assetRequests}: BundleGraphResult =
74
+ await api.runRequest(bundleGraphRequest, {
75
+ force: options.shouldBuildLazily && requestedAssetIds.size > 0,
76
+ });
77
+
78
+ // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381 (Windows only)
79
+ dumpGraphToGraphViz(bundleGraph._graph, 'BundleGraph', bundleGraphEdgeTypes);
80
+
81
+ await report({
82
+ type: 'buildProgress',
83
+ phase: 'bundled',
84
+ bundleGraph: new IBundleGraph(
85
+ bundleGraph,
86
+ (bundle, bundleGraph, options) =>
87
+ NamedBundle.get(bundle, bundleGraph, options),
88
+ options,
89
+ ),
90
+ changedAssets: new Map(
91
+ Array.from(changedAssets).map(([id, asset]) => [
92
+ id,
93
+ assetFromValue(asset, options),
94
+ ]),
95
+ ),
96
+ });
97
+
98
+ let packagingMeasurement = tracer.createMeasurement('packaging');
99
+ let writeBundlesRequest = createWriteBundlesRequest({
100
+ bundleGraph,
101
+ optionsRef,
102
+ });
103
+
104
+ let bundleInfo = await api.runRequest(writeBundlesRequest);
105
+ packagingMeasurement && packagingMeasurement.end();
106
+ assertSignalNotAborted(signal);
107
+
108
+ return {bundleGraph, bundleInfo, changedAssets, assetRequests};
109
+ }