-
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): allow dependsOn to accept a single project dependency (#1…
- Loading branch information
1 parent
7989fac
commit f2f6e35
Showing
11 changed files
with
488 additions
and
123 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
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
104 changes: 104 additions & 0 deletions
104
packages/nx/src/migrations/update-16-0-0/update-depends-on-to-tokens.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,104 @@ | ||
import { | ||
addProjectConfiguration, | ||
getProjects, | ||
readNxJson, | ||
readProjectConfiguration, | ||
} from '../../generators/utils/project-configuration'; | ||
import { Tree } from '../../generators/tree'; | ||
|
||
import update from './update-depends-on-to-tokens'; | ||
import { updateJson, writeJson } from 'nx/src/devkit-exports'; | ||
import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; | ||
|
||
describe('update-depends-on-to-tokens', () => { | ||
it('should update nx.json', async () => { | ||
const tree = createTreeWithEmptyWorkspace(); | ||
updateJson(tree, 'nx.json', (json) => { | ||
json.targetDefaults = { | ||
build: { | ||
dependsOn: [ | ||
{ | ||
projects: 'self', | ||
}, | ||
], | ||
}, | ||
test: { | ||
dependsOn: [ | ||
{ | ||
projects: 'dependencies', | ||
}, | ||
], | ||
}, | ||
other: { | ||
dependsOn: ['^deps'], | ||
}, | ||
}; | ||
return json; | ||
}); | ||
await update(tree); | ||
const nxJson = readNxJson(tree); | ||
const build = nxJson.targetDefaults.build.dependsOn[0] as any; | ||
const test = nxJson.targetDefaults.test.dependsOn[0] as any; | ||
expect(build.projects).toEqual('{self}'); | ||
expect(test.projects).toEqual('{dependencies}'); | ||
expect(nxJson.targetDefaults.other.dependsOn).toEqual(['^deps']); | ||
}); | ||
|
||
it('should update project configurations', async () => { | ||
const tree = createTreeWithEmptyWorkspace(); | ||
addProjectConfiguration(tree, 'proj1', { | ||
root: 'proj1', | ||
targets: { | ||
build: { | ||
dependsOn: [ | ||
{ | ||
projects: 'self', | ||
target: 'build', | ||
}, | ||
], | ||
}, | ||
test: { | ||
dependsOn: [ | ||
{ | ||
projects: 'dependencies', | ||
target: 'test', | ||
}, | ||
], | ||
}, | ||
other: { | ||
dependsOn: ['^deps'], | ||
}, | ||
}, | ||
}); | ||
await update(tree); | ||
const project = readProjectConfiguration(tree, 'proj1'); | ||
const build = project.targets.build.dependsOn[0] as any; | ||
const test = project.targets.test.dependsOn[0] as any; | ||
expect(build.projects).toEqual('{self}'); | ||
expect(test.projects).toEqual('{dependencies}'); | ||
expect(project.targets.other.dependsOn).toEqual(['^deps']); | ||
}); | ||
|
||
it('should not throw on nulls', async () => { | ||
const tree = createTreeWithEmptyWorkspace(); | ||
addProjectConfiguration(tree, 'proj1', { | ||
root: 'proj1', | ||
}); | ||
addProjectConfiguration(tree, 'proj2', { | ||
root: 'proj2', | ||
targets: { | ||
build: {}, | ||
}, | ||
}); | ||
writeJson(tree, 'nx.json', {}); | ||
let promise = update(tree); | ||
await expect(promise).resolves.toBeUndefined(); | ||
writeJson(tree, 'nx.json', { | ||
targetDefaults: { | ||
build: {}, | ||
}, | ||
}); | ||
promise = update(tree); | ||
await expect(promise).resolves.toBeUndefined(); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
packages/nx/src/migrations/update-16-0-0/update-depends-on-to-tokens.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 { | ||
getProjects, | ||
readNxJson, | ||
updateNxJson, | ||
updateProjectConfiguration, | ||
} from '../../generators/utils/project-configuration'; | ||
import { Tree } from '../../generators/tree'; | ||
|
||
export default async function (tree: Tree) { | ||
updateDependsOnInsideNxJson(tree); | ||
|
||
const projectsConfigurations = getProjects(tree); | ||
for (const [projectName, projectConfiguration] of projectsConfigurations) { | ||
let projectChanged = false; | ||
for (const [targetName, targetConfiguration] of Object.entries( | ||
projectConfiguration.targets ?? {} | ||
)) { | ||
for (const dependency of targetConfiguration.dependsOn ?? []) { | ||
if (typeof dependency !== 'string') { | ||
if (dependency.projects === 'self') { | ||
dependency.projects = '{self}'; | ||
projectChanged = true; | ||
} else if (dependency.projects === 'dependencies') { | ||
dependency.projects = '{dependencies}'; | ||
projectChanged = true; | ||
} | ||
} | ||
} | ||
} | ||
if (projectChanged) { | ||
updateProjectConfiguration(tree, projectName, projectConfiguration); | ||
} | ||
} | ||
} | ||
function updateDependsOnInsideNxJson(tree: Tree) { | ||
const nxJson = readNxJson(tree); | ||
let nxJsonChanged = false; | ||
for (const [target, defaults] of Object.entries( | ||
nxJson?.targetDefaults ?? {} | ||
)) { | ||
for (const dependency of defaults.dependsOn ?? []) { | ||
if (typeof dependency !== 'string') { | ||
if (dependency.projects === 'self') { | ||
dependency.projects = '{self}'; | ||
nxJsonChanged = true; | ||
} else if (dependency.projects === 'dependencies') { | ||
dependency.projects = '{dependencies}'; | ||
nxJsonChanged = true; | ||
} | ||
} | ||
} | ||
} | ||
if (nxJsonChanged) { | ||
updateNxJson(tree, nxJson); | ||
} | ||
} |
Oops, something went wrong.
f2f6e35
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.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev