@dsh-workbench/adapter-runtime 1.1.13 → 1.1.14-beta.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 CHANGED
@@ -5,13 +5,18 @@
5
5
  ## 模块
6
6
 
7
7
  ```text
8
- src/cli/ opencli 命令、隔离运行时、窗口参数
9
- src/browser/ 页面读取与查找
10
- src/data/ DataReader(http / browser / command / recipe / 批量 recipe / 公共通道)
11
- channel/ 随包出货的 opencli 插件(workbench fetch / workbench send)
8
+ src/foundation/ 命令解析、隔离路径、session、错误形状
9
+ src/cli/ opencli 命令、隔离运行时、窗口参数
10
+ src/browser/ 页面读取与查找
11
+ src/data/ DataReader(http / browser / command / recipe / 批量 recipe / 公共通道)
12
+ src/git/ git 读端口
13
+ src/libs/ 本机库读端口
14
+ src/command/ 命令面读端口
15
+ channel/ 随包出货的 opencli 插件(workbench fetch / workbench send)
12
16
  ```
13
17
 
14
- 三者共享命令解析、隔离路径、session 和错误形状,所以放在同一个包内,但保持独立目录。
18
+ `foundation` 是最底层;`browser` / `cli` / `data` / `git` / `libs` / `command` 同层,
19
+ 共享 `foundation` 的命令解析、隔离路径、session 和错误形状,所以放在同一个包内,但保持独立目录。
15
20
 
16
21
  `channel/` 不是源码目录:它是**资产**,不进 `tsc`、不进 barrel,只被复制进隔离运行时
17
22
  (`plugins-npm` → peer symlink → `opencli plugin install`)。`cookie` / `cookieValue` 两种凭据来源
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { spawn } from 'node:child_process';
2
+ import { execa } from 'execa';
3
3
  import { existsSync, mkdirSync } from 'node:fs';
4
- import { homedir } from 'node:os';
4
+ import { homedir, userInfo } from 'node:os';
5
5
  import { dirname, join } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
7
 
