-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node): apply migration patch to 16.0.0 and 14.7.6 migrations as w…
…ell (#17419)
- Loading branch information
Showing
3 changed files
with
79 additions
and
24 deletions.
There are no files selected for viewing
26 changes: 14 additions & 12 deletions
26
packages/node/src/migrations/update-14-7-6/update-webpack-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 |
---|---|---|
@@ -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); | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/node/src/migrations/update-16-0-0/update-webpack-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, 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', | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
25 changes: 13 additions & 12 deletions
25
packages/node/src/migrations/update-16-0-0/update-webpack-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 |
---|---|---|
@@ -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); | ||
} |
b8cfbcc
There was a problem hiding this comment.
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