@morlay/dsh-oxc-node 0.2.10-alpha.0 → 0.2.10-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/register.mjs +10 -3
package/package.json
CHANGED
package/register.mjs
CHANGED
|
@@ -29,9 +29,16 @@ if (debug) process.stderr.write(`[ts-register] 已挂载 pid=${String(process.pi
|
|
|
29
29
|
|
|
30
30
|
registerHooks({
|
|
31
31
|
load(url, context, nextLoad) {
|
|
32
|
-
if (!url.startsWith("file:")
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
if (!url.startsWith("file:")) return nextLoad(url, context);
|
|
33
|
+
// 扩展名看**路径**而不是整串 URL:绕缓存的调用方(tsdown 的 `import-without-cache`、vite 的
|
|
34
|
+
// `?t=` 等)会给 URL 加查询串,按 `url.endsWith('.ts')` 判会漏掉它们,文件就落到 Node 的
|
|
35
|
+
// strip-only 上(参数属性、legacy 装饰器直接语法错)。`fileURLToPath` 也不能带查询串。
|
|
36
|
+
const parsed = new URL(url);
|
|
37
|
+
if (!parsed.pathname.endsWith(".ts") && !parsed.pathname.endsWith(".mts")) {
|
|
38
|
+
return nextLoad(url, context);
|
|
39
|
+
}
|
|
40
|
+
if (debug) process.stderr.write(`[ts-register] 转译 ${parsed.pathname}\n`);
|
|
41
|
+
const path = fileURLToPath(parsed);
|
|
35
42
|
// oxlint-disable-next-line node/no-sync -- `registerHooks` 的 load 钩子必须同步返回。
|
|
36
43
|
const original = readFileSync(path, "utf8");
|
|
37
44
|
// oxlint-disable-next-line node/no-sync -- 钩子契约要求同步。
|