@iyowei/sweep-node-modules-cli 0.3.0 → 0.5.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/README.md +20 -12
- package/README.zh-CN.md +39 -31
- package/bin/bunfig.toml +3 -0
- package/bin/sweep-nm.mjs +189 -107
- package/dist/cli.js +22 -2365
- package/dist/manifest.json +3 -3
- package/package.json +9 -7
package/bin/sweep-nm.mjs
CHANGED
|
@@ -1,53 +1,62 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* npm 安装场景的启动器: 挑选运行时 (Bun 优先, 其次 Node) 后启动真实入口。
|
|
4
|
-
* 与 bin/sweep-nm (sh) / bin/sweep-nm.cmd (cmd) 职责同逻辑 (挑选运行时: Bun 优先, Node 回退),
|
|
5
|
-
* 差异在宿主与本文件多加的入口选择 (优先跑编译产物 dist/cli.js, 无产物则回退源码 src/cli.ts;
|
|
6
|
-
* 包内只有产物, 开发态通常无产物):
|
|
7
|
-
* 本文件同时承担 Unix 与 Windows 的 npm shim 目标 (shebang 必须是 node, 否则
|
|
8
|
-
* npm 的 cmd-shim 会按 shebang 解释器生成 Windows 上不存在的调用)。
|
|
3
|
+
* npm 安装场景的启动器: 挑选运行时 (Bun 优先, 其次 Node >= 22.18) 后启动真实入口。
|
|
9
4
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* (
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* dist/cli.js 之前必须与随附的 dist/manifest.json 对账 (形状版本受支持, 且清单记的 cliSha256
|
|
21
|
-
* 必须等于实测摘要), 清单缺失 / 损坏 / 版本不支持 / 摘要不符一律拒收产物并给出指引, 不静默回退
|
|
22
|
-
* 源码 (静默回退会把产物漂移藏起来, 包内也没有源码可回退); 拒收指引按宿主分流 (仓库检出态给
|
|
23
|
-
* 源码入口与重构建, 包态给重装本包)。工作树脏净不进本判定 (开发态常脏), 那是发布闸门
|
|
24
|
-
* scripts/verify-release.ts 的职责; 清单字段契约见 scripts/release-artifact.ts (包内无法
|
|
25
|
-
* 跨语言复用该模块, 两边口径由 src/npm-launcher.smoke.test.ts 的集成用例钉住)。
|
|
26
|
-
*
|
|
27
|
-
* 退出码原样透传; 两个运行时都缺席时给出可操作提示并非零退出。
|
|
5
|
+
* 安全防线与进程模型:
|
|
6
|
+
* 1. 运行时解析防劫持: win32 与 POSIX 均按 PATH 解析绝对路径并跳过空/相对条目
|
|
7
|
+
* (win32 严判盘符或 UNC 绝对路径, 拦截 Git Bash 注入的 `/usr/bin` 盘根相对路径),
|
|
8
|
+
* 绝不从当前被扫目录解析同名 bun/node;
|
|
9
|
+
* 2. Bun 工作目录配置隔离: 选中 Bun 时强制附加 --config=<pkg>/bin/bunfig.toml 与
|
|
10
|
+
* --no-env-file (隔离配置缺失即报错拒绝, 不静默退回无隔离态), 并透传 CLIS_BUN_ISOLATED=1;
|
|
11
|
+
* 3. 产物自证: 执行 dist/cli.js 前必先与 dist/manifest.json 校验 SHA-256;
|
|
12
|
+
* 4. 零多余派生 + 信号收口: 当前进程已是隔离 Bun 或满足 >= 22.18 的纯 Node 时直接同进程
|
|
13
|
+
* import 入口 (保留原始 argv[1]); 需跨运行时切换时以异步 spawn 派发, 运行期父进程忽略
|
|
14
|
+
* SIGINT 防杀父留孤儿, 子进程退出后解挂并透传信号或退出码。
|
|
28
15
|
*/
|
|
29
|
-
import { spawnSync } from 'node:child_process';
|
|
16
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
30
17
|
import { createHash } from 'node:crypto';
|
|
31
18
|
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
32
|
-
import { dirname, join, posix, win32 } from 'node:path';
|
|
33
|
-
import { fileURLToPath } from 'node:url';
|
|
19
|
+
import { basename, dirname, join, posix, win32 } from 'node:path';
|
|
20
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
34
21
|
|
|
35
|
-
/** 产物与清单的文件名 (与 scripts/release-artifact.ts 的 CLI_FILE / MANIFEST_FILE 同值) */
|
|
36
22
|
const CLI_FILE = 'cli.js';
|
|
37
23
|
const MANIFEST_FILE = 'manifest.json';
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* win32 的候选可执行扩展名, 顺序与 Node 实际走的 libuv 搜索一致 (.com 先于 .exe)。
|
|
41
|
-
* 不展开 PATHEXT: .bat / .cmd 无法被 Node 无 shell 直接执行, 展开只会把不可执行的命中当成功;
|
|
42
|
-
* 保持该面与 libuv 等价也意味着本次收紧不改动 win32 上「哪些安装形态能命中」的既有行为。
|
|
43
|
-
*/
|
|
44
24
|
const WIN32_EXEC_EXTS = ['.com', '.exe'];
|
|
25
|
+
const WIN32_ABS_DIR_RE = /^(?:[A-Za-z]:[/\\]|\\\\[^\\]+\\[^\\]+)/;
|
|
26
|
+
const MIN_NODE_MAJOR = 22;
|
|
27
|
+
const MIN_NODE_MINOR = 18;
|
|
28
|
+
|
|
29
|
+
/** 校验 Node.js 版本是否满足 >= 22.18.0 下限 */
|
|
30
|
+
export const isSupportedNodeVersion = (rawVersion) => {
|
|
31
|
+
if (typeof rawVersion !== 'string') return false;
|
|
32
|
+
const match = /^v?(\d+)\.(\d+)/.exec(rawVersion.trim());
|
|
33
|
+
if (match === null) return false;
|
|
34
|
+
const major = Number(match[1]);
|
|
35
|
+
const minor = Number(match[2]);
|
|
36
|
+
return (
|
|
37
|
+
major > MIN_NODE_MAJOR ||
|
|
38
|
+
(major === MIN_NODE_MAJOR && minor >= MIN_NODE_MINOR)
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** 判定解析出的运行时是否为 Bun */
|
|
43
|
+
const isBunRuntime = (runtime) => {
|
|
44
|
+
const name = basename(runtime).toLowerCase();
|
|
45
|
+
return name === 'bun' || name === 'bun.exe' || name === 'bun.com';
|
|
46
|
+
};
|
|
45
47
|
|
|
46
|
-
/** 探测命令是否可执行 (
|
|
47
|
-
const available = (command) =>
|
|
48
|
-
spawnSync(command, ['--version'], {
|
|
48
|
+
/** 探测命令是否可执行 (Bun 看退出码 0, Node 另校验 >= 22.18.0) */
|
|
49
|
+
const available = (command) => {
|
|
50
|
+
const res = spawnSync(command, ['--version'], {
|
|
51
|
+
encoding: 'utf8',
|
|
52
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
53
|
+
});
|
|
54
|
+
if (res.status !== 0) return false;
|
|
55
|
+
if (isBunRuntime(command)) return true;
|
|
56
|
+
return isSupportedNodeVersion(res.stdout);
|
|
57
|
+
};
|
|
49
58
|
|
|
50
|
-
/** 路径处是否为普通文件
|
|
59
|
+
/** 路径处是否为普通文件 */
|
|
51
60
|
const isFileAt = (path) => {
|
|
52
61
|
try {
|
|
53
62
|
return statSync(path).isFile();
|
|
@@ -56,35 +65,25 @@ const isFileAt = (path) => {
|
|
|
56
65
|
}
|
|
57
66
|
};
|
|
58
67
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* 「当前目录」从解析面整个摘掉 —— 空条目 (Windows 上表示当前目录) 与相对条目 (同样按当前
|
|
63
|
-
* 目录解析) 一律跳过, 只认绝对目录; 条目两侧的引号按 libuv 同款剥掉 (Windows PATH 允许
|
|
64
|
-
* 引号包裹含空格的目录)。注入 pathEnv / fileProbe 供测试在非 win32 宿主上覆盖本函数。
|
|
65
|
-
*/
|
|
66
|
-
export const resolveWin32Executable = (name, pathEnv, fileProbe) => {
|
|
68
|
+
/** 在 PATH 中解析命令的全部候选绝对路径 (win32 语义), 严格拦截空、相对与盘根相对条目 */
|
|
69
|
+
export const resolveWin32Executables = (name, pathEnv, fileProbe) => {
|
|
70
|
+
const found = [];
|
|
67
71
|
for (const raw of pathEnv.split(';')) {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
const trimmed = raw.trim();
|
|
73
|
+
const unquoted =
|
|
74
|
+
trimmed.length > 1 && trimmed.startsWith('"') && trimmed.endsWith('"')
|
|
75
|
+
? trimmed.slice(1, -1).trim()
|
|
76
|
+
: trimmed;
|
|
77
|
+
if (unquoted === '' || !WIN32_ABS_DIR_RE.test(unquoted)) continue;
|
|
73
78
|
for (const ext of WIN32_EXEC_EXTS) {
|
|
74
|
-
const candidate = win32.join(
|
|
75
|
-
if (fileProbe(candidate))
|
|
79
|
+
const candidate = win32.join(unquoted, name + ext);
|
|
80
|
+
if (fileProbe(candidate)) found.push(candidate);
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
|
-
return
|
|
83
|
+
return found;
|
|
79
84
|
};
|
|
80
85
|
|
|
81
|
-
/**
|
|
82
|
-
* 在 PATH 中解析命令的全部候选绝对路径 (POSIX 语义, 保持 PATH 顺序), 跳过空条目与相对
|
|
83
|
-
* 条目 (两者在 POSIX 下都按当前目录解析, 属本工具要摘掉的解析面; 与 win32 分支同一理由,
|
|
84
|
-
* 见文件头「运行时解析防劫持」)。返回数组而非首命中: 同名文件可能不可执行, execvp 在
|
|
85
|
-
* 该情形会继续搜索, 候选交由调用方逐个探测以保持同一语义。注入 pathEnv / fileProbe 供
|
|
86
|
-
* 测试在任意宿主上覆盖本函数。
|
|
87
|
-
*/
|
|
86
|
+
/** 在 PATH 中解析命令的全部候选绝对路径 (POSIX 语义), 跳过空与相对条目 */
|
|
88
87
|
export const resolvePosixExecutables = (name, pathEnv, fileProbe) => {
|
|
89
88
|
const found = [];
|
|
90
89
|
for (const dir of pathEnv.split(':')) {
|
|
@@ -95,36 +94,27 @@ export const resolvePosixExecutables = (name, pathEnv, fileProbe) => {
|
|
|
95
94
|
return found;
|
|
96
95
|
};
|
|
97
96
|
|
|
98
|
-
/**
|
|
99
|
-
* 挑选运行时: Bun 优先, 其次 Node; 皆无则 null (由调用处报错退出)。
|
|
100
|
-
* 两个平台都先按 PATH 解析绝对路径再探测 (理由见文件头「运行时解析防劫持」): win32 取
|
|
101
|
-
* 首个解析命中, POSIX 按 PATH 顺序逐个候选探测 (保持 execvp 的继续搜索语义); 各参数
|
|
102
|
-
* 显式传入供测试注入, 生产调用不传。
|
|
103
|
-
*/
|
|
97
|
+
/** 挑选运行时: 缺省 Bun 优先、其次 Node (>= 22.18); 皆无则 null */
|
|
104
98
|
export const pickRuntime = ({
|
|
105
99
|
platform = process.platform,
|
|
106
|
-
pathEnv = process.env.PATH ?? '',
|
|
100
|
+
pathEnv = process.env.PATH ?? process.env.Path ?? '',
|
|
107
101
|
fileProbe = isFileAt,
|
|
108
102
|
probe = available,
|
|
103
|
+
names = ['bun', 'node'],
|
|
109
104
|
} = {}) => {
|
|
110
|
-
for (const name of
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
for (const candidate of resolvePosixExecutables(name, pathEnv, fileProbe)) {
|
|
105
|
+
for (const name of names) {
|
|
106
|
+
const candidates =
|
|
107
|
+
platform === 'win32'
|
|
108
|
+
? resolveWin32Executables(name, pathEnv, fileProbe)
|
|
109
|
+
: resolvePosixExecutables(name, pathEnv, fileProbe);
|
|
110
|
+
for (const candidate of candidates) {
|
|
117
111
|
if (probe(candidate)) return candidate;
|
|
118
112
|
}
|
|
119
113
|
}
|
|
120
114
|
return null;
|
|
121
115
|
};
|
|
122
116
|
|
|
123
|
-
/**
|
|
124
|
-
* 产物自证: 核对 dist/cli.js 与 dist/manifest.json 的摘要是否同源。
|
|
125
|
-
* 通过返回 null, 否则返回人话原因; 原因串全是本文件固定措辞, 不回显清单内容 (清单是外部
|
|
126
|
-
* 文件, 其文本不受控, 不落进输出面)。
|
|
127
|
-
*/
|
|
117
|
+
/** 产物自证: 核对 dist/cli.js 与 dist/manifest.json 的摘要是否同源 */
|
|
128
118
|
const artifactProblem = (distDir) => {
|
|
129
119
|
const manifestPath = join(distDir, MANIFEST_FILE);
|
|
130
120
|
if (!existsSync(manifestPath)) return `缺少产物清单 (dist/${MANIFEST_FILE})`;
|
|
@@ -134,8 +124,6 @@ const artifactProblem = (distDir) => {
|
|
|
134
124
|
} catch {
|
|
135
125
|
return `产物清单 (dist/${MANIFEST_FILE}) 损坏, 不是合法 JSON`;
|
|
136
126
|
}
|
|
137
|
-
// 形状版本先对: 异版本的字段语义无保证, 宁可拒收 (字面量 1 与 scripts/release-artifact.ts 的
|
|
138
|
-
// MANIFEST_SCHEMA_VERSION 同值, 改动须两处同步; 启动器随包分发, 包内无法 import 该模块)
|
|
139
127
|
if (manifest?.schemaVersion !== 1) {
|
|
140
128
|
return `产物清单 (dist/${MANIFEST_FILE}) 的 schemaVersion 不是受支持的版本 (期望 1)`;
|
|
141
129
|
}
|
|
@@ -151,40 +139,81 @@ const artifactProblem = (distDir) => {
|
|
|
151
139
|
} catch {
|
|
152
140
|
return `产物 (dist/${CLI_FILE}) 读不出来, 摘要算不出`;
|
|
153
141
|
}
|
|
154
|
-
if (recorded !== actual)
|
|
142
|
+
if (recorded !== actual) {
|
|
155
143
|
return `产物 (dist/${CLI_FILE}) 的摘要与清单记录不符`;
|
|
144
|
+
}
|
|
156
145
|
return null;
|
|
157
146
|
};
|
|
158
147
|
|
|
159
|
-
/**
|
|
160
|
-
* 本文件是否作为入口被直接执行。
|
|
161
|
-
* 经 realpath 比对而非字面路径: npm 在 Unix 上以符号链接 (或经 shim) 落 bin, 此时 argv[1] 是
|
|
162
|
-
* 链接路径而 import.meta.url 是解析后的真实路径。main 守卫只为让测试 import 本模块取函数时
|
|
163
|
-
* 不触发主流程, 判定失配的后果是入口静默不跑, 故除字面相等外只在 realpath 成功时采信。
|
|
164
|
-
*/
|
|
148
|
+
/** 本文件是否作为入口被直接执行 (双端 realpath.native 展开 win32 8.3 短路径 + 大小写归一) */
|
|
165
149
|
const isEntry = () => {
|
|
166
150
|
const entry = process.argv[1];
|
|
167
151
|
if (typeof entry !== 'string' || entry === '') return false;
|
|
168
152
|
const self = fileURLToPath(import.meta.url);
|
|
169
|
-
|
|
153
|
+
const norm = (value) =>
|
|
154
|
+
process.platform === 'win32' ? value.toLowerCase() : value;
|
|
155
|
+
if (norm(entry) === norm(self)) return true;
|
|
170
156
|
try {
|
|
171
|
-
|
|
157
|
+
const realpath = realpathSync.native ?? realpathSync;
|
|
158
|
+
const realSelf = realpath(self);
|
|
159
|
+
return norm(realpath(entry)) === norm(realSelf);
|
|
172
160
|
} catch {
|
|
173
161
|
return false;
|
|
174
162
|
}
|
|
175
163
|
};
|
|
176
164
|
|
|
177
|
-
|
|
165
|
+
/** 跨运行时异步派生子进程: 运行期父进程忽略 SIGINT 防孤儿, 退出后卸载监听并透传信号或退出码 */
|
|
166
|
+
const runChild = (command, args, extraEnv) =>
|
|
167
|
+
new Promise((resolve) => {
|
|
168
|
+
const ignoreSigint = () => {};
|
|
169
|
+
process.on('SIGINT', ignoreSigint);
|
|
170
|
+
const child = spawn(command, args, {
|
|
171
|
+
stdio: 'inherit',
|
|
172
|
+
env: extraEnv ? { ...process.env, ...extraEnv } : process.env,
|
|
173
|
+
});
|
|
174
|
+
const cleanup = () => {
|
|
175
|
+
process.off('SIGINT', ignoreSigint);
|
|
176
|
+
};
|
|
177
|
+
child.on('error', (error) => {
|
|
178
|
+
cleanup();
|
|
179
|
+
process.stderr.write(`sweep-nm: 启动运行时失败 (${error.message})\n`);
|
|
180
|
+
process.exit(1);
|
|
181
|
+
});
|
|
182
|
+
child.on('exit', (code, signal) => {
|
|
183
|
+
cleanup();
|
|
184
|
+
if (signal) {
|
|
185
|
+
try {
|
|
186
|
+
process.kill(process.pid, signal);
|
|
187
|
+
} catch {
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
resolve();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
process.exit(code ?? 1);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const main = async () => {
|
|
178
198
|
const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
179
199
|
const distDir = join(root, 'dist');
|
|
180
200
|
const built = join(distDir, CLI_FILE);
|
|
201
|
+
const source = join(root, 'src', 'cli.ts');
|
|
181
202
|
const hasBuilt = existsSync(built);
|
|
182
|
-
|
|
203
|
+
const hasSource = existsSync(source);
|
|
204
|
+
|
|
205
|
+
if (!hasBuilt && !hasSource) {
|
|
206
|
+
process.stderr.write(
|
|
207
|
+
`sweep-nm: 缺少可执行入口 (dist/${CLI_FILE} 与 src/cli.ts 均不存在)。\n` +
|
|
208
|
+
' 处置: 重装本包换一份完好分发 (npm install -g @iyowei/sweep-node-modules-cli); 本仓开发态请先执行 bun run build。\n',
|
|
209
|
+
);
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
|
|
183
213
|
const problem = hasBuilt ? artifactProblem(distDir) : null;
|
|
184
214
|
if (problem !== null) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
? '用源码入口跑 (bun src/cli.ts 或 node src/cli.ts), 或重新构建 (bun run build)'
|
|
215
|
+
const advice = hasSource
|
|
216
|
+
? '用源码入口跑 (bun packages/sweep-node-modules-cli/src/cli.ts 或 node packages/sweep-node-modules-cli/src/cli.ts), 或重新构建 (bun run build)'
|
|
188
217
|
: '重装本包换一份完好分发 (npm install -g @iyowei/sweep-node-modules-cli); 重装无效则说明该版本包有缺陷, 需发布者重新构建后再发';
|
|
189
218
|
process.stderr.write(
|
|
190
219
|
`sweep-nm: ${problem}, 已拒绝执行该产物 (无法证明它与构建清单同源)。\n` +
|
|
@@ -192,21 +221,74 @@ const main = () => {
|
|
|
192
221
|
);
|
|
193
222
|
process.exit(1);
|
|
194
223
|
}
|
|
195
|
-
// npm 包内是编译产物 (node 拒绝对 node_modules 内的 TS 做类型剥离, 见 package.json 的 build 脚本);
|
|
196
|
-
// 仓库开发态无 dist, 回退直跑源码 (bun / node 皆可)
|
|
197
|
-
const entry = hasBuilt ? built : join(root, 'src', 'cli.ts');
|
|
198
|
-
const runtime = pickRuntime();
|
|
199
224
|
|
|
200
|
-
|
|
201
|
-
|
|
225
|
+
const entry = hasBuilt ? built : source;
|
|
226
|
+
const isolatedBunfig = join(root, 'bin', 'bunfig.toml');
|
|
227
|
+
const ensureIsolatedBunfig = () => {
|
|
228
|
+
if (existsSync(isolatedBunfig)) return;
|
|
229
|
+
process.stderr.write(
|
|
230
|
+
'sweep-nm: 缺少启动器隔离配置 (bin/bunfig.toml), 为防工作目录 bunfig.toml 劫持已拒绝执行。\n',
|
|
231
|
+
);
|
|
202
232
|
process.exit(1);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// 当前已是 Bun: 隔离态直接同进程 import, 非隔离态直接用 process.execPath 重派隔离态 Bun (不扫 PATH)
|
|
236
|
+
if (typeof process.versions.bun === 'string') {
|
|
237
|
+
ensureIsolatedBunfig();
|
|
238
|
+
if (process.env.CLIS_BUN_ISOLATED === '1') {
|
|
239
|
+
await import(pathToFileURL(entry).href);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
await runChild(
|
|
243
|
+
process.execPath,
|
|
244
|
+
[
|
|
245
|
+
`--config=${isolatedBunfig}`,
|
|
246
|
+
'--no-env-file',
|
|
247
|
+
entry,
|
|
248
|
+
...process.argv.slice(2),
|
|
249
|
+
],
|
|
250
|
+
{ CLIS_BUN_ISOLATED: '1' },
|
|
251
|
+
);
|
|
252
|
+
return;
|
|
203
253
|
}
|
|
204
254
|
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
255
|
+
const isCurrentNodeSupported = isSupportedNodeVersion(process.versions.node);
|
|
256
|
+
|
|
257
|
+
// 当前进程已是合格 Node 时仅探 Bun: 命中切 Bun, 未命中直接同进程 import (零额外派生)
|
|
258
|
+
const runtime = pickRuntime(
|
|
259
|
+
isCurrentNodeSupported ? { names: ['bun'] } : undefined,
|
|
260
|
+
);
|
|
261
|
+
if (runtime !== null && isBunRuntime(runtime)) {
|
|
262
|
+
ensureIsolatedBunfig();
|
|
263
|
+
await runChild(
|
|
264
|
+
runtime,
|
|
265
|
+
[
|
|
266
|
+
`--config=${isolatedBunfig}`,
|
|
267
|
+
'--no-env-file',
|
|
268
|
+
entry,
|
|
269
|
+
...process.argv.slice(2),
|
|
270
|
+
],
|
|
271
|
+
{ CLIS_BUN_ISOLATED: '1' },
|
|
272
|
+
);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (isCurrentNodeSupported) {
|
|
277
|
+
await import(pathToFileURL(entry).href);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (runtime !== null) {
|
|
282
|
+
await runChild(runtime, [entry, ...process.argv.slice(2)]);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
208
285
|
|
|
209
|
-
process.
|
|
286
|
+
process.stderr.write(
|
|
287
|
+
`sweep-nm: 未找到可用的 bun 或 node (>= ${MIN_NODE_MAJOR}.${MIN_NODE_MINOR}.0; 当前 node 为 ${process.versions.node ?? '未知'})\n`,
|
|
288
|
+
);
|
|
289
|
+
process.exit(1);
|
|
210
290
|
};
|
|
211
291
|
|
|
212
|
-
if (isEntry())
|
|
292
|
+
if (isEntry()) {
|
|
293
|
+
await main();
|
|
294
|
+
}
|