fix(build): fs 适配层改静态 import 分发——修复 top-level await 与 CJS 构建不兼容(上个提交遗留)

This commit is contained in:
崮生(子虚) 2026-08-15 16:24:47 +08:00
parent c82da2f6ed
commit 6c79eeb4ab
2 changed files with 28 additions and 7 deletions

View File

@ -1,10 +1,10 @@
/** 首先加载 fs 适配层,必须在 main() 之前完成按运行时选择实现top-level await 保证注册先于一切使用) */
if (typeof __RUNTIME__ !== "undefined" && __RUNTIME__ === "llrt") {
await import("./server/llrt");
} else {
/** Node.jstsx 开发 / tsdown define "node" 构建)走 node 适配器 */
await import("./server/node");
}
/**
* fs import
* import ESM hoistingllrt/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
View File

@ -0,0 +1,21 @@
/**
* fs
*
* __RUNTIME__ tsdown tree-shake
* - LLRT __RUNTIME__="llrt"llrt.ts
* - Node __RUNTIME__="node" devtsx__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");
}