[api-extractor]: update getGlobalVariableAnalyzer to support changes to typescript internals in v4.7 #3394
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR is intended to (hopefully) provide a backwards compatible solution for incoming breaking changes in typescript's internals as of v4.7.0 (currently in beta). This PR closes #3349.
API-Extractor relies on Typescript internals to function, and those internals have been changed with this PR for the upcoming minor version of Typescript: https://github.com/microsoft/TypeScript/pull/36747/files.
Details
This change checks the validity of either API and should execute based on one being available. I tended towards keeping things less verbose to keep from requiring multiple nested if statements, etc. One place this is apparent is the error thrown. Rather than trying to track down which instance is missing, it seemed that providing a note that either is missing keeps parity for the error intent. I'm certainly open to a more verbosity in the checks, it simply seemed unnecessary as we really care that one of these API's exists (depending on version).
This change should not break compatibility from what I can tell, though I'm not super familiar with the use of internals here.
I don't believe this should result in a significant performance degradation - though more verbose alternatives possibly could.
NOTE: I chose to submit this as a patch because it doesn't seem fundamentally additive to the API Extractor in any meaningful way. While it does affect the package, it's both backwards compatible and relatively specific to the internals from what I can tell. Happy to update to minor if folks feel that's needed, but patch seemed most reasonable in my own assessment.
How it was tested
I'm pushing this up for PR first as I assume there may be conversation required about this change - I plan on manually testing this primarily against the v4.7.0-beta branch in one of our local repositories to ensure that things run correctly.Updated a local version of the project to 4.7.0-beta and it appears as though this ran successfully. No project changes meant no changes to our docs, but the error no longer throws and we get green. Edit (again): Ran with changes and api-extractor completed successfully in that scenario as well.