@whyshu/argent 0.1.4 → 0.1.5
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/argent.mjs +21 -2
- package/lib/index.mjs +6 -3
- package/package.json +1 -1
package/bin/argent.mjs
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* 公共参数:--dsh-home <dir> --profile <name> --repo <dir> --json --dry-run
|
|
11
11
|
*/
|
|
12
|
-
import { spawn } from 'node:child_process';
|
|
13
|
-
import { mkdirSync, writeFileSync, rmSync, existsSync, copyFileSync, chmodSync } from 'node:fs';
|
|
12
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
13
|
+
import { mkdirSync, writeFileSync, rmSync, existsSync, copyFileSync, chmodSync, readFileSync } from 'node:fs';
|
|
14
14
|
import { join, dirname } from 'node:path';
|
|
15
15
|
import { homedir } from 'node:os';
|
|
16
16
|
import {
|
|
@@ -45,6 +45,24 @@ function print(obj) {
|
|
|
45
45
|
else for (const [k, v] of Object.entries(obj)) console.log(`${k}: ${typeof v === 'object' ? JSON.stringify(v) : v}`);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
function ensureBundleDeps() {
|
|
49
|
+
const dir = join(opts.dshHome, 'profiles', opts.profile);
|
|
50
|
+
let pkg;
|
|
51
|
+
try { pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')); } catch { return; }
|
|
52
|
+
for (const [name, version] of Object.entries(pkg.dependencies || {})) {
|
|
53
|
+
const depDir = join(dir, 'node_modules', ...name.split('/'));
|
|
54
|
+
if (existsSync(depDir)) continue;
|
|
55
|
+
console.error(`→ 补装缺失 bundle ${name}@${version} …`);
|
|
56
|
+
const r = spawnSync('dsh', ['plugin', '--profile', opts.profile, 'add', `${name}@${version}`], {
|
|
57
|
+
cwd: dir, stdio: 'inherit', env: { ...process.env, DSH_HOME: opts.dshHome },
|
|
58
|
+
});
|
|
59
|
+
if (r.status !== 0) {
|
|
60
|
+
console.error(`❌ 补装失败:${name}(exit ${r.status})`);
|
|
61
|
+
process.exit(2);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
48
66
|
function ensureProfile({ install = true } = {}) {
|
|
49
67
|
const built = buildProfile({ dshHome: opts.dshHome, profile: opts.profile, repo: opts.repo, extraBundles: opts.extraBundles });
|
|
50
68
|
if (!built.ok) {
|
|
@@ -61,6 +79,7 @@ function ensureProfile({ install = true } = {}) {
|
|
|
61
79
|
}
|
|
62
80
|
console.error('✅ profile 依赖装配完成');
|
|
63
81
|
}
|
|
82
|
+
if (install && !has('--no-install')) ensureBundleDeps();
|
|
64
83
|
return built;
|
|
65
84
|
}
|
|
66
85
|
|
package/lib/index.mjs
CHANGED
|
@@ -112,13 +112,16 @@ export function buildProfile({ dshHome = dshHomeOf(), profile = PROFILE_NAME, re
|
|
|
112
112
|
dsh: { profile: { bundles } },
|
|
113
113
|
};
|
|
114
114
|
writeFileSync(join(dir, 'package.json'), JSON.stringify(pkg, null, 2) + '\n');
|
|
115
|
-
const
|
|
115
|
+
const patchLines = [
|
|
116
116
|
'# @whyshu/argent 生成(幂等;手工改动会在此文件重生成时被覆盖)',
|
|
117
117
|
'- id: agent-preset-registry',
|
|
118
118
|
' config:',
|
|
119
119
|
` default: ${DEFAULT_PRESET}`,
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
];
|
|
121
|
+
if (bundles.includes('@linxin666/dsh-client-ui-task-board')) {
|
|
122
|
+
patchLines.push('- insert:', ' - id: ui-task-board', " name: '@linxin666/dsh-client-ui-task-board'");
|
|
123
|
+
}
|
|
124
|
+
const patch = patchLines.join('\n') + '\n';
|
|
122
125
|
writeFileSync(join(dir, 'cordis.patch.yml'), patch);
|
|
123
126
|
// pnpm 配置必须与现有 web profile 同口径:否则 pnpm 会尝试从 registry 自动装 peer(含未发布版本)⇒ 安装失败
|
|
124
127
|
writeFileSync(join(dir, 'pnpm-workspace.yaml'), 'packages:\n - .\nnodeLinker: hoisted\nautoInstallPeers: false\nallowBuilds:\n protobufjs: true\n');
|