refactor(core): undecorated-classes-with-di migration should ignore referenced resources (#32953)

Currently the undecorated-classes-with-di migration leverages NGC in order
to work with metadata resolution. Since NGC by default tries to resolve referenced
resources on initialization of the underlying TS program, it can result in unexpected
migration failures due to missing resource files.

This is especially an issue since the CLI wraps the `AngularCompilerProgram` with
special logic (i.e. to support SCSS preprocessing etc.). We don't have all of this since
we instantiate a vanilla NGC program.

The solution to the problem is to simply treat resource requests as valid, and returning
a fake content. The migration is not dependent on templates or stylesheets.. so it's the
simplest and most robust solution.

Fixes #32826

PR Close #32953
This commit is contained in:
Paul Gschwendtner
2019-10-02 11:28:23 +02:00
committed by atscott
parent 90dda5873a
commit 6f5f481fda
2 changed files with 34 additions and 15 deletions

View File

@ -1457,5 +1457,27 @@ describe('Undecorated classes with DI migration', () => {
expect(errorOutput.length).toBe(1);
expect(errorOutput[0]).toMatch(/error TS1005: 'from' expected/);
});
it('should not throw if resources could not be read', async() => {
writeFile('/index.ts', `
import {Component, NgModule} from '@angular/core';
@Component({
templateUrl: './my-template.pug',
styleUrls: ["./test.scss", "./some-special-file.custom"],
})
export class TestComp {}
@NgModule({declarations: [TestComp]})
export class MyModule {}
`);
writeFile('/test.scss', `@import '~theme.scss';`);
await runMigration();
expect(warnOutput.length).toBe(0);
expect(errorOutput.length).toBe(0);
});
});
});