@x-otto/cli 0.0.1-alpha.0 → 0.0.1-alpha.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/dist/fix-spawn-helper.mjs +58 -0
- package/package.json +3 -3
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 恢复 node-pty `spawn-helper` 的执行位(cli 的 PTY 测试驱动器 tests/helpers/pty-tui.ts 依赖)。
|
|
3
|
+
*
|
|
4
|
+
* pnpm 解包会把 prebuilds/<plat>/spawn-helper 的 +x 剥成 0644 → 运行时 `posix_spawnp failed`。
|
|
5
|
+
* 本脚本在 cli postinstall 跑:定位 node-pty 包,给所有 prebuild 的 spawn-helper chmod +x。
|
|
6
|
+
* 幂等、跨平台安全(Windows 无 spawn-helper、或 node-pty 未装时静默跳过)。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { chmodSync, existsSync, readdirSync, statSync } from 'node:fs'
|
|
10
|
+
import { createRequire } from 'node:module'
|
|
11
|
+
import { dirname, join } from 'node:path'
|
|
12
|
+
|
|
13
|
+
function nodePtyDir() {
|
|
14
|
+
try {
|
|
15
|
+
const require = createRequire(import.meta.url)
|
|
16
|
+
// require.resolve('node-pty') → .../node-pty/lib/index.js;上溯到包根。
|
|
17
|
+
let dir = dirname(require.resolve('node-pty'))
|
|
18
|
+
for (let i = 0; i < 4; i++) {
|
|
19
|
+
if (existsSync(join(dir, 'package.json')) && existsSync(join(dir, 'prebuilds'))) {
|
|
20
|
+
return dir
|
|
21
|
+
}
|
|
22
|
+
dir = dirname(dir)
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
// node-pty 未安装(如纯前端构建场景)——跳过。
|
|
26
|
+
}
|
|
27
|
+
return undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const root = nodePtyDir()
|
|
31
|
+
if (!root) {
|
|
32
|
+
process.exit(0)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 整段兜 try/catch:postinstall 绝不能因任何 FS 异常(EACCES/竞态/只读)而非零退出,
|
|
36
|
+
// 否则会让 `pnpm install` 整个失败——本脚本是 best-effort,永远 exit 0。
|
|
37
|
+
try {
|
|
38
|
+
const prebuilds = join(root, 'prebuilds')
|
|
39
|
+
if (existsSync(prebuilds)) {
|
|
40
|
+
let fixed = 0
|
|
41
|
+
for (const plat of readdirSync(prebuilds)) {
|
|
42
|
+
const helper = join(prebuilds, plat, 'spawn-helper')
|
|
43
|
+
try {
|
|
44
|
+
if (existsSync(helper) && statSync(helper).isFile()) {
|
|
45
|
+
chmodSync(helper, 0o755)
|
|
46
|
+
fixed++
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
// 单个 prebuild 失败——尽力而为,继续
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (fixed > 0) {
|
|
53
|
+
console.log(`[cli] fixed node-pty spawn-helper +x on ${fixed} prebuild(s)`)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
// 永不让 postinstall 失败
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-otto/cli",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@x-otto/service": "0.0.1-alpha.0",
|
|
33
33
|
"@x-otto/session": "0.0.1-alpha.0",
|
|
34
34
|
"@x-otto/session-contract": "0.0.1-alpha.0",
|
|
35
|
-
"@x-otto/setting": "0.0.1-alpha.
|
|
35
|
+
"@x-otto/setting": "0.0.1-alpha.1",
|
|
36
36
|
"@x-otto/shared": "0.1.0-alpha.1",
|
|
37
37
|
"@x-otto/tools": "0.0.1-alpha.0",
|
|
38
38
|
"@x-otto/trace-view": "0.0.1-alpha.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"typecheck:file": "tsc src/index.ts --noEmit --target ES2024 --module ESNext --moduleResolution bundler --esModuleInterop --skipLibCheck",
|
|
56
56
|
"typecheck": "tsc --noEmit",
|
|
57
57
|
"clean": "rm -rf dist",
|
|
58
|
-
"postinstall": "node
|
|
58
|
+
"postinstall": "node dist/fix-spawn-helper.mjs",
|
|
59
59
|
"bundle:extensions": "node scripts/bundle-builtin-extensions.mjs"
|
|
60
60
|
}
|
|
61
61
|
}
|