-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bundling): ensure vitest timestamp files are ignored (#29418)
## Current Behavior Vitest TS config files produce timestamp temp files during project graph creation which are cleaned up. However, the creation and deletion of these files triggers the daemon to recalculate graph. It ends up in a loop. The vite timestamp files were already added to the gitignore to prevent this. ## Expected Behavior Add vitest timestamp files to gitignore
- Loading branch information
Showing
7 changed files
with
116 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/vite/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import addViteTempFilesToGitIgnore from './add-vitest-temp-files-to-git-ignore'; | ||
|
||
describe('addViteTempFilesToGitIgnore', () => { | ||
it('should update an existing .gitignore file to add the glob correctly', () => { | ||
// ARRANGE | ||
const tree = createTreeWithEmptyWorkspace(); | ||
tree.write('.gitignore', '.idea'); | ||
|
||
// ACT | ||
addViteTempFilesToGitIgnore(tree); | ||
|
||
// ASSERT | ||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(` | ||
".idea | ||
vite.config.*.timestamp* | ||
vitest.config.*.timestamp*" | ||
`); | ||
}); | ||
|
||
it('should update an existing .gitignore file and remove incorrect glob and add the glob correctly', () => { | ||
// ARRANGE | ||
const tree = createTreeWithEmptyWorkspace(); | ||
tree.write( | ||
'.gitignore', | ||
`.idea | ||
**/vitest.config.{js,ts,mjs,mts,cjs,cts}.timestamp*` | ||
); | ||
|
||
// ACT | ||
addViteTempFilesToGitIgnore(tree); | ||
|
||
// ASSERT | ||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(` | ||
".idea | ||
vite.config.*.timestamp* | ||
vitest.config.*.timestamp*" | ||
`); | ||
}); | ||
|
||
it('should write a new .gitignore file to add the glob correctly', () => { | ||
// ARRANGE | ||
const tree = createTreeWithEmptyWorkspace(); | ||
tree.delete('.gitignore'); | ||
|
||
// ACT | ||
addViteTempFilesToGitIgnore(tree); | ||
|
||
// ASSERT | ||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(` | ||
"vite.config.*.timestamp* | ||
vitest.config.*.timestamp*" | ||
`); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/vite/src/migrations/update-20-3-0/add-vitest-temp-files-to-git-ignore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Tree } from '@nx/devkit'; | ||
import { addViteTempFilesToGitIgnore as _addViteTempFilesToGitIgnore } from '../../utils/add-vite-temp-files-to-gitignore'; | ||
|
||
export default function addViteTempFilesToGitIgnore(tree: Tree) { | ||
// need to check if .gitignore exists before adding to it | ||
// then need to check if it contains the following pattern | ||
// **/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp* | ||
// if it does, remove just this pattern | ||
if (tree.exists('.gitignore')) { | ||
const gitIgnoreContents = tree.read('.gitignore', 'utf-8'); | ||
if ( | ||
gitIgnoreContents.includes( | ||
'**/vitest.config.{js,ts,mjs,mts,cjs,cts}.timestamp*' | ||
) | ||
) { | ||
tree.write( | ||
'.gitignore', | ||
gitIgnoreContents.replace( | ||
'**/vitest.config.{js,ts,mjs,mts,cjs,cts}.timestamp*', | ||
'' | ||
) | ||
); | ||
} | ||
} | ||
_addViteTempFilesToGitIgnore(tree); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters