From 34509813d910495469b91c1d3cd50656c301ffd1 Mon Sep 17 00:00:00 2001 From: Jianqi Pan Date: Wed, 17 Jan 2024 18:03:45 +0900 Subject: [PATCH] feat(parse): check pnpm-workspace.yaml to fetch the package.json (#25) --- package.json | 2 + pnpm-lock.yaml | 154 ++++++++++++++++++++++-------------------- src/cli/parse-args.ts | 20 +++++- 3 files changed, 99 insertions(+), 77 deletions(-) diff --git a/package.json b/package.json index a835ec4..773d97c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0a2553a..93b4cd6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,69 +4,79 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false -dependencies: - '@jsdevtools/ez-spawn': - specifier: ^3.0.4 - version: 3.0.4 - c12: - specifier: ^1.5.1 - version: 1.5.1 - cac: - specifier: ^6.7.14 - version: 6.7.14 - fast-glob: - specifier: ^3.3.2 - version: 3.3.2 - prompts: - specifier: ^2.4.2 - version: 2.4.2 - semver: - specifier: ^7.5.4 - version: 7.5.4 - -devDependencies: - '@antfu/eslint-config': - specifier: ^2.4.3 - version: 2.4.3(@vue/compiler-sfc@3.3.11)(eslint@8.55.0)(typescript@5.3.3) - '@types/node': - specifier: ^20.10.4 - version: 20.10.4 - '@types/prompts': - specifier: ^2.4.9 - version: 2.4.9 - '@types/semver': - specifier: ^7.5.6 - version: 7.5.6 - detect-indent: - specifier: ^7.0.1 - version: 7.0.1 - detect-newline: - specifier: ^4.0.1 - version: 4.0.1 - eslint: - specifier: ^8.55.0 - version: 8.55.0 - esno: - specifier: ^4.0.0 - version: 4.0.0 - log-symbols: - specifier: ^6.0.0 - version: 6.0.0 - npm-check: - specifier: ^6.0.1 - version: 6.0.1 - picocolors: - specifier: ^1.0.0 - version: 1.0.0 - rimraf: - specifier: ^5.0.5 - version: 5.0.5 - tsup: - specifier: ^8.0.1 - version: 8.0.1(typescript@5.3.3) - typescript: - specifier: ^5.3.3 - version: 5.3.3 +importers: + + .: + dependencies: + '@jsdevtools/ez-spawn': + specifier: ^3.0.4 + version: 3.0.4 + c12: + specifier: ^1.5.1 + version: 1.5.1 + cac: + specifier: ^6.7.14 + version: 6.7.14 + fast-glob: + specifier: ^3.3.2 + version: 3.3.2 + js-yaml: + specifier: ^4.1.0 + version: 4.1.0 + prompts: + specifier: ^2.4.2 + version: 2.4.2 + semver: + specifier: ^7.5.4 + version: 7.5.4 + devDependencies: + '@antfu/eslint-config': + specifier: ^2.4.3 + version: 2.4.3(@vue/compiler-sfc@3.3.11)(eslint@8.55.0)(typescript@5.3.3) + '@types/js-yaml': + specifier: ^4.0.9 + version: 4.0.9 + '@types/node': + specifier: ^20.10.4 + version: 20.10.4 + '@types/prompts': + specifier: ^2.4.9 + version: 2.4.9 + '@types/semver': + specifier: ^7.5.6 + version: 7.5.6 + detect-indent: + specifier: ^7.0.1 + version: 7.0.1 + detect-newline: + specifier: ^4.0.1 + version: 4.0.1 + eslint: + specifier: ^8.55.0 + version: 8.55.0 + esno: + specifier: ^4.0.0 + version: 4.0.0 + log-symbols: + specifier: ^6.0.0 + version: 6.0.0 + npm-check: + specifier: ^6.0.1 + version: 6.0.1 + picocolors: + specifier: ^1.0.0 + version: 1.0.0 + rimraf: + specifier: ^5.0.5 + version: 5.0.5 + tsup: + specifier: ^8.0.1 + version: 8.0.1(typescript@5.3.3) + typescript: + specifier: ^5.3.3 + version: 5.3.3 + + test: {} packages: @@ -1002,6 +1012,10 @@ packages: defer-to-connect: 1.1.3 dev: true + /@types/js-yaml@4.0.9: + resolution: {integrity: sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==} + dev: true + /@types/json-schema@7.0.12: resolution: {integrity: sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==} dev: true @@ -1407,7 +1421,6 @@ packages: /argparse@2.0.1: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} - dev: true /array-differ@3.0.0: resolution: {integrity: sha512-THtfYS6KtME/yIAhKjZ2ul7XI96lQGHRputJQHO80LAWQnuGP4iCIN8vdMRboGbIEYBwU33q8Tch1os2+X0kMg==} @@ -1643,7 +1656,7 @@ packages: normalize-path: 3.0.0 readdirp: 3.6.0 optionalDependencies: - fsevents: 2.3.2 + fsevents: 2.3.3 /chownr@2.0.0: resolution: {integrity: sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==} @@ -2637,19 +2650,11 @@ packages: resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} dev: true - /fsevents@2.3.2: - resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} - engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} - os: [darwin] - requiresBuild: true - optional: true - /fsevents@2.3.3: resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] requiresBuild: true - dev: true optional: true /function-bind@1.1.1: @@ -3190,7 +3195,6 @@ packages: hasBin: true dependencies: argparse: 2.0.1 - dev: true /jsdoc-type-pratt-parser@4.0.0: resolution: {integrity: sha512-YtOli5Cmzy3q4dP26GraSOeAhqecewG04hoO8DY56CH4KJ9Fvv5qKWUCCo3HZob7esJQHCv6/+bnTy72xZZaVQ==} @@ -4254,7 +4258,7 @@ packages: '@rollup/rollup-win32-arm64-msvc': 4.7.0 '@rollup/rollup-win32-ia32-msvc': 4.7.0 '@rollup/rollup-win32-x64-msvc': 4.7.0 - fsevents: 2.3.2 + fsevents: 2.3.3 dev: true /run-async@2.4.1: diff --git a/src/cli/parse-args.ts b/src/cli/parse-args.ts index 444400f..389dea6 100644 --- a/src/cli/parse-args.ts +++ b/src/cli/parse-args.ts @@ -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 @@ -79,9 +81,23 @@ export async function parseArgs(): Promise { 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