@bitefoundry/rtt 0.0.0-stage → 0.3.0
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/LICENSE +21 -0
- package/README.md +85 -2
- package/bin/rtt.js +62 -0
- package/package.json +32 -6
- package/scripts/postinstall.mjs +275 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BiteFoundry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# RTT
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Windows 라이브 캡션의 음성을 터미널에서 실시간으로 받아 적고, 번역하고, 답변을 추천하는 도구입니다.
|
|
4
|
+
|
|
5
|
+
## 필요한 것
|
|
6
|
+
|
|
7
|
+
- Windows 11 22H2 이상 (라이브 캡션 기능 포함; 라이브 캡션이 없는 환경에서는 녹음과 재생만 사용할 수 있습니다)
|
|
8
|
+
- Node.js 18 이상
|
|
9
|
+
- 지원하는 LLM API 키 (선택: 키 없이도 받아 적기와 녹음·재생은 사용할 수 있습니다)
|
|
10
|
+
|
|
11
|
+
## 처음 쓰는 법
|
|
12
|
+
|
|
13
|
+
1. 전역 패키지를 설치합니다.
|
|
14
|
+
|
|
15
|
+
```powershell
|
|
16
|
+
npm i -g @bitefoundry/rtt
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
2. 터미널에서 `rtt`를 실행합니다.
|
|
20
|
+
|
|
21
|
+
```powershell
|
|
22
|
+
rtt
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
3. 라이브 캡션을 처음 쓰는 Windows 계정이면 화면에 라이브 캡션 창이 열립니다. 창에서 동의하고 음성 인식 파일 다운로드가 끝나면 자동으로 다음 단계로 이어집니다.
|
|
26
|
+
4. API 키 입력 화면이 나오면 보유한 API 키를 붙여 넣고 `Enter`를 누릅니다. 키 접두사로 공급자를 자동으로 판별하고 사용 가능한 대화 모델 목록을 불러옵니다.
|
|
27
|
+
5. 목록에서 번역에 쓸 모델을 고르고 `Enter`를 누르면 짧은 시험 호출 뒤 저장되고 실시간 화면으로 들어갑니다. 키 없이 시작하려면 `Esc`를 누릅니다.
|
|
28
|
+
|
|
29
|
+
버전 확인:
|
|
30
|
+
|
|
31
|
+
```powershell
|
|
32
|
+
rtt --version
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 업데이트
|
|
36
|
+
|
|
37
|
+
```powershell
|
|
38
|
+
npm update -g @bitefoundry/rtt
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 지원 공급자
|
|
42
|
+
|
|
43
|
+
모든 대화 호출은 OpenAI 호환 Chat Completions 형식으로 동작합니다.
|
|
44
|
+
|
|
45
|
+
| 공급자 | 코드 | 키 접두사 | 키 발급 페이지 |
|
|
46
|
+
|---|---|---|---|
|
|
47
|
+
| OpenAI | `openai` | `sk-` | https://platform.openai.com/api-keys |
|
|
48
|
+
| Google Gemini | `gemini` | `AIza` | https://aistudio.google.com/apikey |
|
|
49
|
+
| Anthropic | `anthropic` | `sk-ant-` | https://platform.claude.com/settings/keys |
|
|
50
|
+
| OpenRouter | `openrouter` | `sk-or-` | https://openrouter.ai/keys |
|
|
51
|
+
| Groq | `groq` | `gsk_` | https://console.groq.com/keys |
|
|
52
|
+
| NVIDIA | `nvidia` | `nvapi-` | https://build.nvidia.com |
|
|
53
|
+
| 직접 입력 | `custom` | - | OpenAI 호환 `https://` 주소 직접 입력 |
|
|
54
|
+
|
|
55
|
+
## 주요 키
|
|
56
|
+
|
|
57
|
+
| 키 | 동작 |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `Tab` | 탭 전환 (실시간, 세션, 재생, 설정) |
|
|
60
|
+
| `Enter` / `Space` / `r` | 최근 문장에 대한 답변 추천 요청 |
|
|
61
|
+
| `Ctrl+Alt+R` | 전역 단축키로 답변 추천 요청 (`config.json`의 `hotkey`로 변경 가능) |
|
|
62
|
+
| `1`, `2`, `3` | 추천 답변 복사 |
|
|
63
|
+
| `F2` | 녹음 시작/중지 |
|
|
64
|
+
| `F3` | 동작 모드 전환 (번역 / 받아 적기 / 녹음만) |
|
|
65
|
+
| `F9` | 마이크 모드 전환 (끔 / 녹음 / 받아 적기) |
|
|
66
|
+
| `F10` | 듣는 언어 및 번역 언어 선택 |
|
|
67
|
+
| `Ctrl+L` | 실시간 화면 비우기 |
|
|
68
|
+
| `↑` / `↓` / `PgUp` / `PgDn` / `End` | 기록 스크롤 및 최신 위치로 복귀 |
|
|
69
|
+
| `q` / `Ctrl+C` | 종료 |
|
|
70
|
+
|
|
71
|
+
## 데이터가 저장되는 곳
|
|
72
|
+
|
|
73
|
+
- 설정, 일별 사용량, 자막 기록, 로그: `%LOCALAPPDATA%\RTT` (`config.json`, `tui.json`, `usage.json`, `history\`, `rtt.log`)
|
|
74
|
+
- 녹음 세션과 오디오·전사 파일: `문서\RTT` (설정으로 변경 가능)
|
|
75
|
+
- API 키: Windows 자격 증명 관리자 일반 자격 증명 `RTT/api-key` (`config.json`이나 로그에 키를 저장하지 않습니다)
|
|
76
|
+
|
|
77
|
+
## 지우는 법
|
|
78
|
+
|
|
79
|
+
1. `rtt`를 실행해 설정 탭의 키 줄에서 `Del`을 두 번 눌러 Windows 자격 증명 관리자에 저장된 키를 지웁니다.
|
|
80
|
+
2. 패키지를 제거합니다.
|
|
81
|
+
|
|
82
|
+
```powershell
|
|
83
|
+
npm uninstall -g @bitefoundry/rtt
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
필요하면 `%LOCALAPPDATA%\RTT`와 `문서\RTT` 폴더도 직접 삭제합니다.
|
package/bin/rtt.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Ported from @bitefoundry/notion (bin/notion.js).
|
|
5
|
+
const { spawnSync } = require('node:child_process');
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
|
|
9
|
+
const PLATFORM_PACKAGES = {
|
|
10
|
+
'win32-x64': '@bitefoundry/rtt-win32-x64',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function resolveBinary() {
|
|
14
|
+
if (process.env.RTT_BIN_PATH && fs.existsSync(process.env.RTT_BIN_PATH)) {
|
|
15
|
+
return process.env.RTT_BIN_PATH;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const binaryName = process.platform === 'win32' ? 'rtt.exe' : 'rtt';
|
|
19
|
+
const localLinked = path.join(__dirname, binaryName);
|
|
20
|
+
if (fs.existsSync(localLinked)) {
|
|
21
|
+
return localLinked;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const key = `${process.platform}-${process.arch}`;
|
|
25
|
+
const pkgName = PLATFORM_PACKAGES[key];
|
|
26
|
+
if (!pkgName) {
|
|
27
|
+
console.error(
|
|
28
|
+
`[@bitefoundry/rtt] Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_PACKAGES).join(', ')}`,
|
|
29
|
+
);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const pkgJsonPath = require.resolve(`${pkgName}/package.json`);
|
|
35
|
+
const candidate = path.join(path.dirname(pkgJsonPath), 'bin', binaryName);
|
|
36
|
+
if (fs.existsSync(candidate)) {
|
|
37
|
+
return candidate;
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
// Fall through to helpful diagnostic error below.
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
console.error(
|
|
44
|
+
`[@bitefoundry/rtt] Could not locate prebuilt binary from optional dependency "${pkgName}".\n` +
|
|
45
|
+
`Try reinstalling without --omit=optional.`,
|
|
46
|
+
);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const binPath = resolveBinary();
|
|
51
|
+
const result = spawnSync(binPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
52
|
+
|
|
53
|
+
if (result.error) {
|
|
54
|
+
console.error(`[@bitefoundry/rtt] Failed to launch ${binPath}: ${result.error.message}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (result.signal) {
|
|
59
|
+
process.kill(process.pid, result.signal);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
process.exit(result.status ?? 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@bitefoundry/rtt",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitefoundry/rtt",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Real-time captions, translation and reply suggestions for Windows Live Captions (terminal app)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"os": [
|
|
7
|
+
"win32"
|
|
8
|
+
],
|
|
9
|
+
"cpu": [
|
|
10
|
+
"x64"
|
|
11
|
+
],
|
|
12
|
+
"bin": {
|
|
13
|
+
"rtt": "bin/rtt.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin/rtt.js",
|
|
17
|
+
"scripts/postinstall.mjs",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"postinstall": "node scripts/postinstall.mjs",
|
|
26
|
+
"sync-version": "node scripts/sync-version.mjs",
|
|
27
|
+
"build:npm": "node scripts/build-npm.mjs"
|
|
28
|
+
},
|
|
29
|
+
"optionalDependencies": {
|
|
30
|
+
"@bitefoundry/rtt-win32-x64": "0.3.0"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Zero-Node-Process npm native binary linker.
|
|
3
|
+
// Ported from @bitefoundry/notion (scripts/postinstall.mjs).
|
|
4
|
+
//
|
|
5
|
+
// On Windows (win32): creates NTFS hardlink (fallback copy) `bin/rtt.exe`
|
|
6
|
+
// and rewrites npm's `rtt.cmd`, `rtt.ps1`, and POSIX `rtt` shims when present
|
|
7
|
+
// to invoke the native executable directly without spawning `node.exe`.
|
|
8
|
+
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { createRequire } from 'node:module';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
const BIN_NAMES = ['rtt'];
|
|
15
|
+
const PKG_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
16
|
+
|
|
17
|
+
function linkOrCopyFile(source, destination) {
|
|
18
|
+
const tmp = `${destination}.tmp-${process.pid}`;
|
|
19
|
+
try {
|
|
20
|
+
fs.rmSync(tmp, { force: true });
|
|
21
|
+
} catch {
|
|
22
|
+
// Ignore cleanup errors on nonexistent temp paths.
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
fs.linkSync(source, tmp);
|
|
26
|
+
} catch {
|
|
27
|
+
fs.copyFileSync(source, tmp);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
fs.renameSync(tmp, destination);
|
|
31
|
+
} catch {
|
|
32
|
+
try {
|
|
33
|
+
fs.rmSync(destination, { force: true });
|
|
34
|
+
} catch {
|
|
35
|
+
// Ignore; renameSync below will surface or fail safely.
|
|
36
|
+
}
|
|
37
|
+
fs.renameSync(tmp, destination);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function replaceJsWithNativeLinkUnix(binaryPath, destinationJs) {
|
|
42
|
+
const tmp = `${destinationJs}.tmp-${process.pid}`;
|
|
43
|
+
try {
|
|
44
|
+
fs.rmSync(tmp, { force: true });
|
|
45
|
+
} catch {
|
|
46
|
+
// Ignore cleanup errors.
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
fs.linkSync(binaryPath, tmp);
|
|
50
|
+
} catch {
|
|
51
|
+
try {
|
|
52
|
+
fs.rmSync(tmp, { force: true });
|
|
53
|
+
} catch {
|
|
54
|
+
// Ignore cleanup errors.
|
|
55
|
+
}
|
|
56
|
+
fs.symlinkSync(binaryPath, tmp);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
fs.renameSync(tmp, destinationJs);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
try {
|
|
62
|
+
fs.rmSync(tmp, { force: true });
|
|
63
|
+
} catch {
|
|
64
|
+
// Ignore cleanup errors.
|
|
65
|
+
}
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function collectWindowsShimDirs(pkgRoot, env = process.env) {
|
|
71
|
+
const dirs = [];
|
|
72
|
+
const parentScope = path.dirname(pkgRoot);
|
|
73
|
+
const nodeModulesDir = path.dirname(parentScope);
|
|
74
|
+
if (
|
|
75
|
+
path.basename(parentScope) === '@bitefoundry' &&
|
|
76
|
+
path.basename(nodeModulesDir) === 'node_modules'
|
|
77
|
+
) {
|
|
78
|
+
dirs.push(path.join(nodeModulesDir, '.bin'));
|
|
79
|
+
// On global Windows npm installs (`<prefix>\node_modules\@bitefoundry\rtt`),
|
|
80
|
+
// shims sit directly in the parent of `node_modules` even when `npm_config_prefix` is unset in npm v9+.
|
|
81
|
+
dirs.push(path.dirname(nodeModulesDir));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (env.npm_config_global === 'true' && env.npm_config_prefix) {
|
|
85
|
+
const prefix = path.resolve(env.npm_config_prefix);
|
|
86
|
+
dirs.push(prefix);
|
|
87
|
+
dirs.push(path.join(prefix, 'bin'));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return [...new Set(dirs)];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function shimReferencesLauncher(content, name) {
|
|
94
|
+
const normalized = content.replace(/\\/g, '/').toLowerCase();
|
|
95
|
+
return (
|
|
96
|
+
normalized.includes('@bitefoundry/rtt') &&
|
|
97
|
+
normalized.includes(`bin/${name}.js`)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function rewriteWindowsShims(shimDir, pkgRoot) {
|
|
102
|
+
if (!fs.existsSync(shimDir)) return 0;
|
|
103
|
+
let rewritten = 0;
|
|
104
|
+
|
|
105
|
+
for (const name of BIN_NAMES) {
|
|
106
|
+
const exePath = path.join(pkgRoot, 'bin', `${name}.exe`);
|
|
107
|
+
if (!fs.existsSync(exePath)) continue;
|
|
108
|
+
|
|
109
|
+
const relWin = path.relative(shimDir, exePath).replace(/\//g, '\\');
|
|
110
|
+
const relPosix = path.relative(shimDir, exePath).replace(/\\/g, '/');
|
|
111
|
+
|
|
112
|
+
// 1. `<name>.cmd`
|
|
113
|
+
const cmdPath = path.join(shimDir, `${name}.cmd`);
|
|
114
|
+
try {
|
|
115
|
+
if (fs.existsSync(cmdPath)) {
|
|
116
|
+
const content = fs.readFileSync(cmdPath, 'utf8');
|
|
117
|
+
if (shimReferencesLauncher(content, name)) {
|
|
118
|
+
fs.writeFileSync(cmdPath, `@ECHO off\r\n"%~dp0${relWin}" %*\r\n`, 'utf8');
|
|
119
|
+
rewritten += 1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
// Fall back cleanly to bin/<name>.js if shim is read-only or locked.
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 2. `<name>.ps1`
|
|
127
|
+
const ps1Path = path.join(shimDir, `${name}.ps1`);
|
|
128
|
+
try {
|
|
129
|
+
if (fs.existsSync(ps1Path)) {
|
|
130
|
+
const content = fs.readFileSync(ps1Path, 'utf8');
|
|
131
|
+
if (shimReferencesLauncher(content, name)) {
|
|
132
|
+
const ps1Body = [
|
|
133
|
+
'#!/usr/bin/env pwsh',
|
|
134
|
+
'$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent',
|
|
135
|
+
`$exePath = Join-Path $basedir '${relWin.replace(/'/g, "''")}'`,
|
|
136
|
+
'if ($MyInvocation.ExpectingInput) {',
|
|
137
|
+
' $input | & $exePath @args',
|
|
138
|
+
'} else {',
|
|
139
|
+
' & $exePath @args',
|
|
140
|
+
'}',
|
|
141
|
+
'exit $LASTEXITCODE',
|
|
142
|
+
'',
|
|
143
|
+
].join('\n');
|
|
144
|
+
fs.writeFileSync(ps1Path, ps1Body, 'utf8');
|
|
145
|
+
rewritten += 1;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch {
|
|
149
|
+
// Fall back cleanly.
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 3. `<name>` (Git Bash / MSYS2 POSIX shell shim)
|
|
153
|
+
const shPath = path.join(shimDir, name);
|
|
154
|
+
try {
|
|
155
|
+
if (fs.existsSync(shPath)) {
|
|
156
|
+
const content = fs.readFileSync(shPath, 'utf8');
|
|
157
|
+
if (shimReferencesLauncher(content, name)) {
|
|
158
|
+
const shBody = [
|
|
159
|
+
'#!/bin/sh',
|
|
160
|
+
'basedir=$(dirname "$(echo "$0" | sed -e \'s,\\\\,/,g\')")',
|
|
161
|
+
`exec "$basedir/${relPosix}" "$@"`,
|
|
162
|
+
'',
|
|
163
|
+
].join('\n');
|
|
164
|
+
fs.writeFileSync(shPath, shBody, 'utf8');
|
|
165
|
+
rewritten += 1;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
// Fall back cleanly.
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return rewritten;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function runPostinstall(options = {}) {
|
|
177
|
+
const pkgRoot = path.resolve(options.pkgRoot || PKG_ROOT);
|
|
178
|
+
const platform = options.platform || process.platform;
|
|
179
|
+
const arch = options.arch || process.arch;
|
|
180
|
+
const env = options.env || process.env;
|
|
181
|
+
|
|
182
|
+
// CRITICAL SAFETY GUARD: Never mutate files inside the git development repository.
|
|
183
|
+
if (
|
|
184
|
+
fs.existsSync(path.join(pkgRoot, 'Cargo.toml')) ||
|
|
185
|
+
fs.existsSync(path.join(pkgRoot, '.git'))
|
|
186
|
+
) {
|
|
187
|
+
return { skipped: true, reason: 'dev_repo' };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const platformKey = `${platform}-${arch}`;
|
|
191
|
+
const packageName = `@bitefoundry/rtt-${platformKey}`;
|
|
192
|
+
const binaryName = platform === 'win32' ? 'rtt.exe' : 'rtt';
|
|
193
|
+
|
|
194
|
+
let packageDir = null;
|
|
195
|
+
try {
|
|
196
|
+
const requireFromPkg = createRequire(path.join(pkgRoot, 'package.json'));
|
|
197
|
+
packageDir = path.dirname(requireFromPkg.resolve(`${packageName}/package.json`));
|
|
198
|
+
} catch {
|
|
199
|
+
packageDir = null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const binaryPath = packageDir ? path.join(packageDir, 'bin', binaryName) : null;
|
|
203
|
+
if (!binaryPath || !fs.existsSync(binaryPath)) {
|
|
204
|
+
return { skipped: true, reason: 'missing_platform_binary' };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const binDir = path.join(pkgRoot, 'bin');
|
|
208
|
+
if (!fs.existsSync(binDir)) {
|
|
209
|
+
return { skipped: true, reason: 'missing_bin_dir' };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (platform === 'win32') {
|
|
213
|
+
let linked = 0;
|
|
214
|
+
for (const name of BIN_NAMES) {
|
|
215
|
+
const destExe = path.join(binDir, `${name}.exe`);
|
|
216
|
+
try {
|
|
217
|
+
linkOrCopyFile(binaryPath, destExe);
|
|
218
|
+
linked += 1;
|
|
219
|
+
} catch {
|
|
220
|
+
// Leave fallback JS launcher untouched.
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let shimsRewritten = 0;
|
|
225
|
+
for (const shimDir of collectWindowsShimDirs(pkgRoot, env)) {
|
|
226
|
+
try {
|
|
227
|
+
shimsRewritten += rewriteWindowsShims(shimDir, pkgRoot);
|
|
228
|
+
} catch {
|
|
229
|
+
// Never fail npm install on read-only or custom shims.
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return { skipped: false, platform, linked, shimsRewritten };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Unix fallback (not currently packaged for rtt).
|
|
236
|
+
try {
|
|
237
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
238
|
+
} catch {
|
|
239
|
+
// Ignore on read-only stores.
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let linked = 0;
|
|
243
|
+
for (const name of BIN_NAMES) {
|
|
244
|
+
const destJs = path.join(binDir, `${name}.js`);
|
|
245
|
+
try {
|
|
246
|
+
replaceJsWithNativeLinkUnix(binaryPath, destJs);
|
|
247
|
+
linked += 1;
|
|
248
|
+
} catch {
|
|
249
|
+
// Leave fallback JS launcher intact.
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return { skipped: false, platform, linked };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function resolveCanonicalPath(p) {
|
|
257
|
+
try {
|
|
258
|
+
return fs.realpathSync(p);
|
|
259
|
+
} catch {
|
|
260
|
+
return path.resolve(p);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (
|
|
265
|
+
process.argv[1] &&
|
|
266
|
+
resolveCanonicalPath(process.argv[1]) ===
|
|
267
|
+
resolveCanonicalPath(fileURLToPath(import.meta.url))
|
|
268
|
+
) {
|
|
269
|
+
try {
|
|
270
|
+
runPostinstall();
|
|
271
|
+
} catch {
|
|
272
|
+
// Postinstall optimization must never fail npm install.
|
|
273
|
+
}
|
|
274
|
+
process.exit(0);
|
|
275
|
+
}
|