@morlay/dsh-oxc-node 0.2.10-alpha.1 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/register.mjs +10 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morlay/dsh-oxc-node",
3
- "version": "0.2.10-alpha.1",
3
+ "version": "0.2.10-alpha.2",
4
4
  "description": "本仓库的 TS 运行时入口:注册 hooks 后 Node 也能跑 node_modules 下的 .ts(ESM only)。壳与宿主按路径取用(工具把它装进随包运行时)。",
5
5
  "keywords": [
6
6
  "dsh",
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:") || !url.endsWith(".ts")) return nextLoad(url, context);
33
- if (debug) process.stderr.write(`[ts-register] 转译 ${url.slice(7)}\n`);
34
- const path = fileURLToPath(url);
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 -- 钩子契约要求同步。