-
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.
feat(core): update default cache directory to .nx/cache
- Loading branch information
1 parent
8ccd88c
commit 743d15c
Showing
4 changed files
with
66 additions
and
3 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
43 changes: 43 additions & 0 deletions
43
packages/nx/src/migrations/update-17-0-0/move-cache-directory.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,43 @@ | ||
import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; | ||
import migrate from './move-cache-directory'; | ||
|
||
describe('move-cache-directory', () => { | ||
it('should add .nx/cache to the gitignore', () => { | ||
const tree = createTreeWithEmptyWorkspace(); | ||
tree.write('.gitignore', 'node_modules'); | ||
migrate(tree); | ||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(` | ||
"node_modules | ||
.nx/cache" | ||
`); | ||
}); | ||
|
||
it('should work if .gitignore is not present', () => { | ||
const tree = createTreeWithEmptyWorkspace(); | ||
tree.delete('.gitignore'); | ||
migrate(tree); | ||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot( | ||
`".nx/cache"` | ||
); | ||
}); | ||
|
||
it('should not change gitignore if directly ignored', () => { | ||
const tree = createTreeWithEmptyWorkspace(); | ||
tree.write('.gitignore', 'node_modules\n.nx/cache'); | ||
migrate(tree); | ||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(` | ||
"node_modules | ||
.nx/cache" | ||
`); | ||
}); | ||
|
||
it('should not change gitignore if ignored by another pattern', () => { | ||
const tree = createTreeWithEmptyWorkspace(); | ||
tree.write('.gitignore', 'node_modules\n.*/cache'); | ||
migrate(tree); | ||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(` | ||
"node_modules | ||
.*/cache" | ||
`); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/nx/src/migrations/update-17-0-0/move-cache-directory.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,16 @@ | ||
import { Tree } from '../../generators/tree'; | ||
import ignore from 'ignore'; | ||
|
||
export default function moveCacheDirectory(tree: Tree) { | ||
const gitignore = tree.exists('.gitignore') | ||
? tree.read('.gitignore', 'utf-8') | ||
: ''; | ||
const ig = ignore(); | ||
ig.add(gitignore); | ||
if (!ig.ignores('.nx/cache')) { | ||
const updatedLines = gitignore.length | ||
? [gitignore, '.nx/cache'] | ||
: ['.nx/cache']; | ||
tree.write('.gitignore', updatedLines.join('\n')); | ||
} | ||
} |
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