-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(frontend): fix ngrx migration requiring angular cli 8.1
- Loading branch information
1 parent
297eca0
commit 98e5bbc
Showing
2 changed files
with
69 additions
and
13 deletions.
There are no files selected for viewing
71 changes: 60 additions & 11 deletions
71
packages/angular/src/migrations/update-8-3-0/upgrade-ngrx-8-0.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,18 +1,67 @@ | ||
import { chain, Tree, noop } from '@angular-devkit/schematics'; | ||
import { addUpdateTask, readJsonInTree, formatFiles } from '@nrwl/workspace'; | ||
import { chain, Tree, noop, TaskId } from '@angular-devkit/schematics'; | ||
import { | ||
addUpdateTask, | ||
readJsonInTree, | ||
formatFiles, | ||
updateJsonInTree | ||
} from '@nrwl/workspace'; | ||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; | ||
|
||
const runNgrxUpdate = addUpdateTask('@ngrx/store', '8.1.0'); | ||
function updateCLI() { | ||
const tasks: TaskId[] = []; | ||
const rule = chain([ | ||
updateJsonInTree('package.json', json => { | ||
json.devDependencies = json.devDependencies || {}; | ||
const cliVersion = json.devDependencies['@angular/cli']; | ||
|
||
const updateNgrx = (host: Tree) => { | ||
const { dependencies } = readJsonInTree(host, 'package.json'); | ||
if ( | ||
cliVersion && | ||
(cliVersion.startsWith('8.1') || | ||
cliVersion.startsWith('~8.1') || | ||
cliVersion.startsWith('^8.1')) | ||
) { | ||
return json; | ||
} | ||
|
||
if (dependencies && dependencies['@ngrx/store']) { | ||
return chain([runNgrxUpdate, formatFiles()]); | ||
} | ||
if (json['devDependencies']['@angular/cli']) { | ||
json['devDependencies']['@angular/cli'] = '8.1.1'; | ||
} | ||
|
||
return noop(); | ||
}; | ||
if (json['devDependencies']['@angular-devkit/build-angular']) { | ||
json['devDependencies']['@angular-devkit/build-angular'] = '^0.801.1'; | ||
} | ||
|
||
if (json['devDependencies']['@angular-devkit/build-ng-packagr']) { | ||
json['devDependencies']['@angular-devkit/build-ng-packagr'] = | ||
'~0.801.1'; | ||
} | ||
|
||
return json; | ||
}), | ||
(host, context) => { | ||
tasks.push(context.addTask(new NodePackageInstallTask())); | ||
} | ||
]); | ||
|
||
return { rule, tasks }; | ||
} | ||
|
||
function updateNgrx(updateDeps: TaskId[]) { | ||
return (host: Tree) => { | ||
const { dependencies } = readJsonInTree(host, 'package.json'); | ||
|
||
if (dependencies && dependencies['@ngrx/store']) { | ||
return chain([ | ||
addUpdateTask('@ngrx/store', '8.1.0', updateDeps), | ||
formatFiles() | ||
]); | ||
} | ||
|
||
return noop(); | ||
}; | ||
} | ||
|
||
export default function() { | ||
return chain([updateNgrx]); | ||
const { rule: updateCLIRule, tasks } = updateCLI(); | ||
return chain([updateCLIRule, updateNgrx(tasks)]); | ||
} |
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