@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,454 @@
1
+ // @flow strict-local
2
+ import type {Diagnostic} from '@atlaspack/diagnostic';
3
+ import type {
4
+ Async,
5
+ FileCreateInvalidation,
6
+ FilePath,
7
+ Resolver,
8
+ } from '@atlaspack/types';
9
+ import type {StaticRunOpts} from '../RequestTracker';
10
+ import type {
11
+ AssetGroup,
12
+ Config,
13
+ Dependency,
14
+ DevDepRequest,
15
+ AtlaspackOptions,
16
+ } from '../types';
17
+ import type {ConfigAndCachePath} from './AtlaspackConfigRequest';
18
+
19
+ import ThrowableDiagnostic, {
20
+ convertSourceLocationToHighlight,
21
+ errorToDiagnostic,
22
+ md,
23
+ } from '@atlaspack/diagnostic';
24
+ import {PluginLogger} from '@atlaspack/logger';
25
+ import nullthrows from 'nullthrows';
26
+ import path from 'path';
27
+ import {normalizePath} from '@atlaspack/utils';
28
+ import {report} from '../ReporterRunner';
29
+ import {getPublicDependency} from '../public/Dependency';
30
+ import PluginOptions from '../public/PluginOptions';
31
+ import AtlaspackConfig from '../AtlaspackConfig';
32
+ import createAtlaspackConfigRequest, {
33
+ getCachedAtlaspackConfig,
34
+ } from './AtlaspackConfigRequest';
35
+ import {invalidateOnFileCreateToInternal} from '../utils';
36
+ import {
37
+ fromProjectPath,
38
+ fromProjectPathRelative,
39
+ toProjectPath,
40
+ toProjectPathUnsafe,
41
+ } from '../projectPath';
42
+ import {Priority} from '../types';
43
+ import {createBuildCache} from '../buildCache';
44
+ import type {LoadedPlugin} from '../AtlaspackConfig';
45
+ import {createConfig} from '../InternalConfig';
46
+ import {loadPluginConfig, runConfigRequest} from './ConfigRequest';
47
+ import {
48
+ createDevDependency,
49
+ getDevDepRequests,
50
+ invalidateDevDeps,
51
+ runDevDepRequest,
52
+ } from './DevDepRequest';
53
+ import {tracer, PluginTracer} from '@atlaspack/profiler';
54
+ import {requestTypes} from '../RequestTracker';
55
+
56
+ export type PathRequest = {|
57
+ id: string,
58
+ +type: typeof requestTypes.path_request,
59
+ run: (RunOpts<PathRequestResult>) => Async<PathRequestResult>,
60
+ input: PathRequestInput,
61
+ |};
62
+
63
+ export type PathRequestResult = null | void | AssetGroup;
64
+
65
+ export type PathRequestInput = {|
66
+ dependency: Dependency,
67
+ name: string,
68
+ |};
69
+
70
+ type RunOpts<TResult> = {|
71
+ input: PathRequestInput,
72
+ ...StaticRunOpts<TResult>,
73
+ |};
74
+
75
+ const PIPELINE_REGEX = /^([a-z0-9-]+?):(.*)$/i;
76
+
77
+ export default function createPathRequest(
78
+ input: PathRequestInput,
79
+ ): PathRequest {
80
+ return {
81
+ id: input.dependency.id + ':' + input.name,
82
+ type: requestTypes.path_request,
83
+ run,
84
+ input,
85
+ };
86
+ }
87
+
88
+ async function run({input, api, options}): Promise<PathRequestResult> {
89
+ let configResult = nullthrows(
90
+ await api.runRequest<null, ConfigAndCachePath>(
91
+ createAtlaspackConfigRequest(),
92
+ ),
93
+ );
94
+ let config = getCachedAtlaspackConfig(configResult, options);
95
+ let {devDeps, invalidDevDeps} = await getDevDepRequests(api);
96
+ invalidateDevDeps(invalidDevDeps, options, config);
97
+ let resolverRunner = new ResolverRunner({
98
+ options,
99
+ config,
100
+ previousDevDeps: devDeps,
101
+ });
102
+ let result: ResolverResult = await resolverRunner.resolve(input.dependency);
103
+
104
+ if (result.invalidateOnEnvChange) {
105
+ for (let env of result.invalidateOnEnvChange) {
106
+ api.invalidateOnEnvChange(env);
107
+ }
108
+ }
109
+
110
+ if (result.invalidateOnFileCreate) {
111
+ for (let file of result.invalidateOnFileCreate) {
112
+ api.invalidateOnFileCreate(
113
+ invalidateOnFileCreateToInternal(options.projectRoot, file),
114
+ );
115
+ }
116
+ }
117
+
118
+ if (result.invalidateOnFileChange) {
119
+ for (let filePath of result.invalidateOnFileChange) {
120
+ let pp = toProjectPath(options.projectRoot, filePath);
121
+ api.invalidateOnFileUpdate(pp);
122
+ api.invalidateOnFileDelete(pp);
123
+ }
124
+ }
125
+
126
+ for (let config of resolverRunner.configs.values()) {
127
+ await runConfigRequest(api, config);
128
+ }
129
+
130
+ for (let devDepRequest of resolverRunner.devDepRequests.values()) {
131
+ await runDevDepRequest(api, devDepRequest);
132
+ }
133
+
134
+ if (result.assetGroup) {
135
+ api.invalidateOnFileDelete(result.assetGroup.filePath);
136
+ return result.assetGroup;
137
+ }
138
+
139
+ if (result.diagnostics && result.diagnostics.length > 0) {
140
+ let err = new ThrowableDiagnostic({diagnostic: result.diagnostics});
141
+ // $FlowFixMe[prop-missing]
142
+ err.code = 'MODULE_NOT_FOUND';
143
+ throw err;
144
+ }
145
+ }
146
+
147
+ type ResolverRunnerOpts = {|
148
+ config: AtlaspackConfig,
149
+ options: AtlaspackOptions,
150
+ previousDevDeps: Map<string, string>,
151
+ |};
152
+
153
+ type ResolverResult = {|
154
+ assetGroup: ?AssetGroup,
155
+ invalidateOnFileCreate?: Array<FileCreateInvalidation>,
156
+ invalidateOnFileChange?: Array<FilePath>,
157
+ invalidateOnEnvChange?: Array<string>,
158
+ diagnostics?: Array<Diagnostic>,
159
+ |};
160
+
161
+ const configCache = createBuildCache();
162
+
163
+ export class ResolverRunner {
164
+ config: AtlaspackConfig;
165
+ options: AtlaspackOptions;
166
+ pluginOptions: PluginOptions;
167
+ previousDevDeps: Map<string, string>;
168
+ devDepRequests: Map<string, DevDepRequest>;
169
+ configs: Map<string, Config>;
170
+
171
+ constructor({config, options, previousDevDeps}: ResolverRunnerOpts) {
172
+ this.config = config;
173
+ this.options = options;
174
+ this.pluginOptions = new PluginOptions(this.options);
175
+ this.previousDevDeps = previousDevDeps;
176
+ this.devDepRequests = new Map();
177
+ this.configs = new Map();
178
+ }
179
+
180
+ async getDiagnostic(
181
+ dependency: Dependency,
182
+ message: string,
183
+ ): Async<Diagnostic> {
184
+ let diagnostic: Diagnostic = {
185
+ message,
186
+ origin: '@atlaspack/core',
187
+ };
188
+
189
+ if (dependency.loc && dependency.sourcePath != null) {
190
+ let filePath = fromProjectPath(
191
+ this.options.projectRoot,
192
+ dependency.sourcePath,
193
+ );
194
+ diagnostic.codeFrames = [
195
+ {
196
+ filePath,
197
+ code: await this.options.inputFS
198
+ .readFile(filePath, 'utf8')
199
+ .catch(() => ''),
200
+ codeHighlights: dependency.loc
201
+ ? [convertSourceLocationToHighlight(dependency.loc)]
202
+ : [],
203
+ },
204
+ ];
205
+ }
206
+
207
+ return diagnostic;
208
+ }
209
+
210
+ async loadConfigs(
211
+ resolvers: Array<LoadedPlugin<Resolver<mixed>>>,
212
+ ): Promise<void> {
213
+ for (let plugin of resolvers) {
214
+ // Only load config for a plugin once per build.
215
+ let config = configCache.get(plugin.name);
216
+ if (!config && plugin.plugin.loadConfig != null) {
217
+ config = createConfig({
218
+ plugin: plugin.name,
219
+ searchPath: toProjectPathUnsafe('index'),
220
+ });
221
+
222
+ await loadPluginConfig(plugin, config, this.options);
223
+ configCache.set(plugin.name, config);
224
+ this.configs.set(plugin.name, config);
225
+ }
226
+
227
+ if (config) {
228
+ for (let devDep of config.devDeps) {
229
+ let devDepRequest = await createDevDependency(
230
+ devDep,
231
+ this.previousDevDeps,
232
+ this.options,
233
+ );
234
+ this.runDevDepRequest(devDepRequest);
235
+ }
236
+
237
+ this.configs.set(plugin.name, config);
238
+ }
239
+ }
240
+ }
241
+
242
+ runDevDepRequest(devDepRequest: DevDepRequest) {
243
+ let {specifier, resolveFrom} = devDepRequest;
244
+ let key = `${specifier}:${fromProjectPathRelative(resolveFrom)}`;
245
+ this.devDepRequests.set(key, devDepRequest);
246
+ }
247
+
248
+ async resolve(dependency: Dependency): Promise<ResolverResult> {
249
+ let dep = getPublicDependency(dependency, this.options);
250
+ report({
251
+ type: 'buildProgress',
252
+ phase: 'resolving',
253
+ dependency: dep,
254
+ });
255
+
256
+ let resolvers = await this.config.getResolvers();
257
+ await this.loadConfigs(resolvers);
258
+
259
+ let pipeline;
260
+ let specifier;
261
+ let validPipelines = new Set(this.config.getNamedPipelines());
262
+ let match = dependency.specifier.match(PIPELINE_REGEX);
263
+ if (
264
+ match &&
265
+ // Don't consider absolute paths. Absolute paths are only supported for entries,
266
+ // and include e.g. `C:\` on Windows, conflicting with pipelines.
267
+ !path.isAbsolute(dependency.specifier)
268
+ ) {
269
+ [, pipeline, specifier] = match;
270
+ if (!validPipelines.has(pipeline)) {
271
+ // This may be a url protocol or scheme rather than a pipeline, such as
272
+ // `url('http://example.com/foo.png')`. Pass it to resolvers to handle.
273
+ specifier = dependency.specifier;
274
+ pipeline = null;
275
+ }
276
+ } else {
277
+ specifier = dependency.specifier;
278
+ }
279
+
280
+ // Entrypoints, convert ProjectPath in module specifier to absolute path
281
+ if (dep.resolveFrom == null) {
282
+ specifier = path.join(this.options.projectRoot, specifier);
283
+ }
284
+ let diagnostics: Array<Diagnostic> = [];
285
+ let invalidateOnFileCreate = [];
286
+ let invalidateOnFileChange = [];
287
+ let invalidateOnEnvChange = [];
288
+ for (let resolver of resolvers) {
289
+ let measurement;
290
+ try {
291
+ measurement = tracer.createMeasurement(
292
+ resolver.name,
293
+ 'resolve',
294
+ specifier,
295
+ );
296
+ let result = await resolver.plugin.resolve({
297
+ specifier,
298
+ pipeline,
299
+ dependency: dep,
300
+ options: this.pluginOptions,
301
+ logger: new PluginLogger({origin: resolver.name}),
302
+ tracer: new PluginTracer({
303
+ origin: resolver.name,
304
+ category: 'resolver',
305
+ }),
306
+ config: this.configs.get(resolver.name)?.result,
307
+ });
308
+ measurement && measurement.end();
309
+
310
+ if (result) {
311
+ if (result.meta) {
312
+ dependency.resolverMeta = result.meta;
313
+ dependency.meta = {
314
+ ...dependency.meta,
315
+ ...result.meta,
316
+ };
317
+ }
318
+
319
+ if (result.priority != null) {
320
+ dependency.priority = Priority[result.priority];
321
+ }
322
+
323
+ if (result.invalidateOnEnvChange) {
324
+ invalidateOnEnvChange.push(...result.invalidateOnEnvChange);
325
+ }
326
+
327
+ if (result.invalidateOnFileCreate) {
328
+ invalidateOnFileCreate.push(...result.invalidateOnFileCreate);
329
+ }
330
+
331
+ if (result.invalidateOnFileChange) {
332
+ invalidateOnFileChange.push(...result.invalidateOnFileChange);
333
+ }
334
+
335
+ if (result.isExcluded) {
336
+ return {
337
+ assetGroup: null,
338
+ invalidateOnFileCreate,
339
+ invalidateOnFileChange,
340
+ invalidateOnEnvChange,
341
+ };
342
+ }
343
+
344
+ if (result.filePath != null) {
345
+ let resultFilePath = result.filePath;
346
+ if (!path.isAbsolute(resultFilePath)) {
347
+ throw new Error(
348
+ md`Resolvers must return an absolute path, ${resolver.name} returned: ${resultFilePath}`,
349
+ );
350
+ }
351
+
352
+ return {
353
+ assetGroup: {
354
+ canDefer: result.canDefer,
355
+ filePath: toProjectPath(
356
+ this.options.projectRoot,
357
+ resultFilePath,
358
+ ),
359
+ query: result.query?.toString(),
360
+ sideEffects: result.sideEffects,
361
+ code: result.code,
362
+ env: dependency.env,
363
+ pipeline:
364
+ result.pipeline === undefined
365
+ ? pipeline ?? dependency.pipeline
366
+ : result.pipeline,
367
+ isURL: dep.specifierType === 'url',
368
+ },
369
+ invalidateOnFileCreate,
370
+ invalidateOnFileChange,
371
+ invalidateOnEnvChange,
372
+ };
373
+ }
374
+
375
+ if (
376
+ result.diagnostics != null &&
377
+ !(
378
+ Array.isArray(result.diagnostics) &&
379
+ result.diagnostics.length === 0
380
+ )
381
+ ) {
382
+ let errorDiagnostic = errorToDiagnostic(
383
+ new ThrowableDiagnostic({diagnostic: result.diagnostics}),
384
+ {
385
+ origin: resolver.name,
386
+ filePath: specifier,
387
+ },
388
+ );
389
+ diagnostics.push(...errorDiagnostic);
390
+ }
391
+ }
392
+ } catch (e) {
393
+ // Add error to error map, we'll append these to the standard error if we can't resolve the asset
394
+ let errorDiagnostic = errorToDiagnostic(e, {
395
+ origin: resolver.name,
396
+ filePath: specifier,
397
+ });
398
+ if (Array.isArray(errorDiagnostic)) {
399
+ diagnostics.push(...errorDiagnostic);
400
+ } else {
401
+ diagnostics.push(errorDiagnostic);
402
+ }
403
+
404
+ break;
405
+ } finally {
406
+ measurement && measurement.end();
407
+
408
+ // Add dev dependency for the resolver. This must be done AFTER running it due to
409
+ // the potential for lazy require() that aren't executed until the request runs.
410
+ let devDepRequest = await createDevDependency(
411
+ {
412
+ specifier: resolver.name,
413
+ resolveFrom: resolver.resolveFrom,
414
+ },
415
+ this.previousDevDeps,
416
+ this.options,
417
+ );
418
+ this.runDevDepRequest(devDepRequest);
419
+ }
420
+ }
421
+
422
+ if (dep.isOptional) {
423
+ return {
424
+ assetGroup: null,
425
+ invalidateOnFileCreate,
426
+ invalidateOnFileChange,
427
+ invalidateOnEnvChange,
428
+ };
429
+ }
430
+
431
+ let resolveFrom = dependency.resolveFrom ?? dependency.sourcePath;
432
+ let dir =
433
+ resolveFrom != null
434
+ ? normalizePath(fromProjectPathRelative(resolveFrom))
435
+ : '';
436
+
437
+ let diagnostic = await this.getDiagnostic(
438
+ dependency,
439
+ md`Failed to resolve '${dependency.specifier}' ${
440
+ dir ? `from '${dir}'` : ''
441
+ }`,
442
+ );
443
+
444
+ diagnostics.unshift(diagnostic);
445
+
446
+ return {
447
+ assetGroup: null,
448
+ invalidateOnFileCreate,
449
+ invalidateOnFileChange,
450
+ invalidateOnEnvChange,
451
+ diagnostics,
452
+ };
453
+ }
454
+ }