@dsh-workbench/adapter-probe 1.1.14-beta.1 → 1.1.14-beta.2
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/bootstrap-run.d.ts +32 -0
- package/dist/bootstrap-run.js +76 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/platform.d.ts +3 -1
- package/dist/platform.js +5 -2
- package/dist/preflight-route.js +10 -10
- package/dist/preflight.js +3 -3
- package/dist/toolchain.js +7 -1
- package/package.json +5 -5
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ShellKind } from '@dsh-workbench/shared/host';
|
|
2
|
+
export interface BootstrapEnvOptions {
|
|
3
|
+
readonly opencliRoot?: string | undefined;
|
|
4
|
+
readonly realHome?: string | undefined;
|
|
5
|
+
readonly parent?: NodeJS.ProcessEnv | undefined;
|
|
6
|
+
readonly shellKind?: ShellKind | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface BootstrapSpawnOptions {
|
|
9
|
+
readonly env: Readonly<Record<string, string>>;
|
|
10
|
+
readonly timeout: number;
|
|
11
|
+
readonly reject: false;
|
|
12
|
+
readonly stripFinalNewline: false;
|
|
13
|
+
}
|
|
14
|
+
export interface BootstrapSpawnResult {
|
|
15
|
+
readonly exitCode: number | null;
|
|
16
|
+
readonly timedOut?: boolean | undefined;
|
|
17
|
+
readonly stdout: string;
|
|
18
|
+
readonly stderr: string;
|
|
19
|
+
}
|
|
20
|
+
export type BootstrapSpawn = (file: string, args: readonly string[], options: BootstrapSpawnOptions) => Promise<BootstrapSpawnResult>;
|
|
21
|
+
export interface BootstrapRunOptions {
|
|
22
|
+
readonly timeoutMs: number;
|
|
23
|
+
readonly env?: Readonly<Record<string, string>> | undefined;
|
|
24
|
+
readonly shellKind?: ShellKind | undefined;
|
|
25
|
+
readonly spawn?: BootstrapSpawn | undefined;
|
|
26
|
+
}
|
|
27
|
+
export interface BootstrapRunResult {
|
|
28
|
+
readonly ok: boolean;
|
|
29
|
+
readonly detail: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function bootstrapEnv(options?: BootstrapEnvOptions): Record<string, string>;
|
|
32
|
+
export declare function runBootstrapCommand(line: string, options: BootstrapRunOptions): Promise<BootstrapRunResult>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { execa } from 'execa';
|
|
5
|
+
import { isolatedRoot } from '@dsh-workbench/adapter-runtime';
|
|
6
|
+
import { tailLines } from '@dsh-workbench/shared/host';
|
|
7
|
+
import { currentShellKind } from './platform.js';
|
|
8
|
+
export function bootstrapEnv(options = {}) {
|
|
9
|
+
const shellKind = options.shellKind ?? currentShellKind();
|
|
10
|
+
const opencliRoot = options.opencliRoot ?? isolatedRoot();
|
|
11
|
+
const realHome = options.realHome ?? homedir();
|
|
12
|
+
const parent = options.parent ?? process.env;
|
|
13
|
+
const env = {};
|
|
14
|
+
for (const [key, value] of Object.entries(parent)) {
|
|
15
|
+
if (typeof value === 'string')
|
|
16
|
+
env[key] = value;
|
|
17
|
+
}
|
|
18
|
+
const home = join(opencliRoot, 'home');
|
|
19
|
+
env['HOME'] = home;
|
|
20
|
+
if (shellKind === 'pwsh')
|
|
21
|
+
env['USERPROFILE'] = home;
|
|
22
|
+
const userConfig = join(realHome, '.npmrc');
|
|
23
|
+
if (existsSync(userConfig))
|
|
24
|
+
env['NPM_CONFIG_USERCONFIG'] = userConfig;
|
|
25
|
+
const cache = join(opencliRoot, 'npm-cache');
|
|
26
|
+
env['npm_config_cache'] = cache;
|
|
27
|
+
env['NPM_CONFIG_CACHE'] = cache;
|
|
28
|
+
env['NO_COLOR'] = '1';
|
|
29
|
+
env['TERM'] = 'dumb';
|
|
30
|
+
return env;
|
|
31
|
+
}
|
|
32
|
+
function shellOf(line, shellKind) {
|
|
33
|
+
return shellKind === 'pwsh'
|
|
34
|
+
? { file: 'pwsh', args: ['-NoProfile', '-NonInteractive', '-Command', line] }
|
|
35
|
+
: { file: 'bash', args: ['-c', line] };
|
|
36
|
+
}
|
|
37
|
+
const defaultSpawn = async (file, args, options) => {
|
|
38
|
+
const result = await execa(file, [...args], {
|
|
39
|
+
env: { ...options.env },
|
|
40
|
+
timeout: options.timeout,
|
|
41
|
+
reject: options.reject,
|
|
42
|
+
stripFinalNewline: options.stripFinalNewline,
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
exitCode: result.exitCode ?? null,
|
|
46
|
+
timedOut: result.timedOut === true,
|
|
47
|
+
stdout: result.stdout,
|
|
48
|
+
stderr: result.stderr,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export async function runBootstrapCommand(line, options) {
|
|
52
|
+
const shellKind = options.shellKind ?? currentShellKind();
|
|
53
|
+
const spawn = options.spawn ?? defaultSpawn;
|
|
54
|
+
const env = { ...bootstrapEnv({ shellKind }), ...(options.env ?? {}) };
|
|
55
|
+
const command = shellOf(line, shellKind);
|
|
56
|
+
try {
|
|
57
|
+
const result = await spawn(command.file, command.args, {
|
|
58
|
+
env,
|
|
59
|
+
timeout: options.timeoutMs,
|
|
60
|
+
reject: false,
|
|
61
|
+
stripFinalNewline: false,
|
|
62
|
+
});
|
|
63
|
+
if (result.timedOut === true)
|
|
64
|
+
return { ok: false, detail: `超时(${String(options.timeoutMs)} ms):${line}` };
|
|
65
|
+
if (result.exitCode === 0)
|
|
66
|
+
return { ok: true, detail: tailLines(result.stdout, 1) };
|
|
67
|
+
const detail = tailLines(result.stderr || result.stdout, 4);
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
detail: detail === '' ? `没跑通(退出码 ${String(result.exitCode)}):${line}` : detail,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return { ok: false, detail: `${String(error)}:${line}` };
|
|
75
|
+
}
|
|
76
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/platform.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ShellKind } from '@dsh-workbench/shared/host';
|
|
1
2
|
import type { HostOs } from '@dsh-workbench/shared/contract/protocol/platform';
|
|
2
|
-
export { hostOsOf, hostSurface, profileNameOf, type HostSurfaceInput } from '@dsh-workbench/shared/host';
|
|
3
|
+
export { hostOsOf, hostSurface, profileNameOf, shellKindOf, type HostSurfaceInput } from '@dsh-workbench/shared/host';
|
|
3
4
|
export declare function currentHostOs(): HostOs;
|
|
5
|
+
export declare function currentShellKind(): ShellKind;
|
package/dist/platform.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { hostOsOf } from '@dsh-workbench/shared/host';
|
|
2
|
-
export { hostOsOf, hostSurface, profileNameOf } from '@dsh-workbench/shared/host';
|
|
1
|
+
import { hostOsOf, shellKindOf } from '@dsh-workbench/shared/host';
|
|
2
|
+
export { hostOsOf, hostSurface, profileNameOf, shellKindOf } from '@dsh-workbench/shared/host';
|
|
3
3
|
export function currentHostOs() {
|
|
4
4
|
return hostOsOf(process.platform);
|
|
5
5
|
}
|
|
6
|
+
export function currentShellKind() {
|
|
7
|
+
return shellKindOf(process.platform);
|
|
8
|
+
}
|
package/dist/preflight-route.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { basename, join } from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { PREFLIGHT_INSTALL_TIMEOUT_MS, preflightHandler, workbenchRoot } from '@dsh-workbench/shared/host';
|
|
3
3
|
import { WAKE_BROWSER_ROUTE } from '@dsh-workbench/shared/contract/protocol/preflight-wake';
|
|
4
|
+
import { runBootstrapCommand } from './bootstrap-run.js';
|
|
4
5
|
import { createDiyPresetProbe } from './diy-preset-health.js';
|
|
6
|
+
import { opencliInstallCommand } from './install.js';
|
|
5
7
|
import { hostSurface } from './platform.js';
|
|
6
8
|
import { createPreflight } from './preflight.js';
|
|
7
9
|
import { probeDesktopToolchain } from './toolchain-probe.js';
|
|
@@ -23,7 +25,10 @@ function desktopBrowserOf(input) {
|
|
|
23
25
|
}
|
|
24
26
|
export function registerPreflight(input) {
|
|
25
27
|
const command = input.runtimeCommands['opencli'] ?? Object.values(input.runtimeCommands)[0] ?? 'opencli';
|
|
26
|
-
const
|
|
28
|
+
const configuredInstall = process.env.DSH_WORKBENCH_OPENCLI_INSTALL;
|
|
29
|
+
const installCommand = configuredInstall === undefined || configuredInstall === ''
|
|
30
|
+
? opencliInstallCommand()
|
|
31
|
+
: configuredInstall;
|
|
27
32
|
const desktopBrowser = input.desktopBrowser ??
|
|
28
33
|
desktopBrowserOf({
|
|
29
34
|
ctx: input.ctx,
|
|
@@ -33,7 +38,8 @@ export function registerPreflight(input) {
|
|
|
33
38
|
const preflight = createPreflight({
|
|
34
39
|
shell: input.shell,
|
|
35
40
|
command,
|
|
36
|
-
|
|
41
|
+
installCommand,
|
|
42
|
+
install: () => runBootstrapCommand(installCommand, { timeoutMs: PREFLIGHT_INSTALL_TIMEOUT_MS }),
|
|
37
43
|
logger: input.ctx.logger,
|
|
38
44
|
warmReads: input.warmReads,
|
|
39
45
|
...(input.runtimeCapabilities === undefined ? {} : { capabilities: input.runtimeCapabilities }),
|
|
@@ -49,13 +55,7 @@ export function registerPreflight(input) {
|
|
|
49
55
|
root,
|
|
50
56
|
pnpm: process.env.DSH_WB_PNPM?.trim() || 'pnpm',
|
|
51
57
|
npm: 'npm',
|
|
52
|
-
run:
|
|
53
|
-
const ran = await runShell(input.shell, command, { timeoutMs: INSTALL_TIMEOUT_MS });
|
|
54
|
-
return {
|
|
55
|
-
ok: ran.exitCode === 0 && !ran.timedOut,
|
|
56
|
-
detail: tailLines(ran.stderr || ran.stdout, 3),
|
|
57
|
-
};
|
|
58
|
-
},
|
|
58
|
+
run: (command) => runBootstrapCommand(command, { timeoutMs: PREFLIGHT_INSTALL_TIMEOUT_MS }),
|
|
59
59
|
});
|
|
60
60
|
if (result.ok && result.binDir !== undefined) {
|
|
61
61
|
prependPath(result.binDir);
|
package/dist/preflight.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PREFLIGHT_DOCTOR_TIMEOUT_MS, PREFLIGHT_FRESH_MS, PREFLIGHT_INSTALL_TIMEOUT_MS, PREFLIGHT_VERSION_TIMEOUT_MS, WARM_TIMEOUT_MS, } from '@dsh-workbench/shared/host';
|
|
2
2
|
import { tailLines } from '@dsh-workbench/shared/host';
|
|
3
3
|
import { opencliCommandLine } from '@dsh-workbench/adapter-runtime';
|
|
4
4
|
import { runShell } from '@dsh-workbench/shared/host';
|
|
@@ -124,7 +124,7 @@ export function createPreflight(options) {
|
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
126
|
async function probeBridge() {
|
|
127
|
-
const result = await exec('bridge', `${command} doctor`,
|
|
127
|
+
const result = await exec('bridge', `${command} doctor`, PREFLIGHT_DOCTOR_TIMEOUT_MS);
|
|
128
128
|
if (result.kind === 'stalled') {
|
|
129
129
|
return { ok: false, detail: result.detail, issues: ['unknown'], stalled: true };
|
|
130
130
|
}
|
|
@@ -143,7 +143,7 @@ export function createPreflight(options) {
|
|
|
143
143
|
appendLog('cli', installed.detail);
|
|
144
144
|
return installed;
|
|
145
145
|
}
|
|
146
|
-
const result = await exec('cli', installCommand,
|
|
146
|
+
const result = await exec('cli', installCommand, PREFLIGHT_INSTALL_TIMEOUT_MS);
|
|
147
147
|
if (result.kind !== 'ok')
|
|
148
148
|
return { ok: false, detail: result.detail };
|
|
149
149
|
return { ok: true, detail: tailLines(result.stdout, 1) };
|
package/dist/toolchain.js
CHANGED
|
@@ -4,6 +4,7 @@ import writeFileAtomic from 'write-file-atomic';
|
|
|
4
4
|
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { quoteShellArg, quoteShellArgFor } from '@dsh-workbench/shared/host';
|
|
7
|
+
import { bootstrapEnv } from './bootstrap-run.js';
|
|
7
8
|
import { hostSurface } from './platform.js';
|
|
8
9
|
export function desktopPnpmPath(proc = process, exists = existsSync) {
|
|
9
10
|
if (hostSurface({ proc }).deployment !== 'desktop')
|
|
@@ -143,7 +144,12 @@ export function provisionLocalPnpmSync(options) {
|
|
|
143
144
|
try {
|
|
144
145
|
const run = options.run ??
|
|
145
146
|
((line) => {
|
|
146
|
-
execaSync(line, {
|
|
147
|
+
execaSync(line, {
|
|
148
|
+
stdio: 'ignore',
|
|
149
|
+
timeout: 180_000,
|
|
150
|
+
env: bootstrapEnv({ opencliRoot: join(options.root, 'opencli') }),
|
|
151
|
+
shell: true,
|
|
152
|
+
});
|
|
147
153
|
});
|
|
148
154
|
run(command);
|
|
149
155
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-workbench/adapter-probe",
|
|
3
|
-
"version": "1.1.14-beta.
|
|
3
|
+
"version": "1.1.14-beta.2",
|
|
4
4
|
"description": "Workbench adapter-probe adapter.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"execa": "^10.2.0",
|
|
17
17
|
"proper-lockfile": "^4.1.2",
|
|
18
18
|
"write-file-atomic": "^8.0.0",
|
|
19
|
-
"@dsh-workbench/adapter-
|
|
20
|
-
"@dsh-workbench/
|
|
21
|
-
"@dsh-workbench/
|
|
22
|
-
"@dsh-workbench/adapter-
|
|
19
|
+
"@dsh-workbench/adapter-runtime": "1.1.14-beta.2",
|
|
20
|
+
"@dsh-workbench/shared": "1.1.14-beta.2",
|
|
21
|
+
"@dsh-workbench/adapter-profile": "1.1.14-beta.2",
|
|
22
|
+
"@dsh-workbench/adapter-supply": "1.1.14-beta.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^24.19.0",
|