fix: 评审跟进——resolve 链五文件错误信息与测试断言英文化
CI / check (pull_request) Successful in 2m9s

arnold.cui 评审(PR #42 评论 670-686、688):代码中存在较多中文,调整为英文。engine/build/aliasResolve/relativeResolve 四个源文件的 throw 文案与 resolvePlugins.spec 六个用例名、断言消息全部换英文([stack] 前缀与 specifier/importer/root 定位信息保留);scenarios.ts 两处 error 断言随文案联动(无法解析导入 → cannot resolve import)。scenario 与旧 spec 用例名保持中文,未在评审点名范围。
This commit is contained in:
cqh963852 committed 2026-11-11 16:05:45 +08:00
1 parent 3cba21324b
commit b24b8328e3
6 files changed
+25 -20

No files matched your search

+3 -1
View File
@@ -57,7 +57,9 @@ export function aliasResolve(options: AliasResolveOptions = {}): StackHook {
}
const unresolved = (specifier: string, importer: string, ctx: ResolveContext): never => {
throw new Error(`[stack] 无法解析导入 "${specifier}"(来自 ${importer},root=${ctx.root})`)
throw new Error(
`[stack] cannot resolve import "${specifier}" from ${importer} (root=${ctx.root})`,
)
}
const aliasMapOf = (specifier: string): string | null => {
+4 -3
View File
@@ -1,6 +1,6 @@
import type { StackConfig } from './config.ts'
import { DemandEngine } from './engine.ts'
import { withDefaultHooks } from './defaults.ts'
import { DemandEngine } from './engine.ts'
import type { BuildResult } from './hooks.ts'
import { CORE_PRODUCER } from './hooks.ts'
import { DEFAULT_DIST, renderPreserveEsm } from './render.ts'
@@ -11,10 +11,11 @@ export { DEFAULT_DIST }
export async function build(config: StackConfig): Promise<BuildResult> {
if (config.fs === undefined) {
throw new Error(
'[stack] 需要注入 fs:node 宿主用 nodeFs()(@idealjs/stack/node),浏览器/测试用 memoryFs()',
'[stack] fs is required: node hosts use nodeFs() (@idealjs/stack/node), browser/tests use memoryFs()',
)
}
if ((config.inputs ?? []).length === 0) throw new Error('[stack] config.inputs 至少需要一个入口')
if ((config.inputs ?? []).length === 0)
throw new Error('[stack] config.inputs requires at least one entry')
const startedAt = Date.now()
const engine = new DemandEngine(withDefaultHooks(config))
try {
+5 -3
View File
@@ -100,7 +100,7 @@ export class DemandEngine {
async resolveEntry(input: StackInput): Promise<void> {
const resolution = await this.resolveDemand(input.path, `${this.root}/`)
if (resolution.kind === 'external') {
throw new Error(`[stack] 无法解析入口 "${input.path}"(root=${this.root})`)
throw new Error(`[stack] cannot resolve entry "${input.path}" (root=${this.root})`)
}
this.#kindOverrides.set(resolution.id, inputKindOf(input.path, input.type))
this.entries.push({ name: input.name, id: resolution.id })
@@ -304,7 +304,7 @@ export class DemandEngine {
async #runLifecycle(id: string): Promise<FinalModule> {
const entry = this.#registry.get(id)
if (entry === undefined) throw new Error(`[stack] 内部错误:模块未注册:${id}`)
if (entry === undefined) throw new Error(`[stack] internal error: module not registered: ${id}`)
if (entry.final !== null) return entry.final
const kind = entry.kind
const raw = await this.#loading.loadForLifecycle(id)
@@ -360,7 +360,9 @@ export class DemandEngine {
#requireFs(): StackFs {
const fs = this.#config.fs
if (fs === undefined) {
throw new Error('[stack] 需要注入 fs:node 宿主用 nodeFs(),浏览器/测试用 memoryFs()')
throw new Error(
'[stack] fs is required: node hosts use nodeFs(), browser/tests use memoryFs()',
)
}
return fs
}
+1 -1
View File
@@ -19,7 +19,7 @@ export function relativeResolve(options: RelativeResolveOptions = {}): StackHook
: joinPath(dirnamePath(importer), specifier)
const id = await probeFirst(ctx.fs, moduleCandidates(base))
if (id !== null) return { id }
throw new Error(`[stack] 无法解析导入 "${specifier}"(来自 ${importer})`)
throw new Error(`[stack] cannot resolve import "${specifier}" from ${importer}`)
}
const rooted = await probeFirst(ctx.fs, moduleCandidates(joinPath(ctx.root, specifier)))
if (rooted !== null) return { id: rooted }
+10 -10
View File
@@ -8,16 +8,16 @@ const pkgJsonOf = (json: Record<string, unknown>): string => JSON.stringify(json
const codeOf = (result: BuildResult, path: string): string => {
const output = result.outputs.find((candidate) => candidate.name === 'default')
assert.ok(output !== undefined, '缺少 default 产物')
assert.ok(output !== undefined, 'missing default output')
const file = output.files.find((candidate) => candidate.path === path)
assert.ok(
file !== undefined,
`缺少产物文件 ${path}(现有:${output.files.map((f) => f.path).join('、')})`,
`missing output file ${path} (existing: ${output.files.map((f) => f.path).join(', ')})`,
)
return file.code
}
test('config.alias 前缀替换走插件:边界不误伤,未命中别名外部化为原说明符', async () => {
test('config.alias prefix rewrite goes through the plugin: boundary-safe, unmatched alias stays external', async () => {
const files: Record<string, string> = {
'src/app.ts': [
`import { info } from '@/info'`,
@@ -41,7 +41,7 @@ test('config.alias 前缀替换走插件:边界不误伤,未命中别名外
assert.match(app, /from "@utils-extra\/pkg"/)
})
test('tsconfig paths:无 config.alias 时按 paths 映射,锚定项目根', async () => {
test('tsconfig paths: maps without config.alias, anchored at the project root', async () => {
const files: Record<string, string> = {
'src/app.ts': `import { info } from '@/info'\nimport { inner } from '@/nested/inner'\nexport const all = [info, inner]`,
'src/info.ts': `export const info = 'info'`,
@@ -61,13 +61,13 @@ test('tsconfig paths:无 config.alias 时按 paths 映射,锚定项目根',
assert.match(app, /from "\.\/nested\/inner\.js"/)
})
test('tsconfig 含注释与尾逗号时按 JSONC 剥离解析,paths 依然生效', async () => {
test('tsconfig with comments and trailing commas parses as JSONC, paths still work', async () => {
const files: Record<string, string> = {
'src/app.ts': `import { info } from '@/info'\nexport const all = [info]`,
'src/info.ts': `export const info = 'info'`,
'tsconfig.json': [
`{`,
` // 编辑器体验用,编译不读这份`,
` // editor experience only, compilation does not read this`,
` "compilerOptions": {`,
` "paths": { "@/*": ["./src/*"] },`,
` }`,
@@ -83,7 +83,7 @@ test('tsconfig 含注释与尾逗号时按 JSONC 剥离解析,paths 依然生
assert.match(codeOf(result, 'app.js'), /from "\.\/info\.js"/)
})
test('alias 目标为包名时再派发插件链:react 换 preact 落 node_modules,边界不吞 react-dom', async () => {
test('alias target as package name re-dispatches the chain: react lands on preact, boundary does not swallow react-dom', async () => {
const files: Record<string, string> = {
'src/app.ts': [
`import { render } from 'react'`,
@@ -106,7 +106,7 @@ test('alias 目标为包名时再派发插件链:react 换 preact 落 node_mod
assert.match(codeOf(result, '__shared/preact.js'), /preact-render/)
})
test('alias 命中但目标无法解析:响亮报错不静默外化', async () => {
test('alias hit but target unresolvable: throws loudly instead of silently externalizing', async () => {
const files: Record<string, string> = {
'src/app.ts': `import { gone } from '@/missing'\nexport const all = [gone]`,
'src/info.ts': `export const info = 'info'`,
@@ -118,11 +118,11 @@ test('alias 命中但目标无法解析:响亮报错不静默外化', async ()
fs: memoryFs(files),
hooks: [imports()],
}),
/无法解析导入 "@\/missing"/,
/cannot resolve import "@\/missing"/,
)
})
test('裸说明符 root 兜底:非包名的项目根相对路径由 relative 插件承接', async () => {
test('bare specifier root fallback: project-root-relative paths are owned by the relative plugin', async () => {
const files: Record<string, string> = {
'src/app.ts': `import { label } from 'src/label'\nexport const all = [label]`,
'src/label.ts': `export const label = 'page'`,
+2 -2
View File
@@ -243,7 +243,7 @@ export const SCENARIOS: Scenario[] = [
inputs: [{ name: 'main', path: 'src/main.ts' }],
hooks: [imports()],
},
expected: { error: '无法解析导入 "./missing"' },
expected: { error: 'cannot resolve import "./missing"' },
},
{
name: 'imports() 声明的 A↔B 图环:自身闭环捕获降级为边数据,双向说明符重写',
@@ -880,7 +880,7 @@ export const SCENARIOS: Scenario[] = [
inputs: [{ name: 'page', path: 'src/index.html' }],
hooks: [imports()],
},
expected: { error: '无法解析导入 "./missing.ts"' },
expected: { error: 'cannot resolve import "./missing.ts"' },
},
{
name: 'html 内 script src 走 alias:重写指向 alias 解析后的最终落位',