Skip to content

Commit a0c9a61

Browse files
Broccohansl
authored andcommitted
fix(@schematics/angular): update script should remove rxjs from the import blacklist
fixes angular/angular-cli#10259
1 parent 6c65b58 commit a0c9a61

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

packages/schematics/angular/migrations/update-6/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,28 @@ function updatePackageJson(packageManager?: string) {
543543
};
544544
}
545545

546+
function updateTsLintConfig(): Rule {
547+
return (host: Tree, context: SchematicContext) => {
548+
const tsLintPath = '/tslint.json';
549+
const buffer = host.read(tsLintPath);
550+
if (!buffer) {
551+
return;
552+
}
553+
const tsCfg = JSON.parse(buffer.toString());
554+
555+
if (tsCfg.rules && tsCfg.rules['import-blacklist'] &&
556+
tsCfg.rules['import-blacklist'].indexOf('rxjs') !== -1) {
557+
558+
tsCfg.rules['import-blacklist'] = tsCfg.rules['import-blacklist']
559+
.filter((rule: string | boolean) => rule !== 'rxjs');
560+
561+
host.overwrite(tsLintPath, JSON.stringify(tsCfg, null, 2));
562+
}
563+
564+
return host;
565+
};
566+
}
567+
546568
export default function (): Rule {
547569
return (host: Tree, context: SchematicContext) => {
548570
const configPath = getConfigPath(host);
@@ -557,6 +579,7 @@ export default function (): Rule {
557579
migrateConfiguration(config),
558580
updateSpecTsConfig(config),
559581
updatePackageJson(config.packageManager),
582+
updateTsLintConfig(),
560583
])(host, context);
561584
};
562585
}

packages/schematics/angular/migrations/update-6/index_spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,4 +688,36 @@ describe('Migration to v6', () => {
688688
expect(pkg.devDependencies['@angular-devkit/build-angular']).toBeDefined();
689689
});
690690
});
691+
692+
describe('tslint.json', () => {
693+
const tslintPath = '/tslint.json';
694+
// tslint:disable-next-line:no-any
695+
let tslintConfig: any;
696+
beforeEach(() => {
697+
tslintConfig = {
698+
rules: {
699+
'import-blacklist': ['rxjs'],
700+
},
701+
};
702+
});
703+
704+
it('should remove "rxjs" from the "import-blacklist" rule', () => {
705+
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
706+
tree.create(tslintPath, JSON.stringify(tslintConfig, null, 2));
707+
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
708+
const tslint = JSON.parse(tree.readContent(tslintPath));
709+
const blacklist = tslint.rules['import-blacklist'];
710+
expect(blacklist).toEqual([]);
711+
});
712+
713+
it('should work if "rxjs" is not in the "import-blacklist" rule', () => {
714+
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
715+
tslintConfig.rules['import-blacklist'] = [];
716+
tree.create(tslintPath, JSON.stringify(tslintConfig, null, 2));
717+
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
718+
const tslint = JSON.parse(tree.readContent(tslintPath));
719+
const blacklist = tslint.rules['import-blacklist'];
720+
expect(blacklist).toEqual([]);
721+
});
722+
});
691723
});

0 commit comments

Comments
 (0)