refactor(core): remove disabled injectable-pipe migration (#32184)
Initially the plan was to have a migration that adds `@Injectable()` to
all pipes in a CLI project so that the pipes can be injected in Ivy
similarly to how it worked in view engine.
Due to the planned refactorings which ensure that `@Directive`, `@Component`
and `@Pipe` also have a factory definition, this migration is no longer
needed for Ivy. Additionally since it is already disabled (due to
572b54967c
) and we have a more generic
migration (known as `missing-injectable)` that could do the same as
`injectable-pipe`, we remove the migration from the code-base.
PR Close #32184
This commit is contained in:

committed by
Andrew Kushnir

parent
5da5ca5c23
commit
639b732024
@ -9,7 +9,6 @@ ts_library(
|
||||
"//packages/core/schematics:migrations.json",
|
||||
],
|
||||
deps = [
|
||||
"//packages/core/schematics/migrations/injectable-pipe",
|
||||
"//packages/core/schematics/migrations/missing-injectable",
|
||||
"//packages/core/schematics/migrations/move-document",
|
||||
"//packages/core/schematics/migrations/renderer-to-renderer2",
|
||||
|
@ -1,93 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {readFileSync, writeFileSync} from 'fs';
|
||||
import {dirname, join} from 'path';
|
||||
import * as shx from 'shelljs';
|
||||
import {Configuration, Linter} from 'tslint';
|
||||
|
||||
describe('Google3 injectable pipe TSLint rule', () => {
|
||||
const rulesDirectory = dirname(require.resolve('../../migrations/google3/injectablePipeRule'));
|
||||
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
});
|
||||
|
||||
afterEach(() => shx.rm('-r', tmpDir));
|
||||
|
||||
function runTSLint(fix = true) {
|
||||
const program = Linter.createProgram(join(tmpDir, 'tsconfig.json'));
|
||||
const linter = new Linter({fix, rulesDirectory: [rulesDirectory]}, program);
|
||||
const config = Configuration.parseConfigFile(
|
||||
{rules: {'injectable-pipe': true}, linterOptions: {typeCheck: true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
}
|
||||
|
||||
function writeFile(fileName: string, content: string) {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
|
||||
it('should report pipes that are not marked as Injectable', () => {
|
||||
writeFile('index.ts', `
|
||||
import { Pipe } from '@angular/core';
|
||||
|
||||
@Pipe({ name: 'myPipe' })
|
||||
export class MyPipe {
|
||||
}
|
||||
`);
|
||||
|
||||
const linter = runTSLint(false);
|
||||
const failures = linter.getResult().failures;
|
||||
|
||||
expect(failures.length).toBe(1);
|
||||
expect(failures[0].getFailure()).toMatch(/@Pipe should be decorated with @Injectable/);
|
||||
});
|
||||
|
||||
it('should add @Injectable to pipes that do not have it', () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Pipe } from '@angular/core';
|
||||
|
||||
@Pipe({ name: 'myPipe' })
|
||||
export class MyPipe {
|
||||
}
|
||||
`);
|
||||
|
||||
runTSLint();
|
||||
expect(getFile('/index.ts'))
|
||||
.toMatch(/@Injectable\(\)\s+@Pipe\(\{ name: 'myPipe' \}\)\s+export class MyPipe/);
|
||||
});
|
||||
|
||||
it('should add an import for Injectable to the @angular/core import declaration', () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Pipe } from '@angular/core';
|
||||
|
||||
@Pipe()
|
||||
export class MyPipe {
|
||||
}
|
||||
`);
|
||||
|
||||
runTSLint();
|
||||
|
||||
const content = getFile('/index.ts');
|
||||
expect(content).toContain('import { Pipe, Injectable } from \'@angular/core\'');
|
||||
expect((content.match(/import/g) || []).length).toBe(1, 'Expected only one import statement');
|
||||
});
|
||||
|
||||
});
|
@ -1,143 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {getSystemPath, normalize, virtualFs} from '@angular-devkit/core';
|
||||
import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
|
||||
import {HostTree} from '@angular-devkit/schematics';
|
||||
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
|
||||
import * as shx from 'shelljs';
|
||||
|
||||
describe('injectable pipe migration', () => {
|
||||
let runner: SchematicTestRunner;
|
||||
let host: TempScopedNodeJsSyncHost;
|
||||
let tree: UnitTestTree;
|
||||
let tmpDirPath: string;
|
||||
let previousWorkingDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
runner = new SchematicTestRunner('test', require.resolve('./test-migrations.json'));
|
||||
host = new TempScopedNodeJsSyncHost();
|
||||
tree = new UnitTestTree(new HostTree(host));
|
||||
|
||||
writeFile('/tsconfig.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
lib: ['es2015'],
|
||||
}
|
||||
}));
|
||||
writeFile('/angular.json', JSON.stringify({
|
||||
projects: {t: {architect: {build: {options: {tsConfig: './tsconfig.json'}}}}}
|
||||
}));
|
||||
|
||||
previousWorkingDir = shx.pwd();
|
||||
tmpDirPath = getSystemPath(host.root);
|
||||
|
||||
// Switch into the temporary directory path. This allows us to run
|
||||
// the schematic against our custom unit test tree.
|
||||
shx.cd(tmpDirPath);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
shx.cd(previousWorkingDir);
|
||||
shx.rm('-r', tmpDirPath);
|
||||
});
|
||||
|
||||
it('should add @Injectable to pipes that do not have it', async() => {
|
||||
writeFile('/index.ts', `
|
||||
import { Pipe } from '@angular/core';
|
||||
|
||||
@Pipe({ name: 'myPipe' })
|
||||
export class MyPipe {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toMatch(/@Injectable\(\)\s+@Pipe\(\{ name: 'myPipe' \}\)\s+export class MyPipe/);
|
||||
});
|
||||
|
||||
it('should add @Injectable to pipes that do not have it (BOM)', () => {
|
||||
writeFile('/index.ts', `\uFEFF
|
||||
import { Pipe } from '@angular/core';
|
||||
|
||||
@Pipe({ name: 'myPipe' })
|
||||
export class MyPipe {
|
||||
}
|
||||
`);
|
||||
|
||||
runMigration();
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toMatch(/@Injectable\(\)\s+@Pipe\(\{ name: 'myPipe' \}\)\s+export class MyPipe/);
|
||||
});
|
||||
|
||||
it('should add an import for Injectable to the @angular/core import declaration', async() => {
|
||||
writeFile('/index.ts', `
|
||||
import { Pipe } from '@angular/core';
|
||||
|
||||
@Pipe()
|
||||
export class MyPipe {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
|
||||
const content = tree.readContent('/index.ts');
|
||||
expect(content).toContain('import { Pipe, Injectable } from \'@angular/core\'');
|
||||
expect((content.match(/import/g) || []).length).toBe(1, 'Expected only one import statement');
|
||||
});
|
||||
|
||||
it('should not add an import for Injectable if it is imported already', async() => {
|
||||
writeFile('/index.ts', `
|
||||
import { Pipe, Injectable, NgModule } from '@angular/core';
|
||||
|
||||
@Pipe()
|
||||
export class MyPipe {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain('import { Pipe, Injectable, NgModule } from \'@angular/core\'');
|
||||
});
|
||||
|
||||
it('should do nothing if the pipe is marked as injectable already', async() => {
|
||||
const source = `
|
||||
import { Injectable, Pipe } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
@Pipe()
|
||||
export class MyPipe {
|
||||
}
|
||||
`;
|
||||
|
||||
writeFile('/index.ts', source);
|
||||
await runMigration();
|
||||
expect(tree.readContent('/index.ts')).toBe(source);
|
||||
});
|
||||
|
||||
it('should not add @Injectable if @Pipe was not imported from @angular/core', async() => {
|
||||
const source = `
|
||||
import { Pipe } from '@not-angular/core';
|
||||
|
||||
@Pipe()
|
||||
export class MyPipe {
|
||||
}
|
||||
`;
|
||||
|
||||
writeFile('/index.ts', source);
|
||||
await runMigration();
|
||||
expect(tree.readContent('/index.ts')).toBe(source);
|
||||
});
|
||||
|
||||
function writeFile(filePath: string, contents: string) {
|
||||
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
|
||||
}
|
||||
|
||||
function runMigration() {
|
||||
runner.runSchematicAsync('migration-injectable-pipe', {}, tree).toPromise();
|
||||
}
|
||||
});
|
@ -2,10 +2,6 @@
|
||||
// Migrations which are not publicly enabled but still run as part of tests need to
|
||||
// be part of a schematic collection in order to be able to run it.
|
||||
"schematics": {
|
||||
"migration-injectable-pipe": {
|
||||
"description": "Migrates all Pipe classes so that they have an Injectable annotation",
|
||||
"factory": "../migrations/injectable-pipe/index"
|
||||
},
|
||||
"migration-missing-injectable": {
|
||||
"description": "Migrates all declared undecorated providers with the @Injectable decorator",
|
||||
"factory": "../migrations/missing-injectable/index"
|
||||
|
Reference in New Issue
Block a user