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

[build-tools] use frozen lockfile for node modules install for SDK 52+ and RN 0.76+ #463

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

szdziedzic
Copy link
Member

@szdziedzic szdziedzic commented Nov 12, 2024

Why

https://exponent-internal.slack.com/archives/C02123T524U/p1731420965266849?thread_ts=1731420501.834709&cid=C02123T524U
https://exponent-internal.slack.com/archives/C02123T524U/p1731421835879399

We want to use frozen lockfile when installing node_modules on our CI.

How

Enable using frozen lockfile for SDK 52+ and RN 0.76+ in the install node modules phase.

Check for EAS_NO_FROZEN_LOCKFILE env var to skip using frozen lockfile if set.

Don't use frozen lockfile after prebuild as prebuild can sometimes modify the package.json.

Test Plan

Test locally

Copy link
Member Author

szdziedzic commented Nov 12, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

@szdziedzic szdziedzic marked this pull request as ready for review November 12, 2024 17:30
@@ -44,7 +44,7 @@ export async function installNodeModules(
if (packageManager === PackageManager.PNPM) {
args = ['install', '--no-frozen-lockfile'];
Copy link

Choose a reason for hiding this comment

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

question: do we need add frozen-lockfile in this installNodeModules.ts?

Comment on lines +32 to +35
((!!sdkVersionFromPackageJson && semver.satisfies(sdkVersionFromPackageJson, '>=52')) ||
(!!reactNativeVersionFromPackageJson &&
semver.satisfies(reactNativeVersionFromPackageJson, '>=0.76')))
);
Copy link

Choose a reason for hiding this comment

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

the logic looks complicated. maybe refactor some logic out to a function

  const shouldUseFrozenLockfile = Boolean(
    !withoutFrozenLockfile &&
    !ctx.env.EAS_NO_FROZEN_LOCKFILE) ?? useDefaultFrozenLockfile(packageJson);
    
  function useDefaultFrozenLockfile(packageJson: string): boolean {
    const sdkVersion = semver.coerce(packageJson?.dependencies?.expo)?.version;
    const reactNativeVersion = semver.coerce(
      packageJson?.dependencies?.['react-native']
    )?.version;
    if (!sdkVersion || sdkVersion.major < 52) {
      return false;
    }
    if (!reactNativeVersion || reactNativeVersion.major < 76) {
      return false;
    }
    return true;
  }

passing packageJson to the function and we can also save a little time without doing semver parsing when EAS_NO_FROZEN_LOCKFILE=true.

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