@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,419 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = createBundleGraphRequest;
7
+ function _assert() {
8
+ const data = _interopRequireDefault(require("assert"));
9
+ _assert = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _nullthrows() {
15
+ const data = _interopRequireDefault(require("nullthrows"));
16
+ _nullthrows = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _logger() {
22
+ const data = require("@atlaspack/logger");
23
+ _logger = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _diagnostic() {
29
+ const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
30
+ _diagnostic = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ var _AssetGraph = _interopRequireDefault(require("../AssetGraph"));
36
+ var _BundleGraph = _interopRequireDefault(require("../public/BundleGraph"));
37
+ var _BundleGraph2 = _interopRequireWildcard(require("../BundleGraph"));
38
+ var _MutableBundleGraph = _interopRequireDefault(require("../public/MutableBundleGraph"));
39
+ var _Bundle = require("../public/Bundle");
40
+ var _ReporterRunner = require("../ReporterRunner");
41
+ var _dumpGraphToGraphViz = _interopRequireDefault(require("../dumpGraphToGraphViz"));
42
+ function _utils() {
43
+ const data = require("@atlaspack/utils");
44
+ _utils = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _rust() {
50
+ const data = require("@atlaspack/rust");
51
+ _rust = function () {
52
+ return data;
53
+ };
54
+ return data;
55
+ }
56
+ var _PluginOptions = _interopRequireDefault(require("../public/PluginOptions"));
57
+ var _applyRuntimes = _interopRequireDefault(require("../applyRuntimes"));
58
+ var _constants = require("../constants");
59
+ var _utils2 = require("../utils");
60
+ var _AtlaspackConfigRequest = _interopRequireWildcard(require("./AtlaspackConfigRequest"));
61
+ var _DevDepRequest = require("./DevDepRequest");
62
+ var _InternalConfig = require("../InternalConfig");
63
+ var _ConfigRequest = require("./ConfigRequest");
64
+ var _projectPath = require("../projectPath");
65
+ var _AssetGraphRequest = _interopRequireDefault(require("./AssetGraphRequest"));
66
+ var _AssetGraphRequestRust = require("./AssetGraphRequestRust");
67
+ function _profiler() {
68
+ const data = require("@atlaspack/profiler");
69
+ _profiler = function () {
70
+ return data;
71
+ };
72
+ return data;
73
+ }
74
+ var _RequestTracker = require("../RequestTracker");
75
+ 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); }
76
+ 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; }
77
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
78
+ // TODO: Rename to BundleGraphRequestResult
79
+ function createBundleGraphRequest(input) {
80
+ return {
81
+ type: _RequestTracker.requestTypes.bundle_graph_request,
82
+ id: 'BundleGraph',
83
+ run: async input => {
84
+ let {
85
+ options,
86
+ api,
87
+ invalidateReason
88
+ } = input;
89
+ let {
90
+ optionsRef,
91
+ requestedAssetIds,
92
+ signal
93
+ } = input.input;
94
+ let measurement = _profiler().tracer.createMeasurement('building');
95
+ let createAssetGraphRequest = input.rustAtlaspack ? (0, _AssetGraphRequestRust.createAssetGraphRequestRust)(input.rustAtlaspack) : _AssetGraphRequest.default;
96
+ let request = createAssetGraphRequest({
97
+ name: 'Main',
98
+ entries: options.entries,
99
+ optionsRef,
100
+ shouldBuildLazily: options.shouldBuildLazily,
101
+ lazyIncludes: options.lazyIncludes,
102
+ lazyExcludes: options.lazyExcludes,
103
+ requestedAssetIds
104
+ });
105
+ let {
106
+ assetGraph,
107
+ changedAssets,
108
+ assetRequests
109
+ } = await api.runRequest(request, {
110
+ force: options.shouldBuildLazily && requestedAssetIds.size > 0
111
+ });
112
+ measurement && measurement.end();
113
+ (0, _utils2.assertSignalNotAborted)(signal);
114
+
115
+ // If any subrequests are invalid (e.g. dev dep requests or config requests),
116
+ // bail on incremental bundling. We also need to invalidate for option changes,
117
+ // which are hoisted to direct invalidations on the bundle graph request.
118
+ let subRequestsInvalid = Boolean(invalidateReason & _constants.OPTION_CHANGE) || input.api.getSubRequests().some(req => !input.api.canSkipSubrequest(req.id));
119
+ if (subRequestsInvalid) {
120
+ assetGraph.safeToIncrementallyBundle = false;
121
+ }
122
+ let configResult = (0, _nullthrows().default)(await input.api.runRequest((0, _AtlaspackConfigRequest.default)()));
123
+ (0, _utils2.assertSignalNotAborted)(signal);
124
+ let atlaspackConfig = (0, _AtlaspackConfigRequest.getCachedAtlaspackConfig)(configResult, input.options);
125
+ let {
126
+ devDeps,
127
+ invalidDevDeps
128
+ } = await (0, _DevDepRequest.getDevDepRequests)(input.api);
129
+ (0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, input.options, atlaspackConfig);
130
+ let bundlingMeasurement = _profiler().tracer.createMeasurement('bundling');
131
+ let builder = new BundlerRunner(input, atlaspackConfig, devDeps);
132
+ let res = await builder.bundle({
133
+ graph: assetGraph,
134
+ changedAssets: changedAssets,
135
+ assetRequests
136
+ });
137
+ bundlingMeasurement && bundlingMeasurement.end();
138
+ for (let [id, asset] of changedAssets) {
139
+ res.changedAssets.set(id, asset);
140
+ }
141
+ await (0, _dumpGraphToGraphViz.default)(
142
+ // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381 (Windows only)
143
+ res.bundleGraph._graph, 'BundleGraph', _BundleGraph2.bundleGraphEdgeTypes);
144
+ return res;
145
+ },
146
+ input
147
+ };
148
+ }
149
+ class BundlerRunner {
150
+ constructor({
151
+ input,
152
+ api,
153
+ options
154
+ }, config, previousDevDeps) {
155
+ this.options = options;
156
+ this.api = api;
157
+ this.optionsRef = input.optionsRef;
158
+ this.config = config;
159
+ this.previousDevDeps = previousDevDeps;
160
+ this.devDepRequests = new Map();
161
+ this.configs = new Map();
162
+ this.pluginOptions = new _PluginOptions.default((0, _utils2.optionsProxy)(this.options, api.invalidateOnOptionChange));
163
+ this.cacheKey = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:BundleGraph:${JSON.stringify(options.entries) ?? ''}${options.mode}${options.shouldBuildLazily ? 'lazy' : 'eager'}`) + '-BundleGraph';
164
+ }
165
+ async loadConfigs() {
166
+ // Load all configs up front so we can use them in the cache key
167
+ let bundler = await this.config.getBundler();
168
+ await this.loadConfig(bundler);
169
+ let namers = await this.config.getNamers();
170
+ for (let namer of namers) {
171
+ await this.loadConfig(namer);
172
+ }
173
+ let runtimes = await this.config.getRuntimes();
174
+ for (let runtime of runtimes) {
175
+ await this.loadConfig(runtime);
176
+ }
177
+ }
178
+ async loadConfig(plugin) {
179
+ let config = (0, _InternalConfig.createConfig)({
180
+ plugin: plugin.name,
181
+ searchPath: (0, _projectPath.toProjectPathUnsafe)('index')
182
+ });
183
+ await (0, _ConfigRequest.loadPluginConfig)(plugin, config, this.options);
184
+ await (0, _ConfigRequest.runConfigRequest)(this.api, config);
185
+ for (let devDep of config.devDeps) {
186
+ let devDepRequest = await (0, _DevDepRequest.createDevDependency)(devDep, this.previousDevDeps, this.options);
187
+ await this.runDevDepRequest(devDepRequest);
188
+ }
189
+ this.configs.set(plugin.name, config);
190
+ }
191
+ async runDevDepRequest(devDepRequest) {
192
+ let {
193
+ specifier,
194
+ resolveFrom
195
+ } = devDepRequest;
196
+ let key = `${specifier}:${(0, _projectPath.fromProjectPathRelative)(resolveFrom)}`;
197
+ this.devDepRequests.set(key, devDepRequest);
198
+ await (0, _DevDepRequest.runDevDepRequest)(this.api, devDepRequest);
199
+ }
200
+ async bundle({
201
+ graph,
202
+ changedAssets,
203
+ assetRequests
204
+ }) {
205
+ (0, _ReporterRunner.report)({
206
+ type: 'buildProgress',
207
+ phase: 'bundling'
208
+ });
209
+ await this.loadConfigs();
210
+ let plugin = await this.config.getBundler();
211
+ let {
212
+ plugin: bundler,
213
+ name,
214
+ resolveFrom
215
+ } = plugin;
216
+
217
+ // if a previous asset graph hash is passed in, check if the bundle graph is also available
218
+ let previousBundleGraphResult;
219
+ if (graph.safeToIncrementallyBundle) {
220
+ try {
221
+ previousBundleGraphResult = await this.api.getPreviousResult();
222
+ } catch {
223
+ // if the bundle graph had an error or was removed, don't fail the build
224
+ }
225
+ }
226
+ if (previousBundleGraphResult == null) {
227
+ graph.safeToIncrementallyBundle = false;
228
+ }
229
+ let internalBundleGraph;
230
+ let logger = new (_logger().PluginLogger)({
231
+ origin: name
232
+ });
233
+ let tracer = new (_profiler().PluginTracer)({
234
+ origin: name,
235
+ category: 'bundle'
236
+ });
237
+ try {
238
+ if (previousBundleGraphResult) {
239
+ internalBundleGraph = previousBundleGraphResult.bundleGraph;
240
+ for (let changedAssetId of changedAssets.keys()) {
241
+ // Copy over the whole node to also have correct symbol data
242
+ let changedAssetNode = (0, _nullthrows().default)(graph.getNodeByContentKey(changedAssetId));
243
+ (0, _assert().default)(changedAssetNode.type === 'asset');
244
+ internalBundleGraph.updateAsset(changedAssetNode);
245
+ }
246
+ } else {
247
+ var _this$configs$get;
248
+ internalBundleGraph = _BundleGraph2.default.fromAssetGraph(graph, this.options.mode === 'production');
249
+ (0, _assert().default)(internalBundleGraph != null); // ensures the graph was created
250
+
251
+ await (0, _dumpGraphToGraphViz.default)(
252
+ // $FlowFixMe
253
+ internalBundleGraph._graph, 'before_bundle', _BundleGraph2.bundleGraphEdgeTypes);
254
+ let mutableBundleGraph = new _MutableBundleGraph.default(internalBundleGraph, this.options);
255
+ let measurement;
256
+ let measurementFilename;
257
+ if (tracer.enabled) {
258
+ measurementFilename = graph.getEntryAssets().map(asset => (0, _projectPath.fromProjectPathRelative)(asset.filePath)).join(', ');
259
+ measurement = tracer.createMeasurement(plugin.name, 'bundling:bundle', measurementFilename);
260
+ }
261
+
262
+ // this the normal bundle workflow (bundle, optimizing, run-times, naming)
263
+ await bundler.bundle({
264
+ bundleGraph: mutableBundleGraph,
265
+ config: (_this$configs$get = this.configs.get(plugin.name)) === null || _this$configs$get === void 0 ? void 0 : _this$configs$get.result,
266
+ options: this.pluginOptions,
267
+ logger,
268
+ tracer
269
+ });
270
+ measurement && measurement.end();
271
+ if (this.pluginOptions.mode === 'production') {
272
+ let optimizeMeasurement;
273
+ try {
274
+ var _this$configs$get2;
275
+ if (tracer.enabled) {
276
+ optimizeMeasurement = tracer.createMeasurement(plugin.name, 'bundling:optimize', (0, _nullthrows().default)(measurementFilename));
277
+ }
278
+ await bundler.optimize({
279
+ bundleGraph: mutableBundleGraph,
280
+ config: (_this$configs$get2 = this.configs.get(plugin.name)) === null || _this$configs$get2 === void 0 ? void 0 : _this$configs$get2.result,
281
+ options: this.pluginOptions,
282
+ logger
283
+ });
284
+ } catch (e) {
285
+ throw new (_diagnostic().default)({
286
+ diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
287
+ origin: plugin.name
288
+ })
289
+ });
290
+ } finally {
291
+ optimizeMeasurement && optimizeMeasurement.end();
292
+ await (0, _dumpGraphToGraphViz.default)(
293
+ // $FlowFixMe[incompatible-call]
294
+ internalBundleGraph._graph, 'after_optimize');
295
+ }
296
+ }
297
+
298
+ // Add dev dependency for the bundler. This must be done AFTER running it due to
299
+ // the potential for lazy require() that aren't executed until the request runs.
300
+ let devDepRequest = await (0, _DevDepRequest.createDevDependency)({
301
+ specifier: name,
302
+ resolveFrom
303
+ }, this.previousDevDeps, this.options);
304
+ await this.runDevDepRequest(devDepRequest);
305
+ }
306
+ } catch (e) {
307
+ if (internalBundleGraph != null) {
308
+ this.api.storeResult({
309
+ bundleGraph: internalBundleGraph,
310
+ changedAssets: new Map(),
311
+ assetRequests: []
312
+ }, this.cacheKey);
313
+ }
314
+ throw new (_diagnostic().default)({
315
+ diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
316
+ origin: name
317
+ })
318
+ });
319
+ } finally {
320
+ (0, _assert().default)(internalBundleGraph != null); // ensures the graph was created
321
+ await (0, _dumpGraphToGraphViz.default)(
322
+ // $FlowFixMe[incompatible-call]
323
+ internalBundleGraph._graph, 'after_bundle', _BundleGraph2.bundleGraphEdgeTypes);
324
+ }
325
+ let changedRuntimes = new Map();
326
+ if (!previousBundleGraphResult) {
327
+ let namers = await this.config.getNamers();
328
+ // inline bundles must still be named so the PackagerRunner
329
+ // can match them to the correct packager/optimizer plugins.
330
+ let bundles = internalBundleGraph.getBundles({
331
+ includeInline: true
332
+ });
333
+ await Promise.all(bundles.map(bundle => this.nameBundle(namers, bundle, internalBundleGraph)));
334
+ changedRuntimes = await (0, _applyRuntimes.default)({
335
+ bundleGraph: internalBundleGraph,
336
+ api: this.api,
337
+ config: this.config,
338
+ options: this.options,
339
+ optionsRef: this.optionsRef,
340
+ pluginOptions: this.pluginOptions,
341
+ previousDevDeps: this.previousDevDeps,
342
+ devDepRequests: this.devDepRequests,
343
+ configs: this.configs
344
+ });
345
+
346
+ // Add dev deps for namers, AFTER running them to account for lazy require().
347
+ for (let namer of namers) {
348
+ let devDepRequest = await (0, _DevDepRequest.createDevDependency)({
349
+ specifier: namer.name,
350
+ resolveFrom: namer.resolveFrom
351
+ }, this.previousDevDeps, this.options);
352
+ await this.runDevDepRequest(devDepRequest);
353
+ }
354
+ this.validateBundles(internalBundleGraph);
355
+
356
+ // Pre-compute the hashes for each bundle so they are only computed once and shared between workers.
357
+ internalBundleGraph.getBundleGraphHash();
358
+ }
359
+ await (0, _dumpGraphToGraphViz.default)(
360
+ // $FlowFixMe
361
+ internalBundleGraph._graph, 'after_runtimes', _BundleGraph2.bundleGraphEdgeTypes);
362
+ this.api.storeResult({
363
+ bundleGraph: internalBundleGraph,
364
+ changedAssets: new Map(),
365
+ assetRequests: []
366
+ }, this.cacheKey);
367
+ return {
368
+ bundleGraph: internalBundleGraph,
369
+ changedAssets: changedRuntimes,
370
+ assetRequests
371
+ };
372
+ }
373
+ validateBundles(bundleGraph) {
374
+ let bundles = bundleGraph.getBundles();
375
+ let bundleNames = bundles.map(b => (0, _projectPath.joinProjectPath)(b.target.distDir, (0, _nullthrows().default)(b.name)));
376
+ _assert().default.deepEqual(bundleNames, (0, _utils().unique)(bundleNames), 'Bundles must have unique name. Conflicting names: ' + [...(0, _utils().setDifference)(new Set(bundleNames), new Set((0, _utils().unique)(bundleNames)))].join());
377
+ }
378
+ async nameBundle(namers, internalBundle, internalBundleGraph) {
379
+ let bundle = _Bundle.Bundle.get(internalBundle, internalBundleGraph, this.options);
380
+ let bundleGraph = new _BundleGraph.default(internalBundleGraph, _Bundle.NamedBundle.get.bind(_Bundle.NamedBundle), this.options);
381
+ for (let namer of namers) {
382
+ let measurement;
383
+ try {
384
+ var _this$configs$get3;
385
+ measurement = _profiler().tracer.createMeasurement(namer.name, 'namer', bundle.id);
386
+ let name = await namer.plugin.name({
387
+ bundle,
388
+ bundleGraph,
389
+ config: (_this$configs$get3 = this.configs.get(namer.name)) === null || _this$configs$get3 === void 0 ? void 0 : _this$configs$get3.result,
390
+ options: this.pluginOptions,
391
+ logger: new (_logger().PluginLogger)({
392
+ origin: namer.name
393
+ }),
394
+ tracer: new (_profiler().PluginTracer)({
395
+ origin: namer.name,
396
+ category: 'namer'
397
+ })
398
+ });
399
+ if (name != null) {
400
+ internalBundle.name = name;
401
+ let {
402
+ hashReference
403
+ } = internalBundle;
404
+ internalBundle.displayName = name.includes(hashReference) ? name.replace(hashReference, '[hash]') : name;
405
+ return;
406
+ }
407
+ } catch (e) {
408
+ throw new (_diagnostic().default)({
409
+ diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
410
+ origin: namer.name
411
+ })
412
+ });
413
+ } finally {
414
+ measurement && measurement.end();
415
+ }
416
+ }
417
+ throw new Error('Unable to name bundle');
418
+ }
419
+ }
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getConfigHash = getConfigHash;
7
+ exports.getConfigKeyContentHash = getConfigKeyContentHash;
8
+ exports.getConfigRequests = getConfigRequests;
9
+ exports.loadPluginConfig = loadPluginConfig;
10
+ exports.runConfigRequest = runConfigRequest;
11
+ function _utils() {
12
+ const data = require("@atlaspack/utils");
13
+ _utils = function () {
14
+ return data;
15
+ };
16
+ return data;
17
+ }
18
+ var _serializer = require("../serializer.js");
19
+ function _logger() {
20
+ const data = require("@atlaspack/logger");
21
+ _logger = function () {
22
+ return data;
23
+ };
24
+ return data;
25
+ }
26
+ var _PluginOptions = _interopRequireDefault(require("../public/PluginOptions"));
27
+ function _diagnostic() {
28
+ const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
29
+ _diagnostic = function () {
30
+ return data;
31
+ };
32
+ return data;
33
+ }
34
+ var _Config = _interopRequireDefault(require("../public/Config"));
35
+ var _utils2 = require("../utils");
36
+ var _assetUtils = require("../assetUtils");
37
+ function _rust() {
38
+ const data = require("@atlaspack/rust");
39
+ _rust = function () {
40
+ return data;
41
+ };
42
+ return data;
43
+ }
44
+ function _profiler() {
45
+ const data = require("@atlaspack/profiler");
46
+ _profiler = function () {
47
+ return data;
48
+ };
49
+ return data;
50
+ }
51
+ var _RequestTracker = require("../RequestTracker");
52
+ var _projectPath = require("../projectPath");
53
+ var _buildCache = require("../buildCache");
54
+ 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); }
55
+ 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; }
56
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
57
+ async function loadPluginConfig(loadedPlugin, config, options) {
58
+ let loadConfig = loadedPlugin.plugin.loadConfig;
59
+ if (!loadConfig) {
60
+ return;
61
+ }
62
+ try {
63
+ config.result = await loadConfig({
64
+ config: new _Config.default(config, options),
65
+ options: new _PluginOptions.default((0, _utils2.optionsProxy)(options, option => {
66
+ config.invalidateOnOptionChange.add(option);
67
+ })),
68
+ logger: new (_logger().PluginLogger)({
69
+ origin: loadedPlugin.name
70
+ }),
71
+ tracer: new (_profiler().PluginTracer)({
72
+ origin: loadedPlugin.name,
73
+ category: 'loadConfig'
74
+ })
75
+ });
76
+ } catch (e) {
77
+ throw new (_diagnostic().default)({
78
+ diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
79
+ origin: loadedPlugin.name
80
+ })
81
+ });
82
+ }
83
+ }
84
+ const configKeyCache = (0, _buildCache.createBuildCache)();
85
+ async function getConfigKeyContentHash(filePath, configKey, options) {
86
+ let cacheKey = `${(0, _projectPath.fromProjectPathRelative)(filePath)}:${configKey}`;
87
+ let cachedValue = configKeyCache.get(cacheKey);
88
+ if (cachedValue) {
89
+ return cachedValue;
90
+ }
91
+ let conf = await (0, _utils().readConfig)(options.inputFS, (0, _projectPath.fromProjectPath)(options.projectRoot, filePath));
92
+ if (conf == null || conf.config[configKey] == null) {
93
+ // This can occur when a config key has been removed entirely during `respondToFSEvents`
94
+ return '';
95
+ }
96
+ let contentHash = typeof conf.config[configKey] === 'object' ? (0, _utils().hashObject)(conf.config[configKey]) : (0, _rust().hashString)(JSON.stringify(conf.config[configKey]));
97
+ configKeyCache.set(cacheKey, contentHash);
98
+ return contentHash;
99
+ }
100
+ async function runConfigRequest(api, configRequest) {
101
+ let {
102
+ invalidateOnFileChange,
103
+ invalidateOnConfigKeyChange,
104
+ invalidateOnFileCreate,
105
+ invalidateOnEnvChange,
106
+ invalidateOnOptionChange,
107
+ invalidateOnStartup,
108
+ invalidateOnBuild
109
+ } = configRequest;
110
+
111
+ // If there are no invalidations, then no need to create a node.
112
+ if (invalidateOnFileChange.size === 0 && invalidateOnConfigKeyChange.length === 0 && invalidateOnFileCreate.length === 0 && invalidateOnOptionChange.size === 0 && invalidateOnEnvChange.size === 0 && !invalidateOnStartup && !invalidateOnBuild) {
113
+ return;
114
+ }
115
+ await api.runRequest({
116
+ id: 'config_request:' + configRequest.id,
117
+ type: _RequestTracker.requestTypes.config_request,
118
+ run: async ({
119
+ api,
120
+ options
121
+ }) => {
122
+ for (let filePath of invalidateOnFileChange) {
123
+ api.invalidateOnFileUpdate(filePath);
124
+ api.invalidateOnFileDelete(filePath);
125
+ }
126
+ for (let {
127
+ filePath,
128
+ configKey
129
+ } of invalidateOnConfigKeyChange) {
130
+ let contentHash = await getConfigKeyContentHash(filePath, configKey, options);
131
+ api.invalidateOnConfigKeyChange(filePath, configKey, contentHash);
132
+ }
133
+ for (let invalidation of invalidateOnFileCreate) {
134
+ api.invalidateOnFileCreate(invalidation);
135
+ }
136
+ for (let env of invalidateOnEnvChange) {
137
+ api.invalidateOnEnvChange(env);
138
+ }
139
+ for (let option of invalidateOnOptionChange) {
140
+ api.invalidateOnOptionChange(option);
141
+ }
142
+ if (invalidateOnStartup) {
143
+ api.invalidateOnStartup();
144
+ }
145
+ if (invalidateOnBuild) {
146
+ api.invalidateOnBuild();
147
+ }
148
+ },
149
+ input: null
150
+ });
151
+ }
152
+ async function getConfigHash(config, pluginName, options) {
153
+ if (config.result == null) {
154
+ return '';
155
+ }
156
+ let hash = new (_rust().Hash)();
157
+ hash.writeString(config.id);
158
+
159
+ // If there is no result hash set by the transformer, default to hashing the included
160
+ // files if any, otherwise try to hash the config result itself.
161
+ if (config.cacheKey == null) {
162
+ if (config.invalidateOnFileChange.size > 0) {
163
+ hash.writeString(await (0, _assetUtils.getInvalidationHash)([...config.invalidateOnFileChange].map(filePath => ({
164
+ type: 'file',
165
+ filePath
166
+ })), options));
167
+ } else if (config.result != null) {
168
+ try {
169
+ hash.writeBuffer((0, _serializer.serializeRaw)(config.result));
170
+ } catch (err) {
171
+ throw new (_diagnostic().default)({
172
+ diagnostic: {
173
+ message: 'Config result is not hashable because it contains non-serializable objects. Please use config.setCacheKey to set the hash manually.',
174
+ origin: pluginName
175
+ }
176
+ });
177
+ }
178
+ }
179
+ } else {
180
+ hash.writeString(config.cacheKey ?? '');
181
+ }
182
+ return hash.finish();
183
+ }
184
+ function getConfigRequests(configs) {
185
+ return configs.filter(config => {
186
+ // No need to send to the graph if there are no invalidations.
187
+ return config.invalidateOnFileChange.size > 0 || config.invalidateOnConfigKeyChange.length > 0 || config.invalidateOnFileCreate.length > 0 || config.invalidateOnEnvChange.size > 0 || config.invalidateOnOptionChange.size > 0 || config.invalidateOnStartup || config.invalidateOnBuild;
188
+ }).map(config => ({
189
+ id: config.id,
190
+ invalidateOnFileChange: config.invalidateOnFileChange,
191
+ invalidateOnConfigKeyChange: config.invalidateOnConfigKeyChange,
192
+ invalidateOnFileCreate: config.invalidateOnFileCreate,
193
+ invalidateOnEnvChange: config.invalidateOnEnvChange,
194
+ invalidateOnOptionChange: config.invalidateOnOptionChange,
195
+ invalidateOnStartup: config.invalidateOnStartup,
196
+ invalidateOnBuild: config.invalidateOnBuild
197
+ }));
198
+ }