@dsh-workbench/adapter-supply 1.1.8 → 1.1.9

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/dist/index.d.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  export * from './registry-declaration.js';
2
- export * from './installed-module.js';
3
2
  export * from './package-route.js';
4
3
  export * from './plugin-login-hint.js';
5
- export * from './package-kind.js';
6
- export * from './package-content.js';
7
4
  export * from './plugin-units.js';
8
5
  export * from './plugin-tools.js';
9
- export * from './dsh-plugins.js';
6
+ export { dshPluginsHandler, readDshPlugins } from '@dsh-workbench/shared/host';
10
7
  export * from './plugin-catalog.js';
11
- export * from './bundle-manager.js';
12
8
  export * from './plugin-source.js';
9
+ export { OPENCLI_MANIFEST_FILE } from '@dsh-workbench/adapter-runtime';
10
+ export { createDeclarationLookup, dshMarkersOf, isCommandFile, pluginManifestOf, splitNpmSpec, verdictOf, withPackageDir, declarationGaps, declaredPluginCommands, isLocalDependencySpec, isPackedArtifactSpec, isPackageName, isRegistryDependencySpec, moduleDeclarationOf, packageVersionAt, profileDirOf, profileManifestOf, profileModules, readBundleManager, readInstalledModule, readProfilePackage, } from '@dsh-workbench/shared/host';
11
+ export type { BundleManager } from '@dsh-workbench/shared/host';
package/dist/index.js CHANGED
@@ -1,12 +1,10 @@
1
1
  export * from './registry-declaration.js';
2
- export * from './installed-module.js';
3
2
  export * from './package-route.js';
4
3
  export * from './plugin-login-hint.js';
5
- export * from './package-kind.js';
6
- export * from './package-content.js';
7
4
  export * from './plugin-units.js';
8
5
  export * from './plugin-tools.js';
9
- export * from './dsh-plugins.js';
6
+ export { dshPluginsHandler, readDshPlugins } from '@dsh-workbench/shared/host';
10
7
  export * from './plugin-catalog.js';
11
- export * from './bundle-manager.js';
12
8
  export * from './plugin-source.js';
