Skip to content

Commit

Permalink
fix(node): update node migrations to use forEachExecutorOptions (#9471)
Browse files Browse the repository at this point in the history
Co-authored-by: Chau Tran <ctran@Chaus-MacBook-Pro.local>
  • Loading branch information
2 people authored and FrozenPandaz committed Mar 25, 2022
1 parent 2f3d80e commit ba2dfc4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
@@ -1,20 +1,21 @@
import {
formatFiles,
getProjects,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';

export default async function update(host: Tree) {
const projects = getProjects(host);

for (const [name, config] of projects.entries()) {
if (config?.targets?.build?.executor !== '@nrwl/node:build') continue;

config.targets.build.executor = '@nrwl/node:webpack';

updateProjectConfiguration(host, name, config);
}
forEachExecutorOptions(
host,
'@nrwl/node:build',
(_, projectName, targetName) => {
const projectConfiguration = readProjectConfiguration(host, projectName);
projectConfiguration.targets[targetName].executor = '@nrwl/node:webpack';
updateProjectConfiguration(host, projectName, projectConfiguration);
}
);

await formatFiles(host);
}
@@ -1,20 +1,21 @@
import {
formatFiles,
getProjects,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';

export default async function update(host: Tree) {
const projects = getProjects(host);
export default async function update(tree: Tree) {
forEachExecutorOptions(
tree,
'@nrwl/node:execute',
(_, projectName, targetName) => {
const projectConfiguration = readProjectConfiguration(tree, projectName);
projectConfiguration.targets[targetName].executor = '@nrwl/node:node';
updateProjectConfiguration(tree, projectName, projectConfiguration);
}
);

for (const [name, config] of projects.entries()) {
if (config?.targets?.serve?.executor !== '@nrwl/node:execute') continue;

config.targets.serve.executor = '@nrwl/node:node';

updateProjectConfiguration(host, name, config);
}

await formatFiles(host);
await formatFiles(tree);
}
31 changes: 19 additions & 12 deletions packages/node/src/migrations/update-13-8-5/update-package-to-tsc.ts
Expand Up @@ -2,29 +2,36 @@ import {
addDependenciesToPackageJson,
formatFiles,
getProjects,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { nxVersion } from '@nrwl/workspace/src/utils/versions';

export default async function update(host: Tree) {
const projects = getProjects(host);
let installNeeded = false;

for (const [name, config] of projects.entries()) {
if (config?.targets?.build?.executor !== '@nrwl/node:package') continue;
forEachExecutorOptions(
host,
'@nrwl/node:package',
(_, projectName, targetName) => {
installNeeded = true;
const projectConfiguration = readProjectConfiguration(host, projectName);

config.targets.build.executor = '@nrwl/js:tsc';
projectConfiguration.targets[targetName].executor = '@nrwl/js:tsc';

const transformers = config.targets.build.options?.tsPlugins;
if (transformers) {
delete config.targets.build.options.tsPlugins;
config.targets.build.options.transformers = transformers;
}
const transformers =
projectConfiguration.targets[targetName].options?.tsPlugins;
if (transformers) {
delete projectConfiguration.targets[targetName].options.tsPlugins;
projectConfiguration.targets[targetName].options.transformers =
transformers;
}

installNeeded = true;
updateProjectConfiguration(host, name, config);
}
updateProjectConfiguration(host, projectName, projectConfiguration);
}
);

const task = installNeeded
? addDependenciesToPackageJson(
Expand Down

0 comments on commit ba2dfc4

Please sign in to comment.