Skip to content

Commit

Permalink
fix(node): apply migration patch to 16.0.0 and 14.7.6 migrations as w…
Browse files Browse the repository at this point in the history
…ell (#17419)
  • Loading branch information
jaysoo committed Jun 5, 2023
1 parent 1bc7965 commit b8cfbcc
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import {
formatFiles,
getProjects,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nx/devkit';
import { forEachExecutorOptions } from '@nx/devkit/src/generators/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:webpack') {
config.targets.build.executor = '@nrwl/webpack:webpack';
config.targets.build.options.target = 'node';
config.targets.build.options.compiler = 'tsc';
updateProjectConfiguration(host, name, config);
export default async function update(tree: Tree) {
forEachExecutorOptions(
tree,
'@nrwl/node:webpack',
(options, projectName, targetName) => {
const projectConfig = readProjectConfiguration(tree, projectName);
projectConfig.targets[targetName].executor = '@nrwl/webpack:webpack';
projectConfig.targets[targetName].options.compiler = 'tsc';
projectConfig.targets[targetName].options.target = 'node';
updateProjectConfiguration(tree, projectName, projectConfig);
}
}
);

await formatFiles(host);
await formatFiles(tree);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';

import update from './update-webpack-executor';

describe('Migration: @nrwl/webpack', () => {
it(`should update usage of webpack executor`, async () => {
let tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });

addProjectConfiguration(tree, 'myapp', {
root: 'apps/myapp',
sourceRoot: 'apps/myapp/src',
projectType: 'application',
targets: {
foo: {
executor: '@nrwl/node:webpack',
options: {},
},
bar: {
executor: '@nx/node:webpack',
options: {},
},
},
});

await update(tree);

expect(readProjectConfiguration(tree, 'myapp')).toEqual({
$schema: '../../node_modules/nx/schemas/project-schema.json',
name: 'myapp',
root: 'apps/myapp',
sourceRoot: 'apps/myapp/src',
projectType: 'application',
targets: {
foo: {
executor: '@nx/webpack:webpack',
options: {
compiler: 'tsc',
target: 'node',
},
},
bar: {
executor: '@nx/webpack:webpack',
options: {
compiler: 'tsc',
target: 'node',
},
},
},
});
});
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import {
formatFiles,
getProjects,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nx/devkit';
import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils';

export default async function update(host: Tree) {
const projects = getProjects(host);
export default async function update(tree: Tree) {
const migrateProject = (options, projectName, targetName) => {
const projectConfig = readProjectConfiguration(tree, projectName);
projectConfig.targets[targetName].executor = '@nx/webpack:webpack';
projectConfig.targets[targetName].options.compiler = 'tsc';
projectConfig.targets[targetName].options.target = 'node';
updateProjectConfiguration(tree, projectName, projectConfig);
};

for (const [name, config] of projects.entries()) {
if (config?.targets?.build?.executor === '@nrwl/node:webpack') {
config.targets.build.executor = '@nx/webpack:webpack';
config.targets.build.options.target = 'node';
config.targets.build.options.compiler = 'tsc';
updateProjectConfiguration(host, name, config);
}
}
forEachExecutorOptions(tree, '@nx/node:webpack', migrateProject);
forEachExecutorOptions(tree, '@nrwl/node:webpack', migrateProject);

await formatFiles(host);
await formatFiles(tree);
}

1 comment on commit b8cfbcc

@vercel
Copy link

@vercel vercel bot commented on b8cfbcc Jun 5, 2023

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
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.