Skip to content

Commit cb6f426

Browse files
authored
chore: prevent dev server from dirtying tracked files (#15826)
# Overview Running `pnpm dev <suite>` modifies `tsconfig.base.json` and `next-env.d.ts` in ways that show up in `git status` but never belong in commits. This PR eliminates both sources of noise. ## Key Changes - **`tsconfig.base.json` — string replacement instead of full reparse:** `comment-json`'s `stringify` was reformatting the entire file (expanding single-element arrays to multi-line) just to swap the `@payload-config` path. Replaced with a regex that only touches the `@payload-config` value, leaving all other formatting untouched. A shared utility (`scripts/replacePayloadConfigPath.js`) is used by `reset-tsconfig.js`, with an inlined copy in `test/testHooks.ts` (the `test/` tsconfig sets `rootDir` to `test/`, so it can't import from `../scripts/`). - **`next-env.d.ts` — gitignored and untracked:** Next.js rewrites this file on every `next dev`, flipping between single/double quotes and adding/removing semicolons. Since it's auto-generated on first `next dev` or `next build`, it's a build artifact. Untracked all 22 copies across root, test suites, examples, and templates. - **ESLint config:** Added `scripts/**/*.js` to the ignore list since the typescript-eslint project service doesn't cover standalone JS scripts. ## Design Decisions The regex approach (`/"@payload-config":\s*\[\s*)"[^"]*"(\s*\])/`) was chosen over alternatives like `json-stringify-pretty-compact` or moving `@payload-config` resolution to a bundler alias. It's the smallest change that fully solves the problem — no new dependencies, no architecture changes, and the existing `reset-tsconfig.js` lint-staged hook continues to work as before. The utility is duplicated between `scripts/replacePayloadConfigPath.js` and `test/testHooks.ts` because TypeScript's `rootDir` boundary prevents `test/` from importing `../scripts/`. Both copies are small (~10 lines) so the duplication is acceptable.
1 parent 410912c commit cb6f426

File tree

27 files changed

+50
-147
lines changed

27 files changed

+50
-147
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ web_modules/
170170

171171
# Next.js build output
172172
.next
173+
next-env.d.ts
173174
out
174175

175176
# Nuxt.js build / generate output

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const defaultESLintIgnores = [
2626
'**/app',
2727
'src/**/*.spec.ts',
2828
'packages/payload/rollup.dts.config.mjs',
29+
'scripts/**/*.js',
2930
]
3031

3132
/** @typedef {import('eslint').Linter.Config} Config */

examples/astro/payload/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/auth/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/custom-components/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/custom-server/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/draft-preview/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/email/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/live-preview/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/localization/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)