refactor: 跨边界导入改用 Node # subpath imports(package.json + drizzle SQL)
业务代码沿用 @/* (shadcn 等生态约定);仅"跳出 src/"的真实跨边界场景采用 Node 标准 #name: - #package → ./package.json:替换 @/../package.json (2 处) 这种用 alias 跳出根目录的 hack - #drizzle/*.sql → ./drizzle/*.sql:让 codegen 输出的 migrations.gen.ts 不再走 ../../../ 效果: - tsconfig.paths 与 vite.resolve.tsconfigPaths 维持,业务代码 0 改动 - 配置仅新增 package.json#imports 4 行 - Bun runtime / Vite 8 / TS bundler / 编译产物均原生支持 端到端验证: - 编译二进制:CREATE TABLE 和 'fullstack-starter' 内嵌 ✓ - ./server migrate:应用嵌入式迁移成功 ✓ - ./server 运行:/health、/api/spec.json (title/version)、RPC create+list、OpenAPI create、Scalar /api/docs 全部 OK ✓ - bun run dev:Vite SSR <title>fullstack-starter</title> 注入 ✓ - fix/typecheck/test/build/compile 全绿
This commit is contained in:
+1
-2
@@ -4,7 +4,6 @@ import { z } from 'zod'
|
|||||||
|
|
||||||
const JOURNAL = './drizzle/meta/_journal.json'
|
const JOURNAL = './drizzle/meta/_journal.json'
|
||||||
const OUTPUT = './src/server/db/migrations.gen.ts'
|
const OUTPUT = './src/server/db/migrations.gen.ts'
|
||||||
const SQL_RELATIVE_FROM_OUTPUT = '../../../drizzle'
|
|
||||||
|
|
||||||
const journalEntrySchema = z.object({
|
const journalEntrySchema = z.object({
|
||||||
idx: z.number().int().nonnegative(),
|
idx: z.number().int().nonnegative(),
|
||||||
@@ -28,7 +27,7 @@ const main = async () => {
|
|||||||
const entries = await readJournalEntries()
|
const entries = await readJournalEntries()
|
||||||
|
|
||||||
const imports = entries
|
const imports = entries
|
||||||
.map((e) => `import sql_${e.idx} from '${SQL_RELATIVE_FROM_OUTPUT}/${e.tag}.sql' with { type: 'text' }`)
|
.map((e) => `import sql_${e.idx} from '#drizzle/${e.tag}.sql' with { type: 'text' }`)
|
||||||
.join('\n')
|
.join('\n')
|
||||||
|
|
||||||
const arrayBody = entries.length
|
const arrayBody = entries.length
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"imports": {
|
||||||
|
"#package": "./package.json",
|
||||||
|
"#drizzle/*.sql": "./drizzle/*.sql"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "bunx --bun vite build",
|
"build": "bunx --bun vite build",
|
||||||
"cli": "bun bin.ts",
|
"cli": "bun bin.ts",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
|
|||||||
import { createRootRouteWithContext, HeadContent, Scripts } from '@tanstack/react-router'
|
import { createRootRouteWithContext, HeadContent, Scripts } from '@tanstack/react-router'
|
||||||
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
|
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
|
||||||
import type { ReactNode } from 'react'
|
import type { ReactNode } from 'react'
|
||||||
import { name } from '@/../package.json'
|
import { name } from '#package'
|
||||||
import { ErrorComponent } from '@/components/Error'
|
import { ErrorComponent } from '@/components/Error'
|
||||||
import { NotFoundComponent } from '@/components/NotFound'
|
import { NotFoundComponent } from '@/components/NotFound'
|
||||||
import appCss from '@/styles.css?url'
|
import appCss from '@/styles.css?url'
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import { OpenAPIReferencePlugin } from '@orpc/openapi/plugins'
|
|||||||
import { onError } from '@orpc/server'
|
import { onError } from '@orpc/server'
|
||||||
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
|
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
import { name, version } from '@/../package.json'
|
import { name, version } from '#package'
|
||||||
import { handleValidationError, logError } from '@/server/api/interceptors'
|
import { handleValidationError, logError } from '@/server/api/interceptors'
|
||||||
import { router } from '@/server/api/routers'
|
import { router } from '@/server/api/routers'
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// AUTO-GENERATED by `bun run db:embed`. Do not edit.
|
// AUTO-GENERATED by `bun run db:embed`. Do not edit.
|
||||||
import sql_0 from '../../../drizzle/0000_loving_thunderbird.sql' with { type: 'text' }
|
import sql_0 from '#drizzle/0000_loving_thunderbird.sql' with { type: 'text' }
|
||||||
|
|
||||||
export type EmbeddedMigration = { tag: string; sql: string; when: number; breakpoints: boolean }
|
export type EmbeddedMigration = { tag: string; sql: string; when: number; breakpoints: boolean }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user