Skip to content

Commit cb00ba5

Browse files
committed
deps
1 parent 5dc42e5 commit cb00ba5

3 files changed

Lines changed: 2542 additions & 4989 deletions

File tree

packages/makage/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"bugs": {
3232
"url": "https://github.com/hyperweb-io/makage/issues"
3333
},
34+
"dependencies": {
35+
"glob": "^11.0.0",
36+
"yaml": "^2.7.0"
37+
},
3438
"scripts": {
3539
"copy": "cpy ../../LICENSE README.md package.json dist --flat",
3640
"clean": "rimraf dist",

packages/makage/src/commands/updateWorkspace.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import fs from 'node:fs/promises';
22
import path from 'node:path';
3+
import { glob } from 'glob';
4+
import { parse as parseYaml } from 'yaml';
35

46
const DEPENDENCY_TYPES = [
57
'dependencies',
@@ -8,36 +10,53 @@ const DEPENDENCY_TYPES = [
810
'optionalDependencies'
911
] as const;
1012

13+
interface PnpmWorkspace {
14+
packages?: string[];
15+
}
16+
1117
export async function runUpdateWorkspace(_args: string[]) {
12-
// Find all package.json files in the workspace
13-
const packagesDir = path.join(process.cwd(), 'packages');
18+
const cwd = process.cwd();
19+
const workspaceFile = path.join(cwd, 'pnpm-workspace.yaml');
1420

21+
// Read and parse pnpm-workspace.yaml
22+
let workspaceConfig: PnpmWorkspace;
1523
try {
16-
await fs.access(packagesDir);
24+
const content = await fs.readFile(workspaceFile, 'utf-8');
25+
workspaceConfig = parseYaml(content) as PnpmWorkspace;
1726
} catch {
18-
throw new Error('No "packages" directory found. Run this command from the monorepo root.');
27+
throw new Error('No "pnpm-workspace.yaml" found. Run this command from the monorepo root.');
1928
}
2029

21-
const dirs = await fs.readdir(packagesDir, { withFileTypes: true });
22-
const packageDirs = dirs
23-
.filter(dirent => dirent.isDirectory())
24-
.map(dirent => dirent.name);
25-
26-
const packageFiles: string[] = [];
27-
for (const dir of packageDirs) {
28-
const pkgPath = path.join(packagesDir, dir, 'package.json');
29-
try {
30-
await fs.access(pkgPath);
31-
packageFiles.push(path.join(dir, 'package.json'));
32-
} catch {
33-
// Skip if no package.json
34-
}
30+
const patterns = workspaceConfig.packages;
31+
if (!patterns || patterns.length === 0) {
32+
throw new Error('No package patterns found in pnpm-workspace.yaml');
33+
}
34+
35+
console.log(`[makage] Workspace patterns:`, patterns);
36+
37+
// Find all package.json files matching the workspace patterns
38+
const packageJsonPatterns = patterns.map(p => {
39+
// Convert workspace pattern to package.json glob
40+
// e.g., 'packages/*' -> 'packages/*/package.json'
41+
const normalized = p.replace(/\/?\*\*?$/, '');
42+
return `${normalized}/*/package.json`;
43+
});
44+
45+
const packageFiles = await glob(packageJsonPatterns, {
46+
cwd,
47+
absolute: false,
48+
ignore: ['**/node_modules/**']
49+
});
50+
51+
if (packageFiles.length === 0) {
52+
console.log('[makage] No packages found matching workspace patterns');
53+
return;
3554
}
3655

3756
// Build a set of internal package names
3857
const internalPackages = new Set<string>();
3958
for (const file of packageFiles) {
40-
const pkgPath = path.join(packagesDir, file);
59+
const pkgPath = path.join(cwd, file);
4160
const content = await fs.readFile(pkgPath, 'utf-8');
4261
const pkg = JSON.parse(content);
4362
if (pkg.name) {
@@ -50,7 +69,7 @@ export async function runUpdateWorkspace(_args: string[]) {
5069
// Update each package.json
5170
let totalUpdates = 0;
5271
for (const file of packageFiles) {
53-
const pkgPath = path.join(packagesDir, file);
72+
const pkgPath = path.join(cwd, file);
5473
const content = await fs.readFile(pkgPath, 'utf-8');
5574
const pkg = JSON.parse(content);
5675

0 commit comments

Comments
 (0)