-
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(ngcc): do not collect private declarations from external packages #34811
Conversation
53c2d7b
to
a8b07f6
Compare
You can preview a8b07f6 at https://pr34811-a8b07f6.ngbuilds.io/. |
eb0c337
to
38e9d9e
Compare
You can preview 38e9d9e at https://pr34811-38e9d9e.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.
A couple of nits/questions.
Please change references to "within the entry-point" to "within the package" in the commit message. We do not (and cannot reliably) check whether source files are within a specific entry-point.
@@ -38,7 +38,7 @@ fi | |||
|
|||
# Workaround https://github.com/yarnpkg/yarn/issues/2165 | |||
# Yarn will cache file://dist URIs and not update Angular code | |||
readonly cache=.yarn_local_cache | |||
export readonly cache=.yarn_local_cache |
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.
OOC what difference does this make?
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.
Exporting it? It makes it available to other scripts called by this script (i.e. the ngcc/test.sh
script).
|
||
loadTestFiles(TYPINGS_SRC_FILES); | ||
loadTestFiles(TYPINGS_DTS_FILES); | ||
const externalLibWithoutTypingsIndex = _('/an_external_lib_without_typings/index.js'); |
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.
NIT: could we move this declaration to above the TestEsm2015ReflectionHost
class declaration since it is used in that 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.
Done.
class TestEsm2015ReflectionHost extends Esm2015ReflectionHost { | ||
getExportsOfModule(node: ts.Node) { | ||
if (ts.isSourceFile(node) && (node.fileName === externalLibWithoutTypingsIndex)) { | ||
throw new Error('Test error'); |
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.
Can you make this error more descriptive. Getting a failure in a test that just says "Test error" is not so helpful.
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.
Done.
loadTestFiles(TYPINGS_DTS_FILES); | ||
const externalLibWithoutTypingsIndex = _('/an_external_lib_without_typings/index.js'); | ||
const bundle = makeTestBundleProgram( | ||
getRootFiles(TYPINGS_SRC_FILES)[0], false, [externalLibWithoutTypingsIndex]); |
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.
Do you actually need to add this as an additional file? Since it is imported from the entry-point, I would expect it to be included in the program's source files automatically.
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.
That's what I expected too. But it is not included 😕
…sOfModule()` error message
Previously, while trying to build an `NgccReflectionHost`'s `privateDtsDeclarationMap`, `computePrivateDtsDeclarationMap()` would try to collect exported declarations from all source files of the program (i.e. without checking whether they were within the target package, as happens for declarations in `.d.ts` files). Most of the time, that would not be a problem, because external packages would be represented as `.d.ts` files in the program. But when an external package had no typings, the JS files would be used instead. As a result, the `ReflectionHost` would try to (unnecessarilly) parse the file in order to extract exported declarations, which in turn would be harmless in most cases. There are certain cases, though, where the `ReflectionHost` would throw an error, because it cannot parse the external package's JS file. This could happen, for example, in `UmdReflectionHost`, which expects the file to contain exactly one statement. See angular#34544 for more details on a real-world failure. This commit fixes the issue by ensuring that `computePrivateDtsDeclarationMap()` will only collect exported declarations from files within the target package. Jira issue: [FW-1794](https://angular-team.atlassian.net/browse/FW-1794) Fixes angular#34544
38e9d9e
to
74e8273
Compare
You can preview 74e8273 at https://pr34811-74e8273.ngbuilds.io/. |
Would love to see this included in |
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.
Approval for integration
JFYI, the only change that affected g3 is the error message text (function name correction) in |
…#34811) Previously, while trying to build an `NgccReflectionHost`'s `privateDtsDeclarationMap`, `computePrivateDtsDeclarationMap()` would try to collect exported declarations from all source files of the program (i.e. without checking whether they were within the target package, as happens for declarations in `.d.ts` files). Most of the time, that would not be a problem, because external packages would be represented as `.d.ts` files in the program. But when an external package had no typings, the JS files would be used instead. As a result, the `ReflectionHost` would try to (unnecessarilly) parse the file in order to extract exported declarations, which in turn would be harmless in most cases. There are certain cases, though, where the `ReflectionHost` would throw an error, because it cannot parse the external package's JS file. This could happen, for example, in `UmdReflectionHost`, which expects the file to contain exactly one statement. See #34544 for more details on a real-world failure. This commit fixes the issue by ensuring that `computePrivateDtsDeclarationMap()` will only collect exported declarations from files within the target package. Jira issue: [FW-1794](https://angular-team.atlassian.net/browse/FW-1794) Fixes #34544 PR Close #34811
…#34811) Previously, while trying to build an `NgccReflectionHost`'s `privateDtsDeclarationMap`, `computePrivateDtsDeclarationMap()` would try to collect exported declarations from all source files of the program (i.e. without checking whether they were within the target package, as happens for declarations in `.d.ts` files). Most of the time, that would not be a problem, because external packages would be represented as `.d.ts` files in the program. But when an external package had no typings, the JS files would be used instead. As a result, the `ReflectionHost` would try to (unnecessarilly) parse the file in order to extract exported declarations, which in turn would be harmless in most cases. There are certain cases, though, where the `ReflectionHost` would throw an error, because it cannot parse the external package's JS file. This could happen, for example, in `UmdReflectionHost`, which expects the file to contain exactly one statement. See #34544 for more details on a real-world failure. This commit fixes the issue by ensuring that `computePrivateDtsDeclarationMap()` will only collect exported declarations from files within the target package. Jira issue: [FW-1794](https://angular-team.atlassian.net/browse/FW-1794) Fixes #34544 PR Close #34811
…sOfModule()` error message (angular#34811) PR Close angular#34811
…angular#34811) Previously, while trying to build an `NgccReflectionHost`'s `privateDtsDeclarationMap`, `computePrivateDtsDeclarationMap()` would try to collect exported declarations from all source files of the program (i.e. without checking whether they were within the target package, as happens for declarations in `.d.ts` files). Most of the time, that would not be a problem, because external packages would be represented as `.d.ts` files in the program. But when an external package had no typings, the JS files would be used instead. As a result, the `ReflectionHost` would try to (unnecessarilly) parse the file in order to extract exported declarations, which in turn would be harmless in most cases. There are certain cases, though, where the `ReflectionHost` would throw an error, because it cannot parse the external package's JS file. This could happen, for example, in `UmdReflectionHost`, which expects the file to contain exactly one statement. See angular#34544 for more details on a real-world failure. This commit fixes the issue by ensuring that `computePrivateDtsDeclarationMap()` will only collect exported declarations from files within the target package. Jira issue: [FW-1794](https://angular-team.atlassian.net/browse/FW-1794) Fixes angular#34544 PR Close angular#34811
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. |
Previously, while trying to build an
NgccReflectionHost
'sprivateDtsDeclarationMap
,computePrivateDtsDeclarationMap()
would try to collect exported declarations from all source files of the program (i.e. without checking whether they were within the target entry-point, as happens for declarations in.d.ts
files).Most of the time, that would not be a problem, because external packages would be represented as
.d.ts
files in the program. But when an external package had no typings, the JS files would be used instead. As a result, theReflectionHost
would try to (unnecessarilly) parse the file in order to extract exported declarations, which in turn would be harmless in most cases.There are certain cases, though, where the
ReflectionHost
would throw an error, because it cannot not parse the external package's JS file. This could happen, for example, inUmdReflectionHost
, which expects the file to contain exactly one statement. See #34544 for more details on a real-world failure.This commit fixes the issue by ensuring that
computePrivateDtsDeclarationMap()
will only collect exported declarations from files within the target entry-point.Jira issue: FW-1794
Fixes #34544.
For good measure, I have also tested it on the
ngcc-validation
repo (angular/ngcc-validation#777) and nothing broke.