@dsh-workbench/adapter-runtime 1.2.9 → 1.2.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencli-plugin-workbench",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "description": "DSH 工作台的公共通道:带浏览器登录态的 Node 侧 fetch,只服务 cookie / cookieValue 两种凭据来源",
@@ -3,13 +3,25 @@ export declare function toolchainDir(): string;
3
3
  export { OPENCLI_CATALOG_ENV };
4
4
  export declare function toolchainManifestOf(): string;
5
5
  export declare function toolchainNpmrcOf(): string;
6
+ export declare function opencliPackageDir(projectDir: string): string;
7
+ export declare function opencliReadinessAt(projectDir: string): {
8
+ readonly ready: boolean;
9
+ readonly detail: string;
10
+ };
11
+ export declare function opencliReadiness(): {
12
+ readonly ready: boolean;
13
+ readonly detail: string;
14
+ };
15
+ export declare function isOpencliReadyAt(projectDir: string): boolean;
16
+ export declare function isOpencliReady(): boolean;
17
+ export declare function opencliBuiltAt(projectDir: string): string | undefined;
6
18
  export declare function cliCatalogPath(): string;
7
19
  export declare function isolatedCommand(): string;
8
20
  export { libsPrefix } from '../foundation/paths.js';
9
21
  export { libInstallCommand } from '../foundation/install.js';
10
22
  export declare function libDir(name: string): string;
11
23
  export declare function pnpmIsolationFlags(): string;
12
- export declare function isolatedInstallCommand(): string;
13
- export declare function isolatedPnpmInstallCommand(pnpmCjs: string): string;
24
+ export declare function isolatedInstallCommand(dir?: string, store?: string): string;
25
+ export declare function isolatedPnpmInstallCommand(pnpmCjs: string, dir?: string, store?: string): string;
14
26
  export { isolatedHome, isolatedRoot, libsBinDir, npmCacheDir, toolchainOpencliDir, vendorPeerLink, vendorPluginsDir, vendorPrefix } from '../foundation/paths.js';
15
27
  export { OPENCLI_NPM_PACKAGE } from '../foundation/paths.js';
@@ -1,3 +1,4 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
1
2
  import { join } from 'node:path';
2
3
  import { DEFAULT_NPM_REGISTRY, OPENCLI_CATALOG_ENV, OPENCLI_PIN, OPENCLI_REGISTRY_ENV, } from '@dsh-workbench/shared/host';
3
4
  import { quoteShellArg } from '@dsh-workbench/shared/host';
@@ -20,6 +21,55 @@ export function toolchainNpmrcOf() {
20
21
  const registry = asked.endsWith('/') ? asked : `${asked}/`;
21
22
  return `${OPENCLI_NPM_PACKAGE.split('/')[0]}:registry=${registry}\n`;
22
23
  }
24
+ function packageVersionOf(file) {
25
+ try {
26
+ const parsed = JSON.parse(readFileSync(file, 'utf8'));
27
+ if (typeof parsed !== 'object' || parsed === null)
28
+ return undefined;
29
+ const version = parsed['version'];
30
+ return typeof version === 'string' && version.trim() !== '' ? version.trim() : undefined;
31
+ }
32
+ catch {
33
+ return undefined;
34
+ }
35
+ }
36
+ export function opencliPackageDir(projectDir) {
37
+ return join(projectDir, 'node_modules', ...OPENCLI_NPM_PACKAGE.split('/'));
38
+ }
39
+ export function opencliReadinessAt(projectDir) {
40
+ const dir = opencliPackageDir(projectDir);
41
+ if (!existsSync(join(dir, 'package.json')))
42
+ return { ready: false, detail: '隔离副本不在' };
43
+ if (!existsSync(join(dir, 'dist', 'src', 'main.js'))) {
44
+ return { ready: false, detail: '隔离副本缺 dist/src/main.js' };
45
+ }
46
+ const version = packageVersionOf(join(dir, 'package.json'));
47
+ if (version !== OPENCLI_PIN) {
48
+ return { ready: false, detail: `隔离副本是 ${version ?? '读不到的版本'},要 ${OPENCLI_PIN}` };
49
+ }
50
+ return { ready: true, detail: OPENCLI_PIN };
51
+ }
52
+ export function opencliReadiness() {
53
+ return opencliReadinessAt(toolchainDir());
54
+ }
55
+ export function isOpencliReadyAt(projectDir) {
56
+ return opencliReadinessAt(projectDir).ready;
57
+ }
58
+ export function isOpencliReady() {
59
+ return isOpencliReadyAt(toolchainDir());
60
+ }
61
+ export function opencliBuiltAt(projectDir) {
62
+ try {
63
+ const parsed = JSON.parse(readFileSync(join(projectDir, '.ready.json'), 'utf8'));
64
+ if (typeof parsed !== 'object' || parsed === null)
65
+ return undefined;
66
+ const at = parsed['at'];
67
+ return typeof at === 'string' && at.trim() !== '' ? at.trim() : undefined;
68
+ }
69
+ catch {
70
+ return undefined;
71
+ }
72
+ }
23
73
  export function cliCatalogPath() {
24
74
  const override = process.env[OPENCLI_CATALOG_ENV]?.trim();
25
75
  return override === undefined || override === ''
@@ -39,15 +89,14 @@ export function pnpmIsolationFlags() {
39
89
  return (`--config.cache-dir=${quoteShellArg(join(isolatedRoot(), 'pnpm-cache'))} ` +
40
90
  `--config.state-dir=${quoteShellArg(join(isolatedRoot(), 'pnpm-state'))}`);
41
91
  }
42
- export function isolatedInstallCommand() {
92
+ export function isolatedInstallCommand(dir = toolchainDir(), store = storeDirFor(dir)) {
43
93
  const pnpm = process.env.DSH_WB_PNPM?.trim() || 'pnpm';
44
- return `${pnpm} add --dir ${quoteShellArg(toolchainDir())} ${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(storeDirFor(toolchainDir()))} ${pnpmIsolationFlags()} --allow-build=${OPENCLI_NPM_PACKAGE}`;
94
+ return `${pnpm} add --dir ${quoteShellArg(dir)} ${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(store)} ${pnpmIsolationFlags()} --allow-build=${OPENCLI_NPM_PACKAGE} --save-exact`;
45
95
  }
46
- export function isolatedPnpmInstallCommand(pnpmCjs) {
47
- const store = storeDirFor(toolchainDir());
48
- return (`node ${quoteShellArg(pnpmCjs)} add --dir ${quoteShellArg(toolchainDir())} ` +
96
+ export function isolatedPnpmInstallCommand(pnpmCjs, dir = toolchainDir(), store = storeDirFor(dir)) {
97
+ return (`node ${quoteShellArg(pnpmCjs)} add --dir ${quoteShellArg(dir)} ` +
49
98
  `${OPENCLI_NPM_PACKAGE}@${OPENCLI_PIN} --store-dir ${quoteShellArg(store)} ` +
50
- `${pnpmIsolationFlags()} --allow-build=${OPENCLI_NPM_PACKAGE}`);
99
+ `${pnpmIsolationFlags()} --allow-build=${OPENCLI_NPM_PACKAGE} --save-exact`);
51
100
  }
52
101
  export { isolatedHome, isolatedRoot, libsBinDir, npmCacheDir, toolchainOpencliDir, vendorPeerLink, vendorPluginsDir, vendorPrefix } from '../foundation/paths.js';
53
102
  export { OPENCLI_NPM_PACKAGE } from '../foundation/paths.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/adapter-runtime",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
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.9"
20
+ "@dsh-workbench/shared": "1.2.10"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^24.19.0",