@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,993 @@
1
+ // @flow
2
+ import assert from 'assert';
3
+ import nullthrows from 'nullthrows';
4
+ import path from 'path';
5
+ import AtlaspackConfig from '../src/AtlaspackConfig';
6
+ import {
7
+ validateConfigFile,
8
+ mergePipelines,
9
+ mergeMaps,
10
+ mergeConfigs,
11
+ resolveExtends,
12
+ parseAndProcessConfig,
13
+ resolveAtlaspackConfig,
14
+ processConfig,
15
+ } from '../src/requests/AtlaspackConfigRequest';
16
+ import {validatePackageName} from '../src/AtlaspackConfig.schema';
17
+ import {DEFAULT_OPTIONS, relative} from './test-utils';
18
+ import {toProjectPath} from '../src/projectPath';
19
+
20
+ describe('AtlaspackConfigRequest', () => {
21
+ describe('validatePackageName', () => {
22
+ it('should error on an invalid official package', () => {
23
+ assert.throws(() => {
24
+ validatePackageName('@atlaspack/foo-bar', 'transform', 'transformers');
25
+ }, /Official atlaspack transform packages must be named according to "@atlaspack\/transform-{name}"/);
26
+
27
+ assert.throws(() => {
28
+ validatePackageName(
29
+ '@atlaspack/transformer',
30
+ 'transform',
31
+ 'transformers',
32
+ );
33
+ }, /Official atlaspack transform packages must be named according to "@atlaspack\/transform-{name}"/);
34
+ });
35
+
36
+ it('should succeed on a valid official package', () => {
37
+ validatePackageName(
38
+ '@atlaspack/transform-bar',
39
+ 'transform',
40
+ 'transformers',
41
+ );
42
+ });
43
+
44
+ it('should error on an invalid community package', () => {
45
+ assert.throws(() => {
46
+ validatePackageName('foo-bar', 'transform', 'transformers');
47
+ }, /Atlaspack transform packages must be named according to "atlaspack-transform-{name}"/);
48
+
49
+ assert.throws(() => {
50
+ validatePackageName('atlaspack-foo-bar', 'transform', 'transformers');
51
+ }, /Atlaspack transform packages must be named according to "atlaspack-transform-{name}"/);
52
+
53
+ assert.throws(() => {
54
+ validatePackageName('atlaspack-transform', 'transform', 'transformers');
55
+ }, /Atlaspack transform packages must be named according to "atlaspack-transform-{name}"/);
56
+ });
57
+
58
+ it('should succeed on a valid community package', () => {
59
+ validatePackageName(
60
+ 'atlaspack-transform-bar',
61
+ 'transform',
62
+ 'transformers',
63
+ );
64
+ });
65
+
66
+ // Skipping this while the migration to atlaspack occurs
67
+ it.skip('should error on an invalid scoped package', () => {
68
+ assert.throws(() => {
69
+ validatePackageName('@test/foo-bar', 'transform', 'transformers');
70
+ }, /Scoped atlaspack transform packages must be named according to "@test\/atlaspack-transform\[-{name}\]"/);
71
+
72
+ assert.throws(() => {
73
+ validatePackageName(
74
+ '@test/atlaspack-foo-bar',
75
+ 'transform',
76
+ 'transformers',
77
+ );
78
+ }, /Scoped atlaspack transform packages must be named according to "@test\/atlaspack-transform\[-{name}\]"/);
79
+ });
80
+
81
+ it('should succeed on a valid scoped package', () => {
82
+ validatePackageName(
83
+ '@test/atlaspack-transform-bar',
84
+ 'transform',
85
+ 'transformers',
86
+ );
87
+
88
+ validatePackageName(
89
+ '@test/atlaspack-transform',
90
+ 'transform',
91
+ 'transformers',
92
+ );
93
+ });
94
+
95
+ it('should succeed on a local package', () => {
96
+ validatePackageName(
97
+ './atlaspack-transform-bar',
98
+ 'transform',
99
+ 'transformers',
100
+ );
101
+ validatePackageName('./bar', 'transform', 'transformers');
102
+ });
103
+ });
104
+
105
+ describe('validateConfigFile', () => {
106
+ it('should throw on invalid config', () => {
107
+ assert.throws(() => {
108
+ validateConfigFile(
109
+ {
110
+ filePath: '.atlaspackrc',
111
+ extends: 'atlaspack-config-foo',
112
+ transformers: {
113
+ '*.js': ['atlaspack-invalid-plugin'],
114
+ },
115
+ },
116
+ '.atlaspackrc',
117
+ );
118
+ });
119
+ });
120
+
121
+ it('should require pipeline to be an array', () => {
122
+ assert.throws(() => {
123
+ validateConfigFile(
124
+ // $FlowExpectedError[incompatible-call]
125
+ {
126
+ filePath: '.atlaspackrc',
127
+ resolvers: '123',
128
+ },
129
+ '.atlaspackrc',
130
+ );
131
+ });
132
+ });
133
+
134
+ it('should require pipeline elements to be strings', () => {
135
+ assert.throws(() => {
136
+ validateConfigFile(
137
+ {
138
+ filePath: '.atlaspackrc',
139
+ // $FlowExpectedError[incompatible-call]
140
+ resolvers: [1, '123', 5],
141
+ },
142
+ '.atlaspackrc',
143
+ );
144
+ });
145
+ });
146
+
147
+ it('should require package names to be valid', () => {
148
+ assert.throws(() => {
149
+ validateConfigFile(
150
+ {
151
+ filePath: '.atlaspackrc',
152
+ resolvers: ['atlaspack-foo-bar'],
153
+ },
154
+ '.atlaspackrc',
155
+ );
156
+ });
157
+ });
158
+
159
+ it('should succeed with an array of valid package names', () => {
160
+ validateConfigFile(
161
+ {
162
+ filePath: '.atlaspackrc',
163
+ resolvers: ['atlaspack-resolver-test'],
164
+ },
165
+ '.atlaspackrc',
166
+ );
167
+ });
168
+
169
+ it('should support spread elements', () => {
170
+ validateConfigFile(
171
+ {
172
+ filePath: '.atlaspackrc',
173
+ resolvers: ['atlaspack-resolver-test', '...'],
174
+ },
175
+ '.atlaspackrc',
176
+ );
177
+ });
178
+
179
+ it('should require glob map to be an object', () => {
180
+ assert.throws(() => {
181
+ validateConfigFile(
182
+ {
183
+ filePath: '.atlaspackrc',
184
+ // $FlowExpectedError[incompatible-call]
185
+ transformers: ['atlaspack-transformer-test', '...'],
186
+ },
187
+ '.atlaspackrc',
188
+ );
189
+ });
190
+ });
191
+
192
+ it('should trigger the validator function for each key', () => {
193
+ assert.throws(() => {
194
+ validateConfigFile(
195
+ {
196
+ filePath: '.atlaspackrc',
197
+ transformers: {
198
+ 'types:*.{ts,tsx}': ['@atlaspack/transformer-typescript-types'],
199
+ 'bundle-text:*': ['-inline-string', '...'],
200
+ },
201
+ },
202
+ '.atlaspackrc',
203
+ );
204
+ });
205
+ });
206
+
207
+ it('should require extends to be a string or array of strings', () => {
208
+ assert.throws(() => {
209
+ validateConfigFile(
210
+ // $FlowExpectedError[incompatible-call]
211
+ {
212
+ filePath: '.atlaspackrc',
213
+ extends: 2,
214
+ },
215
+ '.atlaspackrc',
216
+ );
217
+ });
218
+
219
+ assert.throws(() => {
220
+ validateConfigFile(
221
+ {
222
+ filePath: '.atlaspackrc',
223
+ // $FlowExpectedError[incompatible-call]
224
+ extends: [2, 7],
225
+ },
226
+ '.atlaspackrc',
227
+ );
228
+ });
229
+ });
230
+
231
+ it('should support relative paths', () => {
232
+ validateConfigFile(
233
+ {
234
+ filePath: '.atlaspackrc',
235
+ extends: './foo',
236
+ },
237
+ '.atlaspackrc',
238
+ );
239
+
240
+ validateConfigFile(
241
+ {
242
+ filePath: '.atlaspackrc',
243
+ extends: ['./foo', './bar'],
244
+ },
245
+ '.atlaspackrc',
246
+ );
247
+ });
248
+
249
+ it('should validate package names', () => {
250
+ assert.throws(() => {
251
+ validateConfigFile(
252
+ {
253
+ filePath: '.atlaspackrc',
254
+ extends: 'foo',
255
+ },
256
+ '.atlaspackrc',
257
+ );
258
+ });
259
+
260
+ assert.throws(() => {
261
+ validateConfigFile(
262
+ {
263
+ filePath: '.atlaspackrc',
264
+ extends: ['foo', 'bar'],
265
+ },
266
+ '.atlaspackrc',
267
+ );
268
+ });
269
+
270
+ validateConfigFile(
271
+ {
272
+ filePath: '.atlaspackrc',
273
+ extends: 'atlaspack-config-foo',
274
+ },
275
+ '.atlaspackrc',
276
+ );
277
+
278
+ validateConfigFile(
279
+ {
280
+ filePath: '.atlaspackrc',
281
+ extends: ['atlaspack-config-foo', 'atlaspack-config-bar'],
282
+ },
283
+ '.atlaspackrc',
284
+ );
285
+ });
286
+
287
+ it('should throw for invalid top level keys', () => {
288
+ assert.throws(
289
+ () => {
290
+ validateConfigFile(
291
+ // $FlowExpectedError
292
+ {
293
+ extends: '@atlaspack/config-default',
294
+ '@atlaspack/transformer-js': {
295
+ inlineEnvironment: false,
296
+ },
297
+ },
298
+ '.atlaspackrc',
299
+ );
300
+ },
301
+ e => {
302
+ assert.strictEqual(
303
+ e.diagnostics[0].codeFrames[0].codeHighlights[0].message,
304
+ `Possible values: "$schema", "bundler", "resolvers", "transformers", "validators", "namers", "packagers", "optimizers", "compressors", "reporters", "runtimes", "filePath", "resolveFrom"`,
305
+ );
306
+ return true;
307
+ },
308
+ );
309
+ });
310
+
311
+ it('should succeed on valid config', () => {
312
+ validateConfigFile(
313
+ {
314
+ filePath: '.atlaspackrc',
315
+ extends: 'atlaspack-config-foo',
316
+ transformers: {
317
+ '*.js': ['atlaspack-transformer-foo'],
318
+ },
319
+ },
320
+ '.atlaspackrc',
321
+ );
322
+ });
323
+
324
+ it('should throw error on empty config file', () => {
325
+ assert.throws(
326
+ () => {
327
+ validateConfigFile({}, '.atlaspackrc');
328
+ },
329
+ {name: 'Error', message: ".atlaspackrc can't be empty"},
330
+ );
331
+ });
332
+ });
333
+
334
+ describe('mergePipelines', () => {
335
+ it('should return an empty array if base and extension are null', () => {
336
+ assert.deepEqual(mergePipelines(null, null), []);
337
+ });
338
+
339
+ it('should return base if extension is null', () => {
340
+ assert.deepEqual(
341
+ mergePipelines(
342
+ [
343
+ {
344
+ packageName: 'atlaspack-transform-foo',
345
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
346
+ keyPath: '/transformers/*.js/0',
347
+ },
348
+ ],
349
+ null,
350
+ ),
351
+ [
352
+ {
353
+ packageName: 'atlaspack-transform-foo',
354
+ resolveFrom: '.atlaspackrc',
355
+ keyPath: '/transformers/*.js/0',
356
+ },
357
+ ],
358
+ );
359
+ });
360
+
361
+ it('should return extension if base is null', () => {
362
+ assert.deepEqual(
363
+ mergePipelines(null, [
364
+ {
365
+ packageName: 'atlaspack-transform-bar',
366
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
367
+ keyPath: '/transformers/*.js/0',
368
+ },
369
+ ]),
370
+ [
371
+ {
372
+ packageName: 'atlaspack-transform-bar',
373
+ resolveFrom: '.atlaspackrc',
374
+ keyPath: '/transformers/*.js/0',
375
+ },
376
+ ],
377
+ );
378
+ });
379
+
380
+ it('should return extension if there are no spread elements', () => {
381
+ assert.deepEqual(
382
+ mergePipelines(
383
+ [
384
+ {
385
+ packageName: 'atlaspack-transform-foo',
386
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
387
+ keyPath: '/transformers/*.js/0',
388
+ },
389
+ ],
390
+ [
391
+ {
392
+ packageName: 'atlaspack-transform-bar',
393
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
394
+ keyPath: '/transformers/*.js/0',
395
+ },
396
+ ],
397
+ ),
398
+ [
399
+ {
400
+ packageName: 'atlaspack-transform-bar',
401
+ resolveFrom: '.atlaspackrc',
402
+ keyPath: '/transformers/*.js/0',
403
+ },
404
+ ],
405
+ );
406
+ });
407
+
408
+ it('should return merge base into extension if there are spread elements', () => {
409
+ assert.deepEqual(
410
+ mergePipelines(
411
+ [
412
+ {
413
+ packageName: 'atlaspack-transform-foo',
414
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
415
+ keyPath: '/transformers/*.js/0',
416
+ },
417
+ ],
418
+ [
419
+ {
420
+ packageName: 'atlaspack-transform-bar',
421
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
422
+ keyPath: '/transformers/*.js/0',
423
+ },
424
+ '...',
425
+ {
426
+ packageName: 'atlaspack-transform-baz',
427
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
428
+ keyPath: '/transformers/*.js/2',
429
+ },
430
+ ],
431
+ ),
432
+ [
433
+ {
434
+ packageName: 'atlaspack-transform-bar',
435
+ resolveFrom: '.atlaspackrc',
436
+ keyPath: '/transformers/*.js/0',
437
+ },
438
+ {
439
+ packageName: 'atlaspack-transform-foo',
440
+ resolveFrom: '.atlaspackrc',
441
+ keyPath: '/transformers/*.js/0',
442
+ },
443
+ {
444
+ packageName: 'atlaspack-transform-baz',
445
+ resolveFrom: '.atlaspackrc',
446
+ keyPath: '/transformers/*.js/2',
447
+ },
448
+ ],
449
+ );
450
+ });
451
+
452
+ it('should throw if more than one spread element is in a pipeline', () => {
453
+ assert.throws(() => {
454
+ mergePipelines(
455
+ [
456
+ {
457
+ packageName: 'atlaspack-transform-foo',
458
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
459
+ keyPath: '/transformers/*.js/0',
460
+ },
461
+ ],
462
+ [
463
+ {
464
+ packageName: 'atlaspack-transform-bar',
465
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
466
+ keyPath: '/transformers/*.js/0',
467
+ },
468
+ '...',
469
+ {
470
+ packageName: 'atlaspack-transform-baz',
471
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
472
+ keyPath: '/transformers/*.js/2',
473
+ },
474
+ '...',
475
+ ],
476
+ );
477
+ }, /Only one spread element can be included in a config pipeline/);
478
+ });
479
+
480
+ it('should remove spread element even without a base map', () => {
481
+ assert.deepEqual(
482
+ mergePipelines(null, [
483
+ {
484
+ packageName: 'atlaspack-transform-bar',
485
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
486
+ keyPath: '/transformers/*.js/0',
487
+ },
488
+ '...',
489
+ {
490
+ packageName: 'atlaspack-transform-baz',
491
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
492
+ keyPath: '/transformers/*.js/2',
493
+ },
494
+ ]),
495
+ [
496
+ {
497
+ packageName: 'atlaspack-transform-bar',
498
+ resolveFrom: '.atlaspackrc',
499
+ keyPath: '/transformers/*.js/0',
500
+ },
501
+ {
502
+ packageName: 'atlaspack-transform-baz',
503
+ resolveFrom: '.atlaspackrc',
504
+ keyPath: '/transformers/*.js/2',
505
+ },
506
+ ],
507
+ );
508
+ });
509
+
510
+ it('should throw if more than one spread element is in a pipeline even without a base map', () => {
511
+ assert.throws(() => {
512
+ mergePipelines(null, [
513
+ {
514
+ packageName: 'atlaspack-transform-bar',
515
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
516
+ keyPath: '/transformers/*.js/0',
517
+ },
518
+ '...',
519
+ {
520
+ packageName: 'atlaspack-transform-baz',
521
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
522
+ keyPath: '/transformers/*.js/2',
523
+ },
524
+ '...',
525
+ ]);
526
+ }, /Only one spread element can be included in a config pipeline/);
527
+ });
528
+ });
529
+
530
+ describe('mergeMaps', () => {
531
+ it('should return an empty object if base and extension are null', () => {
532
+ assert.deepEqual(mergeMaps(null, null), {});
533
+ });
534
+
535
+ it('should return base if extension is null', () => {
536
+ assert.deepEqual(mergeMaps({'*.js': 'foo'}, null), {
537
+ '*.js': 'foo',
538
+ });
539
+ });
540
+
541
+ it('should return extension if base is null', () => {
542
+ assert.deepEqual(mergeMaps(null, {'*.js': 'foo'}), {
543
+ '*.js': 'foo',
544
+ });
545
+ });
546
+
547
+ it('should merge the objects', () => {
548
+ assert.deepEqual(
549
+ mergeMaps({'*.css': 'css', '*.js': 'base-js'}, {'*.js': 'ext-js'}),
550
+ {'*.js': 'ext-js', '*.css': 'css'},
551
+ );
552
+ });
553
+
554
+ it('should ensure that extension properties have a higher precedence than base properties', () => {
555
+ let merged = mergeMaps({'*.{js,jsx}': 'base-js'}, {'*.js': 'ext-js'});
556
+ assert.deepEqual(merged, {'*.js': 'ext-js', '*.{js,jsx}': 'base-js'});
557
+ assert.deepEqual(Object.keys(merged), ['*.js', '*.{js,jsx}']);
558
+ });
559
+
560
+ it('should call a merger function if provided', () => {
561
+ let merger = (a, b) => [a, b];
562
+ assert.deepEqual(
563
+ mergeMaps({'*.js': 'base-js'}, {'*.js': 'ext-js'}, merger),
564
+ {'*.js': ['base-js', 'ext-js']},
565
+ );
566
+ });
567
+ });
568
+
569
+ describe('mergeConfigs', () => {
570
+ it('should merge configs', () => {
571
+ let base = new AtlaspackConfig(
572
+ {
573
+ filePath: toProjectPath('/', '/.atlaspackrc'),
574
+ resolvers: [
575
+ {
576
+ packageName: 'atlaspack-resolver-base',
577
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
578
+ keyPath: '/resolvers/0',
579
+ },
580
+ ],
581
+ transformers: {
582
+ '*.js': [
583
+ {
584
+ packageName: 'atlaspack-transform-base',
585
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
586
+ keyPath: '/transformers/*.js/0',
587
+ },
588
+ ],
589
+ '*.css': [
590
+ {
591
+ packageName: 'atlaspack-transform-css',
592
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
593
+ keyPath: '/transformers/*.css/0',
594
+ },
595
+ ],
596
+ },
597
+ bundler: {
598
+ packageName: 'atlaspack-bundler-base',
599
+ resolveFrom: toProjectPath('/', '/.atlaspackrc'),
600
+ keyPath: '/bundler',
601
+ },
602
+ },
603
+ DEFAULT_OPTIONS,
604
+ );
605
+
606
+ let ext = {
607
+ filePath: '.atlaspackrc',
608
+ resolvers: [
609
+ {
610
+ packageName: 'atlaspack-resolver-ext',
611
+ resolveFrom: '.atlaspackrc',
612
+ keyPath: '/resolvers/0',
613
+ },
614
+ '...',
615
+ ],
616
+ transformers: {
617
+ '*.js': [
618
+ {
619
+ packageName: 'atlaspack-transform-ext',
620
+ resolveFrom: '.atlaspackrc',
621
+ keyPath: '/transformers/*.js/0',
622
+ },
623
+ '...',
624
+ ],
625
+ },
626
+ };
627
+
628
+ let merged = {
629
+ filePath: '.atlaspackrc',
630
+ resolvers: [
631
+ {
632
+ packageName: 'atlaspack-resolver-ext',
633
+ resolveFrom: '.atlaspackrc',
634
+ keyPath: '/resolvers/0',
635
+ },
636
+ {
637
+ packageName: 'atlaspack-resolver-base',
638
+ resolveFrom: '.atlaspackrc',
639
+ keyPath: '/resolvers/0',
640
+ },
641
+ ],
642
+ transformers: {
643
+ '*.js': [
644
+ {
645
+ packageName: 'atlaspack-transform-ext',
646
+ resolveFrom: '.atlaspackrc',
647
+ keyPath: '/transformers/*.js/0',
648
+ },
649
+ {
650
+ packageName: 'atlaspack-transform-base',
651
+ resolveFrom: '.atlaspackrc',
652
+ keyPath: '/transformers/*.js/0',
653
+ },
654
+ ],
655
+ '*.css': [
656
+ {
657
+ packageName: 'atlaspack-transform-css',
658
+ resolveFrom: '.atlaspackrc',
659
+ keyPath: '/transformers/*.css/0',
660
+ },
661
+ ],
662
+ },
663
+ bundler: {
664
+ packageName: 'atlaspack-bundler-base',
665
+ resolveFrom: '.atlaspackrc',
666
+ keyPath: '/bundler',
667
+ },
668
+ runtimes: [],
669
+ namers: [],
670
+ optimizers: {},
671
+ compressors: {},
672
+ packagers: {},
673
+ reporters: [],
674
+ validators: {},
675
+ };
676
+
677
+ // $FlowFixMe
678
+ assert.deepEqual(mergeConfigs(base, ext), merged);
679
+ });
680
+ });
681
+
682
+ describe('resolveExtends', () => {
683
+ it('should resolve a relative path', async () => {
684
+ let resolved = await resolveExtends(
685
+ '../.atlaspackrc',
686
+ path.join(__dirname, 'fixtures', 'config', 'subfolder', '.atlaspackrc'),
687
+ '/extends',
688
+ DEFAULT_OPTIONS,
689
+ );
690
+ assert.equal(
691
+ resolved,
692
+ path.join(__dirname, 'fixtures', 'config', '.atlaspackrc'),
693
+ );
694
+ });
695
+
696
+ it('should resolve a package name', async () => {
697
+ let resolved = await resolveExtends(
698
+ '@atlaspack/config-default',
699
+ path.join(__dirname, 'fixtures', 'config', 'subfolder', '.atlaspackrc'),
700
+ '/extends',
701
+ DEFAULT_OPTIONS,
702
+ );
703
+ assert.equal(resolved, require.resolve('@atlaspack/config-default'));
704
+ });
705
+ });
706
+
707
+ describe('parseAndProcessConfig', () => {
708
+ it('should load and merge configs', async () => {
709
+ let defaultConfigPath = require.resolve('@atlaspack/config-default');
710
+ let defaultConfig = await processConfig(
711
+ {
712
+ ...require('@atlaspack/config-default'),
713
+ filePath: defaultConfigPath,
714
+ },
715
+ DEFAULT_OPTIONS,
716
+ );
717
+ let configFilePath = path.join(
718
+ __dirname,
719
+ 'fixtures',
720
+ 'config',
721
+ '.atlaspackrc',
722
+ );
723
+ let subConfigFilePath = path.join(
724
+ __dirname,
725
+ 'fixtures',
726
+ 'config',
727
+ 'subfolder',
728
+ '.atlaspackrc',
729
+ );
730
+ let {config} = await parseAndProcessConfig(
731
+ subConfigFilePath,
732
+ DEFAULT_OPTIONS.inputFS.readFileSync(subConfigFilePath, 'utf8'),
733
+ DEFAULT_OPTIONS,
734
+ );
735
+
736
+ let transformers = nullthrows(config.transformers);
737
+ assert.deepEqual(transformers['*.js'], [
738
+ {
739
+ packageName: 'atlaspack-transformer-sub',
740
+ resolveFrom: relative(subConfigFilePath),
741
+ keyPath: '/transformers/*.js/0',
742
+ },
743
+ {
744
+ packageName: 'atlaspack-transformer-base',
745
+ resolveFrom: relative(configFilePath),
746
+ keyPath: '/transformers/*.js/0',
747
+ },
748
+ '...',
749
+ ]);
750
+ assert(Object.keys(transformers).length > 1);
751
+ assert.deepEqual(config.resolvers, defaultConfig.resolvers);
752
+ assert.deepEqual(config.bundler, defaultConfig.bundler);
753
+ assert.deepEqual(config.namers, defaultConfig.namers || []);
754
+ assert.deepEqual(config.packagers, defaultConfig.packagers || {});
755
+ assert.deepEqual(config.optimizers, defaultConfig.optimizers || {});
756
+ assert.deepEqual(config.reporters, defaultConfig.reporters || []);
757
+ });
758
+
759
+ it('should emit a codeframe.codeHighlights when a malformed .atlaspackrc was found', async () => {
760
+ let configFilePath = path.join(
761
+ __dirname,
762
+ 'fixtures',
763
+ 'config-malformed',
764
+ '.atlaspackrc',
765
+ );
766
+ let code = await DEFAULT_OPTIONS.inputFS.readFile(configFilePath, 'utf8');
767
+
768
+ let pos = {
769
+ line: 2,
770
+ column: 14,
771
+ };
772
+
773
+ // $FlowFixMe[prop-missing]
774
+ await assert.rejects(
775
+ () => parseAndProcessConfig(configFilePath, code, DEFAULT_OPTIONS),
776
+ {
777
+ name: 'Error',
778
+ diagnostics: [
779
+ {
780
+ message: 'Failed to parse .atlaspackrc',
781
+ origin: '@atlaspack/core',
782
+ codeFrames: [
783
+ {
784
+ filePath: configFilePath,
785
+ language: 'json5',
786
+ code,
787
+ codeHighlights: [
788
+ {
789
+ message: "JSON5: invalid character 'b' at 2:14",
790
+ start: pos,
791
+ end: pos,
792
+ },
793
+ ],
794
+ },
795
+ ],
796
+ },
797
+ ],
798
+ },
799
+ );
800
+ });
801
+
802
+ it('should emit a codeframe when an extended atlaspack config file is not found', async () => {
803
+ let configFilePath = path.join(
804
+ __dirname,
805
+ 'fixtures',
806
+ 'config-extends-not-found',
807
+ '.atlaspackrc',
808
+ );
809
+ let code = await DEFAULT_OPTIONS.inputFS.readFile(configFilePath, 'utf8');
810
+
811
+ // $FlowFixMe[prop-missing]
812
+ await assert.rejects(
813
+ () => parseAndProcessConfig(configFilePath, code, DEFAULT_OPTIONS),
814
+ {
815
+ name: 'Error',
816
+ diagnostics: [
817
+ {
818
+ message: 'Cannot find extended atlaspack config',
819
+ origin: '@atlaspack/core',
820
+ codeFrames: [
821
+ {
822
+ filePath: configFilePath,
823
+ language: 'json5',
824
+ code,
825
+ codeHighlights: [
826
+ {
827
+ message:
828
+ '"./.atlaspckrc-node-modules" does not exist, did you mean "./.atlaspackrc-node-modules"?',
829
+ start: {line: 2, column: 14},
830
+ end: {line: 2, column: 41},
831
+ },
832
+ ],
833
+ },
834
+ ],
835
+ },
836
+ ],
837
+ },
838
+ );
839
+ });
840
+
841
+ it('should emit a codeframe when an extended atlaspack config file is not found in JSON5', async () => {
842
+ let configFilePath = path.join(
843
+ __dirname,
844
+ 'fixtures',
845
+ 'config-extends-not-found',
846
+ '.atlaspackrc-json5',
847
+ );
848
+ let code = await DEFAULT_OPTIONS.inputFS.readFile(configFilePath, 'utf8');
849
+
850
+ // $FlowFixMe[prop-missing]
851
+ await assert.rejects(
852
+ () => parseAndProcessConfig(configFilePath, code, DEFAULT_OPTIONS),
853
+ {
854
+ name: 'Error',
855
+ diagnostics: [
856
+ {
857
+ message: 'Cannot find extended atlaspack config',
858
+ origin: '@atlaspack/core',
859
+ codeFrames: [
860
+ {
861
+ filePath: configFilePath,
862
+ language: 'json5',
863
+ code,
864
+ codeHighlights: [
865
+ {
866
+ message:
867
+ '"./.atlaspckrc-node-modules" does not exist, did you mean "./.atlaspackrc-node-modules"?',
868
+ start: {line: 2, column: 12},
869
+ end: {line: 2, column: 39},
870
+ },
871
+ ],
872
+ },
873
+ ],
874
+ },
875
+ ],
876
+ },
877
+ );
878
+ });
879
+
880
+ it('should emit a codeframe when an extended atlaspack config node module is not found', async () => {
881
+ let configFilePath = path.join(
882
+ __dirname,
883
+ 'fixtures',
884
+ 'config-extends-not-found',
885
+ '.atlaspackrc-node-modules',
886
+ );
887
+ let code = await DEFAULT_OPTIONS.inputFS.readFile(configFilePath, 'utf8');
888
+
889
+ // $FlowFixMe[prop-missing]
890
+ await assert.rejects(
891
+ () => parseAndProcessConfig(configFilePath, code, DEFAULT_OPTIONS),
892
+ {
893
+ name: 'Error',
894
+ diagnostics: [
895
+ {
896
+ message: 'Cannot find extended atlaspack config',
897
+ origin: '@atlaspack/core',
898
+ codeFrames: [
899
+ {
900
+ filePath: configFilePath,
901
+ language: 'json5',
902
+ code,
903
+ codeHighlights: [
904
+ {
905
+ message:
906
+ 'Cannot find module "@atlaspack/config-deflt", did you mean "@atlaspack/config-default"?',
907
+ start: {line: 2, column: 14},
908
+ end: {line: 2, column: 38},
909
+ },
910
+ ],
911
+ },
912
+ ],
913
+ },
914
+ ],
915
+ },
916
+ );
917
+ });
918
+
919
+ it('should emit multiple codeframes when multiple extended configs are not found', async () => {
920
+ let configFilePath = path.join(
921
+ __dirname,
922
+ 'fixtures',
923
+ 'config-extends-not-found',
924
+ '.atlaspackrc-multiple',
925
+ );
926
+ let code = await DEFAULT_OPTIONS.inputFS.readFile(configFilePath, 'utf8');
927
+
928
+ // $FlowFixMe[prop-missing]
929
+ await assert.rejects(
930
+ () => parseAndProcessConfig(configFilePath, code, DEFAULT_OPTIONS),
931
+ {
932
+ name: 'Error',
933
+ diagnostics: [
934
+ {
935
+ message: 'Cannot find extended atlaspack config',
936
+ origin: '@atlaspack/core',
937
+ codeFrames: [
938
+ {
939
+ filePath: configFilePath,
940
+ language: 'json5',
941
+ code,
942
+ codeHighlights: [
943
+ {
944
+ message:
945
+ 'Cannot find module "@atlaspack/config-deflt", did you mean "@atlaspack/config-default"?',
946
+ start: {line: 2, column: 15},
947
+ end: {line: 2, column: 39},
948
+ },
949
+ ],
950
+ },
951
+ ],
952
+ },
953
+ {
954
+ message: 'Cannot find extended atlaspack config',
955
+ origin: '@atlaspack/core',
956
+ codeFrames: [
957
+ {
958
+ filePath: configFilePath,
959
+ language: 'json5',
960
+ code,
961
+ codeHighlights: [
962
+ {
963
+ message:
964
+ '"./.atlaspckrc" does not exist, did you mean "./.atlaspackrc"?',
965
+ start: {line: 2, column: 42},
966
+ end: {line: 2, column: 56},
967
+ },
968
+ ],
969
+ },
970
+ ],
971
+ },
972
+ ],
973
+ },
974
+ );
975
+ });
976
+ });
977
+
978
+ describe('resolve', () => {
979
+ it('should return null if there is no .atlaspackrc file found', async () => {
980
+ let resolved = await resolveAtlaspackConfig(DEFAULT_OPTIONS);
981
+ assert.equal(resolved, null);
982
+ });
983
+
984
+ it('should resolve a config if a .atlaspackrc file is found', async () => {
985
+ let resolved = await resolveAtlaspackConfig({
986
+ ...DEFAULT_OPTIONS,
987
+ projectRoot: path.join(__dirname, 'fixtures', 'config', 'subfolder'),
988
+ });
989
+
990
+ assert(resolved !== null);
991
+ });
992
+ });
993
+ });