Skip to content

Commit fb08e88

Browse files
committed
fix: Windows 下 cpSync 复制 skills 失败导致目标目录为空(#5
- 弃用 cpSync 改用手动递归 + realpathSync,规避 npx 缓存 junction 和 Node 16.7-18 cpSync 实验性 API 在 Windows 上的不稳定行为 - 复制后做计数校验:源 >0 而目标 =0 时报错并给出排查建议 - bump 1.1.6 → 1.1.7
1 parent c86b269 commit fb08e88

5 files changed

Lines changed: 36 additions & 15 deletions

File tree

.claude-plugin/marketplace.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"name": "superpowers-zh",
1111
"description": "AI 编程超能力中文增强版:20 个 skills(14 翻译 + 6 中国原创),支持 Claude Code / Hermes Agent / Cursor 等 16 款工具",
12-
"version": "1.1.6",
12+
"version": "1.1.7",
1313
"source": "./",
1414
"author": {
1515
"name": "jnMetaCode",

.claude-plugin/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "superpowers-zh",
33
"description": "AI 编程超能力中文增强版:20 个 skills(14 翻译 + 6 中国原创),支持 Claude Code / Hermes Agent / Cursor 等 16 款工具",
4-
"version": "1.1.6",
4+
"version": "1.1.7",
55
"author": {
66
"name": "jnMetaCode",
77
"url": "https://github.com/jnMetaCode"

.cursor-plugin/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "superpowers-zh",
33
"displayName": "Superpowers 中文版",
44
"description": "AI 编程超能力中文增强版:20 个 skills(14 翻译 + 6 中国原创),支持 Cursor / Claude Code / Hermes Agent 等 16 款工具",
5-
"version": "1.1.6",
5+
"version": "1.1.7",
66
"author": {
77
"name": "jnMetaCode",
88
"url": "https://github.com/jnMetaCode"

bin/superpowers-zh.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
#!/usr/bin/env node
22

3-
import { existsSync, mkdirSync, cpSync, readdirSync, readFileSync, writeFileSync, copyFileSync, statSync } from 'fs';
3+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, copyFileSync, lstatSync, realpathSync } from 'fs';
44
import { resolve, dirname, join } from 'path';
55
import { fileURLToPath } from 'url';
66

7-
// Node 14/16 兼容:cpSync 在 Node 16.7+ 才可用
7+
// 手动递归复制:跨 Node 版本和操作系统行为一致
8+
// 不使用 cpSync —— 在 Windows + npx 缓存(含 junction)+ Node 16.7-18 下不稳定
89
function copyDirSync(src, dest) {
9-
if (typeof cpSync === 'function') {
10-
cpSync(src, dest, { recursive: true });
11-
return;
12-
}
13-
// 手动递归复制(兼容 Node 14+)
10+
// 解析 junction/symlink,避免 Windows npx 缓存路径下 readdir 返回空
11+
let realSrc = src;
12+
try { realSrc = realpathSync(src); } catch {}
13+
1414
mkdirSync(dest, { recursive: true });
15-
for (const entry of readdirSync(src, { withFileTypes: true })) {
16-
const srcPath = join(src, entry.name);
15+
const entries = readdirSync(realSrc, { withFileTypes: true });
16+
for (const entry of entries) {
17+
const srcPath = join(realSrc, entry.name);
1718
const destPath = join(dest, entry.name);
18-
if (entry.isDirectory()) {
19+
let stat;
20+
try { stat = lstatSync(srcPath); } catch { continue; }
21+
if (stat.isSymbolicLink()) {
22+
// 取消引用后按实际类型处理
23+
try {
24+
const real = realpathSync(srcPath);
25+
const realStat = lstatSync(real);
26+
if (realStat.isDirectory()) copyDirSync(real, destPath);
27+
else copyFileSync(real, destPath);
28+
} catch {}
29+
} else if (stat.isDirectory()) {
1930
copyDirSync(srcPath, destPath);
20-
} else {
31+
} else if (stat.isFile()) {
2132
copyFileSync(srcPath, destPath);
2233
}
2334
}
@@ -340,9 +351,19 @@ function showHelp() {
340351

341352
function installForTarget(target) {
342353
const dest = resolve(PROJECT_DIR, target.dir);
354+
const srcCount = countDirs(SKILLS_SRC);
343355
mkdirSync(dest, { recursive: true });
344356
copyDirSync(SKILLS_SRC, dest);
345357
const count = countDirs(dest);
358+
if (srcCount > 0 && count === 0) {
359+
throw new Error(
360+
`复制 skills 失败:源目录 ${SKILLS_SRC}${srcCount} 个 skill,但目标 ${dest} 为空。` +
361+
`\n 这通常是 npx 缓存目录权限或路径问题。请尝试:\n` +
362+
` 1. 清理缓存后重试: npm cache clean --force && npx superpowers-zh\n` +
363+
` 2. 或全局安装: npm i -g superpowers-zh && superpowers-zh\n` +
364+
` 3. 或手动克隆复制: 见 https://github.com/jnMetaCode/superpowers-zh#方式二手动安装`
365+
);
366+
}
346367
console.log(` ✅ ${target.name}: ${count} 个 skills -> ${dest}`);
347368

348369
if (target.name === 'Trae') {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "superpowers-zh",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
44
"engines": {
55
"node": ">=14.0.0"
66
},

0 commit comments

Comments
 (0)