@@ -10,7 +10,7 @@ const workbenchHome = process.env.DSH_WORKBENCH_HOME?.trim() || join(dshHome, 'w
10
10
  const root = join(workbenchHome, 'opencli');
11
11
  const isolatedHome = join(root, 'home');
12
12
  const main = join(root, 'toolchain', 'node_modules', '@jackwener', 'opencli', 'dist', 'src', 'main.js');
13
- const realHome = process.env.HOME || process.env.USERPROFILE || homedir();
13
+ const realHome = userInfo().homedir;
14
14
  const preload = join(dirname(fileURLToPath(import.meta.url)), 'opencli-node-mode.cjs');
15
15
 
16
16
  mkdirSync(isolatedHome, { recursive: true });
@@ -23,22 +23,28 @@ if (!existsSync(main)) {
23
23
  const env = {
24
24
  ...process.env,
25
25
  HOME: isolatedHome,
26
- npm_config_cache: join(root, 'npm-cache'),
27
26
  };
27
+ for (const key of Object.keys(env)) {
28
+ if (key.toLowerCase() === 'npm_config_cache') delete env[key];
29
+ }
30
+ env.npm_config_cache = join(root, 'npm-cache');
31
+ env.NPM_CONFIG_CACHE = env.npm_config_cache;
28
32
  const userConfig = join(realHome, '.npmrc');
29
33
  if (existsSync(userConfig)) env.NPM_CONFIG_USERCONFIG = userConfig;
30
34
  if (process.versions.electron !== undefined) env.ELECTRON_RUN_AS_NODE = '1';
31
35
 
32
- const child = spawn(process.execPath, ['--require', preload, main, ...process.argv.slice(2)], {
36
+ const child = execa(process.execPath, ['--require', preload, main, ...process.argv.slice(2)], {
33
37
  stdio: 'inherit',
34
38
  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);
39
+ extendEnv: false,
40
+ reject: false,
44
41
  });
42
+ void child
43
+ .then((result) => {
44
+ if (result.signal !== undefined) process.kill(process.pid, result.signal);
45
+ else process.exit(result.exitCode ?? 1);
46
+ })
47
+ .catch((error) => {
48
+ process.stderr.write(`dsh-workbench: opencli 没跑起来:${String(error)}\n`);
49
+ process.exit(1);
50
+ });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencli-plugin-workbench",
3
- "version": "1.1.13",
3
+ "version": "1.1.14-beta.0",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "description": "DSH 工作台的公共通道:带浏览器登录态的 Node 侧 fetch,只服务 cookie / cookieValue 两种凭据来源",
@@ -1,6 +1,6 @@
1
1
  import { parseJsonLoose } from '@dsh-workbench/shared/host';
2
2
  import { BROWSER_READ_SESSION } from './browser-read.js';
3
- import { backgroundLine } from '../cli/index.js';
3
+ import { backgroundLine, OPENCLI_WINDOW_ENV } from '../cli/index.js';
4
4
  import { runShell } from '@dsh-workbench/shared/host';
5
5
  const DEFAULT_TIMEOUT_MS = 25000;
6
6
  const DEFAULT_SETTLE_MS = 2500;
@@ -92,7 +92,7 @@ export function urlOf(stdout) {
92
92
  async function currentUrl(shell, command, session) {
93
93
  const line = backgroundLine(command, ['browser', session, 'get', 'url', '--window', 'background']);
94
94
  try {
95
- const result = await runShell(shell, line, { timeoutMs: URL_TIMEOUT_MS });
95
+ const result = await runShell(shell, line, { timeoutMs: URL_TIMEOUT_MS, env: OPENCLI_WINDOW_ENV });
96
96
  if (result.exitCode !== 0)
97
97
  return '';
98
98
  return urlOf(result.stdout);
@@ -118,7 +118,7 @@ async function findOnce(shell, command, session, css, limit, textMax, timeoutMs)
118
118
  '--window',
119
119
  'background',
120
120
  ]);
121
- const result = await runShell(shell, line, { timeoutMs });
121
+ const result = await runShell(shell, line, { timeoutMs, env: OPENCLI_WINDOW_ENV });
122
122
  if (result.timedOut) {
123
123
  return { kind: 'timeout', detail: `没在 ${Math.round(timeoutMs / 1000)} 秒内返回` };
124
124
  }
@@ -136,7 +136,7 @@ async function openOnce(shell, command, session, url, timeoutMs) {
136
136
  const line = backgroundLine(command, ['browser', session, 'open', url, '--window', 'background']);
137
137
  let result;
138
138
  try {
139
- result = await runShell(shell, line, { timeoutMs });
139
+ result = await runShell(shell, line, { timeoutMs, env: OPENCLI_WINDOW_ENV });
140
140
  }
141
141
  catch (error) {
142
142
  return error instanceof Error ? error.message : String(error);
@@ -1,6 +1,6 @@
1
1
  import { parseJsonLoose } from '@dsh-workbench/shared/host';
2
2
  import { tailLines } from '@dsh-workbench/shared/host';
3
- import { backgroundLine } from '../cli/index.js';
3
+ import { backgroundLine, OPENCLI_WINDOW_ENV } from '../cli/index.js';
4
4
  import { runShell } 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 };
@@ -55,7 +55,7 @@ function sleep(ms) {
55
55
  return new Promise((resolve) => setTimeout(resolve, ms));
56
56
  }
57
57
  async function shellRun(shell, command, argv, timeoutMs) {
58
- const result = await runShell(shell, backgroundLine(command, argv), { timeoutMs });
58
+ const result = await runShell(shell, backgroundLine(command, argv), { timeoutMs, env: OPENCLI_WINDOW_ENV });
59
59
  if (result.timedOut) {
60
60
  return { kind: 'timeout', detail: `没在 ${Math.round(timeoutMs / 1000)} 秒内返回`, stderr: result.stderr };
61
61
  }
@@ -1,9 +1,10 @@
1
+ import { join } from 'node:path';
1
2
  import { OPENCLI_PIN } from '@dsh-workbench/shared/host';
2
3
  import { quoteShellArg } from '@dsh-workbench/shared/host';
3
4
  import { isolatedRoot, libsPrefix, npmCacheDir, toolchainOpencliDir } from '../foundation/paths.js';
4
5
  import { OPENCLI_NPM_PACKAGE } from '../foundation/paths.js';
5
6
  export function toolchainDir() {
6
- return `${isolatedRoot()}/toolchain`;
7
+ return join(isolatedRoot(), 'toolchain');
7
8
  }
8
9
  export const OPENCLI_CATALOG_ENV = 'DSH_WB_OPENCLI_CATALOG';
9
10
  export function toolchainManifestOf() {
@@ -16,23 +17,24 @@ export function toolchainManifestOf() {
16
17
  export function cliCatalogPath() {
17
18
  const override = process.env[OPENCLI_CATALOG_ENV]?.trim();
18
19
  return override === undefined || override === ''
19
- ? `${toolchainOpencliDir()}/cli-manifest.json`
20
+ ? join(toolchainOpencliDir(), 'cli-manifest.json')
20
21
  : override;
21
22
  }
22
23
  export function isolatedCommand() {
23
24
  const name = process.platform === 'win32' ? 'opencli.cmd' : 'opencli';
24
- return `${isolatedRoot()}/bin/${name}`;
25
+ return join(isolatedRoot(), 'bin', name);
25
26
  }
26
27
  export { libsPrefix } from '../foundation/paths.js';
27
28
  export { libInstallCommand } from '../foundation/install.js';
28
29
  export function libDir(name) {
29
- return `${libsPrefix()}/node_modules/${name}`;
30
+ return join(libsPrefix(), 'node_modules', name);
30
31
  }
31
32
  export function isolatedInstallCommand() {
32
- return `npm i --prefix ${quoteShellArg(toolchainDir())} ${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --cache ${quoteShellArg(npmCacheDir())}`;
33
+ 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}`;
33
35
  }
34
36
  export function isolatedPnpmInstallCommand(pnpmCjs) {
35
- const store = `${isolatedRoot()}/pnpm-store`;
37
+ const store = join(isolatedRoot(), 'pnpm-store');
36
38
  return (`node ${quoteShellArg(pnpmCjs)} add --dir ${quoteShellArg(toolchainDir())} ` +
37
39
  `${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(store)} ` +
38
40
  `--allow-build=${OPENCLI_NPM_PACKAGE}`);
@@ -1,2 +1,2 @@
1
- export declare function backgroundPrefix(): readonly string[];
2
- export declare function backgroundLine(command: string, argv: readonly string[]): string;
1
+ export declare const OPENCLI_WINDOW_ENV: Readonly<Record<string, string>>;
2
+ export declare function backgroundLine(command: string, argv: readonly string[], platform?: NodeJS.Platform): string;
@@ -1,7 +1,5 @@
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(' ');
1
+ import { quoteShellArgFor } from '@dsh-workbench/shared/host';
2
+ export const OPENCLI_WINDOW_ENV = { OPENCLI_WINDOW: 'background' };
3
+ export function backgroundLine(command, argv, platform = process.platform) {
4
+ return [quoteShellArgFor(command, platform), ...argv.map((arg) => quoteShellArgFor(arg, platform))].join(' ');
7
5
  }
@@ -1,6 +1,6 @@
1
1
  import type { DshShell } from '@dsh-workbench/shared';
2
2
  import type { Opencli, OpencliSession } from './opencli-types.js';
3
- export declare function opencliCommandLine(command: string, argv: readonly string[], session?: OpencliSession): string;
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
  shell: DshShell;
6
6
  plugin: string;
@@ -1,17 +1,16 @@
1
1
  import { OPENCLI_MAX_CONCURRENT, OPENCLI_TIMEOUT_MS } from '@dsh-workbench/shared/host';
2
2
  import { parseJsonLoose } from '@dsh-workbench/shared/host';
3
- import { quoteShellArg, tailLines } from '@dsh-workbench/shared/host';
3
+ import { quoteShellArgFor, tailLines } from '@dsh-workbench/shared/host';
4
4
  import { helpUrlOf, parseCliErrorEnvelope } from '@dsh-workbench/shared/host';
5
- import { backgroundPrefix } from './opencli-window.js';
5
+ import { OPENCLI_WINDOW_ENV } from './opencli-window.js';
6
6
  import { runShell } 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'];
10
- export function opencliCommandLine(command, argv, session = 'persistent') {
10
+ export function opencliCommandLine(command, argv, session = 'persistent', platform = process.platform) {
11
11
  return [
12
- ...backgroundPrefix(),
13
- quoteShellArg(command),
14
- ...argv.map(quoteShellArg),
12
+ quoteShellArgFor(command, platform),
13
+ ...argv.map((arg) => quoteShellArgFor(arg, platform)),
15
14
  ...(session === 'persistent' ? SITE_SESSION_ARGS : []),
16
15
  '-f',
17
16
  'json',
@@ -52,11 +51,12 @@ export function createOpencli(options) {
52
51
  result = await runShell(shell, commandLine, {
53
52
  ...(workdir === undefined ? {} : { workdir }),
54
53
  timeoutMs,
54
+ env: OPENCLI_WINDOW_ENV,
55
55
  });
56
56
  }
57
57
  catch (error) {
58
58
  throw new WorkbenchDataError('cli-exec-failed', `执行 opencli 失败:${String(error)}`, {
59
- hint: '确认 opencli 已安装且在 PATH 里(which opencli)。',
59
+ hint: '确认 opencli 已安装,并且在 PATH 里。',
60
60
  });
61
61
  }
62
62
  if (result.timedOut) {
@@ -33,23 +33,15 @@ export function createCommandReader(options) {
33
33
  const result = await runShell(shell, quoteAll(argv), {
34
34
  ...(request.timeoutMs === undefined ? {} : { timeoutMs: request.timeoutMs }),
35
35
  ...(request.cwd === undefined ? {} : { workdir: request.cwd }),
36
+ ...(request.env === undefined ? {} : { env: request.env }),
36
37
  });
37
- const filePaths = temp?.paths ?? [];
38
- if (result.timedOut) {
39
- return {
40
- stdout: result.stdout,
41
- stderr: result.stderr,
42
- exitCode: result.exitCode ?? -1,
43
- timedOut: true,
44
- filePaths,
45
- };
46
- }
47
38
  return {
48
39
  stdout: result.stdout,
49
40
  stderr: result.stderr,
50
41
  exitCode: result.exitCode ?? -1,
51
- timedOut: false,
52
- filePaths,
42
+ timedOut: result.timedOut,
43
+ truncated: result.truncated,
44
+ filePaths: temp?.paths ?? [],
53
45
  };
54
46
  }
55
47
  catch (error) {
@@ -58,6 +50,7 @@ export function createCommandReader(options) {
58
50
  stderr: String(error),
59
51
  exitCode: -1,
60
52
  timedOut: false,
53
+ truncated: false,
61
54
  filePaths: temp?.paths ?? [],
62
55
  error: String(error),
63
56
  };
@@ -1,3 +1,4 @@
1
+ import { join } from 'node:path';
1
2
  import { runtimeLayoutOf } from '@dsh-workbench/shared/host';
2
3
  export const OPENCLI_RUNTIME_ID = 'opencli';
3
4
  export const OPENCLI_MANIFEST_FILE = 'opencli-plugin.json';
@@ -25,10 +26,10 @@ export function npmCacheDir() {
25
26
  return layout().npmCacheDir;
26
27
  }
27
28
  export function toolchainOpencliDir() {
28
- return `${isolatedRoot()}/toolchain/node_modules/${OPENCLI_NPM_PACKAGE}`;
29
+ return join(isolatedRoot(), 'toolchain', 'node_modules', ...OPENCLI_NPM_PACKAGE.split('/'));
29
30
  }
30
31
  export function vendorPeerLink() {
31
- const base = `${vendorPrefix()}/node_modules`;
32
+ const base = join(vendorPrefix(), 'node_modules');
32
33
  const [scope] = OPENCLI_NPM_PACKAGE.split('/');
33
- return { dir: `${base}/${OPENCLI_NPM_PACKAGE}`, parent: `${base}/${scope}` };
34
+ return { dir: join(base, ...OPENCLI_NPM_PACKAGE.split('/')), parent: join(base, scope ?? '') };
34
35
  }
@@ -1,5 +1,5 @@
1
1
  import { existsSync, mkdirSync, symlinkSync } from 'node:fs';
2
- import { delimiter, dirname } from 'node:path';
2
+ import { delimiter, dirname, join } from 'node:path';
3
3
  import { OPENCLI_NPM_PACKAGE, libsBinDir, libsPrefix, toolchainOpencliDir } from '../foundation/paths.js';
4
4
  export function ensureLibsBinOnPath(env = process.env) {
5
5
  const dir = libsBinDir();
@@ -10,7 +10,7 @@ export function ensureLibsBinOnPath(env = process.env) {
10
10
  return true;
11
11
  }
12
12
  export function ensureLibsOpencliPeer() {
13
- const link = `${libsPrefix()}/node_modules/${OPENCLI_NPM_PACKAGE}`;
13
+ const link = join(libsPrefix(), 'node_modules', ...OPENCLI_NPM_PACKAGE.split('/'));
14
14
  if (existsSync(link))
15
15
  return false;
16
16
  const target = toolchainOpencliDir();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/adapter-runtime",
3
- "version": "1.1.13",
3
+ "version": "1.1.14-beta.0",
4
4
  "description": "Opencli, browser and data runtime adapters.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -13,10 +13,12 @@
13
13
  "files": [
14
14
  "dist",
15
15
  "channel",
16
+ "!channel/__tests__/**",
16
17
  "bin"
17
18
  ],
18
19
  "dependencies": {
19
- "@dsh-workbench/shared": "1.1.13"
20
+ "execa": "^10.2.0",
21
+ "@dsh-workbench/shared": "1.1.14-beta.0"
20
22
  },
21
23
  "devDependencies": {
22
24
  "@types/node": "^24.19.0",
@@ -1,10 +0,0 @@
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;
@@ -1,36 +0,0 @@
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/install.d.ts DELETED
@@ -1,23 +0,0 @@
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 DELETED
@@ -1,45 +0,0 @@
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/paths.d.ts DELETED
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,33 +0,0 @@
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
- }