Skip to content

Commit

Permalink
feat(parse): check pnpm-workspace.yaml to fetch the package.json (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannchie committed Jan 17, 2024
1 parent 615001b commit 3450981
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 77 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -61,11 +61,13 @@
"c12": "^1.5.1",
"cac": "^6.7.14",
"fast-glob": "^3.3.2",
"js-yaml": "^4.1.0",
"prompts": "^2.4.2",
"semver": "^7.5.4"
},
"devDependencies": {
"@antfu/eslint-config": "^2.4.3",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.10.4",
"@types/prompts": "^2.4.9",
"@types/semver": "^7.5.6",
Expand Down
154 changes: 79 additions & 75 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions src/cli/parse-args.ts
Expand Up @@ -7,6 +7,8 @@ import type { VersionBumpOptions } from '../types/version-bump-options'
import { version } from '../../package.json'
import { bumpConfigDefaults, loadBumpConfig } from '../config'
import { ExitCode } from './exit-code'
import node_fs from 'node:fs'
import yaml from 'js-yaml'

/**
* The parsed command-line arguments
Expand Down Expand Up @@ -79,9 +81,23 @@ export async function parseArgs(): Promise<ParsedArgs> {
if (parsedArgs.options.recursive) {
if (parsedArgs.options.files?.length)
console.log(c.yellow('The --recursive option is ignored when files are specified'))

else
else {
parsedArgs.options.files = ['package.json', 'package-lock.json', 'packages/**/package.json']

// check if pnpm-workspace.yaml exists, if so, add all workspaces to files
if (node_fs.existsSync('pnpm-workspace.yaml')){
// read pnpm-workspace.yaml
const pnpmWorkspace = node_fs.readFileSync('pnpm-workspace.yaml', 'utf8')
// parse yaml
const workspaces = yaml.load(pnpmWorkspace) as {packages: string[]}
// append package.json to each workspace string
const workspacesWithPackageJson = workspaces.packages.map((workspace) => workspace + '/package.json')
// start with ! or already in files should be excluded
const withoutExcludedWorkspaces = workspacesWithPackageJson.filter((workspace) => !workspace.startsWith('!') && !parsedArgs.options.files?.includes(workspace))
// add to files
parsedArgs.options.files = parsedArgs.options.files.concat(withoutExcludedWorkspaces)
}
}
}

return parsedArgs
Expand Down

0 comments on commit 3450981

Please sign in to comment.