@cannbot-ai/install-helper 0.0.2-beta.56 → 0.0.2-beta.58
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/bin/install-helper.js +2 -2
- package/dist/index.js +36 -20
- package/dist/index.js.map +1 -1
- package/dist/install.ps1 +4 -3
- package/package.json +6 -6
package/bin/install-helper.js
CHANGED
|
@@ -33,7 +33,7 @@ if (pkgName) {
|
|
|
33
33
|
const binaryPath = join(dirname(pkgPath), binaryName);
|
|
34
34
|
if (existsSync(binaryPath)) {
|
|
35
35
|
const child = spawn(binaryPath, args, { stdio: "inherit" });
|
|
36
|
-
child.on("exit", (code) => process.exit(code
|
|
36
|
+
child.on("exit", (code, signal) => { process.exit(code ?? (signal ? 1 : 0)); });
|
|
37
37
|
child.on("error", () => runJSFallback());
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
@@ -46,7 +46,7 @@ function runJSFallback() {
|
|
|
46
46
|
const jsPath = join(__dirname, "..", "dist", "index.js");
|
|
47
47
|
if (existsSync(jsPath)) {
|
|
48
48
|
const child = spawn(process.execPath, [jsPath, ...args], { stdio: "inherit" });
|
|
49
|
-
child.on("exit", (code) => process.exit(code
|
|
49
|
+
child.on("exit", (code, signal) => { process.exit(code ?? (signal ? 1 : 0)); });
|
|
50
50
|
child.on("error", () => {
|
|
51
51
|
console.error("install-helper: failed to run");
|
|
52
52
|
process.exit(1);
|
package/dist/index.js
CHANGED
|
@@ -2271,8 +2271,10 @@ function loadRepoUrl() {
|
|
|
2271
2271
|
var REPO_URL = loadRepoUrl();
|
|
2272
2272
|
var RepositoryManager = class {
|
|
2273
2273
|
repoPath;
|
|
2274
|
+
customPath;
|
|
2274
2275
|
constructor(customPath) {
|
|
2275
2276
|
this.repoPath = customPath;
|
|
2277
|
+
this.customPath = customPath;
|
|
2276
2278
|
}
|
|
2277
2279
|
async ensureRepo() {
|
|
2278
2280
|
if (this.repoPath && this.isValidRepo(this.repoPath)) {
|
|
@@ -2298,7 +2300,10 @@ var RepositoryManager = class {
|
|
|
2298
2300
|
}
|
|
2299
2301
|
async ensureRepoAndScan() {
|
|
2300
2302
|
const repoPath = await this.ensureRepo();
|
|
2301
|
-
|
|
2303
|
+
const isUserProvided = !!this.customPath || !!process.env.CANNBOT_REPO_PATH;
|
|
2304
|
+
if (!isUserProvided) {
|
|
2305
|
+
await this.updateRepo();
|
|
2306
|
+
}
|
|
2302
2307
|
mergeDynamicPlugins(repoPath);
|
|
2303
2308
|
const cache = readScanCache();
|
|
2304
2309
|
if (cache && cache.repoCommit === getCurrentCommit(repoPath)) {
|
|
@@ -2368,7 +2373,7 @@ function createRepositoryManager(customPath) {
|
|
|
2368
2373
|
|
|
2369
2374
|
// src/core/installer.ts
|
|
2370
2375
|
import { existsSync as existsSync13 } from "fs";
|
|
2371
|
-
import { join as join12 } from "path";
|
|
2376
|
+
import { join as join12, basename as basename2 } from "path";
|
|
2372
2377
|
import { execa as execa4, execaSync } from "execa";
|
|
2373
2378
|
|
|
2374
2379
|
// src/core/record.ts
|
|
@@ -2407,7 +2412,7 @@ function deleteRecord(pluginId) {
|
|
|
2407
2412
|
unlinkSync2(recordPath);
|
|
2408
2413
|
}
|
|
2409
2414
|
}
|
|
2410
|
-
function scanInstalledFiles(pluginId, displayName, tool, level, installPath, configRoot, manifest) {
|
|
2415
|
+
function scanInstalledFiles(pluginId, displayName, tool, level, installPath, configRoot, manifest, externalRepoNames) {
|
|
2411
2416
|
const files = [];
|
|
2412
2417
|
const directories = [];
|
|
2413
2418
|
if (manifest) {
|
|
@@ -2452,7 +2457,7 @@ function scanInstalledFiles(pluginId, displayName, tool, level, installPath, con
|
|
|
2452
2457
|
if (existsSync10(configFilePath)) {
|
|
2453
2458
|
files.push(configFilePath);
|
|
2454
2459
|
}
|
|
2455
|
-
const repoLinks = ["asc-devkit", "pypto", "tilelang-ascend", "cann-recipes-infer", "cann-samples"];
|
|
2460
|
+
const repoLinks = externalRepoNames && externalRepoNames.length > 0 ? externalRepoNames : ["asc-devkit", "pypto", "tilelang-ascend", "cann-recipes-infer", "cann-samples"];
|
|
2456
2461
|
for (const repoName of repoLinks) {
|
|
2457
2462
|
const repoLinkPath = join9(installPath, repoName);
|
|
2458
2463
|
if (isSymlink(repoLinkPath)) {
|
|
@@ -2702,7 +2707,7 @@ async function showRestorePrompt(backups) {
|
|
|
2702
2707
|
}
|
|
2703
2708
|
|
|
2704
2709
|
// src/core/plugin-installer.ts
|
|
2705
|
-
import { existsSync as existsSync12, mkdirSync as mkdirSync5, symlinkSync, unlinkSync as unlinkSync4, realpathSync, copyFileSync as copyFileSync2, cpSync, writeFileSync as writeFileSync3 } from "fs";
|
|
2710
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync5, symlinkSync, unlinkSync as unlinkSync4, realpathSync, copyFileSync as copyFileSync2, cpSync, writeFileSync as writeFileSync3, rmSync } from "fs";
|
|
2706
2711
|
import { join as join11, basename } from "path";
|
|
2707
2712
|
import { execa as execa3 } from "execa";
|
|
2708
2713
|
function installLink(source, target) {
|
|
@@ -2736,17 +2741,22 @@ function installConfigFile(pluginDir, configFile, tool, level, configRoot, insta
|
|
|
2736
2741
|
} else {
|
|
2737
2742
|
primaryTarget = join11(configRoot, agentsFileName);
|
|
2738
2743
|
}
|
|
2739
|
-
if (existsSync12(primaryTarget) || isSymlink(primaryTarget)) {
|
|
2740
|
-
unlinkSync4(primaryTarget);
|
|
2741
|
-
}
|
|
2742
2744
|
try {
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2745
|
+
const resolvedSource = realpathSync(sourcePath);
|
|
2746
|
+
if (existsSync12(primaryTarget) || isSymlink(primaryTarget)) {
|
|
2747
|
+
unlinkSync4(primaryTarget);
|
|
2748
|
+
}
|
|
2749
|
+
try {
|
|
2750
|
+
symlinkSync(resolvedSource, primaryTarget);
|
|
2751
|
+
} catch (e) {
|
|
2752
|
+
if (e.code === "EPERM") {
|
|
2753
|
+
copyFileSync2(sourcePath, primaryTarget);
|
|
2754
|
+
} else {
|
|
2755
|
+
throw e;
|
|
2756
|
+
}
|
|
2749
2757
|
}
|
|
2758
|
+
} catch (e) {
|
|
2759
|
+
logger.warn(` Failed to install config file: ${e.message}`);
|
|
2750
2760
|
}
|
|
2751
2761
|
if (isProjectLevel && primaryTarget !== join11(configRoot, agentsFileName)) {
|
|
2752
2762
|
if (configRootConfigLink === false) return;
|
|
@@ -2780,6 +2790,10 @@ async function installExternalRepos(repos, repoPath, configRoot, installPath, le
|
|
|
2780
2790
|
await execa3("git", args, { timeout: 12e4 });
|
|
2781
2791
|
} catch {
|
|
2782
2792
|
logger.warn(` git clone failed: ${repo.url}, clone manually: git clone ${repo.url} ${repo.dir}`);
|
|
2793
|
+
try {
|
|
2794
|
+
rmSync(targetDir, { recursive: true, force: true });
|
|
2795
|
+
} catch {
|
|
2796
|
+
}
|
|
2783
2797
|
continue;
|
|
2784
2798
|
}
|
|
2785
2799
|
}
|
|
@@ -3025,7 +3039,8 @@ async function installPlugin(opts) {
|
|
|
3025
3039
|
opts.level,
|
|
3026
3040
|
cwd,
|
|
3027
3041
|
configRoot,
|
|
3028
|
-
result.manifest
|
|
3042
|
+
result.manifest,
|
|
3043
|
+
plugin.externalRepos?.map((r) => basename2(r.dir))
|
|
3029
3044
|
);
|
|
3030
3045
|
if (backupInfo) {
|
|
3031
3046
|
record.backup = {
|
|
@@ -3110,7 +3125,8 @@ async function installPlugin(opts) {
|
|
|
3110
3125
|
opts.level,
|
|
3111
3126
|
cwd,
|
|
3112
3127
|
configRoot,
|
|
3113
|
-
manifest
|
|
3128
|
+
manifest,
|
|
3129
|
+
plugin.externalRepos?.map((r) => basename2(r.dir))
|
|
3114
3130
|
);
|
|
3115
3131
|
if (backupInfo) {
|
|
3116
3132
|
record.backup = {
|
|
@@ -4215,7 +4231,7 @@ async function installPlugins(pluginIds, tool, level, repoPath, installPath, yes
|
|
|
4215
4231
|
|
|
4216
4232
|
// src/commands/uninstall.ts
|
|
4217
4233
|
import { existsSync as existsSync17, unlinkSync as unlinkSync7, rmdirSync as rmdirSync2, readdirSync as readdirSync6 } from "fs";
|
|
4218
|
-
import { resolve, basename as
|
|
4234
|
+
import { resolve, basename as basename3, sep } from "path";
|
|
4219
4235
|
import chalk11 from "chalk";
|
|
4220
4236
|
async function uninstallCommand(names, options) {
|
|
4221
4237
|
const tool = options.tool ? validateTool(options.tool) : "opencode";
|
|
@@ -4258,7 +4274,7 @@ async function uninstallCommand(names, options) {
|
|
|
4258
4274
|
try {
|
|
4259
4275
|
if (existsSync17(filePath) || isSymlink(filePath)) {
|
|
4260
4276
|
unlinkSync7(filePath);
|
|
4261
|
-
const name =
|
|
4277
|
+
const name = basename3(filePath);
|
|
4262
4278
|
logger.step(` ${t("uninstall_remove_label")}: ${name}`);
|
|
4263
4279
|
removedFiles++;
|
|
4264
4280
|
}
|
|
@@ -4275,7 +4291,7 @@ async function uninstallCommand(names, options) {
|
|
|
4275
4291
|
const entries = readdirSync6(dirPath);
|
|
4276
4292
|
if (entries.length === 0) {
|
|
4277
4293
|
rmdirSync2(dirPath);
|
|
4278
|
-
const name =
|
|
4294
|
+
const name = basename3(dirPath);
|
|
4279
4295
|
logger.step(` ${t("uninstall_clean_empty_dir")}: ${name}/`);
|
|
4280
4296
|
removedDirs++;
|
|
4281
4297
|
}
|
|
@@ -4577,7 +4593,7 @@ function handleExit(error) {
|
|
|
4577
4593
|
}
|
|
4578
4594
|
process.on("SIGINT", () => {
|
|
4579
4595
|
console.log("\n" + t("init_cancelled"));
|
|
4580
|
-
process.exit(
|
|
4596
|
+
process.exit(130);
|
|
4581
4597
|
});
|
|
4582
4598
|
process.on("uncaughtException", (error) => {
|
|
4583
4599
|
handleExit(error);
|