Skip to content

Commit d741d4c

Browse files
committed
fix: workspaces
1 parent 85fe7d7 commit d741d4c

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

.claude/skills/add-extension/lib/analyzer.mjs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,36 @@ export function analyzeChanges(extensionPath, extensionFiles, projectPath) {
5757
templateMerges: []
5858
};
5959

60+
// Get existing workspaces from root package.json to avoid duplicates
61+
const existingWorkspaces = new Set();
62+
try {
63+
const rootPkgPath = path.join(projectPath, 'package.json');
64+
if (fs.existsSync(rootPkgPath)) {
65+
const rootPkg = JSON.parse(fs.readFileSync(rootPkgPath, 'utf8'));
66+
if (Array.isArray(rootPkg.workspaces)) {
67+
rootPkg.workspaces.forEach(w => existingWorkspaces.add(w));
68+
} else if (rootPkg.workspaces?.packages) {
69+
rootPkg.workspaces.packages.forEach(w => existingWorkspaces.add(w));
70+
}
71+
}
72+
} catch (error) {
73+
// If we can't read root package.json, continue anyway
74+
}
75+
6076
// Track which .template.mjs files have corresponding .args.mjs files
6177
const argsFiles = new Set(
6278
extensionFiles
6379
.filter(f => f.endsWith('.args.mjs'))
6480
.map(f => f.replace('.args.mjs', ''))
6581
);
6682

83+
// Track packages with package.json for workspace detection
84+
const extensionPackages = new Set(
85+
extensionFiles
86+
.filter(f => f.replace(/\\/g, '/').match(/^packages\/([^/]+)\/package\.json$/))
87+
.map(f => f.replace(/\\/g, '/').match(/^packages\/([^/]+)\//)[1])
88+
);
89+
6790
for (const file of extensionFiles) {
6891
// Handle .args.mjs files
6992
if (file.endsWith('.args.mjs')) {
@@ -155,21 +178,19 @@ export function analyzeChanges(extensionPath, extensionFiles, projectPath) {
155178
}
156179
}
157180

158-
// Detect new workspace packages
159-
const newPackageDirs = new Set();
160-
for (const file of extensionFiles) {
161-
// Normalize path separators for cross-platform compatibility
162-
const normalizedFile = file.replace(/\\/g, '/');
163-
const match = normalizedFile.match(/^packages\/([^/]+)\//);
164-
if (match) {
165-
const pkgName = match[1];
166-
const pkgDir = path.join(projectPath, 'packages', pkgName);
167-
if (!fs.existsSync(pkgDir)) {
168-
newPackageDirs.add(`packages/${pkgName}`);
169-
}
181+
// Detect new workspace packages that need registration
182+
// Add packages that: (1) have a package.json in extension, (2) aren't already registered
183+
for (const pkgName of extensionPackages) {
184+
const workspaceKey = `packages/${pkgName}`;
185+
186+
// Skip if already registered in root package.json
187+
if (existingWorkspaces.has(workspaceKey)) {
188+
continue;
170189
}
190+
191+
// Register as new workspace (even if directory exists but isn't registered)
192+
changes.newWorkspaces.push(workspaceKey);
171193
}
172-
changes.newWorkspaces = Array.from(newPackageDirs);
173194

174195
return changes;
175196
}

.claude/skills/add-extension/lib/templateMerger.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { CREATE_ETH_REPO } from './constants.mjs';
1515

1616
const __dirname = path.dirname(fileURLToPath(import.meta.url));
17-
const TEMP_DIR = path.join(__dirname, '.tmp');
17+
const TEMP_DIR = path.join(__dirname, '..', '.tmp');
1818
const UTILS_PATH = path.join(__dirname, 'create-eth-utils/utils.js');
1919

2020
/**

0 commit comments

Comments
 (0)