Skip to content
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(sys): tweak NodeLazyRequire logic around too-high-versions errors #3347

Merged
merged 2 commits into from
Apr 28, 2022

Conversation

alicewriteswrongs
Copy link
Contributor

This changes the logic that we use in the NodeLazyRequire class to
error out in fewer situations. The changes are:

  • the data structure for specifying our version ranges is changed from
    [string, string] ([minVersion, recommendedVersion]) to an object
    with minVersion recommendedVersion required properties and an
    optional maxVersion property.
  • in the ensure method on NodeLazyRequire we check if maxVersion
    is defined on a given version range requirement.
    • If so, we check that the installed version is greater than or
      equal to minVersion and less than the major version of
      maxVersion.
    • If not, we just check that minVersion <= installedVersion

This should give us the flexibility to mark certain versions of packages
as incompatible (for instance jest@28) without having to do that for all
packages that we lazy require. This is helpful because for most of them
we just want to set a minimum version and don't have a need for an
enforced maximum version.

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Unit tests (npm test) were run locally and passed
  • E2E Tests (npm run test.karma.prod) were run locally and passed
  • Prettier (npm run prettier) was run locally and passed

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

GitHub Issue Number: N/A

In #3346 we added a check that packages that we lazy require for testing and whatnot (basically, jest and a few other things) were between the specified minimum version and the recommended version. This will cause an error at runtime if these requirements are not met.

On further reflection this isn't quite the behavior that we want. We only want to enforce a maximum version right now for Jest, not for the other packages we load in this manner, but the implementation in #3346 doesn't have any granularity to it.

What is the new behavior?

  • the data structure for specifying our version ranges is changed from
    [string, string] ([minVersion, recommendedVersion]) to an object
    with minVersion recommendedVersion required properties and an
    optional maxVersion property.
  • in the ensure method on NodeLazyRequire we check if maxVersion
    is defined on a given version range requirement.
    • If so, we check that the installed version is greater than or
      equal to minVersion and less than the major version of
      maxVersion.
    • If not, we just check that minVersion <= installedVersion

This should give us the flexibility to mark certain versions of packages
as incompatible (for instance jest@28) without having to do that for all
packages that we lazy require. This is helpful because for most of them
we just want to set a minimum version and don't have a need for an
enforced maximum version.

Does this introduce a breaking change?

  • Yes
  • No

Testing

Unit testing, I also built and tried this out in a test component repo and confirmed that we get errors for Jest but not for other dependencies like puppeteer.

Other information

This changes the logic that we use in the `NodeLazyRequire` class to
error out in fewer situations. The changes are:

- the data structure for specifying our version ranges is changed from
  `[string, string]` (`[minVersion, recommendedVersion]`) to an object
  with `minVersion` `recommendedVersion` required properties and an
  optional `maxVersion` property.
- in the `ensure` method on `NodeLazyRequire` we check if `maxVersion`
  is defined on a given version range requirement.
    - If so, we check that the installed version is greater than or
      equal to `minVersion` and less than the major version of
      `maxVersion`.
    - If not, we just check that `minVersion <= installedVersion`

This should give us the flexibility to mark certain versions of packages
as incompatible (for instance jest@28) without having to do that for all
packages that we lazy require. This is helpful because for most of them
we just want to set a minimum version and don't have a need for an
enforced maximum version.
@alicewriteswrongs alicewriteswrongs requested a review from a team April 28, 2022 17:46
Comment on lines +17 to +22
/**
* Max version is optional because we aren't always worried about upgrades.
* This should be set for packages where major version upgrades have
* historically caused problems, or when we've identified a specific issue
* that requires us to stay at or below a certain version. Note that
* `NodeLazyRequire.ensure` only checks the major version.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍 👍

src/sys/node/node-lazy-require.ts Outdated Show resolved Hide resolved
@rwaskiewicz rwaskiewicz merged commit 9bfef1a into main Apr 28, 2022
@rwaskiewicz rwaskiewicz deleted the ap/lazy-version-tweak branch April 28, 2022 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants