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
ngcc: implement a new program-based entry-point finder #37075
ngcc: implement a new program-based entry-point finder #37075
Conversation
The approach here, which involves parsing each source file, could be slow for a large app. |
562fc7e
to
87c7485
Compare
423b945
to
2754a92
Compare
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.
Typo in "capture dynamic import expressions as well as declarations" commit:
- "and creates lesss" -> "and creates less"
packages/compiler-cli/ngcc/src/dependencies/esm_dependency_host.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/ngcc/test/dependencies/esm_dependency_host_spec.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/ngcc/test/dependencies/esm_dependency_host_spec.ts
Show resolved
Hide resolved
packages/compiler-cli/ngcc/src/dependencies/esm_dependency_host.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/ngcc/src/dependencies/esm_dependency_host.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/ngcc/test/entry_point_finder/program_based_entry_point_finder_spec.ts
Show resolved
Hide resolved
2754a92
to
300fde5
Compare
The various dependency hosts had a lot of duplicated code. This commit refactors them to move this into the base class. PR Close #37075
…#37075) Previously we only checked for static import declaration statements. This commit also finds import paths from dynamic import expressions. Also this commit should speed up processing: Previously we were parsing the source code contents into a `ts.SourceFile` and then walking the parsed AST to find import paths. Generating an AST is unnecessary work and it is faster and creates less memory pressure to just scan the source code contents with the TypeScript scanner, identifying import paths from the tokens. PR Close #37075
This finder is designed to only process entry-points that are reachable by the program defined by a tsconfig.json file. It is triggered by calling `mainNgcc()` with the `findEntryPointsFromTsConfigProgram` option set to true. It is ignored if a `targetEntryPointPath` has been provided as well. It is triggered from the command line by adding the `--use-program-dependencies` option, which is also ignored if the `--target` option has been provided. Using this option can speed up processing in cases where there is a large number of dependencies installed but only a small proportion of the entry-points are actually imported into the application. PR Close #37075
The various dependency hosts had a lot of duplicated code. This commit refactors them to move this into the base class. PR Close #37075
…#37075) Previously we only checked for static import declaration statements. This commit also finds import paths from dynamic import expressions. Also this commit should speed up processing: Previously we were parsing the source code contents into a `ts.SourceFile` and then walking the parsed AST to find import paths. Generating an AST is unnecessary work and it is faster and creates less memory pressure to just scan the source code contents with the TypeScript scanner, identifying import paths from the tokens. PR Close #37075
This finder is designed to only process entry-points that are reachable by the program defined by a tsconfig.json file. It is triggered by calling `mainNgcc()` with the `findEntryPointsFromTsConfigProgram` option set to true. It is ignored if a `targetEntryPointPath` has been provided as well. It is triggered from the command line by adding the `--use-program-dependencies` option, which is also ignored if the `--target` option has been provided. Using this option can speed up processing in cases where there is a large number of dependencies installed but only a small proportion of the entry-points are actually imported into the application. PR Close #37075
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.
Post-merge review 😁:
tl;dr LGTM 👍
imports.add(reexportPath); | ||
} | ||
break; | ||
} |
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.
This block would benefit from some comments explaining what each case does and why. It is quite hard (for me) to understand without diving into the Scanner
.
lastToken = currentToken; | ||
} | ||
|
||
// Clear the text from the scanner. |
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.
Why? 😁
@@ -93,7 +225,7 @@ export class EsmDependencyHost extends DependencyHostBase { | |||
* in this file, true otherwise. | |||
*/ | |||
export function hasImportOrReexportStatements(source: string): boolean { | |||
return /(import|export)\s.+from/.test(source); | |||
return /(?:import|export)[\s\S]+?(["'])(?:(?:\\\1|.)*?)\1/.test(source); |
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.
Nice 👍
There is one unneeded set of parenthesis (afaict), but not really important:
return /(?:import|export)[\s\S]+?(["'])(?:(?:\\\1|.)*?)\1/.test(source); | |
return /(?:import|export)[\s\S]+?(["'])(?:\\\1|.)+?\1/.test(source); |
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'm a bit frightened to touch that again :-)
* This is faster than searching the entire file-system for all the entry-points, | ||
* and is used primarily by the CLI integration. | ||
* | ||
* There are two concrete implementation of this class. |
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.
* There are two concrete implementation of this class. | |
* There are two concrete implementations of this class. |
This is a follow-up to angular#37075, because I didn't manage to finish my review before the PR got merged.
This is a follow-up to angular#37075, because I didn't manage to finish my review before the PR got merged.
This is a follow-up to angular#37075, because I didn't manage to finish my review before the PR got merged.
This is a follow-up to angular#37075, because I didn't manage to finish my review before the PR got merged.
…ost` (angular#37075) Previously this host was skipping files if they had imports that spanned multiple lines, or if the import was a dynamic import expression. PR Close angular#37075
…7075) The various dependency hosts had a lot of duplicated code. This commit refactors them to move this into the base class. PR Close angular#37075
…angular#37075) Previously we only checked for static import declaration statements. This commit also finds import paths from dynamic import expressions. Also this commit should speed up processing: Previously we were parsing the source code contents into a `ts.SourceFile` and then walking the parsed AST to find import paths. Generating an AST is unnecessary work and it is faster and creates less memory pressure to just scan the source code contents with the TypeScript scanner, identifying import paths from the tokens. PR Close angular#37075
This finder is designed to only process entry-points that are reachable by the program defined by a tsconfig.json file. It is triggered by calling `mainNgcc()` with the `findEntryPointsFromTsConfigProgram` option set to true. It is ignored if a `targetEntryPointPath` has been provided as well. It is triggered from the command line by adding the `--use-program-dependencies` option, which is also ignored if the `--target` option has been provided. Using this option can speed up processing in cases where there is a large number of dependencies installed but only a small proportion of the entry-points are actually imported into the application. PR Close angular#37075
…pos (angular#37040) This is a follow-up to angular#37075, because I didn't manage to finish my review before the PR got merged. PR Close angular#37040
With this change we consume the change in angular/angular#37075 where the NGCC now exposes a new option `--use-program-dependencies`, to only process packages which are part of the TypeScript program. From the initial benchmarking the time taken for NGCC to process that dependencies needed for an `ng new` application went down by 36% from 10526ms to 6708ms.
With this change we consume the change in angular/angular#37075 where the NGCC now exposes a new option `--use-program-dependencies`, to only process packages which are part of the TypeScript program. From the initial benchmarking the time taken for NGCC to process that dependencies needed for an `ng new` application went down by 36% from 10526ms to 6708ms.
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. |
…ost` (angular#37075) Previously this host was skipping files if they had imports that spanned multiple lines, or if the import was a dynamic import expression. PR Close angular#37075
…7075) The various dependency hosts had a lot of duplicated code. This commit refactors them to move this into the base class. PR Close angular#37075
…angular#37075) Previously we only checked for static import declaration statements. This commit also finds import paths from dynamic import expressions. Also this commit should speed up processing: Previously we were parsing the source code contents into a `ts.SourceFile` and then walking the parsed AST to find import paths. Generating an AST is unnecessary work and it is faster and creates less memory pressure to just scan the source code contents with the TypeScript scanner, identifying import paths from the tokens. PR Close angular#37075
This finder is designed to only process entry-points that are reachable by the program defined by a tsconfig.json file. It is triggered by calling `mainNgcc()` with the `findEntryPointsFromTsConfigProgram` option set to true. It is ignored if a `targetEntryPointPath` has been provided as well. It is triggered from the command line by adding the `--use-program-dependencies` option, which is also ignored if the `--target` option has been provided. Using this option can speed up processing in cases where there is a large number of dependencies installed but only a small proportion of the entry-points are actually imported into the application. PR Close angular#37075
Add a new
EntryPointFinder
that can be seeded from the imports in the program specified by a tsconfig.json file. This should be much faster than theDirectoryWalkerEntryPointFinder
when the active program only imports a small proportion of the installed entry-points.On the AIO project only half the entry-points would be processed by ngcc if the CLI async integration with ngcc made use of the new flag.