Skip to content

Add support for package.json5 format#191

Open
kokoichi206 wants to merge 5 commits intopnpm:masterfrom
kokoichi206:feat/support-package-json5
Open

Add support for package.json5 format#191
kokoichi206 wants to merge 5 commits intopnpm:masterfrom
kokoichi206:feat/support-package-json5

Conversation

@kokoichi206
Copy link
Copy Markdown

@kokoichi206 kokoichi206 commented Nov 14, 2025

Summary

This PR adds support for package.json5 format when reading the packageManager field, making this action consistent with pnpm's own support for JSON5.

Note:
I'm submitting this PR directly with implementation instead of opening an issue first, as the change is small and straightforward. I hope this approach is acceptable
- please let me know if you'd prefer to discuss this in an issue first!

Motivation

According to pnpm's documentation:

In addition to the traditional package.json format, pnpm also supports package.json5 (via json5) and package.yaml (via js-yaml).

This action already supports package.json and package.yaml, but not package.json5. This PR adds the missing support to be consistent with pnpm itself.

Changes

  1. Added json5 package as a dependency
  2. Updated parser logic to use JSON5.parse() instead of JSON.parse() for non-YAML files
  3. Updated README to document package.json5 support

Note:
Since JSON5 is a superset of JSON, the JSON5.parse() can parse both standard JSON and JSON5 formats.
This means existing package.json files continue to work without any changes
- this is a fully backward-compatible enhancement.

Comment on lines +67 to +68
? YAML.parse(content, { merge: true })
: JSON.parse(content)
: JSON5.parse(content)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should change the logic into the following:

  1. If the file name ends with .yaml, use YAML.
  2. If the file name ends with .json5, use JSON5.
  3. Otherwise, use JSON.

IIRC, pnpm only uses JSON5 for package.json5.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KSXGitHub
Thank you for the review.
Fixed in be2217e.

@KSXGitHub KSXGitHub requested a review from zkochan April 4, 2026 14:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for reading the packageManager field from package.json5, aligning this GitHub Action’s manifest parsing behavior with pnpm’s JSON5 support.

Changes:

  • Add json5 as a dependency and lock it in pnpm-lock.yaml.
  • Extend manifest parsing to handle .json5 files when reading packageManager/devEngines.
  • Update README to document package.json5 as a supported manifest format.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 4 comments.

File Description
src/install-pnpm/run.ts Adds JSON5 parsing branch when reading the workspace manifest
README.md Documents package.json5 support for package_json_file
package.json Adds json5 dependency
pnpm-lock.yaml Locks json5 dependency version and integrity
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 14 to 19
"@types/expand-tilde": "^2.0.2",
"@types/node": "^22.0.0",
"expand-tilde": "^2.0.2",
"json5": "^2.2.3",
"yaml": "^2.3.4",
"zod": "^3.22.4"
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dist/index.js is the action entrypoint (action.yml), and the repo's PR workflow rebuilds and checks that dist/index.js is committed. Since this change adds a new runtime dependency (json5) and modifies parsing logic, you need to run pnpm run build and commit the updated dist/index.js; otherwise CI will fail and the published action won't include the change.

Copilot uses AI. Check for mistakes.
Comment on lines 94 to 100
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
const manifest = packageJsonFile.endsWith(".yaml")
? parseYaml(content, { merge: true })
: packageJsonFile.endsWith(".json5")
? JSON5.parse(content)
: JSON.parse(content)
packageManager = manifest.packageManager
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says non-YAML manifests are parsed with JSON5.parse() (which would cover both .json and .json5), but the implementation only uses JSON5.parse() for .json5 and still uses JSON.parse() for .json. Either update the description or simplify the logic to use JSON5.parse() for all non-YAML files (since JSON5 is a superset of JSON).

Copilot uses AI. Check for mistakes.
Comment on lines 95 to 99
const manifest = packageJsonFile.endsWith(".yaml")
? parseYaml(content, { merge: true })
: packageJsonFile.endsWith(".json5")
? JSON5.parse(content)
: JSON.parse(content)
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested ternary for selecting the manifest parser is getting hard to read/extend with multiple formats. Consider refactoring to a small helper (e.g., based on path.extname(packageJsonFile) or a switch) so future additions like .yml don’t further degrade readability.

Copilot uses AI. Check for mistakes.
Comment on lines 53 to 56
### `package_json_file`

**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json`/[`package.yaml`](https://github.com/pnpm/pnpm/pull/1799) to read "packageManager" configuration.
**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json`/[`package.yaml`/`package.json5`](https://github.com/pnpm/pnpm/pull/1799) to read "packageManager" configuration.

Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README documents package.json5 support here, but action.yml’s package_json_file input description still only mentions package.json. To keep the Marketplace/action docs consistent, please update action.yml to mention package.yaml and package.json5 as supported formats too.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants