json5-manifest-sync 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +58 -27
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.3.2] - 2026-11-09
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Clarified the README's explanation and example for documenting npm package manifests with `package.json5`.
|
|
10
|
+
|
|
5
11
|
## [0.3.0] - 2026-11-02
|
|
6
12
|
|
|
7
13
|
### Added
|
package/README.md
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
# json5-manifest-sync
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Add comments to your npm package manifest in `package.json5`, then sync it with the standard `package.json` expected by npm and other tools. Choose either file as the source of truth for manifest values; `package.json` always remains valid strict JSON.
|
|
4
|
+
|
|
5
|
+
For example, document dependencies in `package.json5` and generate `package.json` from it:
|
|
6
|
+
|
|
7
|
+
<!-- prettier-ignore -->
|
|
8
|
+
```json5
|
|
9
|
+
{
|
|
10
|
+
"dependencies": {
|
|
11
|
+
// Keep JSON5 parsing available to the CLI.
|
|
12
|
+
"json5": "^2.2.3",
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx json5-manifest-sync --source=package.json5
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The tool can also work in the other direction: by default, it updates `package.json5` from `package.json`, preserving mapped `//` comments where possible.
|
|
4
22
|
|
|
5
23
|
pnpm supports `package.json5` natively, but other tools in a project’s scripts, CI/CD, publishing, or deployment workflows may still expect `package.json`. When both files exist, pnpm prefers `package.json`; it reads `package.json5` natively when `package.json` is absent. This tool bridges mixed toolchains by keeping both manifests synchronized in either direction.
|
|
6
24
|
|
|
7
25
|
## Quick Start
|
|
8
26
|
|
|
27
|
+
Install with the package manager your project already uses:
|
|
28
|
+
|
|
9
29
|
```bash
|
|
10
30
|
npm install --save-dev json5-manifest-sync
|
|
11
31
|
```
|
|
12
32
|
|
|
33
|
+
```bash
|
|
34
|
+
pnpm add --save-dev json5-manifest-sync
|
|
35
|
+
```
|
|
36
|
+
|
|
13
37
|
Add a script in your project's `package.json`:
|
|
14
38
|
|
|
15
39
|
```json
|
|
@@ -39,13 +63,22 @@ This is also why the long-running Yarn Berry discussion about comment-friendly m
|
|
|
39
63
|
> [!NOTE]
|
|
40
64
|
> pnpm's native `package.json5` support is useful when pnpm controls the workflow, but it does not make `package.json5` universally recognized across npm, CI/CD, deployment, release, and other JavaScript tooling. This project keeps `package.json` available for compatibility while providing a documented companion file.
|
|
41
65
|
|
|
42
|
-
The source of truth is configurable. By default:
|
|
66
|
+
The source of truth for this tool is configurable. By default:
|
|
43
67
|
|
|
44
68
|
- `package.json` is authoritative for manifest values.
|
|
45
69
|
- `package.json5` is authoritative for comments; values are synchronized from `package.json` while mapped `//` comments are preserved where possible.
|
|
46
70
|
|
|
47
71
|
Alternatively, make `package.json5` authoritative for values and generate a strict `package.json` for tools that need it. In this direction, comments remain in `package.json5`; they are not copied to `package.json`.
|
|
48
72
|
|
|
73
|
+
**pnpm consideration:** pnpm has no setting or environment variable to prefer `package.json5` when both files exist. The `--source` option and `JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH` variable configure only this tool; they do not change pnpm's selection. When the two manifests are synchronized, this is straightforward: pnpm reads `package.json`, whose values match `package.json5`. If JSON5 is your source of truth, run this tool with `--source=package.json5` before pnpm operations that need the latest values. Pnpm commands may update `package.json`, so reconcile those changes into `package.json5` before syncing from JSON5 again, or they may be overwritten. Removing `package.json` lets pnpm read `package.json5` directly, but may break Node, npm, or other tools that require `package.json`.
|
|
74
|
+
|
|
75
|
+
For CI or other automated workflows where `package.json5` is authoritative, run the sync as a separate step before pnpm reads the manifest. A lifecycle hook such as `preinstall` may run too late, after pnpm has already selected `package.json`:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm dlx json5-manifest-sync --source=package.json5
|
|
79
|
+
pnpm install
|
|
80
|
+
```
|
|
81
|
+
|
|
49
82
|
## What it does
|
|
50
83
|
|
|
51
84
|
- Finds `package.json` files recursively (excluding `node_modules`)
|
|
@@ -62,28 +95,43 @@ Alternatively, make `package.json5` authoritative for values and generate a stri
|
|
|
62
95
|
|
|
63
96
|
- Per-item comment preservation is most reliable for arrays of strings.
|
|
64
97
|
- Arrays of objects or numbers still serialize correctly, but item-level comments may be dropped.
|
|
65
|
-
- Use `--blank-comments=preserve` to keep existing blank `//` lines without adding new ones.
|
|
66
|
-
- Use `--blank-comments=fill` to add blank `//` placeholders where comments are omitted.
|
|
67
|
-
- Use `--blank-comments=remove` to strip blank `//` lines from the output.
|
|
68
98
|
|
|
69
99
|
Repository: https://github.com/BBaysinger/json5-manifest-sync
|
|
70
100
|
|
|
101
|
+
Package: https://www.npmjs.com/package/json5-manifest-sync
|
|
102
|
+
|
|
71
103
|
## Author
|
|
72
104
|
|
|
73
105
|
Bradley Baysinger ([@BBaysinger](https://github.com/BBaysinger))
|
|
74
106
|
|
|
75
|
-
## Install from npm (recommended)
|
|
107
|
+
## Install from the npm registry (recommended)
|
|
108
|
+
|
|
109
|
+
Use the package manager already used by your project so its lockfile stays consistent.
|
|
110
|
+
|
|
111
|
+
With npm:
|
|
76
112
|
|
|
77
113
|
```bash
|
|
78
114
|
npm install --save-dev json5-manifest-sync
|
|
79
115
|
```
|
|
80
116
|
|
|
117
|
+
With pnpm:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pnpm add --save-dev json5-manifest-sync
|
|
121
|
+
```
|
|
122
|
+
|
|
81
123
|
Global install (optional):
|
|
82
124
|
|
|
83
125
|
```bash
|
|
84
126
|
npm install -g json5-manifest-sync
|
|
85
127
|
```
|
|
86
128
|
|
|
129
|
+
Or with pnpm:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
pnpm add --global json5-manifest-sync
|
|
133
|
+
```
|
|
134
|
+
|
|
87
135
|
## Install from GitHub (alternative)
|
|
88
136
|
|
|
89
137
|
Use this if you want an unreleased branch or tag:
|
|
@@ -110,27 +158,6 @@ Run it:
|
|
|
110
158
|
npm run sync:json5
|
|
111
159
|
```
|
|
112
160
|
|
|
113
|
-
## Generated `package.json5` example
|
|
114
|
-
|
|
115
|
-
Illustrative output (trimmed):
|
|
116
|
-
|
|
117
|
-
<!-- prettier-ignore -->
|
|
118
|
-
```json5
|
|
119
|
-
{
|
|
120
|
-
// Package name used by npm and consumers.
|
|
121
|
-
"name": "consumer-app",
|
|
122
|
-
// Release version (keep in sync with git tags).
|
|
123
|
-
"version": "1.2.3",
|
|
124
|
-
// Development and release scripts.
|
|
125
|
-
"scripts": {
|
|
126
|
-
// Compile TypeScript to dist/.
|
|
127
|
-
"build": "tsc -p tsconfig.json",
|
|
128
|
-
},
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
For the current full output style, see this repo's live example: [`package.json5`](./package.json5).
|
|
133
|
-
|
|
134
161
|
### Options
|
|
135
162
|
|
|
136
163
|
By default, the tool runs with `--blank-comments=preserve`.
|
|
@@ -166,6 +193,10 @@ Choose a blank-comment mode with one of the following:
|
|
|
166
193
|
|
|
167
194
|
To warn after sync when blank `//` placeholders remain, add `--warn-blank-comments`. That warning applies to `preserve` and `fill`; `remove` strips those lines.
|
|
168
195
|
|
|
196
|
+
### Pre-commit synchronization
|
|
197
|
+
|
|
198
|
+
To keep both manifests aligned in each commit, run `json5-manifest-sync` from a Git pre-commit hook after manifest changes. It uses `JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH` or the `--source` option to choose the authoritative file. Make sure the hook stages the generated counterpart as well; if you use partial staging, stage only the file generated by the sync rather than blindly adding both manifests.
|
|
199
|
+
|
|
169
200
|
### Formatting note
|
|
170
201
|
|
|
171
202
|
Recommended: exclude `package.json5` from Prettier (for example via `.prettierignore`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json5-manifest-sync",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Sync package.json and package.json5 manifests in either direction, preserving JSON5 comments where possible.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bradley Baysinger",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"dotenv": "^18.0.10",
|
|
50
|
-
"glob": "^
|
|
51
|
-
"ignore": "^7.0.
|
|
50
|
+
"glob": "^14.0.4",
|
|
51
|
+
"ignore": "^7.0.14",
|
|
52
52
|
"json5": "^2.2.3"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@types/node": "^
|
|
56
|
-
"prettier": "^3.
|
|
57
|
-
"typescript": "^
|
|
58
|
-
"vitest": "^
|
|
55
|
+
"@types/node": "^26.6.6",
|
|
56
|
+
"prettier": "^3.9.10",
|
|
57
|
+
"typescript": "^7.0.2",
|
|
58
|
+
"vitest": "^5.1.0"
|
|
59
59
|
}
|
|
60
60
|
}
|