-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): add migrations to remove root
- Loading branch information
1 parent
6dd0502
commit 9a513da
Showing
5 changed files
with
84 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
{ | ||
"migrations": {} | ||
"generators": { | ||
"14-0-4-remove-root": { | ||
"cli": "nx", | ||
"version": "14.0.4", | ||
"description": "Remove root property from project.json files", | ||
"factory": "./src/migrations/update-14-0-4/remove-roots" | ||
} | ||
} | ||
} |
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,12 @@ | ||
import path = require('path'); | ||
import json = require('./migrations.json'); | ||
|
||
describe('Node migrations', () => { | ||
it('should have valid paths', () => { | ||
Object.values(json.generators).forEach((m) => { | ||
expect(() => | ||
require.resolve(path.join(__dirname, `${m.factory}.ts`)) | ||
).not.toThrow(); | ||
}); | ||
}); | ||
}); |
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
48 changes: 48 additions & 0 deletions
48
packages/nx/src/migrations/update-14-0-4/remove-roots.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,48 @@ | ||
import { Tree } from '../../generators/tree'; | ||
import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; | ||
import { addProjectConfiguration } from '../../generators/utils/project-configuration'; | ||
import { readJson, updateJson } from '../../generators/utils/json'; | ||
import removeRoots from './remove-roots'; | ||
|
||
describe('remove-roots >', () => { | ||
let tree: Tree; | ||
|
||
describe('projects with project.json configs', () => { | ||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(2); | ||
}); | ||
|
||
it('should remove the root property', async () => { | ||
addProjectConfiguration(tree, 'proj1', { | ||
root: 'proj1', | ||
}); | ||
|
||
updateJson(tree, 'proj1/project.json', (config) => ({ | ||
...config, | ||
root: 'proj1', | ||
})); | ||
|
||
await removeRoots(tree); | ||
|
||
expect(readJson(tree, 'proj1/project.json').root).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('projects with project.json configs', () => { | ||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(1); | ||
}); | ||
|
||
it('should remove the root property', async () => { | ||
addProjectConfiguration(tree, 'proj1', { | ||
root: 'proj1', | ||
}); | ||
|
||
await removeRoots(tree); | ||
|
||
expect(readJson(tree, 'workspace.json').projects.proj1.root).toEqual( | ||
'proj1' | ||
); | ||
}); | ||
}); | ||
}); |
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,15 @@ | ||
import { Tree } from '../../generators/tree'; | ||
import { | ||
getProjects, | ||
updateProjectConfiguration, | ||
} from '../../generators/utils/project-configuration'; | ||
import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; | ||
|
||
export default async function (tree: Tree) { | ||
// This looks like it does nothing, but this will actually effectively migrate over all the configs that need to be moved over, but won't touch configs that don't need to be moved | ||
for (const [projName, projConfig] of getProjects(tree)) { | ||
updateProjectConfiguration(tree, projName, projConfig); | ||
} | ||
|
||
await formatChangedFilesWithPrettierIfAvailable(tree); | ||
} |