Skip to content

Commit 3450981

Browse files
authoredJan 17, 2024
feat(parse): check pnpm-workspace.yaml to fetch the package.json (#25)
1 parent 615001b commit 3450981

File tree

3 files changed

+99
-77
lines changed

3 files changed

+99
-77
lines changed
 

‎package.json

+2
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@
6161
"c12": "^1.5.1",
6262
"cac": "^6.7.14",
6363
"fast-glob": "^3.3.2",
64+
"js-yaml": "^4.1.0",
6465
"prompts": "^2.4.2",
6566
"semver": "^7.5.4"
6667
},
6768
"devDependencies": {
6869
"@antfu/eslint-config": "^2.4.3",
70+
"@types/js-yaml": "^4.0.9",
6971
"@types/node": "^20.10.4",
7072
"@types/prompts": "^2.4.9",
7173
"@types/semver": "^7.5.6",

‎pnpm-lock.yaml

+79-75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/cli/parse-args.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import type { VersionBumpOptions } from '../types/version-bump-options'
77
import { version } from '../../package.json'
88
import { bumpConfigDefaults, loadBumpConfig } from '../config'
99
import { ExitCode } from './exit-code'
10+
import node_fs from 'node:fs'
11+
import yaml from 'js-yaml'
1012

1113
/**
1214
* The parsed command-line arguments
@@ -79,9 +81,23 @@ export async function parseArgs(): Promise<ParsedArgs> {
7981
if (parsedArgs.options.recursive) {
8082
if (parsedArgs.options.files?.length)
8183
console.log(c.yellow('The --recursive option is ignored when files are specified'))
82-
83-
else
84+
else {
8485
parsedArgs.options.files = ['package.json', 'package-lock.json', 'packages/**/package.json']
86+
87+
// check if pnpm-workspace.yaml exists, if so, add all workspaces to files
88+
if (node_fs.existsSync('pnpm-workspace.yaml')){
89+
// read pnpm-workspace.yaml
90+
const pnpmWorkspace = node_fs.readFileSync('pnpm-workspace.yaml', 'utf8')
91+
// parse yaml
92+
const workspaces = yaml.load(pnpmWorkspace) as {packages: string[]}
93+
// append package.json to each workspace string
94+
const workspacesWithPackageJson = workspaces.packages.map((workspace) => workspace + '/package.json')
95+
// start with ! or already in files should be excluded
96+
const withoutExcludedWorkspaces = workspacesWithPackageJson.filter((workspace) => !workspace.startsWith('!') && !parsedArgs.options.files?.includes(workspace))
97+
// add to files
98+
parsedArgs.options.files = parsedArgs.options.files.concat(withoutExcludedWorkspaces)
99+
}
100+
}
85101
}
86102

87103
return parsedArgs

0 commit comments

Comments
 (0)