fix: 修复构建脚本跨平台 import specifier 路径规范化
- toImportSpecifier() 使用 replaceAll 替代 split(sep).join,明确 ESM import specifier 语义 - 增加 relativePath 可选参数支持测试注入 Windows relative 语义 - 重写 Windows 路径测试,使用 node:path.win32 显式模拟而非依赖当前平台 sep - 更新 DEVELOPMENT.md 记录构建 code generation 约定 - 同步 static-asset-embedding 和 windows-test-compat spec 新增要求
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, sep } from "node:path";
|
||||
import { join, win32 } from "node:path";
|
||||
|
||||
import { scanDir, toImportSpecifier } from "../../scripts/build-common";
|
||||
|
||||
@@ -65,10 +65,8 @@ describe("toImportSpecifier", () => {
|
||||
});
|
||||
|
||||
test("Windows 路径分隔符转换为正斜杠", () => {
|
||||
const fromDir = ["C:", "project", ".build"].join(sep);
|
||||
const targetPath = ["C:", "project", "dist", "web", "assets", "app.js"].join(sep);
|
||||
const result = toImportSpecifier(fromDir, targetPath);
|
||||
const result = toImportSpecifier("C:\\project\\.build", "C:\\project\\dist\\web\\assets\\app.js", win32.relative);
|
||||
expect(result).toBe("../dist/web/assets/app.js");
|
||||
expect(result).not.toContain(sep);
|
||||
expect(result).not.toContain("\\");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user