(build: EsbuildPluginBuild)
| 1341 | }) |
| 1342 | } |
| 1343 | const resolveEsbuildRuntime = (build: EsbuildPluginBuild) => { |
| 1344 | // esbuild loads stdin as written, which the runtime runs only where it defines no Type |
| 1345 | const stdinProblemOf = async (specifier: string) => { |
| 1346 | if (!resolvesToRuntime(specifier, opts)) return |
| 1347 | const stdin = stdinEntryOf(build.initialOptions)! |
| 1348 | const transformed = (await request( |
| 1349 | "transform", |
| 1350 | stdin.source, |
| 1351 | stdin.id |
| 1352 | )) as TransformedModule | undefined |
| 1353 | if (transformed?.code || transformed?.errors.length) |
| 1354 | return untransformedProblemOf(specifier, "<stdin>", "") |
| 1355 | } |
| 1356 | build.onResolve( |
| 1357 | { |
| 1358 | filter: |
| 1359 | isStandalone ? |
| 1360 | specifiersOf( |
| 1361 | ...runtimeSpecifiers, |
| 1362 | "arktype/runtime", |
| 1363 | "arktype/internal" |
| 1364 | ) |
| 1365 | : specifiersOf("arktype/runtime", ...internalSpecifiers) |
| 1366 | }, |
| 1367 | async args => { |
| 1368 | if (args.pluginData === esbuildResolution) return |
| 1369 | const isRuntime = runtimeSpecifiers.includes(args.path) |
| 1370 | const result = await build.resolve( |
| 1371 | ( |
| 1372 | !isRuntime || |
| 1373 | !resolvesToRuntime(args.path, opts) || |
| 1374 | readsNodes(args.importer) |
| 1375 | ) ? |
| 1376 | args.path |
| 1377 | : runsOnArktype(args.importer, opts?.dependencies) ? |
| 1378 | islandDependencySpecifier |
| 1379 | : "arktype/runtime", |
| 1380 | { |
| 1381 | kind: args.kind, |
| 1382 | importer: args.importer, |
| 1383 | // a virtual module has no directory of its own |
| 1384 | resolveDir: |
| 1385 | args.importer in importersById ? |
| 1386 | dirname(importersById[args.importer]) |
| 1387 | : args.resolveDir, |
| 1388 | pluginData: esbuildResolution |
| 1389 | } |
| 1390 | ) |
| 1391 | const { errors, warnings } = |
| 1392 | isRuntime ? await readDependency(args.importer) : noDiagnostics() |
| 1393 | reportUnsafe(precompiledProblemOf(args.path, args.importer), { |
| 1394 | errors, |
| 1395 | warnings |
| 1396 | }) |
| 1397 | if (isRuntime) { |
| 1398 | reportUnsafe( |
| 1399 | isStdinOf(build.initialOptions, args) ? |
| 1400 | await stdinProblemOf(args.path) |
no test coverage detected