@dsh-workbench/adapter-runtime 1.1.14-beta.1 → 1.1.14
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/channel/package.json +1 -1
- package/dist/browser/browser-find.d.ts +2 -2
- package/dist/browser/browser-find.js +38 -22
- package/dist/browser/browser-read.d.ts +2 -2
- package/dist/browser/browser-read.js +19 -13
- package/dist/cli/command.d.ts +1 -1
- package/dist/cli/command.js +4 -10
- package/dist/cli/opencli-runtime.d.ts +1 -0
- package/dist/cli/opencli-runtime.js +6 -2
- package/dist/cli/opencli.d.ts +2 -2
- package/dist/cli/opencli.js +13 -6
- package/dist/command/index.d.ts +2 -2
- package/dist/command/index.js +7 -5
- package/dist/data/channel.d.ts +2 -2
- package/dist/data/channel.js +3 -3
- package/dist/data/index.d.ts +2 -2
- package/dist/data/index.js +29 -18
- package/dist/extensions/index.d.ts +10 -0
- package/dist/extensions/index.js +36 -0
- package/dist/git/index.d.ts +2 -2
- package/dist/git/index.js +17 -5
- package/dist/install.d.ts +23 -0
- package/dist/install.js +45 -0
- package/dist/libs/index.js +6 -10
- package/dist/paths.d.ts +14 -0
- package/dist/paths.js +33 -0
- package/package.json +2 -3
package/channel/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Seam } from '@dsh-workbench/shared/host';
|
|
2
2
|
export interface BrowserFindEntry {
|
|
3
3
|
readonly text: string;
|
|
4
4
|
readonly tag: string;
|
|
@@ -16,7 +16,7 @@ export interface BrowserFindResult {
|
|
|
16
16
|
readonly helpUrl?: string;
|
|
17
17
|
}
|
|
18
18
|
export interface BrowserFindOptions {
|
|
19
|
-
readonly
|
|
19
|
+
readonly seam: Seam;
|
|
20
20
|
readonly css: string;
|
|
21
21
|
readonly url?: string;
|
|
22
22
|
readonly command?: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { parseJsonLoose } from '@dsh-workbench/shared/host';
|
|
1
|
+
import { now, parseJsonLoose } from '@dsh-workbench/shared/host';
|
|
2
2
|
import { BROWSER_READ_SESSION } from './browser-read.js';
|
|
3
3
|
import { backgroundLine, OPENCLI_WINDOW_ENV } from '../cli/index.js';
|
|
4
|
-
import {
|
|
4
|
+
import { noWrite } from '@dsh-workbench/shared/host';
|
|
5
5
|
const DEFAULT_TIMEOUT_MS = 25000;
|
|
6
6
|
const DEFAULT_SETTLE_MS = 2500;
|
|
7
7
|
const URL_TIMEOUT_MS = 8000;
|
|
@@ -89,10 +89,16 @@ export function urlOf(stdout) {
|
|
|
89
89
|
}
|
|
90
90
|
return bare;
|
|
91
91
|
}
|
|
92
|
-
async function currentUrl(
|
|
92
|
+
async function currentUrl(seam, command, session) {
|
|
93
93
|
const line = backgroundLine(command, ['browser', session, 'get', 'url', '--window', 'background']);
|
|
94
94
|
try {
|
|
95
|
-
const result = await
|
|
95
|
+
const result = await seam.run({
|
|
96
|
+
command: line,
|
|
97
|
+
intent: noWrite(),
|
|
98
|
+
retry: 'safe',
|
|
99
|
+
timeoutMs: URL_TIMEOUT_MS,
|
|
100
|
+
env: OPENCLI_WINDOW_ENV,
|
|
101
|
+
});
|
|
96
102
|
if (result.exitCode !== 0)
|
|
97
103
|
return '';
|
|
98
104
|
return urlOf(result.stdout);
|
|
@@ -104,7 +110,7 @@ async function currentUrl(shell, command, session) {
|
|
|
104
110
|
function sleep(ms) {
|
|
105
111
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
106
112
|
}
|
|
107
|
-
async function findOnce(
|
|
113
|
+
async function findOnce(seam, command, session, css, limit, textMax, timeoutMs) {
|
|
108
114
|
const line = backgroundLine(command, [
|
|
109
115
|
'browser',
|
|
110
116
|
session,
|
|
@@ -118,7 +124,13 @@ async function findOnce(shell, command, session, css, limit, textMax, timeoutMs)
|
|
|
118
124
|
'--window',
|
|
119
125
|
'background',
|
|
120
126
|
]);
|
|
121
|
-
const result = await
|
|
127
|
+
const result = await seam.run({
|
|
128
|
+
command: line,
|
|
129
|
+
intent: noWrite(),
|
|
130
|
+
retry: 'safe',
|
|
131
|
+
timeoutMs,
|
|
132
|
+
env: OPENCLI_WINDOW_ENV,
|
|
133
|
+
});
|
|
122
134
|
if (result.timedOut) {
|
|
123
135
|
return { kind: 'timeout', detail: `没在 ${Math.round(timeoutMs / 1000)} 秒内返回` };
|
|
124
136
|
}
|
|
@@ -132,35 +144,39 @@ async function findOnce(shell, command, session, css, limit, textMax, timeoutMs)
|
|
|
132
144
|
const entries = entriesOf(parseJsonLoose(result.stdout));
|
|
133
145
|
return { kind: 'ok', entries, stdout: result.stdout };
|
|
134
146
|
}
|
|
135
|
-
async function openOnce(
|
|
147
|
+
async function openOnce(seam, command, session, url, timeoutMs) {
|
|
136
148
|
const line = backgroundLine(command, ['browser', session, 'open', url, '--window', 'background']);
|
|
137
|
-
let result;
|
|
138
149
|
try {
|
|
139
|
-
result = await
|
|
150
|
+
const result = await seam.run({
|
|
151
|
+
command: line,
|
|
152
|
+
intent: noWrite(),
|
|
153
|
+
timeoutMs,
|
|
154
|
+
env: OPENCLI_WINDOW_ENV,
|
|
155
|
+
});
|
|
156
|
+
if (result.timedOut)
|
|
157
|
+
return `没在 ${Math.round(timeoutMs / 1000)} 秒内打开`;
|
|
158
|
+
if (result.exitCode !== 0) {
|
|
159
|
+
const reason = reasonOf(result.stdout, result.stderr);
|
|
160
|
+
return reason === '' ? `opencli 打开失败(退出码 ${String(result.exitCode ?? '?')})` : reason;
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
140
163
|
}
|
|
141
164
|
catch (error) {
|
|
142
165
|
return error instanceof Error ? error.message : String(error);
|
|
143
166
|
}
|
|
144
|
-
if (result.timedOut)
|
|
145
|
-
return `没在 ${Math.round(timeoutMs / 1000)} 秒内打开`;
|
|
146
|
-
if (result.exitCode !== 0) {
|
|
147
|
-
const reason = reasonOf(result.stdout, result.stderr);
|
|
148
|
-
return reason === '' ? `opencli 打开失败(退出码 ${String(result.exitCode ?? '?')})` : reason;
|
|
149
|
-
}
|
|
150
|
-
return undefined;
|
|
151
167
|
}
|
|
152
168
|
export async function browserFind(options) {
|
|
153
|
-
const {
|
|
169
|
+
const { seam, css, url, open = true } = options;
|
|
154
170
|
const command = options.command ?? 'opencli';
|
|
155
171
|
const session = options.session ?? BROWSER_READ_SESSION;
|
|
156
172
|
const limit = options.limit ?? DEFAULT_LIMIT;
|
|
157
173
|
const textMax = options.textMax ?? DEFAULT_TEXT_MAX;
|
|
158
174
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
159
175
|
const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;
|
|
160
|
-
const at =
|
|
176
|
+
const at = now();
|
|
161
177
|
const find = async () => {
|
|
162
178
|
try {
|
|
163
|
-
return await findOnce(
|
|
179
|
+
return await findOnce(seam, command, session, css, limit, textMax, timeoutMs);
|
|
164
180
|
}
|
|
165
181
|
catch (error) {
|
|
166
182
|
return {
|
|
@@ -172,9 +188,9 @@ export async function browserFind(options) {
|
|
|
172
188
|
};
|
|
173
189
|
const canMove = open && url !== undefined;
|
|
174
190
|
if (canMove) {
|
|
175
|
-
const here = await currentUrl(
|
|
191
|
+
const here = await currentUrl(seam, command, session);
|
|
176
192
|
if (here !== '' && !sameOrigin(here, url)) {
|
|
177
|
-
const opened = await openOnce(
|
|
193
|
+
const opened = await openOnce(seam, command, session, url, timeoutMs);
|
|
178
194
|
if (opened !== undefined) {
|
|
179
195
|
return {
|
|
180
196
|
ok: false,
|
|
@@ -196,7 +212,7 @@ export async function browserFind(options) {
|
|
|
196
212
|
return { ok: false, code: 'cli-exec-failed', at, entries: [], count: 0, message: '没找到元素' };
|
|
197
213
|
}
|
|
198
214
|
if (outcome.kind === 'failed' && canMove) {
|
|
199
|
-
const opened = await openOnce(
|
|
215
|
+
const opened = await openOnce(seam, command, session, url, timeoutMs);
|
|
200
216
|
if (opened === undefined) {
|
|
201
217
|
await sleep(settleMs);
|
|
202
218
|
const second = await find();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Seam } from '@dsh-workbench/shared/host';
|
|
2
2
|
import { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION } from '@dsh-workbench/shared/host';
|
|
3
3
|
export { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION };
|
|
4
4
|
export interface BrowserReadResult {
|
|
@@ -13,7 +13,7 @@ export interface BrowserReadResult {
|
|
|
13
13
|
readonly helpUrl?: string;
|
|
14
14
|
}
|
|
15
15
|
export interface BrowserReadOptions {
|
|
16
|
-
readonly
|
|
16
|
+
readonly seam: Seam;
|
|
17
17
|
readonly script: string;
|
|
18
18
|
readonly url?: string;
|
|
19
19
|
readonly loginUrl?: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { parseJsonLoose } from '@dsh-workbench/shared/host';
|
|
1
|
+
import { now, parseJsonLoose } from '@dsh-workbench/shared/host';
|
|
2
2
|
import { tailLines } from '@dsh-workbench/shared/host';
|
|
3
3
|
import { backgroundLine, OPENCLI_WINDOW_ENV } from '../cli/index.js';
|
|
4
|
-
import {
|
|
4
|
+
import { noWrite } from '@dsh-workbench/shared/host';
|
|
5
5
|
import { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION } from '@dsh-workbench/shared/host';
|
|
6
6
|
export { BROWSER_READ_SESSION, BROWSER_RECORD_SESSION, BROWSER_SCREEN_SESSION };
|
|
7
7
|
const DEFAULT_TIMEOUT_MS = 25000;
|
|
@@ -54,8 +54,14 @@ function blockerFor(code) {
|
|
|
54
54
|
function sleep(ms) {
|
|
55
55
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
56
56
|
}
|
|
57
|
-
async function shellRun(
|
|
58
|
-
const result = await
|
|
57
|
+
async function shellRun(seam, command, argv, timeoutMs) {
|
|
58
|
+
const result = await seam.run({
|
|
59
|
+
command: backgroundLine(command, argv),
|
|
60
|
+
intent: noWrite(),
|
|
61
|
+
retry: 'safe',
|
|
62
|
+
timeoutMs,
|
|
63
|
+
env: OPENCLI_WINDOW_ENV,
|
|
64
|
+
});
|
|
59
65
|
if (result.timedOut) {
|
|
60
66
|
return { kind: 'timeout', detail: `没在 ${Math.round(timeoutMs / 1000)} 秒内返回`, stderr: result.stderr };
|
|
61
67
|
}
|
|
@@ -64,11 +70,11 @@ async function shellRun(shell, command, argv, timeoutMs) {
|
|
|
64
70
|
}
|
|
65
71
|
return { kind: 'ok', stdout: result.stdout };
|
|
66
72
|
}
|
|
67
|
-
async function evalOnce(
|
|
73
|
+
async function evalOnce(seam, command, session, script, timeoutMs, retryMs) {
|
|
68
74
|
const run = async () => {
|
|
69
75
|
let attempt;
|
|
70
76
|
try {
|
|
71
|
-
attempt = await shellRun(
|
|
77
|
+
attempt = await shellRun(seam, command, ['browser', session, 'eval', script, '--window', 'background'], timeoutMs);
|
|
72
78
|
}
|
|
73
79
|
catch (error) {
|
|
74
80
|
return {
|
|
@@ -131,10 +137,10 @@ async function evalOnce(shell, command, session, script, timeoutMs, retryMs) {
|
|
|
131
137
|
await sleep(retryMs);
|
|
132
138
|
return run();
|
|
133
139
|
}
|
|
134
|
-
async function openOnce(
|
|
140
|
+
async function openOnce(seam, command, session, url, timeoutMs) {
|
|
135
141
|
let attempt;
|
|
136
142
|
try {
|
|
137
|
-
attempt = await shellRun(
|
|
143
|
+
attempt = await shellRun(seam, command, ['browser', session, 'open', url, '--window', 'background'], timeoutMs);
|
|
138
144
|
}
|
|
139
145
|
catch (error) {
|
|
140
146
|
return {
|
|
@@ -158,14 +164,14 @@ async function openOnce(shell, command, session, url, timeoutMs) {
|
|
|
158
164
|
};
|
|
159
165
|
}
|
|
160
166
|
export async function browserRead(options) {
|
|
161
|
-
const {
|
|
167
|
+
const { seam, script, url, loginUrl, open = true } = options;
|
|
162
168
|
const command = options.command ?? 'opencli';
|
|
163
169
|
const session = options.session ?? BROWSER_READ_SESSION;
|
|
164
170
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
165
171
|
const retryMs = options.retryMs ?? DEFAULT_RETRY_MS;
|
|
166
172
|
const settleMs = options.settleMs ?? DEFAULT_SETTLE_MS;
|
|
167
|
-
const at =
|
|
168
|
-
const first = await evalOnce(
|
|
173
|
+
const at = now();
|
|
174
|
+
const first = await evalOnce(seam, command, session, script, timeoutMs, retryMs);
|
|
169
175
|
if (first.kind === 'failure')
|
|
170
176
|
return { ...first.result, at };
|
|
171
177
|
let page = first.value;
|
|
@@ -181,11 +187,11 @@ export async function browserRead(options) {
|
|
|
181
187
|
...(url === undefined ? {} : { helpUrl: url }),
|
|
182
188
|
};
|
|
183
189
|
}
|
|
184
|
-
const opened = await openOnce(
|
|
190
|
+
const opened = await openOnce(seam, command, session, url, timeoutMs);
|
|
185
191
|
if (opened !== undefined)
|
|
186
192
|
return { ...opened, at };
|
|
187
193
|
await sleep(settleMs);
|
|
188
|
-
const second = await evalOnce(
|
|
194
|
+
const second = await evalOnce(seam, command, session, script, timeoutMs, retryMs);
|
|
189
195
|
if (second.kind === 'failure')
|
|
190
196
|
return { ...second.result, at };
|
|
191
197
|
page = second.value;
|
package/dist/cli/command.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface OpencliResolution {
|
|
|
8
8
|
readonly isolated: string | null;
|
|
9
9
|
}
|
|
10
10
|
export declare const OPENCLI_PATH_FALLBACK = "opencli";
|
|
11
|
-
export declare function isolatedOpencliPathOf(
|
|
11
|
+
export declare function isolatedOpencliPathOf(_ctx: HostContextLike): string | null;
|
|
12
12
|
export declare function opencliCommandOf(ctx: HostContextLike): OpencliResolution;
|
|
13
13
|
export * from './opencli.js';
|
|
14
14
|
export * from './opencli-runtime.js';
|
package/dist/cli/command.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { runtimeLayoutOf } from '@dsh-workbench/shared/host';
|
|
4
|
+
import { OPENCLI_RUNTIME_ID } from '../foundation/paths.js';
|
|
3
5
|
export const OPENCLI_PATH_FALLBACK = 'opencli';
|
|
4
6
|
function binName(platform = process.platform) {
|
|
5
7
|
return platform === 'win32' ? 'opencli.cmd' : 'opencli';
|
|
6
8
|
}
|
|
7
|
-
export function isolatedOpencliPathOf(
|
|
8
|
-
|
|
9
|
-
if (typeof homePath !== 'function')
|
|
10
|
-
return null;
|
|
11
|
-
try {
|
|
12
|
-
return join(homePath('workbench/opencli/bin'), binName());
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
9
|
+
export function isolatedOpencliPathOf(_ctx) {
|
|
10
|
+
return join(runtimeLayoutOf(OPENCLI_RUNTIME_ID).root, 'bin', binName());
|
|
17
11
|
}
|
|
18
12
|
export function opencliCommandOf(ctx) {
|
|
19
13
|
const isolated = isolatedOpencliPathOf(ctx);
|
|
@@ -6,6 +6,7 @@ export declare function isolatedCommand(): string;
|
|
|
6
6
|
export { libsPrefix } from '../foundation/paths.js';
|
|
7
7
|
export { libInstallCommand } from '../foundation/install.js';
|
|
8
8
|
export declare function libDir(name: string): string;
|
|
9
|
+
export declare function pnpmIsolationFlags(): string;
|
|
9
10
|
export declare function isolatedInstallCommand(): string;
|
|
10
11
|
export declare function isolatedPnpmInstallCommand(pnpmCjs: string): string;
|
|
11
12
|
export { isolatedHome, isolatedRoot, libsBinDir, npmCacheDir, toolchainOpencliDir, vendorPeerLink, vendorPluginsDir, vendorPrefix } from '../foundation/paths.js';
|
|
@@ -29,15 +29,19 @@ export { libInstallCommand } from '../foundation/install.js';
|
|
|
29
29
|
export function libDir(name) {
|
|
30
30
|
return join(libsPrefix(), 'node_modules', name);
|
|
31
31
|
}
|
|
32
|
+
export function pnpmIsolationFlags() {
|
|
33
|
+
return (`--config.cache-dir=${quoteShellArg(join(isolatedRoot(), 'pnpm-cache'))} ` +
|
|
34
|
+
`--config.state-dir=${quoteShellArg(join(isolatedRoot(), 'pnpm-state'))}`);
|
|
35
|
+
}
|
|
32
36
|
export function isolatedInstallCommand() {
|
|
33
37
|
const pnpm = process.env.DSH_WB_PNPM?.trim() || 'pnpm';
|
|
34
|
-
return `${pnpm} add --dir ${quoteShellArg(toolchainDir())} ${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(npmCacheDir())} --allow-build=${OPENCLI_NPM_PACKAGE}`;
|
|
38
|
+
return `${pnpm} add --dir ${quoteShellArg(toolchainDir())} ${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(npmCacheDir())} ${pnpmIsolationFlags()} --allow-build=${OPENCLI_NPM_PACKAGE}`;
|
|
35
39
|
}
|
|
36
40
|
export function isolatedPnpmInstallCommand(pnpmCjs) {
|
|
37
41
|
const store = join(isolatedRoot(), 'pnpm-store');
|
|
38
42
|
return (`node ${quoteShellArg(pnpmCjs)} add --dir ${quoteShellArg(toolchainDir())} ` +
|
|
39
43
|
`${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(store)} ` +
|
|
40
|
-
|
|
44
|
+
`${pnpmIsolationFlags()} --allow-build=${OPENCLI_NPM_PACKAGE}`);
|
|
41
45
|
}
|
|
42
46
|
export { isolatedHome, isolatedRoot, libsBinDir, npmCacheDir, toolchainOpencliDir, vendorPeerLink, vendorPluginsDir, vendorPrefix } from '../foundation/paths.js';
|
|
43
47
|
export { OPENCLI_NPM_PACKAGE } from '../foundation/paths.js';
|
package/dist/cli/opencli.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Seam } from '@dsh-workbench/shared/host';
|
|
2
2
|
import type { Opencli, OpencliSession } from './opencli-types.js';
|
|
3
3
|
export declare function opencliCommandLine(command: string, argv: readonly string[], session?: OpencliSession, platform?: NodeJS.Platform): string;
|
|
4
4
|
export declare function createOpencli(options: {
|
|
5
|
-
|
|
5
|
+
seam: Seam;
|
|
6
6
|
plugin: string;
|
|
7
7
|
logger?: {
|
|
8
8
|
warn?(message: string): void;
|
package/dist/cli/opencli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { OPENCLI_MAX_CONCURRENT, OPENCLI_TIMEOUT_MS } from '@dsh-workbench/shared/host';
|
|
1
|
+
import { OPENCLI_MAX_CONCURRENT, OPENCLI_TIMEOUT_MS, now } from '@dsh-workbench/shared/host';
|
|
2
2
|
import { parseJsonLoose } from '@dsh-workbench/shared/host';
|
|
3
|
-
import { quoteShellArgFor, tailLines } from '@dsh-workbench/shared/host';
|
|
3
|
+
import { productWrite, quoteShellArgFor, tailLines } from '@dsh-workbench/shared/host';
|
|
4
4
|
import { helpUrlOf, parseCliErrorEnvelope } from '@dsh-workbench/shared/host';
|
|
5
5
|
import { OPENCLI_WINDOW_ENV } from './opencli-window.js';
|
|
6
|
-
import {
|
|
6
|
+
import { SeamError } from '@dsh-workbench/shared/host';
|
|
7
7
|
import { WorkbenchDataError } from '@dsh-workbench/shared/host';
|
|
8
8
|
const FORBIDDEN_CODES = new Set(['FORBIDDEN', 'PERMISSION_DENIED']);
|
|
9
9
|
const SITE_SESSION_ARGS = ['--site-session', 'persistent'];
|
|
@@ -17,7 +17,7 @@ export function opencliCommandLine(command, argv, session = 'persistent', platfo
|
|
|
17
17
|
].join(' ');
|
|
18
18
|
}
|
|
19
19
|
export function createOpencli(options) {
|
|
20
|
-
const {
|
|
20
|
+
const { seam, plugin, logger, command = 'opencli', timeoutMs = OPENCLI_TIMEOUT_MS, maxConcurrent = OPENCLI_MAX_CONCURRENT, } = options;
|
|
21
21
|
const inflight = new Map();
|
|
22
22
|
const MAX_CONCURRENT = maxConcurrent;
|
|
23
23
|
let running = 0;
|
|
@@ -48,13 +48,20 @@ export function createOpencli(options) {
|
|
|
48
48
|
async function call(commandLine, workdir) {
|
|
49
49
|
let result;
|
|
50
50
|
try {
|
|
51
|
-
result = await
|
|
51
|
+
result = await seam.run({
|
|
52
|
+
command: commandLine,
|
|
53
|
+
intent: productWrite(),
|
|
52
54
|
...(workdir === undefined ? {} : { workdir }),
|
|
53
55
|
timeoutMs,
|
|
54
56
|
env: OPENCLI_WINDOW_ENV,
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
catch (error) {
|
|
60
|
+
if (error instanceof SeamError) {
|
|
61
|
+
throw new WorkbenchDataError('cli-exec-failed', error.message, {
|
|
62
|
+
hint: '这条命令被沙箱挡住了:把命令与写入域记下来交给维护者。',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
58
65
|
throw new WorkbenchDataError('cli-exec-failed', `执行 opencli 失败:${String(error)}`, {
|
|
59
66
|
hint: '确认 opencli 已安装,并且在 PATH 里。',
|
|
60
67
|
});
|
|
@@ -107,7 +114,7 @@ export function createOpencli(options) {
|
|
|
107
114
|
const commandLine = opencliCommandLine(command, [plugin, ...args], session);
|
|
108
115
|
const once = async () => {
|
|
109
116
|
const value = await call(commandLine, workdir);
|
|
110
|
-
return { value, at:
|
|
117
|
+
return { value, at: now() };
|
|
111
118
|
};
|
|
112
119
|
const task = runLimited(async () => {
|
|
113
120
|
try {
|
package/dist/command/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { DshShell } from '@dsh-workbench/shared';
|
|
2
1
|
import type { CommandReader } from '@dsh-workbench/shared';
|
|
2
|
+
import { type Seam } from '@dsh-workbench/shared/host';
|
|
3
3
|
export interface CommandReaderOptions {
|
|
4
|
-
readonly
|
|
4
|
+
readonly seam: Seam;
|
|
5
5
|
readonly tmpRoot?: string | undefined;
|
|
6
6
|
}
|
|
7
7
|
export declare function createCommandReader(options: CommandReaderOptions): CommandReader;
|
package/dist/command/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { mkdtempSync, rmSync
|
|
1
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import { quoteShellArg,
|
|
4
|
+
import { noWrite, quoteShellArg, writeTextFile } from '@dsh-workbench/shared/host';
|
|
5
5
|
function quoteAll(argv) {
|
|
6
6
|
return argv.map((arg) => quoteShellArg(arg)).join(' ');
|
|
7
7
|
}
|
|
@@ -12,13 +12,13 @@ function writeFiles(request, tmpRoot) {
|
|
|
12
12
|
const paths = request.files.map((file, index) => {
|
|
13
13
|
const suffix = file.suffix === undefined || file.suffix === '' ? '' : `.${file.suffix}`;
|
|
14
14
|
const path = join(dir, `file-${String(index)}${suffix}`);
|
|
15
|
-
|
|
15
|
+
writeTextFile(path, file.content);
|
|
16
16
|
return path;
|
|
17
17
|
});
|
|
18
18
|
return { dir, paths };
|
|
19
19
|
}
|
|
20
20
|
export function createCommandReader(options) {
|
|
21
|
-
const {
|
|
21
|
+
const { seam } = options;
|
|
22
22
|
const tmpRoot = options.tmpRoot ?? tmpdir();
|
|
23
23
|
return {
|
|
24
24
|
async run(request) {
|
|
@@ -30,7 +30,9 @@ export function createCommandReader(options) {
|
|
|
30
30
|
for (const path of temp.paths)
|
|
31
31
|
argv.push(request.appendFileArgs, path);
|
|
32
32
|
}
|
|
33
|
-
const result = await
|
|
33
|
+
const result = await seam.run({
|
|
34
|
+
command: quoteAll(argv),
|
|
35
|
+
intent: noWrite(),
|
|
34
36
|
...(request.timeoutMs === undefined ? {} : { timeoutMs: request.timeoutMs }),
|
|
35
37
|
...(request.cwd === undefined ? {} : { workdir: request.cwd }),
|
|
36
38
|
...(request.env === undefined ? {} : { env: request.env }),
|
package/dist/data/channel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Seam } from '@dsh-workbench/shared/host';
|
|
2
2
|
import type { CallOverrides, RequestRecipe } from '@dsh-workbench/shared/host';
|
|
3
3
|
export declare const CHANNEL_DIR: string;
|
|
4
4
|
export type ChannelState = 'unknown' | 'ready' | 'unavailable';
|
|
@@ -13,7 +13,7 @@ export declare function wireBodyOf(recipe: RequestRecipe, overrides: CallOverrid
|
|
|
13
13
|
};
|
|
14
14
|
export declare function channelCallOf(recipe: RequestRecipe, overrides: CallOverrides, command: string): ChannelCall | undefined;
|
|
15
15
|
export declare function channelAlreadyInstalled(): boolean;
|
|
16
|
-
export declare function ensureChannel(
|
|
16
|
+
export declare function ensureChannel(seam: Seam, command: string, state: {
|
|
17
17
|
value: ChannelState;
|
|
18
18
|
}, ready?: () => boolean): Promise<boolean>;
|
|
19
19
|
export declare function channelCommandLine(call: ChannelCall): string;
|
package/dist/data/channel.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import { DEFAULT_RECIPE_MAX_BYTES,
|
|
2
|
+
import { DEFAULT_RECIPE_MAX_BYTES, productWrite, quoteShellArg, } from '@dsh-workbench/shared/host';
|
|
3
3
|
import { channelInstalledVersion, channelPluginPlan, channelSiteInstalled, channelVersionOf, } from './channel-plugin.js';
|
|
4
4
|
export const CHANNEL_DIR = fileURLToPath(new URL('../../channel/', import.meta.url));
|
|
5
5
|
function authOf(recipe) {
|
|
@@ -99,7 +99,7 @@ export function channelAlreadyInstalled() {
|
|
|
99
99
|
const shipped = channelVersionOf(CHANNEL_DIR);
|
|
100
100
|
return shipped !== undefined && channelInstalledVersion() === shipped && channelSiteInstalled();
|
|
101
101
|
}
|
|
102
|
-
export async function ensureChannel(
|
|
102
|
+
export async function ensureChannel(seam, command, state, ready = channelAlreadyInstalled) {
|
|
103
103
|
if (state.value === 'ready')
|
|
104
104
|
return true;
|
|
105
105
|
if (state.value === 'unavailable')
|
|
@@ -113,7 +113,7 @@ export async function ensureChannel(shell, command, state, ready = channelAlread
|
|
|
113
113
|
state.value = 'unavailable';
|
|
114
114
|
return false;
|
|
115
115
|
}
|
|
116
|
-
const result = await
|
|
116
|
+
const result = await seam.run({ command: plan.line, intent: productWrite(), timeoutMs: 120_000 });
|
|
117
117
|
state.value = result.exitCode === 0 && !result.timedOut ? 'ready' : 'unavailable';
|
|
118
118
|
return state.value === 'ready';
|
|
119
119
|
}
|
package/dist/data/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Seam } from '@dsh-workbench/shared/host';
|
|
2
2
|
import type { DataReader } from '@dsh-workbench/shared/host';
|
|
3
3
|
export * from './channel-plugin.js';
|
|
4
4
|
export interface DataReaderOptions {
|
|
5
|
-
readonly
|
|
5
|
+
readonly seam?: Seam | undefined;
|
|
6
6
|
readonly command?: string | undefined;
|
|
7
7
|
readonly fetch?: typeof fetch | undefined;
|
|
8
8
|
readonly channel?: boolean | undefined;
|
package/dist/data/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { callsProblemOf,
|
|
1
|
+
import { callsProblemOf, noWrite, recipeProblemOf, scriptOf, scriptOfMany } from '@dsh-workbench/shared/host';
|
|
2
2
|
import { browserRead } from '../browser/index.js';
|
|
3
3
|
import { createOpencli } from '../cli/index.js';
|
|
4
4
|
import { WorkbenchDataError } from '@dsh-workbench/shared/host';
|
|
@@ -127,10 +127,10 @@ export function createDataReader(options = {}) {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
async function readBrowser(request) {
|
|
130
|
-
if (options.
|
|
131
|
-
return failure('invalid-request', '
|
|
130
|
+
if (options.seam === undefined)
|
|
131
|
+
return failure('invalid-request', '没有执行缝,读不了浏览器');
|
|
132
132
|
const result = await browserRead({
|
|
133
|
-
|
|
133
|
+
seam: options.seam,
|
|
134
134
|
script: request.script,
|
|
135
135
|
command,
|
|
136
136
|
...(request.url === undefined ? {} : { url: request.url }),
|
|
@@ -144,8 +144,18 @@ export function createDataReader(options = {}) {
|
|
|
144
144
|
return { ok: true, data: result.value };
|
|
145
145
|
}
|
|
146
146
|
const channelState = { value: 'unknown' };
|
|
147
|
-
async function readChannel(
|
|
148
|
-
const result = await
|
|
147
|
+
async function readChannel(seam, call, recipe) {
|
|
148
|
+
const result = await seam
|
|
149
|
+
.run({
|
|
150
|
+
command: channelCommandLine(call),
|
|
151
|
+
intent: noWrite(),
|
|
152
|
+
retry: recipe.request.method === 'GET' ? 'safe' : 'never',
|
|
153
|
+
timeoutMs: call.timeoutMs + 5000,
|
|
154
|
+
bestEffort: true,
|
|
155
|
+
})
|
|
156
|
+
.catch(() => undefined);
|
|
157
|
+
if (result === undefined)
|
|
158
|
+
return undefined;
|
|
149
159
|
if (result.timedOut)
|
|
150
160
|
return failure('timeout', `通道读超时(${call.timeoutMs}ms)`);
|
|
151
161
|
if (result.exitCode !== 0)
|
|
@@ -187,12 +197,12 @@ export function createDataReader(options = {}) {
|
|
|
187
197
|
if (mode === 'request' && recipe.request.method !== 'GET') {
|
|
188
198
|
return failure('invalid-request', 'request 只读 GET;写走 submit');
|
|
189
199
|
}
|
|
190
|
-
if (options.
|
|
191
|
-
return failure('invalid-request', '
|
|
200
|
+
if (options.seam === undefined)
|
|
201
|
+
return failure('invalid-request', '没有执行缝,读不了浏览器');
|
|
202
|
+
const seam = options.seam;
|
|
192
203
|
const call = options.channel === false ? undefined : channelCallOf(recipe, overrides ?? {}, command);
|
|
193
|
-
if (call !== undefined &&
|
|
194
|
-
|
|
195
|
-
const viaChannel = await readChannel(options.shell, call, recipe);
|
|
204
|
+
if (call !== undefined && (await ensureChannel(seam, command, channelState, options.channelInstalled))) {
|
|
205
|
+
const viaChannel = await readChannel(seam, call, recipe);
|
|
196
206
|
if (viaChannel !== undefined)
|
|
197
207
|
return viaChannel;
|
|
198
208
|
channelState.value = 'unavailable';
|
|
@@ -205,7 +215,7 @@ export function createDataReader(options = {}) {
|
|
|
205
215
|
return failure('invalid-request', error instanceof Error ? error.message : String(error));
|
|
206
216
|
}
|
|
207
217
|
const result = await browserRead({
|
|
208
|
-
|
|
218
|
+
seam,
|
|
209
219
|
script,
|
|
210
220
|
command,
|
|
211
221
|
url: recipe.origin,
|
|
@@ -234,8 +244,9 @@ export function createDataReader(options = {}) {
|
|
|
234
244
|
if (recipe.request.method !== 'GET') {
|
|
235
245
|
return allFailure(names, 'invalid-request', 'requestMany 只读 GET;写走 submit');
|
|
236
246
|
}
|
|
237
|
-
if (options.
|
|
238
|
-
return allFailure(names, 'invalid-request', '
|
|
247
|
+
if (options.seam === undefined)
|
|
248
|
+
return allFailure(names, 'invalid-request', '没有执行缝,读不了浏览器');
|
|
249
|
+
const seam = options.seam;
|
|
239
250
|
let script;
|
|
240
251
|
try {
|
|
241
252
|
script = scriptOfMany(recipe, calls);
|
|
@@ -244,7 +255,7 @@ export function createDataReader(options = {}) {
|
|
|
244
255
|
return allFailure(names, 'invalid-request', error instanceof Error ? error.message : String(error));
|
|
245
256
|
}
|
|
246
257
|
const result = await browserRead({
|
|
247
|
-
|
|
258
|
+
seam,
|
|
248
259
|
script,
|
|
249
260
|
command,
|
|
250
261
|
url: recipe.origin,
|
|
@@ -297,7 +308,7 @@ export function createDataReader(options = {}) {
|
|
|
297
308
|
if (cached !== undefined)
|
|
298
309
|
return cached;
|
|
299
310
|
const created = createOpencli({
|
|
300
|
-
|
|
311
|
+
seam: options.seam,
|
|
301
312
|
plugin,
|
|
302
313
|
command,
|
|
303
314
|
timeoutMs,
|
|
@@ -306,8 +317,8 @@ export function createDataReader(options = {}) {
|
|
|
306
317
|
return created;
|
|
307
318
|
}
|
|
308
319
|
async function readCommand(request) {
|
|
309
|
-
if (options.
|
|
310
|
-
return failure('invalid-request', '
|
|
320
|
+
if (options.seam === undefined)
|
|
321
|
+
return failure('invalid-request', '没有执行缝,跑不了命令');
|
|
311
322
|
if (request.adapter !== 'opencli') {
|
|
312
323
|
return failure('invalid-request', `不认识的命令适配器:${request.adapter}`);
|
|
313
324
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DshShell } from '@dsh-workbench/shared';
|
|
2
|
+
import type { ExtensionReader } from '@dsh-workbench/shared/host';
|
|
3
|
+
export interface ExtensionReaderOptions {
|
|
4
|
+
readonly shell?: DshShell | undefined;
|
|
5
|
+
readonly command?: string | undefined;
|
|
6
|
+
readonly logger?: {
|
|
7
|
+
warn?(message: string): void;
|
|
8
|
+
} | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare function createExtensionReader(options: ExtensionReaderOptions): ExtensionReader;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { WorkbenchDataError } from '@dsh-workbench/shared/host';
|
|
2
|
+
import { createOpencli } from '../cli/index.js';
|
|
3
|
+
export function createExtensionReader(options) {
|
|
4
|
+
const readers = new Map();
|
|
5
|
+
function readerOf(need) {
|
|
6
|
+
if (need.runtime !== 'opencli') {
|
|
7
|
+
throw new WorkbenchDataError('unsupported-runtime', `没有能跑 ${need.runtime} 扩展的适配器:这个模块要的是 ${need.name}`, { hint: '换一个带这种运行时的适配器集合,或把这条需要改成 opencli 扩展。' });
|
|
8
|
+
}
|
|
9
|
+
if (options.shell === undefined) {
|
|
10
|
+
throw new WorkbenchDataError('cli-exec-failed', `读不了:这台机器上没有 shell 服务(${need.name})`, {
|
|
11
|
+
hint: '工作台的 shell 服务没起来,重启一下工作台再试',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const cached = readers.get(need.name);
|
|
15
|
+
if (cached !== undefined)
|
|
16
|
+
return cached;
|
|
17
|
+
const created = createOpencli({
|
|
18
|
+
shell: options.shell,
|
|
19
|
+
plugin: need.name,
|
|
20
|
+
...(options.command === undefined ? {} : { command: options.command }),
|
|
21
|
+
...(options.logger === undefined ? {} : { logger: options.logger }),
|
|
22
|
+
});
|
|
23
|
+
readers.set(need.name, created);
|
|
24
|
+
return created;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
async json(need, args, callOptions = {}) {
|
|
28
|
+
const result = await readerOf(need).json(args, {
|
|
29
|
+
...(callOptions.key === undefined ? {} : { key: callOptions.key }),
|
|
30
|
+
...(callOptions.workdir === undefined ? {} : { workdir: callOptions.workdir }),
|
|
31
|
+
...(callOptions.session === undefined ? {} : { session: callOptions.session }),
|
|
32
|
+
});
|
|
33
|
+
return result;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
package/dist/git/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { DshShell } from '@dsh-workbench/shared';
|
|
2
1
|
import type { GitReader } from '@dsh-workbench/shared';
|
|
2
|
+
import { type Seam } from '@dsh-workbench/shared/host';
|
|
3
3
|
export interface GitReaderOptions {
|
|
4
|
-
readonly
|
|
4
|
+
readonly seam: Seam;
|
|
5
5
|
readonly logger?: {
|
|
6
6
|
warn?(message: string): void;
|
|
7
7
|
} | undefined;
|
package/dist/git/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { noWrite, quoteShellArg, tailLines } from '@dsh-workbench/shared/host';
|
|
2
2
|
function keyOf(path) {
|
|
3
3
|
return String(path ?? '').trim();
|
|
4
4
|
}
|
|
5
5
|
export function createGitReader(options) {
|
|
6
|
-
const {
|
|
6
|
+
const { seam, logger } = options;
|
|
7
7
|
return {
|
|
8
8
|
async origin(path) {
|
|
9
9
|
const key = keyOf(path);
|
|
@@ -11,7 +11,11 @@ export function createGitReader(options) {
|
|
|
11
11
|
return { kind: 'unknown', reason: 'no-path' };
|
|
12
12
|
let result;
|
|
13
13
|
try {
|
|
14
|
-
result = await
|
|
14
|
+
result = await seam.run({
|
|
15
|
+
command: `git -C ${quoteShellArg(key)} remote get-url origin`,
|
|
16
|
+
intent: noWrite(),
|
|
17
|
+
retry: 'safe',
|
|
18
|
+
});
|
|
15
19
|
}
|
|
16
20
|
catch (error) {
|
|
17
21
|
logger?.warn?.(`[dsh-workbench] git remote 执行失败:${String(error)}`);
|
|
@@ -27,7 +31,11 @@ export function createGitReader(options) {
|
|
|
27
31
|
return { kind: 'unknown', reason: 'no-path' };
|
|
28
32
|
let result;
|
|
29
33
|
try {
|
|
30
|
-
result = await
|
|
34
|
+
result = await seam.run({
|
|
35
|
+
command: `git -C ${quoteShellArg(key)} rev-parse --abbrev-ref HEAD`,
|
|
36
|
+
intent: noWrite(),
|
|
37
|
+
retry: 'safe',
|
|
38
|
+
});
|
|
31
39
|
}
|
|
32
40
|
catch (error) {
|
|
33
41
|
logger?.warn?.(`[dsh-workbench] git rev-parse --abbrev-ref 执行失败:${String(error)}`);
|
|
@@ -46,7 +54,11 @@ export function createGitReader(options) {
|
|
|
46
54
|
return { kind: 'unknown', reason: 'no-path' };
|
|
47
55
|
let result;
|
|
48
56
|
try {
|
|
49
|
-
result = await
|
|
57
|
+
result = await seam.run({
|
|
58
|
+
command: `git -C ${quoteShellArg(key)} rev-parse HEAD`,
|
|
59
|
+
intent: noWrite(),
|
|
60
|
+
retry: 'safe',
|
|
61
|
+
});
|
|
50
62
|
}
|
|
51
63
|
catch (error) {
|
|
52
64
|
logger?.warn?.(`[dsh-workbench] git rev-parse 执行失败:${String(error)}`);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BinNeed, LibNeed, SupplySource } from '@dsh-workbench/shared';
|
|
2
|
+
import type { HostOs } from '@dsh-workbench/shared';
|
|
3
|
+
export type NpmSource = Extract<SupplySource, {
|
|
4
|
+
kind: 'npm';
|
|
5
|
+
}>;
|
|
6
|
+
export declare function libInstallCommand(options: {
|
|
7
|
+
readonly need: LibNeed;
|
|
8
|
+
readonly source: NpmSource;
|
|
9
|
+
readonly version?: string | undefined;
|
|
10
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
11
|
+
}): string;
|
|
12
|
+
/**
|
|
13
|
+
* 这个 bin 在这台机器上怎么装:作者写了 `install` 且平台对得上才给出那条命令。
|
|
14
|
+
* `command` 原样照抄;`npm` 装进隔离运行时的共用依赖前缀(那份包里的 bin 会自动上 PATH)。
|
|
15
|
+
* @param need 一条 bin 需要。
|
|
16
|
+
* @param os 宿主平台(由平台适配器给出)。
|
|
17
|
+
* @param env 取 registry 环境变量的地方。
|
|
18
|
+
* @returns 一条能直接粘进终端的命令;没声明或平台不对就是 undefined。
|
|
19
|
+
*/
|
|
20
|
+
export declare function libUninstallCommand(options: {
|
|
21
|
+
readonly need: LibNeed;
|
|
22
|
+
}): string;
|
|
23
|
+
export declare function binInstallCommand(need: BinNeed, os: HostOs, env?: NodeJS.ProcessEnv): string | undefined;
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { npmRegistryOf } from '@dsh-workbench/shared/host';
|
|
2
|
+
import { quoteShellArg } from '@dsh-workbench/shared/host';
|
|
3
|
+
import { libsPrefix, npmCacheDir } from './paths.js';
|
|
4
|
+
export function libInstallCommand(options) {
|
|
5
|
+
const { need, source, version } = options;
|
|
6
|
+
const registry = npmRegistryOf(source, options.env ?? process.env);
|
|
7
|
+
const spec = version ?? need.version ?? 'latest';
|
|
8
|
+
const registryFlag = registry.ok ? ` --registry ${quoteShellArg(registry.value)}` : '';
|
|
9
|
+
return `npm i --prefix ${quoteShellArg(libsPrefix())} ${quoteShellArg(`${need.name}@${spec}`)}${registryFlag} --cache ${quoteShellArg(npmCacheDir())}`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 这个 bin 在这台机器上怎么装:作者写了 `install` 且平台对得上才给出那条命令。
|
|
13
|
+
* `command` 原样照抄;`npm` 装进隔离运行时的共用依赖前缀(那份包里的 bin 会自动上 PATH)。
|
|
14
|
+
* @param need 一条 bin 需要。
|
|
15
|
+
* @param os 宿主平台(由平台适配器给出)。
|
|
16
|
+
* @param env 取 registry 环境变量的地方。
|
|
17
|
+
* @returns 一条能直接粘进终端的命令;没声明或平台不对就是 undefined。
|
|
18
|
+
*/
|
|
19
|
+
export function libUninstallCommand(options) {
|
|
20
|
+
return `npm uninstall --prefix ${quoteShellArg(libsPrefix())} ${quoteShellArg(options.need.name)}`;
|
|
21
|
+
}
|
|
22
|
+
export function binInstallCommand(need, os, env = process.env) {
|
|
23
|
+
const install = need.install;
|
|
24
|
+
if (install === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
if (install.platforms !== undefined && !install.platforms.includes(os))
|
|
27
|
+
return undefined;
|
|
28
|
+
if (install.kind === 'command') {
|
|
29
|
+
const line = install.line.trim();
|
|
30
|
+
return line === '' ? undefined : line;
|
|
31
|
+
}
|
|
32
|
+
const packageName = install.package.trim();
|
|
33
|
+
if (packageName === '')
|
|
34
|
+
return undefined;
|
|
35
|
+
return libInstallCommand({
|
|
36
|
+
need: { kind: 'lib', name: packageName, purpose: need.purpose },
|
|
37
|
+
source: {
|
|
38
|
+
kind: 'npm',
|
|
39
|
+
package: packageName,
|
|
40
|
+
...(install.registryEnv === undefined ? {} : { registryEnv: install.registryEnv }),
|
|
41
|
+
...(install.registryDefault === undefined ? {} : { registryDefault: install.registryDefault }),
|
|
42
|
+
},
|
|
43
|
+
env,
|
|
44
|
+
});
|
|
45
|
+
}
|
package/dist/libs/index.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
export * from './links.js';
|
|
2
2
|
export * from './runner.js';
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
5
4
|
import { join, normalize } from 'node:path';
|
|
6
5
|
import { pathToFileURL } from 'node:url';
|
|
7
|
-
import { WorkbenchDataError } from '@dsh-workbench/shared/host';
|
|
6
|
+
import { runtimeLayoutOf, WorkbenchDataError } from '@dsh-workbench/shared/host';
|
|
8
7
|
import { libInstallCommand } from '../foundation/install.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
join(home, 'workbench', 'opencli', 'toolchain', 'node_modules'),
|
|
14
|
-
];
|
|
8
|
+
import { OPENCLI_RUNTIME_ID } from '../foundation/paths.js';
|
|
9
|
+
function rootsOf() {
|
|
10
|
+
const layout = runtimeLayoutOf(OPENCLI_RUNTIME_ID);
|
|
11
|
+
return [join(layout.libsPrefix, 'node_modules'), join(layout.root, 'toolchain', 'node_modules')];
|
|
15
12
|
}
|
|
16
13
|
function entryProblem(entry) {
|
|
17
14
|
if (entry.trim() === '')
|
|
@@ -23,8 +20,7 @@ function entryProblem(entry) {
|
|
|
23
20
|
return null;
|
|
24
21
|
}
|
|
25
22
|
export function createLibReader(options = {}) {
|
|
26
|
-
const
|
|
27
|
-
const roots = options.roots ?? rootsOf(env);
|
|
23
|
+
const roots = options.roots ?? rootsOf();
|
|
28
24
|
return {
|
|
29
25
|
async load(need, entry) {
|
|
30
26
|
const problem = entryProblem(entry);
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const OPENCLI_RUNTIME_ID = "opencli";
|
|
2
|
+
export declare const OPENCLI_NPM_PACKAGE = "@jackwener/opencli";
|
|
3
|
+
export declare function isolatedRoot(): string;
|
|
4
|
+
export declare function isolatedHome(): string;
|
|
5
|
+
export declare function vendorPrefix(): string;
|
|
6
|
+
export declare function vendorPluginsDir(): string;
|
|
7
|
+
export declare function libsPrefix(): string;
|
|
8
|
+
export declare function libsBinDir(): string;
|
|
9
|
+
export declare function npmCacheDir(): string;
|
|
10
|
+
export declare function toolchainOpencliDir(): string;
|
|
11
|
+
export declare function vendorPeerLink(): {
|
|
12
|
+
readonly dir: string;
|
|
13
|
+
readonly parent: string;
|
|
14
|
+
};
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { runtimeLayoutOf } from '@dsh-workbench/shared/host';
|
|
2
|
+
export const OPENCLI_RUNTIME_ID = 'opencli';
|
|
3
|
+
export const OPENCLI_NPM_PACKAGE = '@jackwener/opencli';
|
|
4
|
+
const layout = () => runtimeLayoutOf(OPENCLI_RUNTIME_ID);
|
|
5
|
+
export function isolatedRoot() {
|
|
6
|
+
return layout().root;
|
|
7
|
+
}
|
|
8
|
+
export function isolatedHome() {
|
|
9
|
+
return layout().home;
|
|
10
|
+
}
|
|
11
|
+
export function vendorPrefix() {
|
|
12
|
+
return layout().vendorPrefix;
|
|
13
|
+
}
|
|
14
|
+
export function vendorPluginsDir() {
|
|
15
|
+
return layout().vendorPluginsDir;
|
|
16
|
+
}
|
|
17
|
+
export function libsPrefix() {
|
|
18
|
+
return layout().libsPrefix;
|
|
19
|
+
}
|
|
20
|
+
export function libsBinDir() {
|
|
21
|
+
return layout().libsBinDir;
|
|
22
|
+
}
|
|
23
|
+
export function npmCacheDir() {
|
|
24
|
+
return layout().npmCacheDir;
|
|
25
|
+
}
|
|
26
|
+
export function toolchainOpencliDir() {
|
|
27
|
+
return `${isolatedRoot()}/toolchain/node_modules/${OPENCLI_NPM_PACKAGE}`;
|
|
28
|
+
}
|
|
29
|
+
export function vendorPeerLink() {
|
|
30
|
+
const base = `${vendorPrefix()}/node_modules`;
|
|
31
|
+
const [scope] = OPENCLI_NPM_PACKAGE.split('/');
|
|
32
|
+
return { dir: `${base}/${OPENCLI_NPM_PACKAGE}`, parent: `${base}/${scope}` };
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-workbench/adapter-runtime",
|
|
3
|
-
"version": "1.1.14
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"description": "Opencli, browser and data runtime adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
"bin"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"
|
|
21
|
-
"@dsh-workbench/shared": "1.1.14-beta.1"
|
|
20
|
+
"@dsh-workbench/shared": "1.1.14"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
23
|
"@types/node": "^24.19.0",
|