0x80 / isolate-package

Isolate a monorepo package with its internal dependencies to form a self-contained directory with a pruned lockfile
MIT License
121 stars 13 forks source link

Support parsing jsonc and json with trailing comas #57

Closed vajahath closed 7 months ago

vajahath commented 7 months ago

Recently prettier started adding trailing , to tsconfig.json. This resulted in breaking the workflow for many project. So lets support it.

JSON.parse(jsonWithTrailingComa) ---> error

Error:

Error: Failed to read JSON from /Users/vajahathahmed/Projects/mono/out/apps/functions/tsconfig.json: Unexpected token } in JSON at position 151
    at readTypedJson (file:///Users/vajahathahmed/Projects/mono/out/node_modules/.pnpm/isolate-package@1.10.1/node_modules/isolate-package/src/lib/utils/pack.ts:1:10)
    at getBuildOutputDir (file:///Users/vajahathahmed/Projects/mono/out/node_modules/.pnpm/isolate-package@1.10.1/node_modules/isolate-package/src/lib/output/get-build-output-dir.ts:33:8)
    at isolate (file:///Users/vajahathahmed/Projects/mono/out/node_modules/.pnpm/isolate-package@1.10.1/node_modules/isolate-package/src/isolate.ts:78:5)
    at run (file:///Users/vajahathahmed/Projects/mono/out/node_modules/.pnpm/isolate-package@1.10.1/node_modules/isolate-package/src/isolate-bin.ts:17:5)

Generally tools should support jsonc.

This PR fixes it via https://github.com/sindresorhus/strip-json-comments?tab=readme-ov-file#trailingcommas