mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 23:02:27 +08:00
fix(build): fs 适配层改静态 import 分发——修复 top-level await 与 CJS 构建不兼容(上个提交遗留)
This commit is contained in:
parent
c82da2f6ed
commit
6c79eeb4ab
@ -1,10 +1,10 @@
|
||||
/** 首先加载 fs 适配层,必须在 main() 之前完成!按运行时选择实现(top-level await 保证注册先于一切使用) */
|
||||
if (typeof __RUNTIME__ !== "undefined" && __RUNTIME__ === "llrt") {
|
||||
await import("./server/llrt");
|
||||
} else {
|
||||
/** Node.js(tsx 开发 / tsdown define "node" 构建)走 node 适配器 */
|
||||
await import("./server/node");
|
||||
}
|
||||
/**
|
||||
* 首先加载 fs 适配层,必须在所有其他 import 之前!
|
||||
* 静态 import 依赖 ESM hoisting:无论源码书写顺序,llrt/node 适配器都会最先执行
|
||||
* (implInterface 直接给 interface.ts 的导出变量赋值,注册必须先于任何使用)。
|
||||
* 不能用 top-level await import —— tsdown 的 CJS 产物不支持。
|
||||
*/
|
||||
import "./server/llrt_lr";
|
||||
|
||||
import { mimeTypes } from "./server/mime_type";
|
||||
import type { cMiddleware } from "./server/req_res";
|
||||
|
||||
21
backend/server/llrt_lr.ts
Normal file
21
backend/server/llrt_lr.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* fs 适配层分发器。
|
||||
*
|
||||
* 按编译期 __RUNTIME__ 常量选择实现 —— tsdown 会把未命中分支 tree-shake 掉:
|
||||
* - LLRT 构建(__RUNTIME__="llrt"):llrt.ts 生效
|
||||
* - Node 构建(__RUNTIME__="node")与 dev(tsx,__RUNTIME__ 未定义):node.ts 生效
|
||||
*
|
||||
* 两个适配器都在模块顶层调用 implInterface 完成注册(副作用 import),
|
||||
* ESM import hoisting 保证分发器先于 app.ts 其余 import 执行。
|
||||
* 注意:不能用 top-level await import —— tsdown 的 CJS 产物不支持;
|
||||
* 条件 require 在打包时同样会被静态分析,未命中分支整块消除。
|
||||
*/
|
||||
|
||||
/** 编译期常量:tsdown define 注入,dev 下未定义 */
|
||||
declare const __RUNTIME__: string | undefined;
|
||||
|
||||
if (typeof __RUNTIME__ !== "undefined" && __RUNTIME__ === "llrt") {
|
||||
require("./llrt");
|
||||
} else {
|
||||
require("./node");
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user