From cca7e63ec3f305439a29b14d1ce77991d80bd323 Mon Sep 17 00:00:00 2001 From: snowy-yang <102860110+snowy-yang@users.noreply.github.com> Date: Fri, 2 Oct 2026 21:09:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(dev):=20pnpm=20dev=20=E5=AE=B9=E5=BF=8D=20s?= =?UTF-8?q?ources/=20=E7=BC=BA=E5=A4=B1=E2=80=94=E2=80=94scripts/dev.mjs?= =?UTF-8?q?=20=E4=BB=85=E4=B8=BA=E5=AD=98=E5=9C=A8=E7=9A=84=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E6=B3=A8=E5=86=8C=20--watch-path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- scripts/dev.mjs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 scripts/dev.mjs diff --git a/package.json b/package.json index f30e3f0..501aa78 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "typecheck": "tsc", "start": "node src/server.ts", - "dev": "node --watch-path=./src --watch-path=./sdk --watch-path=./sources --watch --watch-preserve-output src/server.ts", + "dev": "node scripts/dev.mjs", "test": "pnpm run typecheck && node test/source-simple-test.ts && node test/smoke-test.ts" }, "dependencies": { diff --git a/scripts/dev.mjs b/scripts/dev.mjs new file mode 100644 index 0000000..23a5240 --- /dev/null +++ b/scripts/dev.mjs @@ -0,0 +1,29 @@ +// pnpm dev 的包装:node --watch-path 指向不存在的目录会直接 ENOENT 崩溃。 +// sources/ 不入库(第三方音源脚本,gitignore 整目录),新 clone 的仓库里没有它, +// 所以这里只为实际存在的目录注册 watch。 +import { existsSync } from 'node:fs' +import { spawn } from 'node:child_process' +import { dirname, join, resolve } from 'node:path' +import { fileURLToPath } from 'node:url' + +const root = resolve(dirname(fileURLToPath(import.meta.url)), '..') + +const watchTargets = ['src', 'sdk', 'sources'] + .map((dir) => join(root, dir)) + .filter((dir) => existsSync(dir)) + +const child = spawn( + process.execPath, + [ + ...watchTargets.flatMap((dir) => ['--watch-path', dir]), + '--watch', + '--watch-preserve-output', + join(root, 'src/server.ts'), + ], + { stdio: 'inherit', cwd: root }, +) + +child.on('exit', (code, signal) => { + if (signal) process.kill(process.pid, signal) + else process.exit(code ?? 1) +})