json5-manifest-sync 0.2.2 → 0.3.1
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 +13 -0
- package/README.md +74 -16
- package/dist/json5-manifest-sync.d.ts +8 -6
- package/dist/json5-manifest-sync.js +97 -28
- package/package.json +10 -8
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.3.0] - 2026-11-02
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Added bidirectional synchronization with configurable `package.json` or `package.json5` source of truth.
|
|
10
|
+
- Added `JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH` support in `.env` and the process environment.
|
|
11
|
+
- Added JSON5-only project discovery and generation of a strict-JSON `package.json`.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Report invalid source-of-truth environment values with a descriptive error.
|
|
16
|
+
- Skip writes when synchronization produces unchanged content.
|
|
17
|
+
|
|
5
18
|
## [0.2.2] - 2026-05-13
|
|
6
19
|
|
|
7
20
|
### Changed
|
package/README.md
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
# json5-manifest-sync
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Keep `package.json` and a documented `package.json5` in sync. Choose either file as the source of truth: maintain comments in `package.json5` and generate strict JSON for tools that require it, or update the JSON5 companion from `package.json`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
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
6
|
|
|
7
7
|
## Quick Start
|
|
8
8
|
|
|
9
|
+
Install with the package manager your project already uses:
|
|
10
|
+
|
|
9
11
|
```bash
|
|
10
12
|
npm install --save-dev json5-manifest-sync
|
|
11
13
|
```
|
|
12
14
|
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add --save-dev json5-manifest-sync
|
|
17
|
+
```
|
|
18
|
+
|
|
13
19
|
Add a script in your project's `package.json`:
|
|
14
20
|
|
|
15
21
|
```json
|
|
@@ -32,36 +38,45 @@ npm run sync:json5
|
|
|
32
38
|
|
|
33
39
|
`package.json` is arguably the most important file in most JavaScript/TypeScript repositories. It drives install behavior, scripts, dependency policy, packaging, and release workflows—so it deserves clear inline documentation.
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
Some tooling does not treat `package.json5` as a package manifest source. While pnpm supports it in supported workflows, npm, Node-based tooling, legacy CI/CD environments, deployment systems, release tooling, and other ecosystem integrations may still require the conventional `package.json` filename. A companion `package.json5` approach provides documented manifests without giving up broad compatibility.
|
|
36
42
|
|
|
37
43
|
This is also why the long-running Yarn Berry discussion about comment-friendly manifests is relevant here: [yarnpkg/berry#241](https://github.com/yarnpkg/berry/issues/241) describes the same underlying need, along with the ecosystem compatibility constraints that make a companion `package.json5` approach useful today.
|
|
38
44
|
|
|
39
|
-
There is also a long-running Stack Overflow discussion around the same practical question from the npm side: [How do I add comments to package.json for npm install?](https://stackoverflow.com/questions/14221579/how-do-i-add-comments-to-package-json-for-npm-install/79939348#79939348). It is a useful community reference for why teams keep reaching for comment-friendly manifest workflows even though `package.json` itself must remain strict JSON.
|
|
40
|
-
|
|
41
45
|
> [!NOTE]
|
|
42
|
-
>
|
|
46
|
+
> 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.
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
The source of truth for this tool is configurable. By default:
|
|
45
49
|
|
|
46
|
-
- `package.json`
|
|
47
|
-
- `package.json5`
|
|
50
|
+
- `package.json` is authoritative for manifest values.
|
|
51
|
+
- `package.json5` is authoritative for comments; values are synchronized from `package.json` while mapped `//` comments are preserved where possible.
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
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`.
|
|
54
|
+
|
|
55
|
+
**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`.
|
|
56
|
+
|
|
57
|
+
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`:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pnpm dlx json5-manifest-sync --source=package.json5
|
|
61
|
+
pnpm install
|
|
62
|
+
```
|
|
51
63
|
|
|
52
64
|
## What it does
|
|
53
65
|
|
|
54
66
|
- Finds `package.json` files recursively (excluding `node_modules`)
|
|
55
67
|
- Skips paths ignored by your root `.gitignore`
|
|
56
|
-
-
|
|
68
|
+
- Synchronizes each matching `package.json` / `package.json5` pair in either direction
|
|
69
|
+
- By default, rewrites `package.json5` values from `package.json` (including `version`, scripts, dependencies, and other manifest fields)
|
|
70
|
+
- With `--source=package.json5`, parses JSON5 and creates or updates a strict-JSON `package.json`
|
|
57
71
|
- Preserves/migrates mapped `//` comments for keys and supported array items
|
|
58
|
-
- Supports three blank-comment modes: `preserve
|
|
72
|
+
- Supports three blank-comment modes: `preserve`, `fill`, and `remove`
|
|
59
73
|
- Writes stable JSON5 formatting with trailing commas for cleaner diffs
|
|
74
|
+
- Keeps a documented `package.json5` synchronized while retaining `package.json` compatibility for npm, legacy CI/CD, and other tooling that requires it
|
|
60
75
|
|
|
61
76
|
### Current limitations
|
|
62
77
|
|
|
63
78
|
- Per-item comment preservation is most reliable for arrays of strings.
|
|
64
|
-
- Arrays of objects or numbers still serialize correctly, but item-level comments
|
|
79
|
+
- Arrays of objects or numbers still serialize correctly, but item-level comments may be dropped.
|
|
65
80
|
|
|
66
81
|
Repository: https://github.com/BBaysinger/json5-manifest-sync
|
|
67
82
|
|
|
@@ -71,18 +86,34 @@ Package: https://www.npmjs.com/package/json5-manifest-sync
|
|
|
71
86
|
|
|
72
87
|
Bradley Baysinger ([@BBaysinger](https://github.com/BBaysinger))
|
|
73
88
|
|
|
74
|
-
## Install from npm (recommended)
|
|
89
|
+
## Install from the npm registry (recommended)
|
|
90
|
+
|
|
91
|
+
Use the package manager already used by your project so its lockfile stays consistent.
|
|
92
|
+
|
|
93
|
+
With npm:
|
|
75
94
|
|
|
76
95
|
```bash
|
|
77
96
|
npm install --save-dev json5-manifest-sync
|
|
78
97
|
```
|
|
79
98
|
|
|
99
|
+
With pnpm:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
pnpm add --save-dev json5-manifest-sync
|
|
103
|
+
```
|
|
104
|
+
|
|
80
105
|
Global install (optional):
|
|
81
106
|
|
|
82
107
|
```bash
|
|
83
108
|
npm install -g json5-manifest-sync
|
|
84
109
|
```
|
|
85
110
|
|
|
111
|
+
Or with pnpm:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pnpm add --global json5-manifest-sync
|
|
115
|
+
```
|
|
116
|
+
|
|
86
117
|
## Install from GitHub (alternative)
|
|
87
118
|
|
|
88
119
|
Use this if you want an unreleased branch or tag:
|
|
@@ -134,6 +165,29 @@ For the current full output style, see this repo's live example: [`package.json5
|
|
|
134
165
|
|
|
135
166
|
By default, the tool runs with `--blank-comments=preserve`.
|
|
136
167
|
|
|
168
|
+
Choose which manifest is authoritative with:
|
|
169
|
+
|
|
170
|
+
- `--source=package.json` (default): update `package.json5` from `package.json`, preserving mapped JSON5 comments.
|
|
171
|
+
- `--source=package.json5`: create or update `package.json` from `package.json5`; comments remain only in the JSON5 file.
|
|
172
|
+
|
|
173
|
+
To retain the choice across runs, set `JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH` in the project-root `.env` file:
|
|
174
|
+
|
|
175
|
+
```dotenv
|
|
176
|
+
JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH=package.json5
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
An existing shell environment variable takes precedence over `.env`, and `--source=...` takes precedence over both. If the setting is omitted, the default remains `package.json`.
|
|
180
|
+
|
|
181
|
+
For a project that has only `package.json5`, run the tool through `npx` (or install it globally) to generate the initial `package.json`—no pnpm installation is needed:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
npx --yes --package=json5-manifest-sync json5-manifest-sync --source=package.json5
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
You cannot use a local `npm run` script or install this tool as a local dev dependency until `package.json` exists. Once generated, npm and other strict-JSON tools can use it. Note that commands such as `npm install` update `package.json`; reconcile those changes back into `package.json5` with the default `--source=package.json` mode before regenerating JSON from the JSON5 source, or those updates could be overwritten.
|
|
188
|
+
|
|
189
|
+
Because pnpm prefers `package.json` when both files exist, it will read the generated JSON copy in that setup; it reads `package.json5` directly only when `package.json` is absent.
|
|
190
|
+
|
|
137
191
|
Choose a blank-comment mode with one of the following:
|
|
138
192
|
|
|
139
193
|
- `--blank-comments=preserve`
|
|
@@ -142,6 +196,10 @@ Choose a blank-comment mode with one of the following:
|
|
|
142
196
|
|
|
143
197
|
To warn after sync when blank `//` placeholders remain, add `--warn-blank-comments`. That warning applies to `preserve` and `fill`; `remove` strips those lines.
|
|
144
198
|
|
|
199
|
+
### Pre-commit synchronization
|
|
200
|
+
|
|
201
|
+
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.
|
|
202
|
+
|
|
145
203
|
### Formatting note
|
|
146
204
|
|
|
147
205
|
Recommended: exclude `package.json5` from Prettier (for example via `.prettierignore`).
|
|
@@ -166,7 +224,7 @@ Example prompt:
|
|
|
166
224
|
```json
|
|
167
225
|
{
|
|
168
226
|
"dependencies": {
|
|
169
|
-
"json5-manifest-sync": "^0.
|
|
227
|
+
"json5-manifest-sync": "^0.3.0"
|
|
170
228
|
}
|
|
171
229
|
}
|
|
172
230
|
```
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* JSON5 Package Synchronization Tool
|
|
4
4
|
*
|
|
5
|
-
* Synchronizes package.
|
|
5
|
+
* Synchronizes paired package.json and package.json5 manifests in either direction.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* By default, package.json is the source of manifest values and package.json5 is
|
|
8
|
+
* rewritten with stable formatting and with *some* `//` comments preserved/migrated.
|
|
9
|
+
* The CLI can instead use package.json5 as the source and generate package.json.
|
|
10
10
|
*
|
|
11
11
|
* Important: this script does NOT attempt to preserve arbitrary formatting (blank
|
|
12
12
|
* lines, exact indentation, key ordering, etc.). It regenerates the JSON5 structure
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
* objects/numbers will serialize correctly but per-item comment preservation is limited.
|
|
28
28
|
*/
|
|
29
29
|
export type BlankCommentMode = "preserve" | "fill" | "remove";
|
|
30
|
+
export declare const manifestSourceOptions: readonly ["package.json", "package.json5"];
|
|
31
|
+
export type ManifestSource = (typeof manifestSourceOptions)[number];
|
|
30
32
|
export type SyncOptions = {
|
|
31
33
|
/**
|
|
32
34
|
* Controls how blank comment lines (`//`) are handled.
|
|
@@ -59,8 +61,8 @@ export declare function syncJson5(raw: string, source: Record<string, unknown>,
|
|
|
59
61
|
/**
|
|
60
62
|
* CLI entrypoint.
|
|
61
63
|
*
|
|
62
|
-
* Scans from the current working directory and synchronizes
|
|
63
|
-
* `package.json5` files
|
|
64
|
+
* Scans from the current working directory and synchronizes paired
|
|
65
|
+
* `package.json` and `package.json5` files in the selected direction.
|
|
64
66
|
*
|
|
65
67
|
* @param args - Optional CLI arguments (defaults to process argv slice)
|
|
66
68
|
*/
|
|
@@ -2,8 +2,25 @@
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
+
import JSON5 from "json5";
|
|
6
|
+
import { parse as parseDotenv } from "dotenv";
|
|
5
7
|
import { sync as globSync } from "glob";
|
|
6
8
|
import ignore from "ignore";
|
|
9
|
+
export const manifestSourceOptions = ["package.json", "package.json5"];
|
|
10
|
+
function isManifestSource(value) {
|
|
11
|
+
return manifestSourceOptions.includes(value);
|
|
12
|
+
}
|
|
13
|
+
function describeManifestSources() {
|
|
14
|
+
return manifestSourceOptions.map((source) => `"${source}"`).join(" or ");
|
|
15
|
+
}
|
|
16
|
+
function writeFileIfChanged(filePath, content) {
|
|
17
|
+
if (fs.existsSync(filePath) &&
|
|
18
|
+
fs.readFileSync(filePath, "utf8") === content) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
fs.writeFileSync(filePath, content);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
7
24
|
function isBlankCommentLine(line) {
|
|
8
25
|
return /^\s*\/\/\s*$/.test(line);
|
|
9
26
|
}
|
|
@@ -328,16 +345,16 @@ export function syncJson5(raw, source, options = { blankCommentMode: "preserve"
|
|
|
328
345
|
}
|
|
329
346
|
// 🔁 Main Execution Runner
|
|
330
347
|
//
|
|
331
|
-
// This section handles
|
|
332
|
-
// - Finds
|
|
333
|
-
// - Checks for
|
|
348
|
+
// This section handles source-specific file discovery and processing:
|
|
349
|
+
// - Finds the selected manifest type in the project (excluding node_modules)
|
|
350
|
+
// - Checks for the counterpart when package.json is the source
|
|
334
351
|
// - Applies root .gitignore rules to skip excluded files
|
|
335
352
|
// - Performs synchronization for each valid pair
|
|
336
353
|
/**
|
|
337
354
|
* CLI entrypoint.
|
|
338
355
|
*
|
|
339
|
-
* Scans from the current working directory and synchronizes
|
|
340
|
-
* `package.json5` files
|
|
356
|
+
* Scans from the current working directory and synchronizes paired
|
|
357
|
+
* `package.json` and `package.json5` files in the selected direction.
|
|
341
358
|
*
|
|
342
359
|
* @param args - Optional CLI arguments (defaults to process argv slice)
|
|
343
360
|
*/
|
|
@@ -349,15 +366,31 @@ export function runCli(args = process.argv.slice(2)) {
|
|
|
349
366
|
if (fs.existsSync(gitignorePath)) {
|
|
350
367
|
ig.add(fs.readFileSync(gitignorePath, "utf8"));
|
|
351
368
|
}
|
|
352
|
-
// Find all package.json files recursively, excluding node_modules
|
|
353
|
-
const packageJsonPaths = globSync("**/package.json", {
|
|
354
|
-
cwd: rootDir,
|
|
355
|
-
ignore: ["**/node_modules/**"],
|
|
356
|
-
absolute: true,
|
|
357
|
-
});
|
|
358
369
|
// Parse CLI flags for options
|
|
359
370
|
let blankCommentMode = "preserve";
|
|
360
371
|
let warnOnBlankComments = false;
|
|
372
|
+
const dotenvPath = path.join(rootDir, ".env");
|
|
373
|
+
const dotenvValues = fs.existsSync(dotenvPath)
|
|
374
|
+
? parseDotenv(fs.readFileSync(dotenvPath))
|
|
375
|
+
: {};
|
|
376
|
+
const sourceSettings = [
|
|
377
|
+
{
|
|
378
|
+
value: dotenvValues.JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH,
|
|
379
|
+
location: ".env",
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
value: process.env.JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH,
|
|
383
|
+
location: "the process environment",
|
|
384
|
+
},
|
|
385
|
+
];
|
|
386
|
+
const invalidSourceSetting = sourceSettings.find(({ value }) => value !== undefined && !isManifestSource(value));
|
|
387
|
+
if (invalidSourceSetting) {
|
|
388
|
+
throw new Error(`Invalid JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH in ${invalidSourceSetting.location}: "${invalidSourceSetting.value}". Expected ${describeManifestSources()}.`);
|
|
389
|
+
}
|
|
390
|
+
const configuredSource = process.env.JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH ??
|
|
391
|
+
dotenvValues.JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH ??
|
|
392
|
+
"package.json";
|
|
393
|
+
let sourceOverride;
|
|
361
394
|
for (const arg of args) {
|
|
362
395
|
if (arg.startsWith("--blank-comments=")) {
|
|
363
396
|
const v = arg.split("=", 2)[1]?.toLowerCase();
|
|
@@ -365,33 +398,69 @@ export function runCli(args = process.argv.slice(2)) {
|
|
|
365
398
|
blankCommentMode = v;
|
|
366
399
|
}
|
|
367
400
|
}
|
|
401
|
+
else if (arg.startsWith("--source=")) {
|
|
402
|
+
const v = arg.slice("--source=".length);
|
|
403
|
+
if (isManifestSource(v)) {
|
|
404
|
+
sourceOverride = v;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
console.error(`Invalid source "${v}". Use --source=${manifestSourceOptions.join(" or --source=")}.`);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
368
411
|
else if (arg === "--warn-blank-comments") {
|
|
369
412
|
warnOnBlankComments = true;
|
|
370
413
|
}
|
|
371
414
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
415
|
+
const configuredSourceValue = sourceOverride ?? configuredSource;
|
|
416
|
+
if (!isManifestSource(configuredSourceValue)) {
|
|
417
|
+
console.error(`Invalid JSON5_MANIFEST_SYNC_SOURCE_OF_TRUTH "${configuredSourceValue}". Use ${manifestSourceOptions.join(" or ")}.`);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const source = configuredSourceValue;
|
|
421
|
+
const sourcePattern = source === "package.json" ? "**/package.json" : "**/package.json5";
|
|
422
|
+
const sourcePaths = globSync(sourcePattern, {
|
|
423
|
+
cwd: rootDir,
|
|
424
|
+
ignore: ["**/node_modules/**"],
|
|
425
|
+
absolute: true,
|
|
426
|
+
});
|
|
427
|
+
// Process each manifest using the selected source of truth.
|
|
428
|
+
for (const sourcePath of sourcePaths) {
|
|
429
|
+
const relPath = path.relative(rootDir, sourcePath);
|
|
375
430
|
// Skip files that match gitignore patterns
|
|
376
431
|
if (ig.ignores(relPath))
|
|
377
432
|
continue;
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
433
|
+
const packageJsonPath = source === "package.json"
|
|
434
|
+
? sourcePath
|
|
435
|
+
: path.join(path.dirname(sourcePath), "package.json");
|
|
436
|
+
const json5Path = source === "package.json" ? `${sourcePath}5` : sourcePath;
|
|
437
|
+
// The default direction requires an existing JSON5 companion. In the
|
|
438
|
+
// reverse direction, package.json is created when it does not exist.
|
|
439
|
+
if (source === "package.json" && !fs.existsSync(json5Path)) {
|
|
381
440
|
console.info(`⏩ Skipping ${relPath} — no package.json5 found`);
|
|
382
441
|
continue;
|
|
383
442
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
443
|
+
if (source === "package.json") {
|
|
444
|
+
const rawJson5 = fs.readFileSync(json5Path, "utf8");
|
|
445
|
+
const sourceJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
446
|
+
const updated = syncJson5(rawJson5, sourceJson, {
|
|
447
|
+
blankCommentMode,
|
|
448
|
+
});
|
|
449
|
+
const changed = writeFileIfChanged(json5Path, updated);
|
|
450
|
+
console.info(changed
|
|
451
|
+
? `✅ Synced ${relPath} → ${path.basename(json5Path)}`
|
|
452
|
+
: `⏭️ Unchanged ${relPath} → ${path.basename(json5Path)}`);
|
|
453
|
+
if (warnOnBlankComments && blankCommentMode !== "remove") {
|
|
454
|
+
warnAboutBlankComments(json5Path, collectBlankCommentLineNumbers(updated));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
const sourceJson5 = JSON5.parse(fs.readFileSync(json5Path, "utf8"));
|
|
459
|
+
const updated = `${JSON.stringify(sourceJson5, null, 2)}\n`;
|
|
460
|
+
const changed = writeFileIfChanged(packageJsonPath, updated);
|
|
461
|
+
console.info(changed
|
|
462
|
+
? `✅ Synced ${path.basename(json5Path)} → ${relPath}`
|
|
463
|
+
: `⏭️ Unchanged ${path.basename(json5Path)} → ${relPath}`);
|
|
395
464
|
}
|
|
396
465
|
}
|
|
397
466
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json5-manifest-sync",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Sync package.json5
|
|
3
|
+
"version": "0.3.1",
|
|
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",
|
|
7
7
|
"url": "https://github.com/BBaysinger"
|
|
@@ -46,13 +46,15 @@
|
|
|
46
46
|
"node": ">=18"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"
|
|
50
|
-
"
|
|
49
|
+
"dotenv": "^18.0.10",
|
|
50
|
+
"glob": "^14.0.4",
|
|
51
|
+
"ignore": "^7.0.14",
|
|
52
|
+
"json5": "^2.2.3"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^
|
|
54
|
-
"prettier": "^3.
|
|
55
|
-
"typescript": "^
|
|
56
|
-
"vitest": "^
|
|
55
|
+
"@types/node": "^26.6.6",
|
|
56
|
+
"prettier": "^3.9.10",
|
|
57
|
+
"typescript": "^7.0.2",
|
|
58
|
+
"vitest": "^5.1.0"
|
|
57
59
|
}
|
|
58
60
|
}
|