@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,298 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _diagnostic() {
8
+ const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
9
+ _diagnostic = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _json() {
15
+ const data = _interopRequireDefault(require("json5"));
16
+ _json = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _utils() {
22
+ const data = require("@atlaspack/utils");
23
+ _utils = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _path() {
29
+ const data = require("path");
30
+ _path = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ var _loadAtlaspackPlugin = _interopRequireDefault(require("./loadAtlaspackPlugin"));
36
+ var _projectPath = require("./projectPath");
37
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
+ 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); }
39
+ 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; }
40
+ class AtlaspackConfig {
41
+ constructor(config, options) {
42
+ this.options = options;
43
+ this.filePath = config.filePath;
44
+ this.resolvers = config.resolvers || [];
45
+ this.transformers = config.transformers || {};
46
+ this.runtimes = config.runtimes || [];
47
+ this.bundler = config.bundler;
48
+ this.namers = config.namers || [];
49
+ this.packagers = config.packagers || {};
50
+ this.optimizers = config.optimizers || {};
51
+ this.compressors = config.compressors || {};
52
+ this.reporters = config.reporters || [];
53
+ this.validators = config.validators || {};
54
+ this.pluginCache = new Map();
55
+ this.regexCache = new Map();
56
+ }
57
+ static deserialize(serialized) {
58
+ return new AtlaspackConfig(serialized.config, serialized.options);
59
+ }
60
+ getConfig() {
61
+ return {
62
+ filePath: this.filePath,
63
+ resolvers: this.resolvers,
64
+ transformers: this.transformers,
65
+ validators: this.validators,
66
+ runtimes: this.runtimes,
67
+ bundler: this.bundler,
68
+ namers: this.namers,
69
+ packagers: this.packagers,
70
+ optimizers: this.optimizers,
71
+ compressors: this.compressors,
72
+ reporters: this.reporters
73
+ };
74
+ }
75
+ serialize() {
76
+ return {
77
+ $$raw: false,
78
+ config: this.getConfig(),
79
+ options: this.options
80
+ };
81
+ }
82
+ _loadPlugin(node) {
83
+ let plugin = this.pluginCache.get(node.packageName);
84
+ if (plugin) {
85
+ return plugin;
86
+ }
87
+ plugin = (0, _loadAtlaspackPlugin.default)(node.packageName, (0, _projectPath.fromProjectPath)(this.options.projectRoot, node.resolveFrom), node.keyPath, this.options);
88
+ this.pluginCache.set(node.packageName, plugin);
89
+ return plugin;
90
+ }
91
+ async loadPlugin(node) {
92
+ let plugin = await this._loadPlugin(node);
93
+ return {
94
+ ...plugin,
95
+ name: node.packageName,
96
+ keyPath: node.keyPath
97
+ };
98
+ }
99
+ invalidatePlugin(packageName) {
100
+ this.pluginCache.delete(packageName);
101
+ }
102
+ loadPlugins(plugins) {
103
+ return Promise.all(plugins.map(p => this.loadPlugin(p)));
104
+ }
105
+ async getResolvers() {
106
+ if (this.resolvers.length === 0) {
107
+ throw await this.missingPluginError(this.resolvers, 'No resolver plugins specified in .atlaspackrc config', '/resolvers');
108
+ }
109
+ return this.loadPlugins(this.resolvers);
110
+ }
111
+ _getValidatorNodes(filePath) {
112
+ let validators = this.matchGlobMapPipelines(filePath, this.validators) || [];
113
+ return validators;
114
+ }
115
+ getValidatorNames(filePath) {
116
+ let validators = this._getValidatorNodes(filePath);
117
+ return validators.map(v => v.packageName);
118
+ }
119
+ getValidators(filePath) {
120
+ let validators = this._getValidatorNodes(filePath);
121
+ return this.loadPlugins(validators);
122
+ }
123
+ getNamedPipelines() {
124
+ return Object.keys(this.transformers).filter(glob => glob.includes(':')).map(glob => glob.split(':')[0]);
125
+ }
126
+ async getTransformers(filePath, pipeline, allowEmpty) {
127
+ let transformers = this.matchGlobMapPipelines(filePath, this.transformers, pipeline);
128
+ if (!transformers || transformers.length === 0) {
129
+ if (allowEmpty) {
130
+ return [];
131
+ }
132
+ throw await this.missingPluginError(this.transformers, (0, _diagnostic().md)`No transformers found for __${(0, _projectPath.fromProjectPathRelative)(filePath)}__` + (pipeline != null ? ` with pipeline: '${pipeline}'` : '') + '.', '/transformers');
133
+ }
134
+ return this.loadPlugins(transformers);
135
+ }
136
+ async getBundler() {
137
+ if (!this.bundler) {
138
+ throw await this.missingPluginError([], 'No bundler specified in .atlaspackrc config', '/bundler');
139
+ }
140
+ return this.loadPlugin(this.bundler);
141
+ }
142
+ async getNamers() {
143
+ if (this.namers.length === 0) {
144
+ throw await this.missingPluginError(this.namers, 'No namer plugins specified in .atlaspackrc config', '/namers');
145
+ }
146
+ return this.loadPlugins(this.namers);
147
+ }
148
+ getRuntimes() {
149
+ if (!this.runtimes) {
150
+ return Promise.resolve([]);
151
+ }
152
+ return this.loadPlugins(this.runtimes);
153
+ }
154
+ async getPackager(filePath) {
155
+ let packager = this.matchGlobMap((0, _projectPath.toProjectPathUnsafe)(filePath), this.packagers);
156
+ if (!packager) {
157
+ throw await this.missingPluginError(this.packagers, (0, _diagnostic().md)`No packager found for __${filePath}__.`, '/packagers');
158
+ }
159
+ return this.loadPlugin(packager);
160
+ }
161
+ _getOptimizerNodes(filePath, pipeline) {
162
+ // If a pipeline is specified, but it doesn't exist in the optimizers config, ignore it.
163
+ // Pipelines for bundles come from their entry assets, so the pipeline likely exists in transformers.
164
+ if (pipeline) {
165
+ let prefix = pipeline + ':';
166
+ if (!Object.keys(this.optimizers).some(glob => glob.startsWith(prefix))) {
167
+ pipeline = null;
168
+ }
169
+ }
170
+ return this.matchGlobMapPipelines((0, _projectPath.toProjectPathUnsafe)(filePath), this.optimizers, pipeline) ?? [];
171
+ }
172
+ getOptimizerNames(filePath, pipeline) {
173
+ let optimizers = this._getOptimizerNodes(filePath, pipeline);
174
+ return optimizers.map(o => o.packageName);
175
+ }
176
+ getOptimizers(filePath, pipeline) {
177
+ let optimizers = this._getOptimizerNodes(filePath, pipeline);
178
+ if (optimizers.length === 0) {
179
+ return Promise.resolve([]);
180
+ }
181
+ return this.loadPlugins(optimizers);
182
+ }
183
+ async getCompressors(filePath) {
184
+ let compressors = this.matchGlobMapPipelines((0, _projectPath.toProjectPathUnsafe)(filePath), this.compressors) ?? [];
185
+ if (compressors.length === 0) {
186
+ throw await this.missingPluginError(this.compressors, (0, _diagnostic().md)`No compressors found for __${filePath}__.`, '/compressors');
187
+ }
188
+ return this.loadPlugins(compressors);
189
+ }
190
+ getReporters() {
191
+ return this.loadPlugins(this.reporters);
192
+ }
193
+ isGlobMatch(projectPath, pattern, pipeline) {
194
+ // glob's shouldn't be dependant on absolute paths anyway
195
+ let filePath = (0, _projectPath.fromProjectPathRelative)(projectPath);
196
+ let [patternPipeline, patternGlob] = pattern.split(':');
197
+ if (!patternGlob) {
198
+ patternGlob = patternPipeline;
199
+ patternPipeline = null;
200
+ }
201
+ let re = this.regexCache.get(patternGlob);
202
+ if (!re) {
203
+ re = (0, _utils().globToRegex)(patternGlob, {
204
+ dot: true,
205
+ nocase: true
206
+ });
207
+ this.regexCache.set(patternGlob, re);
208
+ }
209
+ return (pipeline === patternPipeline || !pipeline && !patternPipeline) && (re.test(filePath) || re.test((0, _path().basename)(filePath)));
210
+ }
211
+ matchGlobMap(filePath, globMap) {
212
+ for (let pattern in globMap) {
213
+ if (this.isGlobMatch(filePath, pattern)) {
214
+ return globMap[pattern];
215
+ }
216
+ }
217
+ return null;
218
+ }
219
+ matchGlobMapPipelines(filePath, globMap, pipeline) {
220
+ let matches = [];
221
+ if (pipeline) {
222
+ // If a pipeline is requested, a the glob needs to match exactly
223
+ let exactMatch;
224
+ for (let pattern in globMap) {
225
+ if (this.isGlobMatch(filePath, pattern, pipeline)) {
226
+ exactMatch = globMap[pattern];
227
+ break;
228
+ }
229
+ }
230
+ if (!exactMatch) {
231
+ return [];
232
+ } else {
233
+ matches.push(exactMatch);
234
+ }
235
+ }
236
+ for (let pattern in globMap) {
237
+ if (this.isGlobMatch(filePath, pattern)) {
238
+ matches.push(globMap[pattern]);
239
+ }
240
+ }
241
+ let flatten = () => {
242
+ let pipeline = matches.shift() || [];
243
+ let spreadIndex = pipeline.indexOf('...');
244
+ if (spreadIndex >= 0) {
245
+ pipeline = [...pipeline.slice(0, spreadIndex), ...flatten(), ...pipeline.slice(spreadIndex + 1)];
246
+ }
247
+ if (pipeline.includes('...')) {
248
+ throw new Error('Only one spread parameter can be included in a config pipeline');
249
+ }
250
+ return pipeline;
251
+ };
252
+ let res = flatten();
253
+ // $FlowFixMe afaik this should work
254
+ return res;
255
+ }
256
+ async missingPluginError(plugins, message, key) {
257
+ let configsWithPlugin;
258
+ if (Array.isArray(plugins)) {
259
+ configsWithPlugin = new Set(getConfigPaths(this.options, plugins));
260
+ } else {
261
+ configsWithPlugin = new Set(Object.keys(plugins).flatMap(k => Array.isArray(plugins[k]) ? getConfigPaths(this.options, plugins[k]) : [getConfigPath(this.options, plugins[k])]));
262
+ }
263
+ if (configsWithPlugin.size === 0) {
264
+ configsWithPlugin.add((0, _projectPath.fromProjectPath)(this.options.projectRoot, this.filePath));
265
+ }
266
+ let seenKey = false;
267
+ let codeFrames = await Promise.all([...configsWithPlugin].map(async filePath => {
268
+ let configContents = await this.options.inputFS.readFile(filePath, 'utf8');
269
+ if (!_json().default.parse(configContents)[key.slice(1)]) {
270
+ key = '';
271
+ } else {
272
+ seenKey = true;
273
+ }
274
+ return {
275
+ filePath,
276
+ code: configContents,
277
+ codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(configContents, [{
278
+ key
279
+ }])
280
+ };
281
+ }));
282
+ return new (_diagnostic().default)({
283
+ diagnostic: {
284
+ message,
285
+ origin: '@atlaspack/core',
286
+ codeFrames,
287
+ hints: !seenKey ? ['Try extending __@atlaspack/config-default__'] : []
288
+ }
289
+ });
290
+ }
291
+ }
292
+ exports.default = AtlaspackConfig;
293
+ function getConfigPaths(options, nodes) {
294
+ return nodes.map(node => node !== '...' ? getConfigPath(options, node) : null).filter(Boolean);
295
+ }
296
+ function getConfigPath(options, node) {
297
+ return (0, _projectPath.fromProjectPath)(options.projectRoot, node.resolveFrom);
298
+ }
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ exports.validatePackageName = validatePackageName;
8
+ function _assert() {
9
+ const data = _interopRequireDefault(require("assert"));
10
+ _assert = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ // Reasoning behind this validation:
17
+ // https://github.com/parcel-bundler/parcel/issues/3397#issuecomment-521353931
18
+ function validatePackageName(pkg, pluginType, key) {
19
+ // $FlowFixMe
20
+ if (!pkg) {
21
+ return;
22
+ }
23
+ (0, _assert().default)(typeof pkg === 'string', `"${key}" must be a string`);
24
+ if (pkg.startsWith('@atlaspack')) {
25
+ (0, _assert().default)(pkg.replace(/^@atlaspack\//, '').startsWith(`${pluginType}-`), `Official atlaspack ${pluginType} packages must be named according to "@atlaspack/${pluginType}-{name}"`);
26
+ } else if (pkg.startsWith('@')) {
27
+ // Disabling this validation to allow for migration to atlaspack
28
+ // let [scope, name] = pkg.split('/');
29
+ // assert(
30
+ // name.startsWith(`atlaspack-${pluginType}-`) ||
31
+ // name === `atlaspack-${pluginType}` ||
32
+ // name.startsWith(`parcel-${pluginType}-`) ||
33
+ // name === `parcel-${pluginType}`,
34
+ // `Scoped atlaspack ${pluginType} packages must be named according to "${scope}/atlaspack-${pluginType}[-{name}]"`,
35
+ // );
36
+ } else if (!pkg.startsWith('.')) {
37
+ (0, _assert().default)(pkg.startsWith(`atlaspack-${pluginType}-`), `Atlaspack ${pluginType} packages must be named according to "atlaspack-${pluginType}-{name}"`);
38
+ }
39
+ }
40
+ const validatePluginName = (pluginType, key) => {
41
+ return val => {
42
+ // allow plugin spread...
43
+ if (val === '...') return;
44
+ try {
45
+ validatePackageName(val, pluginType, key);
46
+ } catch (e) {
47
+ return e.message;
48
+ }
49
+ };
50
+ };
51
+ const validateExtends = val => {
52
+ // allow relative paths...
53
+ if (val.startsWith('.')) return;
54
+ try {
55
+ validatePackageName(val, 'config', 'extends');
56
+ } catch (e) {
57
+ return e.message;
58
+ }
59
+ };
60
+ const pipelineSchema = (pluginType, key) => {
61
+ return {
62
+ type: 'array',
63
+ items: {
64
+ type: 'string',
65
+ __validate: validatePluginName(pluginType, key)
66
+ }
67
+ };
68
+ };
69
+ const mapPipelineSchema = (pluginType, key) => {
70
+ return {
71
+ type: 'object',
72
+ properties: {},
73
+ additionalProperties: pipelineSchema(pluginType, key)
74
+ };
75
+ };
76
+ const mapStringSchema = (pluginType, key) => {
77
+ return {
78
+ type: 'object',
79
+ properties: {},
80
+ additionalProperties: {
81
+ type: 'string',
82
+ __validate: validatePluginName(pluginType, key)
83
+ }
84
+ };
85
+ };
86
+ var _default = exports.default = {
87
+ type: 'object',
88
+ properties: {
89
+ $schema: {
90
+ type: 'string'
91
+ },
92
+ extends: {
93
+ oneOf: [{
94
+ type: 'string',
95
+ __validate: validateExtends
96
+ }, {
97
+ type: 'array',
98
+ items: {
99
+ type: 'string',
100
+ __validate: validateExtends
101
+ }
102
+ }]
103
+ },
104
+ bundler: {
105
+ type: 'string',
106
+ __validate: validatePluginName('bundler', 'bundler')
107
+ },
108
+ resolvers: pipelineSchema('resolver', 'resolvers'),
109
+ transformers: mapPipelineSchema('transformer', 'transformers'),
110
+ validators: mapPipelineSchema('validator', 'validators'),
111
+ namers: pipelineSchema('namer', 'namers'),
112
+ packagers: mapStringSchema('packager', 'packagers'),
113
+ optimizers: mapPipelineSchema('optimizer', 'optimizers'),
114
+ compressors: mapPipelineSchema('compressor', 'compressors'),
115
+ reporters: pipelineSchema('reporter', 'reporters'),
116
+ runtimes: pipelineSchema('runtime', 'runtimes'),
117
+ filePath: {
118
+ type: 'string'
119
+ },
120
+ resolveFrom: {
121
+ type: 'string'
122
+ }
123
+ },
124
+ additionalProperties: false
125
+ };