Skip to content

Commit b1514d5

Browse files
crisbetothePunderWoman
authored andcommitted
fix(migrations): incorrect filtering in inject migration (#62913)
The inject migration wasn't implementing file filtering properly which resulted in it passing an invalid tsconfig path to TypeScript. Fixes #62866. PR Close #62913
1 parent cbc258e commit b1514d5

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

packages/core/schematics/ng-generate/inject-migration/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@ import {canMigrateFile, createMigrationProgram} from '../../utils/typescript/com
1414

1515
import {migrateFile} from './migration';
1616
import {MigrationOptions} from './analysis';
17+
import {getProjectTsConfigPaths} from '../../utils/project_tsconfig_paths';
1718

1819
interface Options extends MigrationOptions {
1920
path: string;
2021
}
2122

2223
export function migrate(options: Options): Rule {
2324
return async (tree: Tree) => {
25+
const {buildPaths, testPaths} = await getProjectTsConfigPaths(tree);
2426
const basePath = process.cwd();
27+
const allPaths = [...buildPaths, ...testPaths];
2528
const pathToMigrate = normalizePath(join(basePath, options.path));
26-
let allPaths = [];
27-
if (pathToMigrate.trim() !== '') {
28-
allPaths.push(pathToMigrate);
29-
}
3029

3130
if (!allPaths.length) {
3231
throw new SchematicsException(

packages/core/schematics/test/inject_migration_spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,56 @@ describe('inject migration', () => {
411411
]);
412412
});
413413

414+
it('should only migrate the specified file', async () => {
415+
writeFile(
416+
'/dir.ts',
417+
[
418+
`import { Directive } from '@angular/core';`,
419+
`import { Foo } from 'foo';`,
420+
``,
421+
`@Directive()`,
422+
`class MyDir {`,
423+
` constructor(private foo: Foo) {}`,
424+
`}`,
425+
].join('\n'),
426+
);
427+
428+
writeFile(
429+
'/other-dir.ts',
430+
[
431+
`import { Directive } from '@angular/core';`,
432+
`import { Foo } from 'foo';`,
433+
``,
434+
`@Directive()`,
435+
`class MyOtherDir {`,
436+
` constructor(private foo: Foo) {}`,
437+
`}`,
438+
].join('\n'),
439+
);
440+
441+
await runMigration({path: '/dir.ts'});
442+
443+
expect(tree.readContent('/dir.ts').split('\n')).toEqual([
444+
`import { Directive, inject } from '@angular/core';`,
445+
`import { Foo } from 'foo';`,
446+
``,
447+
`@Directive()`,
448+
`class MyDir {`,
449+
` private foo = inject(Foo);`,
450+
`}`,
451+
]);
452+
453+
expect(tree.readContent('/other-dir.ts').split('\n')).toEqual([
454+
`import { Directive } from '@angular/core';`,
455+
`import { Foo } from 'foo';`,
456+
``,
457+
`@Directive()`,
458+
`class MyOtherDir {`,
459+
` constructor(private foo: Foo) {}`,
460+
`}`,
461+
]);
462+
});
463+
414464
it('should not migrate classes decorated with a non-Angular decorator', async () => {
415465
writeFile(
416466
'/dir.ts',

0 commit comments

Comments
 (0)