diff --git a/README.md b/README.md index f6b5bbd..7967ad4 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ npm init svelte@next Once that is set up, run this command in your project directory to set up Jest: -> ❗️ __When running with TypeScript support enabled, remove comments within `tsconfig.json` or the adder will fail. This is a known limitation of [Preset](https://usepreset.dev/), as it relies upon JSON.parse.__ - ```sh npx apply rossyman/svelte-add-jest # --no-ssh ``` diff --git a/package.json b/package.json index 934c8e4..d8a36a9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@rossyman/svelte-add-jest", - "version": "1.1.1", + "version": "1.1.2", "description": "SvelteKit adder for Jest unit testing", "license": "MIT", "keywords": [ @@ -20,6 +20,7 @@ ], "preset": "preset.ts", "devDependencies": { - "apply": "^0.2.13" + "apply": "^0.2.13", + "comment-json": "^4.1.0" } } diff --git a/preset.ts b/preset.ts index af1563a..b9a892f 100644 --- a/preset.ts +++ b/preset.ts @@ -1,3 +1,4 @@ +import { assign, parse, stringify } from 'comment-json'; import { Preset, color } from 'apply'; type Dependencies = { @@ -187,12 +188,10 @@ class SvelteJestAdder extends Adder { .withTitle('Enabling Jest DOM Support') .if(() => this.getConfiguration('jest-dom')); - Preset - .editJson('tsconfig.json').merge({ - exclude: ['src/**/*.spec.ts'] - }) - .withTitle('Modifying TypeScript config for project') - .if(() => this.getConfiguration('ts')); + Preset.edit('tsconfig.json').update((content) => + stringify(assign(parse(content), { exclude: ['src/**/*.spec.ts'] }), null, 4)) + .withTitle('Modifying TypeScript config for project') + .if(() => this.getConfiguration('ts')); Preset .editJson('jest.config.json').merge({