@dsh-workbench/adapter-runtime 1.2.1 → 1.2.3-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/channel/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { OPENCLI_CATALOG_ENV, OPENCLI_PIN } from '@dsh-workbench/shared/host';
|
|
3
3
|
import { quoteShellArg } from '@dsh-workbench/shared/host';
|
|
4
|
-
import { isolatedRoot, libsPrefix,
|
|
4
|
+
import { isolatedRoot, libsPrefix, storeDirFor, toolchainOpencliDir } from '../foundation/paths.js';
|
|
5
5
|
import { OPENCLI_NPM_PACKAGE } from '../foundation/paths.js';
|
|
6
6
|
export function toolchainDir() {
|
|
7
7
|
return join(isolatedRoot(), 'toolchain');
|
|
@@ -35,10 +35,10 @@ export function pnpmIsolationFlags() {
|
|
|
35
35
|
}
|
|
36
36
|
export function isolatedInstallCommand() {
|
|
37
37
|
const pnpm = process.env.DSH_WB_PNPM?.trim() || 'pnpm';
|
|
38
|
-
return `${pnpm} add --dir ${quoteShellArg(toolchainDir())} ${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(
|
|
38
|
+
return `${pnpm} add --dir ${quoteShellArg(toolchainDir())} ${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(storeDirFor(toolchainDir()))} ${pnpmIsolationFlags()} --allow-build=${OPENCLI_NPM_PACKAGE}`;
|
|
39
39
|
}
|
|
40
40
|
export function isolatedPnpmInstallCommand(pnpmCjs) {
|
|
41
|
-
const store =
|
|
41
|
+
const store = storeDirFor(toolchainDir());
|
|
42
42
|
return (`node ${quoteShellArg(pnpmCjs)} add --dir ${quoteShellArg(toolchainDir())} ` +
|
|
43
43
|
`${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(store)} ` +
|
|
44
44
|
`${pnpmIsolationFlags()} --allow-build=${OPENCLI_NPM_PACKAGE}`);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { binInstallCommand as binAt, libInstallCommand as libAt, libUninstallCommand as uninstallAt, } from '@dsh-workbench/shared/host';
|
|
2
|
-
import { libsPrefix,
|
|
2
|
+
import { libsPrefix, storeDirFor } from './paths.js';
|
|
3
3
|
export function libInstallCommand(options) {
|
|
4
|
-
return libAt({ ...options, prefix: libsPrefix(),
|
|
4
|
+
return libAt({ ...options, prefix: libsPrefix(), storeDir: storeDirFor(libsPrefix()) });
|
|
5
5
|
}
|
|
6
6
|
export function binInstallCommand(need, os, env = process.env) {
|
|
7
|
-
return binAt(need, os, env, libsPrefix(),
|
|
7
|
+
return binAt(need, os, env, libsPrefix(), storeDirFor(libsPrefix()));
|
|
8
8
|
}
|
|
9
9
|
export function libUninstallCommand(options) {
|
|
10
10
|
return uninstallAt({ need: options.need, prefix: libsPrefix() });
|
|
@@ -9,6 +9,8 @@ export declare function vendorPluginsDir(): string;
|
|
|
9
9
|
export declare function libsPrefix(): string;
|
|
10
10
|
export declare function libsBinDir(): string;
|
|
11
11
|
export declare function npmCacheDir(): string;
|
|
12
|
+
export declare function pnpmStoreDir(): string;
|
|
13
|
+
export declare function storeDirFor(projectDir: string, read?: (file: string) => string | undefined): string;
|
|
12
14
|
export declare function toolchainOpencliDir(): string;
|
|
13
15
|
export declare function vendorPeerLink(): {
|
|
14
16
|
readonly dir: string;
|
package/dist/foundation/paths.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
1
2
|
import { join } from 'node:path';
|
|
2
3
|
import { OPENCLI_NPM_PACKAGE, runtimeLayoutOf } from '@dsh-workbench/shared/host';
|
|
3
4
|
export const OPENCLI_RUNTIME_ID = 'opencli';
|
|
@@ -25,6 +26,48 @@ export function libsBinDir() {
|
|
|
25
26
|
export function npmCacheDir() {
|
|
26
27
|
return layout().npmCacheDir;
|
|
27
28
|
}
|
|
29
|
+
export function pnpmStoreDir() {
|
|
30
|
+
return layout().pnpmStoreDir;
|
|
31
|
+
}
|
|
32
|
+
function readTextFile(file) {
|
|
33
|
+
try {
|
|
34
|
+
return readFileSync(file, 'utf8');
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function unquote(value) {
|
|
41
|
+
const first = value.at(0);
|
|
42
|
+
const last = value.at(-1);
|
|
43
|
+
const paired = value.length >= 2 && (first === '"' || first === "'") && last === first;
|
|
44
|
+
return paired ? value.slice(1, -1).trim() : value;
|
|
45
|
+
}
|
|
46
|
+
function jsonStoreDir(text) {
|
|
47
|
+
try {
|
|
48
|
+
const parsed = JSON.parse(text);
|
|
49
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
50
|
+
return undefined;
|
|
51
|
+
const value = parsed['storeDir'];
|
|
52
|
+
return typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function lineStoreDir(text) {
|
|
59
|
+
const line = text.split(/\r?\n/u).find((entry) => entry.startsWith('storeDir:'));
|
|
60
|
+
if (line === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
const value = unquote(line.slice('storeDir:'.length).trim());
|
|
63
|
+
return value === '' ? undefined : value;
|
|
64
|
+
}
|
|
65
|
+
export function storeDirFor(projectDir, read = readTextFile) {
|
|
66
|
+
const text = read(join(projectDir, 'node_modules', '.modules.yaml'));
|
|
67
|
+
if (text === undefined)
|
|
68
|
+
return pnpmStoreDir();
|
|
69
|
+
return jsonStoreDir(text) ?? lineStoreDir(text) ?? pnpmStoreDir();
|
|
70
|
+
}
|
|
28
71
|
export function toolchainOpencliDir() {
|
|
29
72
|
return join(isolatedRoot(), 'toolchain', 'node_modules', ...OPENCLI_NPM_PACKAGE.split('/'));
|
|
30
73
|
}
|
package/dist/libs/links.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { existsSync, mkdirSync,
|
|
1
|
+
import { existsSync, mkdirSync, realpathSync } from 'node:fs';
|
|
2
2
|
import { delimiter, dirname, join } from 'node:path';
|
|
3
|
+
import { linkDir } from '@dsh-workbench/shared/host';
|
|
3
4
|
import { OPENCLI_NPM_PACKAGE, libsBinDir, libsPrefix, toolchainOpencliDir } from '../foundation/paths.js';
|
|
4
5
|
export function ensureLibsBinOnPath(env = process.env) {
|
|
5
6
|
const dir = libsBinDir();
|
|
@@ -9,16 +10,24 @@ export function ensureLibsBinOnPath(env = process.env) {
|
|
|
9
10
|
env.PATH = [dir, ...parts].join(delimiter);
|
|
10
11
|
return true;
|
|
11
12
|
}
|
|
13
|
+
function pointsAt(link, target) {
|
|
14
|
+
try {
|
|
15
|
+
return realpathSync(link) === realpathSync(target);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
12
21
|
export function ensureLibsOpencliPeer() {
|
|
13
22
|
const link = join(libsPrefix(), 'node_modules', ...OPENCLI_NPM_PACKAGE.split('/'));
|
|
14
|
-
if (existsSync(link))
|
|
15
|
-
return false;
|
|
16
23
|
const target = toolchainOpencliDir();
|
|
17
24
|
if (!existsSync(target))
|
|
18
25
|
return false;
|
|
26
|
+
if (pointsAt(link, target))
|
|
27
|
+
return false;
|
|
19
28
|
try {
|
|
20
29
|
mkdirSync(dirname(link), { recursive: true });
|
|
21
|
-
|
|
30
|
+
linkDir(target, link);
|
|
22
31
|
return true;
|
|
23
32
|
}
|
|
24
33
|
catch {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-workbench/adapter-runtime",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3-beta.0",
|
|
4
4
|
"description": "Opencli, browser and data runtime adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"bin"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@dsh-workbench/shared": "1.2.
|
|
20
|
+
"@dsh-workbench/shared": "1.2.3-beta.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^24.19.0",
|
package/bin/opencli-isolated
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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" "$@"
|