@lancetw/aiyu 0.4.0 → 0.4.1
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/install.js +16 -3
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -22,7 +22,7 @@ import fs from "node:fs";
|
|
|
22
22
|
import os from "node:os";
|
|
23
23
|
import path from "node:path";
|
|
24
24
|
import { execFileSync } from "node:child_process";
|
|
25
|
-
import { fileURLToPath
|
|
25
|
+
import { fileURLToPath } from "node:url";
|
|
26
26
|
|
|
27
27
|
const HOST_NAME = "com.lancetw.aiyu";
|
|
28
28
|
// 擴充 ID。host 的 allowed_origins 同時信任兩者(dual-ID):
|
|
@@ -313,7 +313,20 @@ async function main() {
|
|
|
313
313
|
|
|
314
314
|
export { parseBrowsersFlag, resolveSelection };
|
|
315
315
|
|
|
316
|
-
// 直接執行才跑 main;被 import
|
|
317
|
-
|
|
316
|
+
// 直接執行才跑 main;被 import(測試)時不跑。
|
|
317
|
+
// 用 realpath 比對而非字串相等:npx/npm 透過 node_modules/.bin/<name> 的 symlink 啟動 bin,
|
|
318
|
+
// 此時 process.argv[1] 是 symlink 路徑,需解析回真實檔才會等於 import.meta.url(Node 已對其做 realpath)。
|
|
319
|
+
// 否則守衛誤判「非進入點」→ main() 不執行 → 安裝器經 npx 靜默失效。
|
|
320
|
+
function isEntryPoint() {
|
|
321
|
+
const entry = process.argv[1];
|
|
322
|
+
if (!entry) return false; // 例如 node -e,無 argv[1]
|
|
323
|
+
try {
|
|
324
|
+
return fs.realpathSync(entry) === fileURLToPath(import.meta.url);
|
|
325
|
+
} catch {
|
|
326
|
+
return false; // argv[1] 不是可解析的真實檔
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (isEntryPoint()) {
|
|
318
331
|
main().catch((e) => { console.error(e); process.exit(1); });
|
|
319
332
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lancetw/aiyu",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Installs the native-messaging host for the aiyu Chrome extension, letting it call your local claude/codex/agy CLI to translate YouTube subtitles and selected text. Run: npx @lancetw/aiyu",
|
|
6
6
|
"bin": {
|