Skip to content

Commit

Permalink
fix(node): extend @nx/node:webpack migration to all targets (#17337)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed May 31, 2023
1 parent 2fe5a43 commit 51ff862
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/node/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
"version": "16.0.0-beta.5",
"description": "Replace @nrwl/node:webpack with @nx/node:webpack",
"implementation": "./src/migrations/update-16-0-0/update-webpack-executor"
},
"update-16-3-1-update-executor": {
"cli": "nx",
"version": "16.3.1-beta.0",
"description": "Replace @nx/node:webpack with @nx/node:webpack for all project targets",
"implementation": "./src/migrations/update-16-3-1/update-webpack-executor"
}
},
"packageJsonUpdates": {
Expand Down
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
@@ -0,0 +1,22 @@
import {
formatFiles,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nx/devkit';
import { forEachExecutorOptions } from '@nx/devkit/src/generators/executor-options-utils';

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);
};

forEachExecutorOptions(tree, '@nx/node:webpack', migrateProject);
forEachExecutorOptions(tree, '@nrwl/node:webpack', migrateProject);

await formatFiles(tree);
}

1 comment on commit 51ff862

@vercel
Copy link

@vercel vercel bot commented on 51ff862 May 31, 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-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.