9
+ export { OPENCLI_MANIFEST_FILE } from '@dsh-workbench/adapter-runtime';
10
+ export { createDeclarationLookup, dshMarkersOf, isCommandFile, pluginManifestOf, splitNpmSpec, verdictOf, withPackageDir, declarationGaps, declaredPluginCommands, isLocalDependencySpec, isPackedArtifactSpec, isPackageName, isRegistryDependencySpec, moduleDeclarationOf, packageVersionAt, profileDirOf, profileManifestOf, profileModules, readBundleManager, readInstalledModule, readProfilePackage, } from '@dsh-workbench/shared/host';
@@ -1,4 +1,4 @@
1
- export type PackageKind = 'opencli-plugin' | 'dsh-bundle' | 'both' | 'neither';
1
+ export type PackageKind = 'runtime-plugin' | 'dsh-bundle' | 'both' | 'neither';
2
2
  export interface PackageVerdict {
3
3
  readonly kind: PackageKind;
4
4
  readonly pkg?: string;
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { isPackageName } from './installed-module.js';
3
+ import { isPackageName } from '@dsh-workbench/shared/host';
4
4
  import { dshRecordOf, packageManifestOf, packageNameOf } from './registry-declaration.js';
5
5
  export const OPENCLI_MANIFEST_FILE = 'opencli-plugin.json';
6
6
  const VERSION = /^[a-zA-Z0-9][a-zA-Z0-9._+-]*$/;
@@ -60,7 +60,7 @@ export function verdictOf(dir) {
60
60
  if (packageManifestOf(dir) === undefined && plugin === undefined)
61
61
  return undefined;
62
62
  const dsh = dshMarkersOf(dshRecordOf(dir));
63
- const kind = plugin !== undefined && dsh ? 'both' : plugin !== undefined ? 'opencli-plugin' : dsh ? 'dsh-bundle' : 'neither';
63
+ const kind = plugin !== undefined && dsh ? 'both' : plugin !== undefined ? 'runtime-plugin' : dsh ? 'dsh-bundle' : 'neither';
64
64
  const pkg = packageNameOf(dir);
65
65
  return {
66
66
  kind,
@@ -1,11 +1,5 @@
1
- import type { DshShell } from '@dsh-workbench/shared';
2
- import { type ResolvedPluginSource } from './plugin-source.js';
3
- export type PackageRouteKind = 'opencli-plugin' | 'dsh-bundle' | 'neither';
4
- export interface PackageRoute {
5
- readonly kind: PackageRouteKind;
6
- readonly pkg?: string;
7
- readonly pluginName?: string;
8
- }
1
+ import type { DshShell, ResolvedPluginSource } from '@dsh-workbench/shared';
2
+ import type { PackageRoute } from '@dsh-workbench/shared/host';
9
3
  export declare const LOCAL_PLUGIN_ENV = "DSH_WB_OPENCLI_PLUGIN_PATH";
10
4
  export declare const PLUGIN_REGISTRY_ENV = "DSH_WB_OPENCLI_PLUGIN_REGISTRY";
11
5
  export declare function packageRouteOf(options: {
@@ -1,55 +1,19 @@
1
- import { VERSION_CHECK_TTL_MS } from '@dsh-workbench/shared/host';
1
+ import { createPackageRouter, localDirOf, splitNpmSpec } from '@dsh-workbench/shared/host';
2
+ import { npmCacheDir, OPENCLI_MANIFEST_FILE } from '@dsh-workbench/adapter-runtime';
3
+ import { registryDshOf } from './registry-declaration.js';
2
4
  import { resolvePluginSource } from './plugin-source.js';
3
- import { dshMarkersOf, splitNpmSpec, verdictOf } from './package-kind.js';
4
- import { withPackageDir } from './package-content.js';
5
- import { localDirOf, registryDshOf } from './registry-declaration.js';
6
5
  export const LOCAL_PLUGIN_ENV = 'DSH_WB_OPENCLI_PLUGIN_PATH';
7
6
  export const PLUGIN_REGISTRY_ENV = 'DSH_WB_OPENCLI_PLUGIN_REGISTRY';
8
- const cache = new Map();
9
- function routeOfVerdict(verdict, fallback) {
10
- const pkg = verdict.pkg ?? fallback;
11
- if (verdict.kind === 'neither')
12
- return { kind: 'neither', ...(pkg === undefined ? {} : { pkg }) };
13
- if (verdict.kind === 'dsh-bundle' || verdict.kind === 'both')
14
- return { kind: 'dsh-bundle' };
15
- return {
16
- kind: 'opencli-plugin',
17
- ...(pkg === undefined ? {} : { pkg }),
18
- ...(verdict.pluginName === undefined ? {} : { pluginName: verdict.pluginName }),
19
- };
20
- }
7
+ const router = createPackageRouter({
8
+ manifestFile: OPENCLI_MANIFEST_FILE,
9
+ cacheDir: npmCacheDir(),
10
+ dshLookup: (options) => registryDshOf(options),
11
+ });
21
12
  export async function packageRouteOf(options) {
22
- const local = localDirOf(options.spec);
23
- if (local !== undefined) {
24
- const verdict = verdictOf(local);
25
- return verdict === undefined ? undefined : routeOfVerdict(verdict, splitNpmSpec(options.spec)?.name);
26
- }
27
- const ref = splitNpmSpec(options.spec);
28
- if (ref === undefined)
29
- return undefined;
30
- const shell = options.shell;
31
- const registry = options.registry;
32
- if (shell === undefined || registry === undefined)
33
- return undefined;
34
- const key = `${registry}|${options.spec}`;
35
- const hit = cache.get(key);
36
- if (options.force !== true && hit !== undefined && Date.now() - hit.at < VERSION_CHECK_TTL_MS) {
37
- return hit.route ?? undefined;
38
- }
39
- const found = await registryDshOf({ shell, name: options.spec, registry });
40
- let route;
41
- if (found.readable && dshMarkersOf(found.raw)) {
42
- route = { kind: 'dsh-bundle' };
43
- }
44
- else {
45
- const verdict = await withPackageDir({ shell, spec: options.spec, registry }, (dir) => verdictOf(dir));
46
- route = verdict === undefined ? undefined : routeOfVerdict(verdict, ref.name);
47
- }
48
- cache.set(key, { at: Date.now(), route: route ?? null });
49
- return route;
13
+ return router.packageRouteOf(options);
50
14
  }
51
15
  export function resetPackageRouteCache() {
52
- cache.clear();
16
+ router.reset();
53
17
  }
54
18
  export function pluginInstallPlan(options) {
55
19
  const local = localDirOf(options.spec);
@@ -1,2 +1,5 @@
1
- export type { ProvisionProblem } from '@dsh-workbench/shared/host';
2
- export { npmRegistryOf, resolvePluginSource, type PluginSourceCommand, type PluginSourceOptions, type ResolvedPluginSource, } from '@dsh-workbench/shared/host';
1
+ import type { SupplySource } from '@dsh-workbench/shared';
2
+ import type { PluginSourceOptions, ResolvedPluginSource } from '@dsh-workbench/shared';
3
+ export type { PluginSourceCommand, PluginSourceOptions, ResolvedPluginSource, } from '@dsh-workbench/shared';
4
+ export { npmRegistryOf } from '@dsh-workbench/shared/host';
5
+ export declare function resolvePluginSource(source: SupplySource | undefined, env: Readonly<Record<string, string | undefined>>, options?: PluginSourceOptions): ResolvedPluginSource;
@@ -1 +1,80 @@
1
- export { npmRegistryOf, resolvePluginSource, } from '@dsh-workbench/shared/host';
1
+ import { npmRegistryOf, quoteShellArg } from '@dsh-workbench/shared/host';
2
+ import { npmCacheDir, toolchainOpencliDir, vendorPeerLink, vendorPrefix } from '@dsh-workbench/adapter-runtime';
3
+ export { npmRegistryOf } from '@dsh-workbench/shared/host';
4
+ function envValue(env, name) {
5
+ const value = env[name]?.trim();
6
+ return value === undefined || value === '' ? { ok: false } : { ok: true, value };
7
+ }
8
+ function mergeLines(commands) {
9
+ return commands.map((item) => (item.optional === true ? `(${item.line} || true)` : item.line)).join(' && ');
10
+ }
11
+ function installOne(command, spec) {
12
+ const line = `${quoteShellArg(command)} plugin install ${quoteShellArg(spec)}`;
13
+ return { ok: true, commands: [{ line }], line };
14
+ }
15
+ function pluginPackageOf(source, plugin) {
16
+ if (source.kind === 'npm') {
17
+ const pkg = source.package?.trim() ?? '';
18
+ if (pkg !== '')
19
+ return pkg;
20
+ return plugin.trim() === '' ? '' : `opencli-plugin-${plugin.trim()}`;
21
+ }
22
+ if (source.kind === 'git')
23
+ return source.url.trim();
24
+ return '';
25
+ }
26
+ function npmSource(source, env, options) {
27
+ const registry = npmRegistryOf(source, env);
28
+ if (!registry.ok)
29
+ return { ok: false, problem: 'env-missing', env: registry.env };
30
+ const { command = 'opencli', plugin = '', version = 'latest', mode = 'install' } = options;
31
+ const name = pluginPackageOf(source, plugin);
32
+ if (name === '')
33
+ return { ok: false, problem: 'malformed' };
34
+ const prefix = vendorPrefix();
35
+ const dirInPrefix = `${prefix}/node_modules/${name}`;
36
+ const peer = vendorPeerLink();
37
+ const commands = [
38
+ {
39
+ line: [
40
+ 'npm i',
41
+ `--prefix ${quoteShellArg(prefix)}`,
42
+ quoteShellArg(`${name}@${version}`),
43
+ `--registry ${quoteShellArg(registry.value)}`,
44
+ `--cache ${quoteShellArg(npmCacheDir())}`,
45
+ ].join(' '),
46
+ },
47
+ {
48
+ line: `rm -rf ${quoteShellArg(peer.dir)} && mkdir -p ${quoteShellArg(peer.parent)} && ln -s ${quoteShellArg(toolchainOpencliDir())} ${quoteShellArg(peer.dir)}`,
49
+ },
50
+ ];
51
+ if (mode === 'install') {
52
+ if (plugin !== '') {
53
+ commands.push({
54
+ line: `${quoteShellArg(command)} plugin uninstall ${quoteShellArg(plugin)}`,
55
+ optional: true,
56
+ });
57
+ }
58
+ commands.push({
59
+ line: `NPM_CONFIG_REGISTRY=${quoteShellArg(registry.value)} ${quoteShellArg(command)} plugin install ${quoteShellArg(dirInPrefix)}`,
60
+ });
61
+ }
62
+ return { ok: true, commands, line: mergeLines(commands) };
63
+ }
64
+ export function resolvePluginSource(source, env, options = {}) {
65
+ if (source === undefined)
66
+ return { ok: false, problem: 'not-declared' };
67
+ const command = options.command ?? 'opencli';
68
+ if (source.kind === 'git') {
69
+ const url = source.url.trim();
70
+ return url === '' ? { ok: false, problem: 'malformed' } : installOne(command, url);
71
+ }
72
+ if (source.kind === 'npm')
73
+ return npmSource(source, env, options);
74
+ const value = source.env === undefined ? { ok: false } : envValue(env, source.env);
75
+ if (value.ok)
76
+ return installOne(command, value.value);
77
+ if (source.path !== undefined && source.path.trim() !== '')
78
+ return installOne(command, source.path.trim());
79
+ return { ok: false, problem: 'env-missing', env: source.env ?? '' };
80
+ }
@@ -102,7 +102,7 @@ function faceOf(unit, opencliFor, note) {
102
102
  tools: unit.tools.map((tool) => ({
103
103
  name: tool.name,
104
104
  writes: pluginToolWrites(tool.command),
105
- opencli: {
105
+ runtime: {
106
106
  plugin: unit.plugin,
107
107
  command: tool.command.name,
108
108
  args: tool.command.args.map((arg) => arg.name),
@@ -1,23 +1,18 @@
1
1
  import type { DshShell } from '@dsh-workbench/shared';
2
- export declare function localDirOf(spec: string): string | undefined;
3
- export declare function packageManifestOf(dir: string): Readonly<Record<string, unknown>> | undefined;
4
- export declare function dshRecordOf(dir: string): unknown | undefined;
5
- export declare function packageNameOf(dir: string): string | undefined;
6
- export declare function pathDeclarationOf(spec: string): unknown | undefined;
7
- export interface RegistryDshLookup {
8
- readonly readable: boolean;
9
- readonly raw: unknown;
10
- }
2
+ export { declarationRefusalOf, dshRecordOf, localDirOf, packageManifestOf, packageNameOf, pathDeclarationOf, } from '@dsh-workbench/shared/host';
3
+ export type { RegistryDshLookup } from '@dsh-workbench/shared/host';
11
4
  export declare function registryDshOf(options: {
12
5
  shell: DshShell;
13
6
  name: string;
14
7
  registry?: string | undefined;
15
8
  force?: boolean;
16
- }): Promise<RegistryDshLookup>;
9
+ }): Promise<{
10
+ readonly readable: boolean;
11
+ readonly raw: unknown;
12
+ }>;
17
13
  export declare function registryDeclarationOf(options: {
18
14
  shell: DshShell;
19
15
  name: string;
20
16
  registry: string;
21
17
  force?: boolean;
22
18
  }): Promise<unknown | undefined>;
23
- export declare function declarationRefusalOf(name: string, raw: unknown): readonly string[];
@@ -1,56 +1,10 @@
1
- import fs from 'node:fs';
2
1
  import { npmCacheDir } from '@dsh-workbench/adapter-runtime';
3
- import path from 'node:path';
4
- import { declarationProblemsOf, parseJsonLoose, quoteShellArg, runShell, VERSION_CHECK_TIMEOUT_MS, VERSION_CHECK_TTL_MS, } from '@dsh-workbench/shared/host';
5
- const cache = new Map();
6
- function asRecord(value) {
7
- return typeof value === 'object' && value !== null ? value : undefined;
8
- }
9
- export function localDirOf(spec) {
10
- const dir = spec.trim().replace(/^(?:file|link):/, '');
11
- return path.isAbsolute(dir) ? dir : undefined;
12
- }
13
- export function packageManifestOf(dir) {
14
- try {
15
- const parsed = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
16
- return asRecord(parsed);
17
- }
18
- catch {
19
- return undefined;
20
- }
21
- }
22
- export function dshRecordOf(dir) {
23
- return packageManifestOf(dir)?.dsh;
24
- }
25
- export function packageNameOf(dir) {
26
- const name = packageManifestOf(dir)?.name;
27
- return typeof name === 'string' && name.trim() !== '' ? name.trim() : undefined;
28
- }
29
- export function pathDeclarationOf(spec) {
30
- const dir = localDirOf(spec);
31
- return dir === undefined ? undefined : asRecord(dshRecordOf(dir))?.workbench;
32
- }
2
+ import { createRegistryLookup } from '@dsh-workbench/shared/host';
3
+ export { declarationRefusalOf, dshRecordOf, localDirOf, packageManifestOf, packageNameOf, pathDeclarationOf, } from '@dsh-workbench/shared/host';
4
+ const lookup = createRegistryLookup();
33
5
  export async function registryDshOf(options) {
34
- const { shell, name, registry, force = false } = options;
35
- const key = `${registry ?? ''}|${name}`;
36
- const hit = cache.get(key);
37
- if (!force && hit !== undefined && Date.now() - hit.at < VERSION_CHECK_TTL_MS) {
38
- return { readable: true, raw: hit.raw };
39
- }
40
- const at = registry === undefined ? '' : ` --registry ${quoteShellArg(registry)}`;
41
- const result = await runShell(shell, `npm view ${quoteShellArg(name)} dsh --json${at} --cache ${quoteShellArg(npmCacheDir())}`, { timeoutMs: VERSION_CHECK_TIMEOUT_MS }).catch(() => undefined);
42
- const parsed = result?.exitCode === 0 ? parseJsonLoose(result.stdout) : undefined;
43
- if (parsed === undefined)
44
- return { readable: false, raw: undefined };
45
- cache.set(key, { at: Date.now(), raw: parsed });
46
- return { readable: true, raw: parsed };
6
+ return lookup.registryDshOf({ ...options, cacheDir: npmCacheDir() });
47
7
  }
48
8
  export async function registryDeclarationOf(options) {
49
- const found = await registryDshOf(options);
50
- return found.readable ? asRecord(found.raw)?.workbench : undefined;
51
- }
52
- export function declarationRefusalOf(name, raw) {
53
- if (raw === undefined)
54
- return [];
55
- return declarationProblemsOf(name, raw);
9
+ return lookup.registryDeclarationOf({ ...options, cacheDir: npmCacheDir() });
56
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-workbench/adapter-supply",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Workbench supply adapter package.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,8 +22,8 @@
22
22
  "directory": "packages/adapter-supply"
23
23
  },
24
24
  "dependencies": {
25
- "@dsh-workbench/adapter-runtime": "1.1.8",
26
- "@dsh-workbench/shared": "1.1.8"
25
+ "@dsh-workbench/shared": "1.1.9",
26
+ "@dsh-workbench/adapter-runtime": "1.1.9"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^24.19.0",