-
Notifications
You must be signed in to change notification settings - Fork 27.2k
fix(ivy): prevent ngcc from referencing missing ɵsetClassMetadata #27055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
013c333
dcbead9
9811ee4
789d323
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * @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 * as ts from 'typescript'; | ||
|
|
||
| /** | ||
| * A bundle represents the currently compiled entry point format, containing | ||
| * information that is necessary for compiling @angular/core with ngcc. | ||
| */ | ||
| export interface BundleInfo { | ||
| isCore: boolean; | ||
| isFlat: boolean; | ||
| rewriteCoreImportsTo: ts.SourceFile|null; | ||
| rewriteCoreDtsImportsTo: ts.SourceFile|null; | ||
| } | ||
|
|
||
| export function createBundleInfo( | ||
| isCore: boolean, rewriteCoreImportsTo: ts.SourceFile | null, | ||
| rewriteCoreDtsImportsTo: ts.SourceFile | null): BundleInfo { | ||
| return { | ||
| isCore, | ||
| isFlat: rewriteCoreImportsTo === null, | ||
| rewriteCoreImportsTo: rewriteCoreImportsTo, | ||
| rewriteCoreDtsImportsTo: rewriteCoreDtsImportsTo, | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ import {EsmRenderer} from '../rendering/esm_renderer'; | |||||||
| import {FileInfo, Renderer} from '../rendering/renderer'; | ||||||||
|
|
||||||||
| import {checkMarkerFile, writeMarkerFile} from './build_marker'; | ||||||||
| import {BundleInfo, createBundleInfo} from './bundle'; | ||||||||
| import {EntryPoint, EntryPointFormat} from './entry_point'; | ||||||||
|
|
||||||||
| /** | ||||||||
|
|
@@ -70,27 +71,40 @@ export class Transformer { | |||||||
| const host = ts.createCompilerHost(options); | ||||||||
| const rootDirs = this.getRootDirs(host, options); | ||||||||
| const isCore = entryPoint.name === '@angular/core'; | ||||||||
| const r3SymbolsPath = isCore ? this.findR3SymbolsPath(dirname(entryPointFilePath)) : null; | ||||||||
| const r3SymbolsPath = | ||||||||
| isCore ? this.findR3SymbolsPath(dirname(entryPointFilePath), 'r3_symbols.js') : null; | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work even if we're compiling a FESM entrypoint?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. For FESMs, the angular/packages/compiler-cli/src/ngcc/src/rendering/ngcc_import_manager.ts Lines 17 to 19 in 789d323
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glad that is sorted :-) |
||||||||
| const rootPaths = r3SymbolsPath ? [entryPointFilePath, r3SymbolsPath] : [entryPointFilePath]; | ||||||||
| const packageProgram = ts.createProgram(rootPaths, options, host); | ||||||||
| console.time(entryPoint.name + '(dtsmappper creation)'); | ||||||||
| const r3SymbolsFile = r3SymbolsPath && packageProgram.getSourceFile(r3SymbolsPath) || null; | ||||||||
|
|
||||||||
| // Create the program for processing DTS files if enabled for this format. | ||||||||
| const dtsFilePath = entryPoint.typings; | ||||||||
| const dtsProgram = transformDts ? ts.createProgram([entryPoint.typings], options, host) : null; | ||||||||
| console.timeEnd(entryPoint.name + '(dtsmappper creation)'); | ||||||||
| let dtsProgram: ts.Program|null = null; | ||||||||
| let r3SymbolsDtsFile: ts.SourceFile|null = null; | ||||||||
| if (transformDts) { | ||||||||
| console.time(`${entryPoint.name} (dtsMapper creation)`); | ||||||||
| const r3SymbolsDtsPath = | ||||||||
| isCore ? this.findR3SymbolsPath(dirname(dtsFilePath), 'r3_symbols.d.ts') : null; | ||||||||
| const rootDtsPaths = r3SymbolsDtsPath ? [dtsFilePath, r3SymbolsDtsPath] : [dtsFilePath]; | ||||||||
|
|
||||||||
| dtsProgram = ts.createProgram(rootDtsPaths, options, host); | ||||||||
| r3SymbolsDtsFile = r3SymbolsDtsPath && dtsProgram.getSourceFile(r3SymbolsDtsPath) || null; | ||||||||
| console.timeEnd(`${entryPoint.name} (dtsMapper creation)`); | ||||||||
| } | ||||||||
|
|
||||||||
| const bundle = createBundleInfo(isCore, r3SymbolsFile, r3SymbolsDtsFile); | ||||||||
| const reflectionHost = this.getHost(isCore, format, packageProgram, dtsFilePath, dtsProgram); | ||||||||
| const r3SymbolsFile = r3SymbolsPath && packageProgram.getSourceFile(r3SymbolsPath) || null; | ||||||||
|
|
||||||||
| // Parse and analyze the files. | ||||||||
| const {decorationAnalyses, switchMarkerAnalyses} = | ||||||||
| this.analyzeProgram(packageProgram, reflectionHost, rootDirs, isCore); | ||||||||
|
|
||||||||
| console.time(entryPoint.name + '(rendering)'); | ||||||||
| console.time(`${entryPoint.name} (rendering)`); | ||||||||
| // Transform the source files and source maps. | ||||||||
| const renderer = this.getRenderer( | ||||||||
| format, packageProgram, reflectionHost, isCore, r3SymbolsFile, transformDts); | ||||||||
| const renderer = this.getRenderer(format, packageProgram, reflectionHost, bundle, transformDts); | ||||||||
| const renderedFiles = | ||||||||
| renderer.renderProgram(packageProgram, decorationAnalyses, switchMarkerAnalyses); | ||||||||
| console.timeEnd(entryPoint.name + '(rendering)'); | ||||||||
| console.timeEnd(`${entryPoint.name} (rendering)`); | ||||||||
|
|
||||||||
| // Write out all the transformed files. | ||||||||
| renderedFiles.forEach(file => this.writeFile(file)); | ||||||||
|
|
@@ -125,17 +139,15 @@ export class Transformer { | |||||||
| } | ||||||||
|
|
||||||||
| getRenderer( | ||||||||
| format: string, program: ts.Program, host: NgccReflectionHost, isCore: boolean, | ||||||||
| rewriteCoreImportsTo: ts.SourceFile|null, transformDts: boolean): Renderer { | ||||||||
| format: string, program: ts.Program, host: NgccReflectionHost, bundle: BundleInfo, | ||||||||
| transformDts: boolean): Renderer { | ||||||||
| switch (format) { | ||||||||
| case 'esm2015': | ||||||||
| case 'fesm2015': | ||||||||
| return new EsmRenderer( | ||||||||
| host, isCore, rewriteCoreImportsTo, this.sourcePath, this.targetPath, transformDts); | ||||||||
| return new EsmRenderer(host, bundle, this.sourcePath, this.targetPath, transformDts); | ||||||||
| case 'esm5': | ||||||||
| case 'fesm5': | ||||||||
| return new Esm5Renderer( | ||||||||
| host, isCore, rewriteCoreImportsTo, this.sourcePath, this.targetPath, transformDts); | ||||||||
| return new Esm5Renderer(host, bundle, this.sourcePath, this.targetPath, transformDts); | ||||||||
| default: | ||||||||
| throw new Error(`Renderer for "${format}" not yet implemented.`); | ||||||||
| } | ||||||||
|
|
@@ -162,8 +174,8 @@ export class Transformer { | |||||||
| writeFileSync(file.path, file.contents, 'utf8'); | ||||||||
| } | ||||||||
|
|
||||||||
| findR3SymbolsPath(directory: string): string|null { | ||||||||
| const r3SymbolsFilePath = resolve(directory, 'r3_symbols.js'); | ||||||||
| findR3SymbolsPath(directory: string, fileName: string): string|null { | ||||||||
| const r3SymbolsFilePath = resolve(directory, fileName); | ||||||||
| if (existsSync(r3SymbolsFilePath)) { | ||||||||
| return r3SymbolsFilePath; | ||||||||
| } | ||||||||
|
|
@@ -181,7 +193,7 @@ export class Transformer { | |||||||
| }); | ||||||||
|
|
||||||||
| for (const subDirectory of subDirectories) { | ||||||||
| const r3SymbolsFilePath = this.findR3SymbolsPath(resolve(directory, subDirectory)); | ||||||||
| const r3SymbolsFilePath = this.findR3SymbolsPath(resolve(directory, subDirectory), fileName); | ||||||||
| if (r3SymbolsFilePath) { | ||||||||
| return r3SymbolsFilePath; | ||||||||
| } | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the concept of an object to hold this stuff, I am not happy with the name though.
Bundleis too generic.Also I still switch back and forth between passing everything into the constructor versus passing everything to the
renderProgrammethod versus (our current situation) of passing some things to each.