@oh-my-tool/cli 0.3.4 → 0.3.6
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/package.json +2 -2
- package/src/extension/discovery.ts +10 -2
- package/src/extension/install.ts +53 -6
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-tool/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Oh My Tool CLI - local and enterprise tools for agents",
|
|
6
6
|
"keywords": [
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@clack/prompts": "^1.7.0",
|
|
31
31
|
"@modelcontextprotocol/client": "2.0.0",
|
|
32
|
-
"@oh-my-tool/sdk": "0.3.
|
|
32
|
+
"@oh-my-tool/sdk": "0.3.6",
|
|
33
33
|
"open": "11.0.0"
|
|
34
34
|
},
|
|
35
35
|
"engines": {
|
|
@@ -37,6 +37,7 @@ export function discoverExtensions(home: string): InstalledExtension[] {
|
|
|
37
37
|
for (const id of readdirSync(root)) {
|
|
38
38
|
const idDir = join(root, id);
|
|
39
39
|
if (!statSync(idDir).isDirectory()) continue;
|
|
40
|
+
const candidates: InstalledExtension[] = [];
|
|
40
41
|
for (const version of readdirSync(idDir)) {
|
|
41
42
|
const versionDir = join(idDir, version);
|
|
42
43
|
if (!statSync(versionDir).isDirectory()) continue;
|
|
@@ -46,7 +47,7 @@ export function discoverExtensions(home: string): InstalledExtension[] {
|
|
|
46
47
|
const manifest = parseManifest(readFileSync(manifestPath, "utf8"));
|
|
47
48
|
validateManifest(manifest);
|
|
48
49
|
checkSdkCompatibility(manifest.sdkVersion);
|
|
49
|
-
|
|
50
|
+
candidates.push({
|
|
50
51
|
id,
|
|
51
52
|
version,
|
|
52
53
|
dir: versionDir,
|
|
@@ -57,6 +58,13 @@ export function discoverExtensions(home: string): InstalledExtension[] {
|
|
|
57
58
|
// skip invalid or incompatible manifests
|
|
58
59
|
}
|
|
59
60
|
}
|
|
61
|
+
const active = candidates.reduce<InstalledExtension | undefined>((current, candidate) => {
|
|
62
|
+
if (current === undefined || Bun.semver.order(candidate.manifest.version, current.manifest.version) > 0) {
|
|
63
|
+
return candidate;
|
|
64
|
+
}
|
|
65
|
+
return current;
|
|
66
|
+
}, undefined);
|
|
67
|
+
if (active !== undefined) out.push(active);
|
|
60
68
|
}
|
|
61
69
|
return out;
|
|
62
|
-
}
|
|
70
|
+
}
|
package/src/extension/install.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cp, mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
1
|
+
import { cp, mkdir, mkdtemp, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
2
2
|
import { execFile as execFileCallback } from "node:child_process";
|
|
3
3
|
import { promisify } from "node:util";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
@@ -24,8 +24,21 @@ export interface NpmExtensionSpec {
|
|
|
24
24
|
|
|
25
25
|
export class ExtensionInstallError extends Error {}
|
|
26
26
|
|
|
27
|
+
export function npmExecutableForPlatform(platform: string = process.platform): string {
|
|
28
|
+
return platform === "win32" ? "npm.cmd" : "npm";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function npmShellForPlatform(platform: string = process.platform): boolean {
|
|
32
|
+
return platform === "win32";
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
export interface NpmInstallDependencies {
|
|
28
36
|
install(spec: string, tempDir: string): Promise<void>;
|
|
37
|
+
execFile?(
|
|
38
|
+
file: string,
|
|
39
|
+
args: string[],
|
|
40
|
+
options: { cwd: string; shell: boolean; timeout: number; maxBuffer: number },
|
|
41
|
+
): Promise<unknown>;
|
|
29
42
|
}
|
|
30
43
|
|
|
31
44
|
export function normalizeNpmExtensionSpec(spec: string): NpmExtensionSpec {
|
|
@@ -75,9 +88,39 @@ async function installExtensionDirectory(home: string, srcDir: string, expectedP
|
|
|
75
88
|
force: true,
|
|
76
89
|
filter: (s: string) => basename(s) !== "node_modules",
|
|
77
90
|
});
|
|
91
|
+
await retireInactiveVersions(home, manifest.id, manifest.version);
|
|
78
92
|
return { id: manifest.id, version: manifest.version, target };
|
|
79
93
|
}
|
|
80
94
|
|
|
95
|
+
async function retireInactiveVersions(home: string, id: string, activeVersion: string): Promise<void> {
|
|
96
|
+
const extensionRoot = join(home, "extensions", id);
|
|
97
|
+
let entries: string[];
|
|
98
|
+
try {
|
|
99
|
+
entries = await readdir(extensionRoot);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (isMissingPathError(error)) return;
|
|
102
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
103
|
+
throw new ExtensionInstallError(`failed to inspect installed versions for '${id}': ${message}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
for (const entry of entries) {
|
|
107
|
+
if (entry === activeVersion || !EXACT_VERSION_RE.test(entry)) continue;
|
|
108
|
+
const entryPath = join(extensionRoot, entry);
|
|
109
|
+
try {
|
|
110
|
+
if ((await stat(entryPath)).isDirectory()) {
|
|
111
|
+
await rm(entryPath, { recursive: true, force: true });
|
|
112
|
+
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
115
|
+
throw new ExtensionInstallError(`failed to retire inactive extension '${id}/${entry}': ${message}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function isMissingPathError(error: unknown): boolean {
|
|
121
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
122
|
+
}
|
|
123
|
+
|
|
81
124
|
export async function installLocalExtension(home: string, srcDir: string): Promise<InstalledRef> {
|
|
82
125
|
return installExtensionDirectory(home, srcDir);
|
|
83
126
|
}
|
|
@@ -95,19 +138,23 @@ export async function installNpmExtension(
|
|
|
95
138
|
if (dependencies.install !== undefined) {
|
|
96
139
|
await dependencies.install(normalized.npmSpec, temp);
|
|
97
140
|
} else {
|
|
98
|
-
|
|
141
|
+
const runNpm: NonNullable<NpmInstallDependencies["execFile"]> = dependencies.execFile ?? (async (file, args, options) => {
|
|
142
|
+
await execFile(file, args, options);
|
|
143
|
+
});
|
|
144
|
+
await runNpm(npmExecutableForPlatform(), [
|
|
99
145
|
"install",
|
|
100
|
-
"--prefix",
|
|
146
|
+
"--prefix", ".",
|
|
101
147
|
"--ignore-scripts",
|
|
102
148
|
"--no-save",
|
|
103
149
|
"--no-package-lock",
|
|
104
150
|
"--omit=dev",
|
|
105
151
|
"--registry=https://registry.npmjs.org",
|
|
106
152
|
"--", normalized.npmSpec,
|
|
107
|
-
], { timeout: 120_000, maxBuffer: 4 * 1024 * 1024 });
|
|
153
|
+
], { cwd: temp, timeout: 120_000, maxBuffer: 4 * 1024 * 1024, shell: npmShellForPlatform() });
|
|
108
154
|
}
|
|
109
|
-
} catch {
|
|
110
|
-
|
|
155
|
+
} catch (error) {
|
|
156
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
157
|
+
throw new ExtensionInstallError(`failed to download npm extension '${normalized.npmSpec}': ${message}`);
|
|
111
158
|
}
|
|
112
159
|
|
|
113
160
|
const packageDir = join(temp, "node_modules", ...normalized.packageName.split("/"));
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.3.
|
|
1
|
+
export const VERSION = "0.3.6";
|