-
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): migrate @nrwl/workspace:run-script to nx:run-script
- Loading branch information
1 parent
f255030
commit ad4233f
Showing
3 changed files
with
87 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.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,52 @@ | ||
import { | ||
addProjectConfiguration, | ||
readJson, | ||
readProjectConfiguration, | ||
readWorkspaceConfiguration, | ||
Tree, | ||
updateWorkspaceConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import changeNpmScriptExecutor from './change-npm-script-executor'; | ||
|
||
describe('changeNxJsonPresets', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
|
||
addProjectConfiguration(tree, 'proj1', { | ||
root: 'proj1', | ||
targets: { | ||
scriptTarget: { | ||
executor: '@nrwl/workspace:run-script', | ||
options: {}, | ||
}, | ||
notScriptTarget: { | ||
executor: '@nrwl/workspace:something', | ||
options: {}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should change the npm script executor to nx:npm-script', async () => { | ||
await changeNpmScriptExecutor(tree); | ||
|
||
expect(readProjectConfiguration(tree, 'proj1')).toMatchInlineSnapshot(` | ||
Object { | ||
"root": "proj1", | ||
"targets": Object { | ||
"notScriptTarget": Object { | ||
"executor": "@nrwl/workspace:something", | ||
"options": Object {}, | ||
}, | ||
"scriptTarget": Object { | ||
"executor": "nx:run-script", | ||
"options": Object {}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/workspace/src/migrations/update-14-0-0/change-npm-script-executor.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,29 @@ | ||
import { | ||
formatFiles, | ||
readProjectConfiguration, | ||
readWorkspaceConfiguration, | ||
TargetConfiguration, | ||
Tree, | ||
updateProjectConfiguration, | ||
updateWorkspaceConfiguration, | ||
} from '@nrwl/devkit'; | ||
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; | ||
|
||
export async function changeNpmScriptExecutor(tree: Tree) { | ||
forEachExecutorOptions( | ||
tree, | ||
'@nrwl/workspace:run-script', | ||
(currentValue, project, target) => { | ||
const projectConfig = readProjectConfiguration(tree, project); | ||
const targetConfig = projectConfig.targets[target]; | ||
|
||
targetConfig.executor = 'nx:run-script'; | ||
|
||
updateProjectConfiguration(tree, project, projectConfig); | ||
} | ||
); | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
export default changeNpmScriptExecutor; |