@dsh-workbench/adapter-runtime 1.1.8 → 1.1.10
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/bin/opencli-isolated +62 -0
- package/bin/opencli-isolated.mjs +44 -0
- package/bin/opencli-node-mode.cjs +1 -0
- package/channel/package.json +1 -1
- package/dist/cli/opencli-runtime.d.ts +5 -10
- package/dist/cli/opencli-runtime.js +13 -16
- package/dist/cli/opencli-window.d.ts +2 -2
- package/dist/cli/opencli-window.js +7 -2
- package/dist/data/channel-plugin.d.ts +15 -0
- package/dist/data/channel-plugin.js +42 -0
- package/dist/data/channel.js +2 -1
- package/dist/data/index.d.ts +1 -0
- package/dist/data/index.js +1 -0
- package/dist/foundation/install.d.ts +14 -0
- package/dist/foundation/install.js +11 -0
- package/dist/foundation/paths.d.ts +15 -0
- package/dist/foundation/paths.js +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/install.d.ts +23 -0
- package/dist/install.js +45 -0
- package/dist/libs/index.d.ts +2 -0
- package/dist/libs/index.js +4 -1
- package/dist/libs/links.d.ts +2 -0
- package/dist/libs/links.js +27 -0
- package/dist/libs/runner.d.ts +6 -0
- package/dist/libs/runner.js +40 -0
- package/dist/paths.d.ts +14 -0
- package/dist/paths.js +33 -0
- package/package.json +6 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# 工作台**隔离的** opencli:所有 opencli 调用都从这里过(探测、取数、装/卸插件)。
|
|
4
|
+
#
|
|
5
|
+
# 为什么需要它:opencli 的**插件目录只认 `HOME`** —— `dist/src/plugin.js` 里
|
|
6
|
+
#
|
|
7
|
+
# function getHomeDir() {
|
|
8
|
+
# return process.env.HOME || process.env.USERPROFILE || os.homedir();
|
|
9
|
+
# }
|
|
10
|
+
#
|
|
11
|
+
# 而 `OPENCLI_CONFIG_DIR` 只管配置 / trace / browser-profiles。两套开关,别混。
|
|
12
|
+
# 所以想让"工作台装的插件"与"用户本机装的插件"分开,唯一的开关是 `HOME`:
|
|
13
|
+
# 指到工作台自己的目录,`~/.opencli` 就一个字节都不会被碰。
|
|
14
|
+
#
|
|
15
|
+
# 为什么必须是**单一路径、不含空格**:`DSH_WORKBENCH_OPENCLI` 既被**原样**当命令跑
|
|
16
|
+
# (能力探测:`$DSH_WORKBENCH_OPENCLI plugin list -f json`),又被 `quoteShellArg`
|
|
17
|
+
# 整体单引号包住(一键修那条 line)。写 `HOME=/x opencli` 会被包成 `'HOME=/x opencli'`,
|
|
18
|
+
# 当成一个不存在的可执行文件。
|
|
19
|
+
#
|
|
20
|
+
# ⚠️ 落点必须与 `src/shared/api/host/opencli-runtime.ts` 一致(两边都从 $DSH_HOME 推)。
|
|
21
|
+
#
|
|
22
|
+
set -euo pipefail
|
|
23
|
+
|
|
24
|
+
DSH_HOME="${DSH_HOME:-$HOME/.dsh}"
|
|
25
|
+
WORKBENCH_HOME="${DSH_WORKBENCH_HOME:-$DSH_HOME/workbench}"
|
|
26
|
+
ROOT="$WORKBENCH_HOME/opencli"
|
|
27
|
+
REAL_HOME="$HOME"
|
|
28
|
+
|
|
29
|
+
mkdir -p "$ROOT/home"
|
|
30
|
+
|
|
31
|
+
# 隔离的 HOME:插件、plugins.lock.json、monorepo 克隆、trace 全落这下面。
|
|
32
|
+
export HOME="$ROOT/home"
|
|
33
|
+
|
|
34
|
+
# 换 HOME 会连带丢掉 ~/.npmrc —— 里面有私有源的 _authToken
|
|
35
|
+
# (内网源地址由使用者自己配)。不指回去,从私有源装插件会 404/401(实测)。
|
|
36
|
+
if [ -f "$REAL_HOME/.npmrc" ]; then
|
|
37
|
+
export NPM_CONFIG_USERCONFIG="$REAL_HOME/.npmrc"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# npm 缓存**必须留在隔离运行时里**(与 `opencli-runtime.ts` 的 npmCacheDir() 同一落点)。
|
|
41
|
+
#
|
|
42
|
+
# ⚠️ **不能用 `${npm_config_cache:-…}`**:用 `npx` / `npm exec dsh-workbench` 起工作台时,
|
|
43
|
+
# npm 会往进程里**注入** `npm_config_cache=/Users/<你>/.npm`(实测:`npm exec -- node -e …`
|
|
44
|
+
# 打出来就是它),这个值一路继承到执行缝里的每条命令。带默认值等于"外面给什么就用什么",
|
|
45
|
+
# 于是隔离形同虚设 —— opencli 自己内部还会跑 npm(`plugin install` 就要,见它 dist 里
|
|
46
|
+
# `execFileSync('npm', ['install', …])`),那次会去写 `~/.npm`;而执行缝只放行
|
|
47
|
+
# `$DSH_HOME/workbench`(或 `DSH_WORKBENCH_HOME`),写入被拒 → 市场装插件**报错退出 1**,报的还是 npm 那句
|
|
48
|
+
# "cache folder contains root-owned files"(那台机器上其实一个 root 文件都没有,是假话术)。
|
|
49
|
+
# 所以这里是**无条件改写**:缓存落点只有这一处说了算。
|
|
50
|
+
#
|
|
51
|
+
# 另一条老账:`~/.npm` 里只要有一个 root 的文件(以前 `sudo npm` 留下的),npm 也会拒绝
|
|
52
|
+
# 使用整个缓存。隔离运行时本来就有自己的缓存,没理由去赌用户那份。
|
|
53
|
+
export npm_config_cache="$ROOT/npm-cache"
|
|
54
|
+
|
|
55
|
+
BIN="$ROOT/toolchain/node_modules/.bin/opencli"
|
|
56
|
+
if [ ! -x "$BIN" ]; then
|
|
57
|
+
echo "dsh-workbench: opencli 的隔离运行时还没装好($ROOT/toolchain)。" >&2
|
|
58
|
+
echo " 打开工作台:启动体检会给出一条能直接照做的安装命令。" >&2
|
|
59
|
+
exit 127
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
exec "$BIN" "$@"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const dshHome = process.env.DSH_HOME?.trim() || join(homedir(), '.dsh');
|
|
9
|
+
const workbenchHome = process.env.DSH_WORKBENCH_HOME?.trim() || join(dshHome, 'workbench');
|
|
10
|
+
const root = join(workbenchHome, 'opencli');
|
|
11
|
+
const isolatedHome = join(root, 'home');
|
|
12
|
+
const main = join(root, 'toolchain', 'node_modules', '@jackwener', 'opencli', 'dist', 'src', 'main.js');
|
|
13
|
+
const realHome = process.env.HOME || process.env.USERPROFILE || homedir();
|
|
14
|
+
const preload = join(dirname(fileURLToPath(import.meta.url)), 'opencli-node-mode.cjs');
|
|
15
|
+
|
|
16
|
+
mkdirSync(isolatedHome, { recursive: true });
|
|
17
|
+
if (!existsSync(main)) {
|
|
18
|
+
process.stderr.write(`dsh-workbench: opencli 的隔离运行时还没装好(${join(root, 'toolchain')})。\n`);
|
|
19
|
+
process.stderr.write(' 打开工作台:启动体检会给出一条能直接照做的安装命令。\n');
|
|
20
|
+
process.exit(127);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const env = {
|
|
24
|
+
...process.env,
|
|
25
|
+
HOME: isolatedHome,
|
|
26
|
+
npm_config_cache: join(root, 'npm-cache'),
|
|
27
|
+
};
|
|
28
|
+
const userConfig = join(realHome, '.npmrc');
|
|
29
|
+
if (existsSync(userConfig)) env.NPM_CONFIG_USERCONFIG = userConfig;
|
|
30
|
+
if (process.versions.electron !== undefined) env.ELECTRON_RUN_AS_NODE = '1';
|
|
31
|
+
|
|
32
|
+
const child = spawn(process.execPath, ['--require', preload, main, ...process.argv.slice(2)], {
|
|
33
|
+
stdio: 'inherit',
|
|
34
|
+
env,
|
|
35
|
+
windowsHide: true,
|
|
36
|
+
});
|
|
37
|
+
child.on('error', (error) => {
|
|
38
|
+
process.stderr.write(`dsh-workbench: opencli 没跑起来:${String(error)}\n`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
});
|
|
41
|
+
child.on('exit', (code, signal) => {
|
|
42
|
+
if (signal !== null) process.kill(process.pid, signal);
|
|
43
|
+
else process.exit(code ?? 1);
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
process.defaultApp = true;
|
package/channel/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
export declare const OPENCLI_NPM_PACKAGE = "@jackwener/opencli";
|
|
2
1
|
export declare function toolchainDir(): string;
|
|
3
|
-
export declare function toolchainOpencliDir(): string;
|
|
4
2
|
export declare const OPENCLI_CATALOG_ENV = "DSH_WB_OPENCLI_CATALOG";
|
|
3
|
+
export declare function toolchainManifestOf(): string;
|
|
5
4
|
export declare function cliCatalogPath(): string;
|
|
6
|
-
export declare function vendorPeerLink(): {
|
|
7
|
-
readonly dir: string;
|
|
8
|
-
readonly parent: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function npmCacheDir(): string;
|
|
11
5
|
export declare function isolatedCommand(): string;
|
|
12
|
-
export { libsPrefix } from '
|
|
13
|
-
export { libInstallCommand } from '
|
|
6
|
+
export { libsPrefix } from '../foundation/paths.js';
|
|
7
|
+
export { libInstallCommand } from '../foundation/install.js';
|
|
14
8
|
export declare function libDir(name: string): string;
|
|
15
9
|
export declare function isolatedInstallCommand(): string;
|
|
16
10
|
export declare function isolatedPnpmInstallCommand(pnpmCjs: string): string;
|
|
17
|
-
export { isolatedHome, isolatedRoot, vendorPluginsDir, vendorPrefix } from '
|
|
11
|
+
export { isolatedHome, isolatedRoot, libsBinDir, npmCacheDir, toolchainOpencliDir, vendorPeerLink, vendorPluginsDir, vendorPrefix } from '../foundation/paths.js';
|
|
12
|
+
export { OPENCLI_NPM_PACKAGE } from '../foundation/paths.js';
|
|
@@ -1,34 +1,30 @@
|
|
|
1
1
|
import { OPENCLI_PIN } from '@dsh-workbench/shared/host';
|
|
2
2
|
import { quoteShellArg } from '@dsh-workbench/shared/host';
|
|
3
|
-
import { isolatedRoot, libsPrefix,
|
|
4
|
-
|
|
3
|
+
import { isolatedRoot, libsPrefix, npmCacheDir, toolchainOpencliDir } from '../foundation/paths.js';
|
|
4
|
+
import { OPENCLI_NPM_PACKAGE } from '../foundation/paths.js';
|
|
5
5
|
export function toolchainDir() {
|
|
6
6
|
return `${isolatedRoot()}/toolchain`;
|
|
7
7
|
}
|
|
8
|
-
export function toolchainOpencliDir() {
|
|
9
|
-
return `${toolchainDir()}/node_modules/${OPENCLI_NPM_PACKAGE}`;
|
|
10
|
-
}
|
|
11
8
|
export const OPENCLI_CATALOG_ENV = 'DSH_WB_OPENCLI_CATALOG';
|
|
9
|
+
export function toolchainManifestOf() {
|
|
10
|
+
return `${JSON.stringify({
|
|
11
|
+
name: 'dsh-workbench-toolchain',
|
|
12
|
+
private: true,
|
|
13
|
+
dependencies: { [OPENCLI_NPM_PACKAGE]: OPENCLI_PIN },
|
|
14
|
+
}, null, 2)}\n`;
|
|
15
|
+
}
|
|
12
16
|
export function cliCatalogPath() {
|
|
13
17
|
const override = process.env[OPENCLI_CATALOG_ENV]?.trim();
|
|
14
18
|
return override === undefined || override === ''
|
|
15
19
|
? `${toolchainOpencliDir()}/cli-manifest.json`
|
|
16
20
|
: override;
|
|
17
21
|
}
|
|
18
|
-
export function vendorPeerLink() {
|
|
19
|
-
const base = `${vendorPrefix()}/node_modules`;
|
|
20
|
-
const [scope] = OPENCLI_NPM_PACKAGE.split('/');
|
|
21
|
-
return { dir: `${base}/${OPENCLI_NPM_PACKAGE}`, parent: `${base}/${scope}` };
|
|
22
|
-
}
|
|
23
|
-
export function npmCacheDir() {
|
|
24
|
-
return `${isolatedRoot()}/npm-cache`;
|
|
25
|
-
}
|
|
26
22
|
export function isolatedCommand() {
|
|
27
23
|
const name = process.platform === 'win32' ? 'opencli.cmd' : 'opencli';
|
|
28
24
|
return `${isolatedRoot()}/bin/${name}`;
|
|
29
25
|
}
|
|
30
|
-
export { libsPrefix } from '
|
|
31
|
-
export { libInstallCommand } from '
|
|
26
|
+
export { libsPrefix } from '../foundation/paths.js';
|
|
27
|
+
export { libInstallCommand } from '../foundation/install.js';
|
|
32
28
|
export function libDir(name) {
|
|
33
29
|
return `${libsPrefix()}/node_modules/${name}`;
|
|
34
30
|
}
|
|
@@ -41,4 +37,5 @@ export function isolatedPnpmInstallCommand(pnpmCjs) {
|
|
|
41
37
|
`${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(store)} ` +
|
|
42
38
|
`--allow-build=${OPENCLI_NPM_PACKAGE}`);
|
|
43
39
|
}
|
|
44
|
-
export { isolatedHome, isolatedRoot, vendorPluginsDir, vendorPrefix } from '
|
|
40
|
+
export { isolatedHome, isolatedRoot, libsBinDir, npmCacheDir, toolchainOpencliDir, vendorPeerLink, vendorPluginsDir, vendorPrefix } from '../foundation/paths.js';
|
|
41
|
+
export { OPENCLI_NPM_PACKAGE } from '../foundation/paths.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
export declare function backgroundPrefix(): readonly string[];
|
|
2
|
+
export declare function backgroundLine(command: string, argv: readonly string[]): string;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
1
|
+
import { quoteShellArg } from '@dsh-workbench/shared/host';
|
|
2
|
+
export function backgroundPrefix() {
|
|
3
|
+
return [quoteShellArg('env'), quoteShellArg('OPENCLI_WINDOW=background')];
|
|
4
|
+
}
|
|
5
|
+
export function backgroundLine(command, argv) {
|
|
6
|
+
return [...backgroundPrefix(), quoteShellArg(command), ...argv.map(quoteShellArg)].join(' ');
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const CHANNEL_PLUGIN_NAME = "opencli-plugin-workbench";
|
|
2
|
+
export declare const CHANNEL_PLUGIN_SITE = "workbench";
|
|
3
|
+
export interface ChannelPluginPlan {
|
|
4
|
+
readonly dest: string;
|
|
5
|
+
readonly version: string;
|
|
6
|
+
readonly commands: readonly string[];
|
|
7
|
+
readonly line: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function channelVersionOf(dir: string): string | undefined;
|
|
10
|
+
export declare function channelPluginPlan(options: {
|
|
11
|
+
readonly channelDir: string;
|
|
12
|
+
readonly command?: string;
|
|
13
|
+
}): ChannelPluginPlan | undefined;
|
|
14
|
+
export declare function channelInstalledVersion(): string | undefined;
|
|
15
|
+
export declare function channelSiteInstalled(): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { quoteShellArg } from '@dsh-workbench/shared/host';
|
|
4
|
+
import { isolatedHome, toolchainOpencliDir, vendorPeerLink, vendorPluginsDir } from '../foundation/paths.js';
|
|
5
|
+
export const CHANNEL_PLUGIN_NAME = 'opencli-plugin-workbench';
|
|
6
|
+
export const CHANNEL_PLUGIN_SITE = 'workbench';
|
|
7
|
+
function textOf(value) {
|
|
8
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
9
|
+
}
|
|
10
|
+
export function channelVersionOf(dir) {
|
|
11
|
+
try {
|
|
12
|
+
const parsed = JSON.parse(readFileSync(join(dir, 'opencli-plugin.json'), 'utf8'));
|
|
13
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
14
|
+
return undefined;
|
|
15
|
+
const version = textOf(parsed['version']);
|
|
16
|
+
return version === '' ? undefined : version;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function channelPluginPlan(options) {
|
|
23
|
+
const version = channelVersionOf(options.channelDir);
|
|
24
|
+
if (version === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
const command = options.command ?? 'opencli';
|
|
27
|
+
const dest = join(vendorPluginsDir(), CHANNEL_PLUGIN_NAME);
|
|
28
|
+
const peer = vendorPeerLink();
|
|
29
|
+
const commands = [
|
|
30
|
+
`rm -rf ${quoteShellArg(dest)} && mkdir -p ${quoteShellArg(dest)} && cp -R ${quoteShellArg(options.channelDir)}/. ${quoteShellArg(dest)}/`,
|
|
31
|
+
`rm -rf ${quoteShellArg(peer.dir)} && mkdir -p ${quoteShellArg(peer.parent)} && ln -s ${quoteShellArg(toolchainOpencliDir())} ${quoteShellArg(peer.dir)}`,
|
|
32
|
+
`(${quoteShellArg(command)} plugin uninstall ${quoteShellArg(CHANNEL_PLUGIN_SITE)} || true)`,
|
|
33
|
+
`${quoteShellArg(command)} plugin install ${quoteShellArg(dest)}`,
|
|
34
|
+
];
|
|
35
|
+
return { dest, version, commands, line: commands.join(' && ') };
|
|
36
|
+
}
|
|
37
|
+
export function channelInstalledVersion() {
|
|
38
|
+
return channelVersionOf(join(vendorPluginsDir(), CHANNEL_PLUGIN_NAME));
|
|
39
|
+
}
|
|
40
|
+
export function channelSiteInstalled() {
|
|
41
|
+
return existsSync(join(isolatedHome(), '.opencli', 'plugins', CHANNEL_PLUGIN_SITE));
|
|
42
|
+
}
|
package/dist/data/channel.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_RECIPE_MAX_BYTES, quoteShellArg, runShell, } from '@dsh-workbench/shared/host';
|
|
3
|
+
import { channelInstalledVersion, channelPluginPlan, channelSiteInstalled, channelVersionOf, } from './channel-plugin.js';
|
|
3
4
|
export const CHANNEL_DIR = fileURLToPath(new URL('../../channel/', import.meta.url));
|
|
4
5
|
function authOf(recipe) {
|
|
5
6
|
return recipe.auth ?? { source: { kind: 'cookie' }, place: { in: 'cookie' } };
|
package/dist/data/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DshShell } from '@dsh-workbench/shared';
|
|
2
2
|
import type { DataReader } from '@dsh-workbench/shared/host';
|
|
3
|
+
export * from './channel-plugin.js';
|
|
3
4
|
export interface DataReaderOptions {
|
|
4
5
|
readonly shell?: DshShell | undefined;
|
|
5
6
|
readonly command?: string | undefined;
|
package/dist/data/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { browserRead } from '../browser/index.js';
|
|
|
3
3
|
import { createOpencli } from '../cli/index.js';
|
|
4
4
|
import { WorkbenchDataError } from '@dsh-workbench/shared/host';
|
|
5
5
|
import { channelCallOf, channelCommandLine, ensureChannel, } from './channel.js';
|
|
6
|
+
export * from './channel-plugin.js';
|
|
6
7
|
const DEFAULT_TIMEOUT_MS = 20_000;
|
|
7
8
|
function failure(code, message, extra = {}) {
|
|
8
9
|
return { ok: false, error: { code, message, ...extra } };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BinNeed, LibNeed } from '@dsh-workbench/shared';
|
|
2
|
+
import type { HostOs } from '@dsh-workbench/shared';
|
|
3
|
+
import { type NpmSource } from '@dsh-workbench/shared/host';
|
|
4
|
+
export type { NpmSource };
|
|
5
|
+
export declare function libInstallCommand(options: {
|
|
6
|
+
readonly need: LibNeed;
|
|
7
|
+
readonly source: NpmSource;
|
|
8
|
+
readonly version?: string | undefined;
|
|
9
|
+
readonly env?: NodeJS.ProcessEnv | undefined;
|
|
10
|
+
}): string;
|
|
11
|
+
export declare function binInstallCommand(need: BinNeed, os: HostOs, env?: NodeJS.ProcessEnv): string | undefined;
|
|
12
|
+
export declare function libUninstallCommand(options: {
|
|
13
|
+
readonly need: LibNeed;
|
|
14
|
+
}): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { binInstallCommand as binAt, libInstallCommand as libAt, libUninstallCommand as uninstallAt, } from '@dsh-workbench/shared/host';
|
|
2
|
+
import { libsPrefix, npmCacheDir } from './paths.js';
|
|
3
|
+
export function libInstallCommand(options) {
|
|
4
|
+
return libAt({ ...options, prefix: libsPrefix(), cacheDir: npmCacheDir() });
|
|
5
|
+
}
|
|
6
|
+
export function binInstallCommand(need, os, env = process.env) {
|
|
7
|
+
return binAt(need, os, env, libsPrefix(), npmCacheDir());
|
|
8
|
+
}
|
|
9
|
+
export function libUninstallCommand(options) {
|
|
10
|
+
return uninstallAt({ need: options.need, prefix: libsPrefix() });
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const OPENCLI_RUNTIME_ID = "opencli";
|
|
2
|
+
export declare const OPENCLI_MANIFEST_FILE = "opencli-plugin.json";
|
|
3
|
+
export declare const OPENCLI_NPM_PACKAGE = "@jackwener/opencli";
|
|
4
|
+
export declare function isolatedRoot(): string;
|
|
5
|
+
export declare function isolatedHome(): string;
|
|
6
|
+
export declare function vendorPrefix(): string;
|
|
7
|
+
export declare function vendorPluginsDir(): string;
|
|
8
|
+
export declare function libsPrefix(): string;
|
|
9
|
+
export declare function libsBinDir(): string;
|
|
10
|
+
export declare function npmCacheDir(): string;
|
|
11
|
+
export declare function toolchainOpencliDir(): string;
|
|
12
|
+
export declare function vendorPeerLink(): {
|
|
13
|
+
readonly dir: string;
|
|
14
|
+
readonly parent: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { runtimeLayoutOf } from '@dsh-workbench/shared/host';
|
|
2
|
+
export const OPENCLI_RUNTIME_ID = 'opencli';
|
|
3
|
+
export const OPENCLI_MANIFEST_FILE = 'opencli-plugin.json';
|
|
4
|
+
export const OPENCLI_NPM_PACKAGE = '@jackwener/opencli';
|
|
5
|
+
const layout = () => runtimeLayoutOf(OPENCLI_RUNTIME_ID);
|
|
6
|
+
export function isolatedRoot() {
|
|
7
|
+
return layout().root;
|
|
8
|
+
}
|
|
9
|
+
export function isolatedHome() {
|
|
10
|
+
return layout().home;
|
|
11
|
+
}
|
|
12
|
+
export function vendorPrefix() {
|
|
13
|
+
return layout().vendorPrefix;
|
|
14
|
+
}
|
|
15
|
+
export function vendorPluginsDir() {
|
|
16
|
+
return layout().vendorPluginsDir;
|
|
17
|
+
}
|
|
18
|
+
export function libsPrefix() {
|
|
19
|
+
return layout().libsPrefix;
|
|
20
|
+
}
|
|
21
|
+
export function libsBinDir() {
|
|
22
|
+
return layout().libsBinDir;
|
|
23
|
+
}
|
|
24
|
+
export function npmCacheDir() {
|
|
25
|
+
return layout().npmCacheDir;
|
|
26
|
+
}
|
|
27
|
+
export function toolchainOpencliDir() {
|
|
28
|
+
return `${isolatedRoot()}/toolchain/node_modules/${OPENCLI_NPM_PACKAGE}`;
|
|
29
|
+
}
|
|
30
|
+
export function vendorPeerLink() {
|
|
31
|
+
const base = `${vendorPrefix()}/node_modules`;
|
|
32
|
+
const [scope] = OPENCLI_NPM_PACKAGE.split('/');
|
|
33
|
+
return { dir: `${base}/${OPENCLI_NPM_PACKAGE}`, parent: `${base}/${scope}` };
|
|
34
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -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.d.ts
CHANGED
package/dist/libs/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
export * from './links.js';
|
|
2
|
+
export * from './runner.js';
|
|
1
3
|
import { existsSync } from 'node:fs';
|
|
2
4
|
import { homedir } from 'node:os';
|
|
3
5
|
import { join, normalize } from 'node:path';
|
|
4
6
|
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import {
|
|
7
|
+
import { WorkbenchDataError } from '@dsh-workbench/shared/host';
|
|
8
|
+
import { libInstallCommand } from '../foundation/install.js';
|
|
6
9
|
function rootsOf(env) {
|
|
7
10
|
const home = env['DSH_HOME'] ?? join(homedir(), '.dsh');
|
|
8
11
|
return [
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, symlinkSync } from 'node:fs';
|
|
2
|
+
import { delimiter, dirname } from 'node:path';
|
|
3
|
+
import { OPENCLI_NPM_PACKAGE, libsBinDir, libsPrefix, toolchainOpencliDir } from '../foundation/paths.js';
|
|
4
|
+
export function ensureLibsBinOnPath(env = process.env) {
|
|
5
|
+
const dir = libsBinDir();
|
|
6
|
+
const parts = (env.PATH ?? '').split(delimiter).filter((one) => one !== '');
|
|
7
|
+
if (parts.includes(dir))
|
|
8
|
+
return false;
|
|
9
|
+
env.PATH = [dir, ...parts].join(delimiter);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
export function ensureLibsOpencliPeer() {
|
|
13
|
+
const link = `${libsPrefix()}/node_modules/${OPENCLI_NPM_PACKAGE}`;
|
|
14
|
+
if (existsSync(link))
|
|
15
|
+
return false;
|
|
16
|
+
const target = toolchainOpencliDir();
|
|
17
|
+
if (!existsSync(target))
|
|
18
|
+
return false;
|
|
19
|
+
try {
|
|
20
|
+
mkdirSync(dirname(link), { recursive: true });
|
|
21
|
+
symlinkSync(target, link);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DataRequest, DataResult, LibRunner } from '@dsh-workbench/shared';
|
|
2
|
+
export type OpencliRead = (request: DataRequest) => Promise<DataResult<unknown>>;
|
|
3
|
+
export interface OpencliRunnerOptions {
|
|
4
|
+
readonly timeoutMs?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function opencliRunnerOf(read: OpencliRead, options?: OpencliRunnerOptions): LibRunner;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const AUTH_REQUIRED_EXIT_CODE = 77;
|
|
2
|
+
function textOf(value) {
|
|
3
|
+
return typeof value === 'string' ? value : '';
|
|
4
|
+
}
|
|
5
|
+
function failedOf(args, error) {
|
|
6
|
+
const head = `Command failed: opencli ${args.join(' ')}`;
|
|
7
|
+
const auth = error?.pageCode === 'auth-required';
|
|
8
|
+
const helpUrl = textOf(error?.helpUrl);
|
|
9
|
+
const detail = textOf(error?.detail);
|
|
10
|
+
const hint = textOf(error?.hint);
|
|
11
|
+
const failed = new Error([
|
|
12
|
+
head,
|
|
13
|
+
...(auth
|
|
14
|
+
? ['code: AUTH_REQUIRED', `message: ${textOf(error?.message)}`]
|
|
15
|
+
: [textOf(error?.message) || 'opencli 这条命令没跑通']),
|
|
16
|
+
...(detail === '' ? [] : [detail]),
|
|
17
|
+
...(hint === '' ? [] : [hint]),
|
|
18
|
+
...(auth && helpUrl !== ''
|
|
19
|
+
? [`help: Please open Chrome or Chromium and log in to ${helpUrl}`]
|
|
20
|
+
: []),
|
|
21
|
+
].join('\n'));
|
|
22
|
+
if (auth)
|
|
23
|
+
failed.code = AUTH_REQUIRED_EXIT_CODE;
|
|
24
|
+
return failed;
|
|
25
|
+
}
|
|
26
|
+
export function opencliRunnerOf(read, options = {}) {
|
|
27
|
+
return async (args) => {
|
|
28
|
+
const result = await read({
|
|
29
|
+
kind: 'command',
|
|
30
|
+
adapter: 'opencli',
|
|
31
|
+
argv: [...args],
|
|
32
|
+
...(options.timeoutMs === undefined
|
|
33
|
+
? {}
|
|
34
|
+
: { timeoutMs: options.timeoutMs }),
|
|
35
|
+
});
|
|
36
|
+
if (result.ok)
|
|
37
|
+
return { stdout: JSON.stringify(result.data) };
|
|
38
|
+
throw failedOf(args, result.error);
|
|
39
|
+
};
|
|
40
|
+
}
|
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,20 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-workbench/adapter-runtime",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"description": "Opencli, browser and data runtime adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"default": "./dist/index.js"
|
|
10
|
-
}
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
14
|
"dist",
|
|
14
|
-
"channel"
|
|
15
|
+
"channel",
|
|
16
|
+
"bin"
|
|
15
17
|
],
|
|
16
18
|
"dependencies": {
|
|
17
|
-
"@dsh-workbench/shared": "1.1.
|
|
19
|
+
"@dsh-workbench/shared": "1.1.10"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
20
22
|
"@types/node": "^24.19.0",
|