Problem
Pointing fix-headers at a .json file writes a /** … */ JS comment block at the top. JSON has no comments, so the file becomes invalid.
Reproduced on @cldmv/fix-headers@2.1.3:
npx fix-headers --input package.json --verbose
# fix-headers complete: scanned=1, updated=1, dryRun=false
# updated: package.json
head -3 package.json
# /**
# *
# * @Project: fh-repro
Node then refuses the package. Every npm command in that directory, and any require() resolving through it, fails with:
Error: Invalid package config .../package.json. code: 'ERR_INVALID_PACKAGE_CONFIG'
It happened for real during the CJS-entry sweep (CLDMV/vitest-runner#69): running it on package.json broke npm run build until the edit was reverted. The README lists JSON among the supported formats, so nothing warns you off doing this.
Fix
JSON (.json, .jsonc aside) can't carry a comment header. Skip strict-JSON files, or handle them explicitly in a way that keeps the file valid, and never write a comment into one. If --input names a file that is skipped, report it as skipped rather than "updated". Add a test asserting that package.json (and any *.json) is unchanged and still parses after a run.
Problem
Pointing fix-headers at a
.jsonfile writes a/** … */JS comment block at the top. JSON has no comments, so the file becomes invalid.Reproduced on
@cldmv/fix-headers@2.1.3:Node then refuses the package. Every
npmcommand in that directory, and anyrequire()resolving through it, fails with:It happened for real during the CJS-entry sweep (CLDMV/vitest-runner#69): running it on
package.jsonbrokenpm run builduntil the edit was reverted. The README lists JSON among the supported formats, so nothing warns you off doing this.Fix
JSON (
.json,.jsoncaside) can't carry a comment header. Skip strict-JSON files, or handle them explicitly in a way that keeps the file valid, and never write a comment into one. If--inputnames a file that is skipped, report it as skipped rather than "updated". Add a test asserting thatpackage.json(and any*.json) is unchanged and still parses after a run.