-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): update default cache directory to .nx/cache #19536
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
import { createTree } from '../../generators/testing-utils/create-tree'; | ||
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" | ||
`); | ||
}); | ||
|
||
it('should not update gitignore for lerna repos without nx.json', () => { | ||
const tree = createTree(); | ||
tree.write('.gitignore', 'node_modules'); | ||
tree.write('lerna.json', '{}'); | ||
migrate(tree); | ||
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot( | ||
`"node_modules"` | ||
); | ||
}); | ||
|
||
it('should handle prettierignore', () => { | ||
const tree = createTree(); | ||
tree.write('.prettierignore', '/dist'); | ||
migrate(tree); | ||
expect(tree.read('.prettierignore', 'utf-8')).toMatchInlineSnapshot(` | ||
"/dist | ||
/.nx/cache" | ||
`); | ||
}); | ||
|
||
it('should handle missing prettierignore', () => { | ||
const tree = createTree(); | ||
tree.delete('.prettierignore'); | ||
migrate(tree); | ||
expect(tree.exists('.prettierignore')).toBeFalsy(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
import { Tree } from '../../generators/tree'; | ||
import ignore from 'ignore'; | ||
|
||
export default function moveCacheDirectory(tree: Tree) { | ||
// If nx.json doesn't exist the repo can't utilize | ||
// caching, so .nx/cache is less relevant. Lerna users | ||
// that don't want to fully opt in to Nx at this time | ||
// may also be caught off guard by the appearance of | ||
// a .nx directory, so we are going to special case | ||
// this for the time being. | ||
if (tree.exists('lerna.json') && !tree.exists('nx.json')) { | ||
return; | ||
} | ||
|
||
updateGitIgnore(tree); | ||
|
||
if (tree.exists('.prettierignore')) { | ||
const ignored = tree.read('.prettierignore', 'utf-8'); | ||
if (!ignored.includes('.nx/cache')) { | ||
tree.write('.prettierignore', [ignored, '/.nx/cache'].join('\n')); | ||
} | ||
} | ||
} | ||
|
||
function updateGitIgnore(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
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 |
---|---|---|
|
@@ -37,3 +37,5 @@ testem.log | |
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
.nx/cache |
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 |
---|---|---|
|
@@ -37,3 +37,5 @@ testem.log | |
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
.nx/cache |
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 |
---|---|---|
|
@@ -37,3 +37,5 @@ testem.log | |
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
.nx/cache |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for keeping this specific, we will have a need for some tracked files in
.nx
soon!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wrapper also lives here and needs to be checked in so it had to be specific 😃