From e154b0c778efe2be27c92f0202833db5592bbee2 Mon Sep 17 00:00:00 2001 From: Sheraff Date: Sat, 31 Oct 2026 11:06:59 +0100 Subject: [PATCH] fix(router-utils): a `name:` specifier may be a plugin's or an alias's Only `virtual:` was analysed, so a builder module behind an alias or a plugin's scheme (`app:b`) was unreadable, its export unknown, and `.handler()` shipped silently. Main follows them. Runtimes' schemes stay unread. Co-Authored-By: Claude Opus 5.5 --- packages/router-utils/src/compiler/host.ts | 21 +++++++++--------- .../start-build-builder-shapes.test.ts | 22 ++++++++++++++++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/packages/router-utils/src/compiler/host.ts b/packages/router-utils/src/compiler/host.ts index 4b0629b733..c4b09999b5 100644 --- a/packages/router-utils/src/compiler/host.ts +++ b/packages/router-utils/src/compiler/host.ts @@ -501,21 +501,20 @@ export function fingerprintSourceFor( } } +/** The schemes of what only a runtime loads (`node:fs`, `cloudflare:workers`, `data:…`). */ +const RUNTIME_SCHEME_RE = + /^(?:node|bun|deno|cloudflare|workerd|data|https?|file):/i + /** * Whether a specifier can name a module the analysis reads (a project module - * or a package). A Node builtin and a URL-scheme specifier (`node:`, `bun:`, - * `cloudflare:`, `data:`, …) never do: the bundler resolves them for the - * bundle, and asking it only for the analysis surfaces its diagnostics for - * an import the output may not keep (Vite's "externalized for browser - * compatibility" warning for a builtin a deleted handler read, G16). A - * bundler's `virtual:` module passes: it may be a project module. + * or a package). A Node builtin and a runtime's scheme never do: the bundler + * resolves them for the bundle, and asking it only for the analysis surfaces + * its diagnostics for an import the output may not keep (Vite's "externalized + * for browser compatibility" warning for a builtin a deleted handler read, + * G16). Any other `name:` may be a plugin's or an alias's. */ export function isAnalyzableSpecifier(specifier: string): boolean { - if (isBuiltin(specifier)) { - return false - } - const scheme = /^([a-z][\w+.-]+):/i.exec(specifier) - return scheme === null || scheme[1]!.toLowerCase() === 'virtual' + return !isBuiltin(specifier) && !RUNTIME_SCHEME_RE.test(specifier) } /** diff --git a/packages/start-plugin-core/tests/integration/start-build-builder-shapes.test.ts b/packages/start-plugin-core/tests/integration/start-build-builder-shapes.test.ts index df3d2766e9..fdb30e3295 100644 --- a/packages/start-plugin-core/tests/integration/start-build-builder-shapes.test.ts +++ b/packages/start-plugin-core/tests/integration/start-build-builder-shapes.test.ts @@ -6,6 +6,7 @@ import { describe, expect, test } from 'vitest' import { expectDiagnostic } from '@tanstack/compiler-test-utils/diagnostics' import { StartBuildError, buildStart, startBundlers } from '../build-harness' +import type { StartBundler } from '../build-harness' import type { RsbuildConfig } from '@rsbuild/core' import type { InlineConfig } from 'vite' @@ -22,6 +23,8 @@ interface Compiled { files: Record viteConfig?: InlineConfig rsbuildConfig?: RsbuildConfig + /** Default: every bundler. */ + bundlers?: Array } interface Refused extends Compiled { @@ -643,8 +646,25 @@ export const fn = createServerFn().handler(async () => 'MARK_SERVER_SECRET') }, ) +compiled.push( + { + name: 'a builder module under an alias with a colon', + viteConfig: { resolve: { alias: { 'app:b': '/src/b.ts' } } }, + // (Rspack refuses the scheme itself) + bundlers: ['vite'], + files: { + 'src/b.ts': `import { createServerFn } from '@tanstack/react-start' +export const base = createServerFn() +`, + 'src/entry.ts': `import { base } from 'app:b' +export const fn = base.handler(async () => 'MARK_SERVER_SECRET') +`, + }, + }, +) + describe.each(startBundlers)('%s build', (bundler) => { - test.each(compiled)( + test.each(compiled.filter((row) => row.bundlers?.includes(bundler) ?? true))( '$name compiles', async (row) => { const build = await buildStart({