UNPKG

1.04 kBPlain TextView Raw
1import { Rule, SchematicContext, Tree, SchematicsException, chain, } from '@angular-devkit/schematics';
2import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
3
4const rxjsCompatVersion = '^6.0.0-rc.0';
5
6export function rxjsV6MigrationSchematic(_options: any): Rule {
7 return (tree: Tree, context: SchematicContext) => {
8 const pkgPath = '/package.json';
9 const buffer = tree.read(pkgPath);
10 if (buffer == null) {
11 throw new SchematicsException('Could not read package.json');
12 }
13 const content = buffer.toString();
14 const pkg = JSON.parse(content);
15
16 if (pkg === null || typeof pkg !== 'object' || Array.isArray(pkg)) {
17 throw new SchematicsException('Error reading package.json');
18 }
19
20 if (!pkg.dependencies) {
21 pkg.dependencies = {};
22 }
23
24 pkg.dependencies['rxjs-compat'] = rxjsCompatVersion;
25
26 tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2));
27 context.addTask(new NodePackageInstallTask());
28
29 return tree; // <3
30 };
31}