diff --git a/package.json b/package.json index 07930a3..bfd9874 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "d3-node": "3.0.0", "fast-glob": "^3.3.1", "ini": "^4.0.0", + "js-yaml": "^4.1.0", "node-fetch": "^3.3.1", "ora": "6.1.2", "prompts": "^2.4.2", diff --git a/src/files/workspace.js b/src/files/workspace.js index 3ceb2ca..8551cea 100644 --- a/src/files/workspace.js +++ b/src/files/workspace.js @@ -1,39 +1,55 @@ const fs = require('fs'); const path = require('path'); const fg = require('fast-glob'); +const yaml = require('js-yaml'); const {loadManifest, getPackageSize} = require('.'); const loadWorkspace = async (startPath) => { const resolvedAppPath = path.resolve(startPath); const manifestPath = path.join(resolvedAppPath, 'package.json'); - if (fs.existsSync(manifestPath)) { + const pnpmConfigPath = path.join(resolvedAppPath, 'pnpm-workspace.yaml'); + let packagePaths; + + if (fs.existsSync(pnpmConfigPath)) { + const pnpmConfig = yaml.load(fs.readFileSync(pnpmConfigPath, 'utf8')); + + if (Array.isArray(pnpmConfig.packages)) { + packagePaths = pnpmConfig.packages; + } + } + + if (!packagePaths && fs.existsSync(manifestPath)) { const manifest = await loadManifest(resolvedAppPath); if (Array.isArray(manifest.workspaces)) { - const entries = await fg(manifest.workspaces, { - onlyDirectories: true, - unique: true, - cwd: resolvedAppPath, + packagePaths = manifest.workspaces; + } + } + + if (packagePaths) { + const entries = await fg(packagePaths, { + onlyDirectories: true, + unique: true, + cwd: resolvedAppPath, + }); + + const workspaceProjects = await entries.reduce(async (aggPromise, relativePath) => { + const agg = await aggPromise; + const projectPath = path.join(resolvedAppPath, relativePath); + const projectManifest = await loadManifest(projectPath); + agg.push({ + ...projectManifest, + relativePath, + size: await getPackageSize(projectPath), }); + return agg; + }, Promise.resolve([])); - const workspaceProjects = await entries.reduce(async (aggPromise, relativePath) => { - const agg = await aggPromise; - const projectPath = path.join(resolvedAppPath, relativePath); - const projectManifest = await loadManifest(projectPath); - agg.push({ - ...projectManifest, - relativePath, - size: await getPackageSize(projectPath), - }); - return agg; - }, Promise.resolve([])); - - return { - path: resolvedAppPath, - workspaceProjects, - }; - } + return { + path: resolvedAppPath, + workspaceProjects, + }; } if (resolvedAppPath !== '/') {