@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,342 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _assert() {
8
+ const data = _interopRequireDefault(require("assert"));
9
+ _assert = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _stream() {
15
+ const data = require("stream");
16
+ _stream = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _sourceMap() {
22
+ const data = _interopRequireDefault(require("@parcel/source-map"));
23
+ _sourceMap = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _utils() {
29
+ const data = require("@atlaspack/utils");
30
+ _utils = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _rust() {
36
+ const data = require("@atlaspack/rust");
37
+ _rust = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ var _serializer = require("./serializer");
43
+ var _Dependency = require("./Dependency");
44
+ var _Environment = require("./Environment");
45
+ var _constants = require("./constants");
46
+ var _assetUtils = require("./assetUtils");
47
+ var _types = require("./types");
48
+ var _utils2 = require("./utils");
49
+ var _projectPath = require("./projectPath");
50
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51
+ class UncommittedAsset {
52
+ constructor({
53
+ value,
54
+ options,
55
+ content,
56
+ mapBuffer,
57
+ ast,
58
+ isASTDirty,
59
+ idBase,
60
+ invalidations
61
+ }) {
62
+ this.value = value;
63
+ this.options = options;
64
+ this.content = content;
65
+ this.mapBuffer = mapBuffer;
66
+ this.ast = ast;
67
+ this.isASTDirty = isASTDirty || false;
68
+ this.idBase = idBase;
69
+ this.invalidations = invalidations || (0, _utils2.createInvalidations)();
70
+ }
71
+
72
+ /*
73
+ * Prepares the asset for being serialized to the cache by committing its
74
+ * content and map of the asset to the cache.
75
+ */
76
+ async commit() {
77
+ // If there is a dirty AST, clear out any old content and map as these
78
+ // must be regenerated later and shouldn't be committed.
79
+ if (this.ast != null && this.isASTDirty) {
80
+ this.content = null;
81
+ this.mapBuffer = null;
82
+ }
83
+ let size = 0;
84
+ let outputHash = '';
85
+ let contentKey = this.content == null ? null : this.getCacheKey('content');
86
+ let mapKey = this.mapBuffer == null ? null : this.getCacheKey('map');
87
+ let astKey = this.ast == null ? null : this.getCacheKey('ast');
88
+
89
+ // Since we can only read from the stream once, compute the content length
90
+ // and hash while it's being written to the cache.
91
+ await Promise.all([contentKey != null && this.commitContent(contentKey).then(s => (size = s.size, outputHash = s.hash)), this.mapBuffer != null && mapKey != null && this.options.cache.setBlob(mapKey, this.mapBuffer), astKey != null && this.options.cache.setBlob(astKey, (0, _serializer.serializeRaw)(this.ast))]);
92
+ this.value.contentKey = contentKey;
93
+ this.value.mapKey = mapKey;
94
+ this.value.astKey = astKey;
95
+ this.value.outputHash = outputHash;
96
+ if (this.content != null) {
97
+ this.value.stats.size = size;
98
+ }
99
+ this.value.isLargeBlob = this.content instanceof _stream().Readable;
100
+ this.value.committed = true;
101
+ }
102
+ async commitContent(contentKey) {
103
+ let content = await this.content;
104
+ if (content == null) {
105
+ return {
106
+ size: 0,
107
+ hash: ''
108
+ };
109
+ }
110
+ let size = 0;
111
+ if (content instanceof _stream().Readable) {
112
+ let hash = new (_rust().Hash)();
113
+ await this.options.cache.setStream(contentKey, content.pipe(new (_utils().TapStream)(buf => {
114
+ hash.writeBuffer(buf);
115
+ size += buf.length;
116
+ })));
117
+ return {
118
+ size,
119
+ hash: hash.finish()
120
+ };
121
+ }
122
+ let hash;
123
+ if (typeof content === 'string') {
124
+ hash = (0, _rust().hashString)(content);
125
+ size = Buffer.byteLength(content);
126
+ } else {
127
+ hash = (0, _rust().hashBuffer)(content);
128
+ size = content.length;
129
+ }
130
+ await this.options.cache.setBlob(contentKey, content);
131
+ return {
132
+ size,
133
+ hash
134
+ };
135
+ }
136
+ async getCode() {
137
+ if (this.ast != null && this.isASTDirty) {
138
+ throw new Error('Cannot call getCode() on an asset with a dirty AST. For transformers, implement canReuseAST() and check asset.isASTDirty.');
139
+ }
140
+ let content = await this.content;
141
+ if (typeof content === 'string' || content instanceof Buffer) {
142
+ return content.toString();
143
+ } else if (content != null) {
144
+ this.content = (0, _utils().bufferStream)(content);
145
+ return (await this.content).toString();
146
+ }
147
+ (0, _assert().default)(false, 'Internal error: missing content');
148
+ }
149
+ async getBuffer() {
150
+ let content = await this.content;
151
+ if (content == null) {
152
+ return Buffer.alloc(0);
153
+ } else if (content instanceof Buffer) {
154
+ return content;
155
+ } else if (typeof content === 'string') {
156
+ return Buffer.from(content);
157
+ }
158
+ this.content = (0, _utils().bufferStream)(content);
159
+ return this.content;
160
+ }
161
+ getStream() {
162
+ if (this.content instanceof _stream().Readable) {
163
+ // Remove content if it's a stream, as it should not be reused.
164
+ let content = this.content;
165
+ this.content = null;
166
+ return content;
167
+ }
168
+ if (this.content instanceof Promise) {
169
+ return (0, _utils().streamFromPromise)(this.content);
170
+ }
171
+ return (0, _utils().blobToStream)(this.content ?? Buffer.alloc(0));
172
+ }
173
+ setCode(code) {
174
+ this.content = code;
175
+ this.clearAST();
176
+ }
177
+ setBuffer(buffer) {
178
+ this.content = buffer;
179
+ this.clearAST();
180
+ }
181
+ setStream(stream) {
182
+ this.content = stream;
183
+ this.clearAST();
184
+ }
185
+ async loadExistingSourcemap() {
186
+ if (this.map) {
187
+ return this.map;
188
+ }
189
+ let code = await this.getCode();
190
+ let map = await (0, _utils().loadSourceMap)((0, _projectPath.fromProjectPath)(this.options.projectRoot, this.value.filePath), code, {
191
+ fs: this.options.inputFS,
192
+ projectRoot: this.options.projectRoot
193
+ });
194
+ if (map) {
195
+ this.map = map;
196
+ this.mapBuffer = map.toBuffer();
197
+ this.setCode(code.replace(_utils().SOURCEMAP_RE, ''));
198
+ }
199
+ return this.map;
200
+ }
201
+ getMapBuffer() {
202
+ return Promise.resolve(this.mapBuffer);
203
+ }
204
+ async getMap() {
205
+ if (this.map == null) {
206
+ let mapBuffer = this.mapBuffer ?? (await this.getMapBuffer());
207
+ if (mapBuffer) {
208
+ // Get sourcemap from flatbuffer
209
+ this.map = new (_sourceMap().default)(this.options.projectRoot, mapBuffer);
210
+ }
211
+ }
212
+ return this.map;
213
+ }
214
+ setMap(map) {
215
+ var _this$map;
216
+ // If we have sourceContent available, it means this asset is source code without
217
+ // a previous source map. Ensure that the map set by the transformer has the original
218
+ // source content available.
219
+ if (map != null && this.sourceContent != null) {
220
+ map.setSourceContent((0, _projectPath.fromProjectPath)(this.options.projectRoot, this.value.filePath),
221
+ // $FlowFixMe
222
+ this.sourceContent);
223
+ this.sourceContent = null;
224
+ }
225
+ this.map = map;
226
+ this.mapBuffer = (_this$map = this.map) === null || _this$map === void 0 ? void 0 : _this$map.toBuffer();
227
+ }
228
+ getAST() {
229
+ return Promise.resolve(this.ast);
230
+ }
231
+ setAST(ast) {
232
+ this.ast = ast;
233
+ this.isASTDirty = true;
234
+ this.value.astGenerator = {
235
+ type: ast.type,
236
+ version: ast.version
237
+ };
238
+ }
239
+ clearAST() {
240
+ this.ast = null;
241
+ this.isASTDirty = false;
242
+ this.value.astGenerator = null;
243
+ }
244
+ getCacheKey(key) {
245
+ return (0, _rust().hashString)(_constants.ATLASPACK_VERSION + key + this.value.id);
246
+ }
247
+ addDependency(opts) {
248
+ // eslint-disable-next-line no-unused-vars
249
+ let {
250
+ env,
251
+ symbols,
252
+ ...rest
253
+ } = opts;
254
+ let dep = (0, _Dependency.createDependency)(this.options.projectRoot, {
255
+ ...rest,
256
+ // $FlowFixMe "convert" the $ReadOnlyMaps to the interal mutable one
257
+ symbols,
258
+ env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, this.value.env, env),
259
+ sourceAssetId: this.value.id,
260
+ sourcePath: (0, _projectPath.fromProjectPath)(this.options.projectRoot, this.value.filePath)
261
+ });
262
+ let existing = this.value.dependencies.get(dep.id);
263
+ if (existing) {
264
+ (0, _Dependency.mergeDependencies)(existing, dep);
265
+ } else {
266
+ this.value.dependencies.set(dep.id, dep);
267
+ }
268
+ return dep.id;
269
+ }
270
+ invalidateOnFileChange(filePath) {
271
+ this.invalidations.invalidateOnFileChange.add(filePath);
272
+ }
273
+ invalidateOnFileCreate(invalidation) {
274
+ this.invalidations.invalidateOnFileCreate.push((0, _utils2.invalidateOnFileCreateToInternal)(this.options.projectRoot, invalidation));
275
+ }
276
+ invalidateOnEnvChange(key) {
277
+ this.invalidations.invalidateOnEnvChange.add(key);
278
+ }
279
+ invalidateOnBuild() {
280
+ this.invalidations.invalidateOnBuild = true;
281
+ }
282
+ invalidateOnStartup() {
283
+ this.invalidations.invalidateOnStartup = true;
284
+ }
285
+ getDependencies() {
286
+ return Array.from(this.value.dependencies.values());
287
+ }
288
+ createChildAsset(result, plugin, configPath, configKeyPath) {
289
+ let content = result.content ?? null;
290
+ let asset = new UncommittedAsset({
291
+ value: (0, _assetUtils.createAsset)(this.options.projectRoot, {
292
+ idBase: this.idBase,
293
+ filePath: this.value.filePath,
294
+ type: result.type,
295
+ bundleBehavior: result.bundleBehavior ?? (this.value.bundleBehavior == null ? null : _types.BundleBehaviorNames[this.value.bundleBehavior]),
296
+ isBundleSplittable: result.isBundleSplittable ?? this.value.isBundleSplittable,
297
+ isSource: this.value.isSource,
298
+ env: (0, _Environment.mergeEnvironments)(this.options.projectRoot, this.value.env, result.env),
299
+ dependencies: this.value.type === result.type ? new Map(this.value.dependencies) : new Map(),
300
+ meta: {
301
+ ...this.value.meta,
302
+ ...result.meta
303
+ },
304
+ pipeline: result.pipeline ?? (this.value.type === result.type ? this.value.pipeline : null),
305
+ stats: {
306
+ time: 0,
307
+ size: this.value.stats.size
308
+ },
309
+ // $FlowFixMe
310
+ symbols: result.symbols,
311
+ sideEffects: result.sideEffects ?? this.value.sideEffects,
312
+ uniqueKey: result.uniqueKey,
313
+ astGenerator: result.ast ? {
314
+ type: result.ast.type,
315
+ version: result.ast.version
316
+ } : null,
317
+ plugin,
318
+ configPath,
319
+ configKeyPath
320
+ }),
321
+ options: this.options,
322
+ content,
323
+ ast: result.ast,
324
+ isASTDirty: result.ast === this.ast ? this.isASTDirty : true,
325
+ mapBuffer: result.map ? result.map.toBuffer() : null,
326
+ idBase: this.idBase,
327
+ invalidations: this.invalidations
328
+ });
329
+ let dependencies = result.dependencies;
330
+ if (dependencies) {
331
+ for (let dep of dependencies) {
332
+ asset.addDependency(dep);
333
+ }
334
+ }
335
+ return asset;
336
+ }
337
+ updateId() {
338
+ // $FlowFixMe - this is fine
339
+ this.value.id = (0, _assetUtils.createAssetIdFromOptions)(this.value);
340
+ }
341
+ }
342
+ exports.default = UncommittedAsset;
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _utils() {
15
+ const data = require("@atlaspack/utils");
16
+ _utils = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _logger() {
22
+ const data = _interopRequireWildcard(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 _AtlaspackConfig = _interopRequireDefault(require("./AtlaspackConfig"));
36
+ var _UncommittedAsset = _interopRequireDefault(require("./UncommittedAsset"));
37
+ var _assetUtils = require("./assetUtils");
38
+ var _Asset = require("./public/Asset");
39
+ var _PluginOptions = _interopRequireDefault(require("./public/PluginOptions"));
40
+ var _summarizeRequest = _interopRequireDefault(require("./summarizeRequest"));
41
+ var _projectPath = require("./projectPath");
42
+ function _profiler() {
43
+ const data = require("@atlaspack/profiler");
44
+ _profiler = 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
+ 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); }
57
+ 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; }
58
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
59
+ class Validation {
60
+ allAssets = {};
61
+ allValidators = {};
62
+ constructor({
63
+ config,
64
+ dedicatedThread,
65
+ options,
66
+ requests,
67
+ report,
68
+ workerApi
69
+ }) {
70
+ this.dedicatedThread = dedicatedThread ?? false;
71
+ this.options = options;
72
+ this.atlaspackConfig = config;
73
+ this.report = report;
74
+ this.requests = requests;
75
+ this.workerApi = workerApi;
76
+ }
77
+ async run() {
78
+ let pluginOptions = new _PluginOptions.default(this.options);
79
+ await this.buildAssetsAndValidators();
80
+ await Promise.all(Object.keys(this.allValidators).map(async validatorName => {
81
+ let assets = this.allAssets[validatorName];
82
+ if (assets) {
83
+ let plugin = this.allValidators[validatorName];
84
+ let validatorLogger = new (_logger().PluginLogger)({
85
+ origin: validatorName
86
+ });
87
+ let validatorTracer = new (_profiler().PluginTracer)({
88
+ origin: validatorName,
89
+ category: 'validator'
90
+ });
91
+ let validatorResults = [];
92
+ try {
93
+ // If the plugin supports the single-threading validateAll method, pass all assets to it.
94
+ if (plugin.validateAll && this.dedicatedThread) {
95
+ validatorResults = await plugin.validateAll({
96
+ assets: assets.map(asset => new _Asset.Asset(asset)),
97
+ options: pluginOptions,
98
+ logger: validatorLogger,
99
+ tracer: validatorTracer,
100
+ resolveConfigWithPath: (configNames, assetFilePath) => (0, _utils().resolveConfig)(this.options.inputFS, assetFilePath, configNames, this.options.projectRoot)
101
+ });
102
+ }
103
+
104
+ // Otherwise, pass the assets one-at-a-time
105
+ else if (plugin.validate && !this.dedicatedThread) {
106
+ await Promise.all(assets.map(async input => {
107
+ let config = null;
108
+ let publicAsset = new _Asset.Asset(input);
109
+ if (plugin.getConfig) {
110
+ config = await plugin.getConfig({
111
+ asset: publicAsset,
112
+ options: pluginOptions,
113
+ logger: validatorLogger,
114
+ tracer: validatorTracer,
115
+ resolveConfig: configNames => (0, _utils().resolveConfig)(this.options.inputFS, publicAsset.filePath, configNames, this.options.projectRoot)
116
+ });
117
+ }
118
+ let validatorResult = await plugin.validate({
119
+ asset: publicAsset,
120
+ options: pluginOptions,
121
+ config,
122
+ logger: validatorLogger,
123
+ tracer: validatorTracer
124
+ });
125
+ validatorResults.push(validatorResult);
126
+ }));
127
+ }
128
+ this.handleResults(validatorResults);
129
+ } catch (e) {
130
+ throw new (_diagnostic().default)({
131
+ diagnostic: (0, _diagnostic().errorToDiagnostic)(e, {
132
+ origin: validatorName
133
+ })
134
+ });
135
+ }
136
+ }
137
+ }));
138
+ }
139
+ async buildAssetsAndValidators() {
140
+ // Figure out what validators need to be run, and group the assets by the relevant validators.
141
+ await Promise.all(this.requests.map(async request => {
142
+ this.report({
143
+ type: 'validation',
144
+ filePath: (0, _projectPath.fromProjectPath)(this.options.projectRoot, request.filePath)
145
+ });
146
+ let asset = await this.loadAsset(request);
147
+ let validators = await this.atlaspackConfig.getValidators(request.filePath);
148
+ for (let validator of validators) {
149
+ this.allValidators[validator.name] = validator.plugin;
150
+ if (this.allAssets[validator.name]) {
151
+ this.allAssets[validator.name].push(asset);
152
+ } else {
153
+ this.allAssets[validator.name] = [asset];
154
+ }
155
+ }
156
+ }));
157
+ }
158
+ handleResults(validatorResults) {
159
+ let warnings = [];
160
+ let errors = [];
161
+ validatorResults.forEach(result => {
162
+ if (result) {
163
+ warnings.push(...result.warnings);
164
+ errors.push(...result.errors);
165
+ }
166
+ });
167
+ if (errors.length > 0) {
168
+ throw new (_diagnostic().default)({
169
+ diagnostic: errors
170
+ });
171
+ }
172
+ if (warnings.length > 0) {
173
+ _logger().default.warn(warnings);
174
+ }
175
+ }
176
+ async loadAsset(request) {
177
+ let {
178
+ filePath,
179
+ env,
180
+ code,
181
+ sideEffects,
182
+ query
183
+ } = request;
184
+ let {
185
+ content,
186
+ size,
187
+ isSource
188
+ } = await (0, _summarizeRequest.default)(this.options.inputFS, {
189
+ filePath: (0, _projectPath.fromProjectPath)(this.options.projectRoot, request.filePath)
190
+ });
191
+
192
+ // If the transformer request passed code rather than a filename,
193
+ // use a hash as the base for the id to ensure it is unique.
194
+ let idBase = code != null ? (0, _rust().hashString)(code) : (0, _projectPath.fromProjectPathRelative)(filePath);
195
+ return new _UncommittedAsset.default({
196
+ idBase,
197
+ value: (0, _assetUtils.createAsset)(this.options.projectRoot, {
198
+ idBase,
199
+ filePath: filePath,
200
+ isSource,
201
+ type: _path().default.extname((0, _projectPath.fromProjectPathRelative)(filePath)).slice(1),
202
+ query,
203
+ env: env,
204
+ stats: {
205
+ time: 0,
206
+ size
207
+ },
208
+ sideEffects: sideEffects
209
+ }),
210
+ options: this.options,
211
+ content
212
+ });
213
+ }
214
+ }
215
+ exports.default = Validation;