Skip to content

Commit

Permalink
feat(core): migrate @nrwl/workspace:run-script to nx:run-script
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 13, 2022
1 parent f255030 commit ad4233f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/workspace/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
"description": "Changes the presets in nx.json to come from the nx package",
"cli": "nx",
"implementation": "./src/migrations/update-14-0-0/change-nx-json-presets"
},
"14-0-0-change-npm-script-executor": {
"version": "14.0.0-beta.0",
"description": "Migrates from @nrwl/workspace:run-script to nx:run-script",
"cli": "nx",
"implementation": "./src/migrations/update-14-0-0/change-npm-script-executor"
}
},
"packageJsonUpdates": {
Expand Down
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 {},
},
},
}
`);
});
});
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;

0 comments on commit ad4233f

Please sign in to comment.