-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Fix g3 core imports #27998
Fix g3 core imports #27998
Conversation
You can preview 0f8b677 at https://pr27998-0f8b677.ngbuilds.io/. |
0f8b677
to
317e2e4
Compare
317e2e4
to
525cdfb
Compare
You can preview 317e2e4 at https://pr27998-317e2e4.ngbuilds.io/. |
You can preview 525cdfb at https://pr27998-525cdfb.ngbuilds.io/. |
Nice work! I can't properly review from my phone (on holiday this week) but I have one request: could you update the comment in |
525cdfb
to
15eaf33
Compare
@JoostK nice catch, done! |
You can preview 15eaf33 at https://pr27998-15eaf33.ngbuilds.io/. |
c3c77a5
to
e2b7501
Compare
You can preview c3c77a5 at https://pr27998-c3c77a5.ngbuilds.io/. |
You can preview e2b7501 at https://pr27998-e2b7501.ngbuilds.io/. |
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.
From an ngcc point-of-view this looks like a really nice code tidy-up. A couple of minor nits.
packages/compiler-cli/src/ngcc/src/rendering/ngcc_import_rewriter.ts
Outdated
Show resolved
Hide resolved
e2b7501
to
3fc9187
Compare
You can preview 3fc9187 at https://pr27998-3fc9187.ngbuilds.io/. |
const constantPool = new ConstantPool(); | ||
const importManager = new ImportManager(coreImportsFrom !== null); | ||
const importManager = new ImportManager(importRewriter || undefined); |
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.
Isn't importRewriter
always defined?
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.
Good catch, fixed.
if (ts.isImportDeclaration(stmt) && ts.isStringLiteral(stmt.moduleSpecifier) && | ||
stmt.moduleSpecifier.text === '@angular/core') { | ||
const rewrittenModuleSpecifier = | ||
importRewriter.rewriteSpecifier('@angular/core', sourceFilePath); | ||
// Update the import path to point to the correct file (coreImportsFrom). |
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.
coreImportsFrom
does no longer exist.
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.
Fixed.
return true; | ||
} | ||
} | ||
rewriteSymbol(symbol: string, specifier: string): string { |
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.
No empty line between methods 😞
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.
Fixed.
Currently the ImportManager class handles various rewriting actions of imports when compiling @angular/core. This is required as code compiled within @angular/core cannot import from '@angular/core'. To work around this, imports are rewritten to get core symbols from a particular file, r3_symbols.ts. In this refactoring, this rewriting logic is moved out of the ImportManager and put behind an interface, ImportRewriter. There are three implementers of the interface: * NoopImportRewriter, used for compiling all non-core packages. * R3SymbolsImportRewriter, used when ngtsc compiles @angular/core. * NgccFlatImportRewriter, used when ngcc compiles @angular/core (special logic is needed because ngcc has to rewrite imports in flat bundles differently than in non-flat bundles). This is a precursor to using this rewriting logic in other contexts besides the ImportManager.
Generated factory shims can import from @angular/core. However, we have special logic in place to rewrite self-imports when generating code for @angular/core. This commit leverages the new standalone ImportRewriter interface to properly rewrite imports in generated factory shims. Before this fix, a generated factory file for core would look like: ```typescript import * as i0 from './r3_symbols'; export var ApplicationModuleNgFactory = new ɵNgModuleFactory(...); ``` This is invalid, as ɵNgModuleFactory is just NgModuleFactory when imported via r3_symbols. FW-881 #resolve
3fc9187
to
cfb588d
Compare
You can preview cfb588d at https://pr27998-cfb588d.ngbuilds.io/. |
|
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.
Looks good, one nit is the way we work with '@angular/core': in some places we put it in a const and reference it, in other places, we just use this as a string to compare with a given value. We should probably unify that at some point (I noticed that in other places as well). This is a minor thing and definitely not a blocker to approve this PR :)
Generated factory shims can import from @angular/core. However, we have special logic in place to rewrite self-imports when generating code for @angular/core. This commit leverages the new standalone ImportRewriter interface to properly rewrite imports in generated factory shims. Before this fix, a generated factory file for core would look like: ```typescript import * as i0 from './r3_symbols'; export var ApplicationModuleNgFactory = new ɵNgModuleFactory(...); ``` This is invalid, as ɵNgModuleFactory is just NgModuleFactory when imported via r3_symbols. FW-881 #resolve PR Close #27998
…gular#27998) Currently the ImportManager class handles various rewriting actions of imports when compiling @angular/core. This is required as code compiled within @angular/core cannot import from '@angular/core'. To work around this, imports are rewritten to get core symbols from a particular file, r3_symbols.ts. In this refactoring, this rewriting logic is moved out of the ImportManager and put behind an interface, ImportRewriter. There are three implementers of the interface: * NoopImportRewriter, used for compiling all non-core packages. * R3SymbolsImportRewriter, used when ngtsc compiles @angular/core. * NgccFlatImportRewriter, used when ngcc compiles @angular/core (special logic is needed because ngcc has to rewrite imports in flat bundles differently than in non-flat bundles). This is a precursor to using this rewriting logic in other contexts besides the ImportManager. PR Close angular#27998
…r#27998) Generated factory shims can import from @angular/core. However, we have special logic in place to rewrite self-imports when generating code for @angular/core. This commit leverages the new standalone ImportRewriter interface to properly rewrite imports in generated factory shims. Before this fix, a generated factory file for core would look like: ```typescript import * as i0 from './r3_symbols'; export var ApplicationModuleNgFactory = new ɵNgModuleFactory(...); ``` This is invalid, as ɵNgModuleFactory is just NgModuleFactory when imported via r3_symbols. FW-881 #resolve PR Close angular#27998
…gular#27998) Currently the ImportManager class handles various rewriting actions of imports when compiling @angular/core. This is required as code compiled within @angular/core cannot import from '@angular/core'. To work around this, imports are rewritten to get core symbols from a particular file, r3_symbols.ts. In this refactoring, this rewriting logic is moved out of the ImportManager and put behind an interface, ImportRewriter. There are three implementers of the interface: * NoopImportRewriter, used for compiling all non-core packages. * R3SymbolsImportRewriter, used when ngtsc compiles @angular/core. * NgccFlatImportRewriter, used when ngcc compiles @angular/core (special logic is needed because ngcc has to rewrite imports in flat bundles differently than in non-flat bundles). This is a precursor to using this rewriting logic in other contexts besides the ImportManager. PR Close angular#27998
…r#27998) Generated factory shims can import from @angular/core. However, we have special logic in place to rewrite self-imports when generating code for @angular/core. This commit leverages the new standalone ImportRewriter interface to properly rewrite imports in generated factory shims. Before this fix, a generated factory file for core would look like: ```typescript import * as i0 from './r3_symbols'; export var ApplicationModuleNgFactory = new ɵNgModuleFactory(...); ``` This is invalid, as ɵNgModuleFactory is just NgModuleFactory when imported via r3_symbols. FW-881 #resolve PR Close angular#27998
…gular#27998) Currently the ImportManager class handles various rewriting actions of imports when compiling @angular/core. This is required as code compiled within @angular/core cannot import from '@angular/core'. To work around this, imports are rewritten to get core symbols from a particular file, r3_symbols.ts. In this refactoring, this rewriting logic is moved out of the ImportManager and put behind an interface, ImportRewriter. There are three implementers of the interface: * NoopImportRewriter, used for compiling all non-core packages. * R3SymbolsImportRewriter, used when ngtsc compiles @angular/core. * NgccFlatImportRewriter, used when ngcc compiles @angular/core (special logic is needed because ngcc has to rewrite imports in flat bundles differently than in non-flat bundles). This is a precursor to using this rewriting logic in other contexts besides the ImportManager. PR Close angular#27998
…r#27998) Generated factory shims can import from @angular/core. However, we have special logic in place to rewrite self-imports when generating code for @angular/core. This commit leverages the new standalone ImportRewriter interface to properly rewrite imports in generated factory shims. Before this fix, a generated factory file for core would look like: ```typescript import * as i0 from './r3_symbols'; export var ApplicationModuleNgFactory = new ɵNgModuleFactory(...); ``` This is invalid, as ɵNgModuleFactory is just NgModuleFactory when imported via r3_symbols. FW-881 #resolve PR Close angular#27998
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Based on #27743 (for now)