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(expo): use node resolution when invoking @expo/cli from expo #23220

Merged
merged 4 commits into from
Jul 1, 2023

Conversation

byCedric
Copy link
Member

@byCedric byCedric commented Jun 30, 2023

Why

Fixes #23194

We've had reports of package managers being unable to resolve the @expo/cli when executing from the expo package.

I've had a similar experience with pnpm and yarn v1 and workspaces with "noHoist": ["**"]. This should fix some parts of that.

vscode-expo fixtures issue I ran into image

Note
I've tested this in: https://github.com/byCedric/being-productive-can-have-many-reasons/blob/main/ISSUES.md (a repository with fixes required for pnpm). You can clone that repository, and try it yourself. Make sure you always install with pnpm install, because the patches are only set for pnpm.

How

Instead of creating a new process, either through spawnAsync or npm exec, we just execute the @expo/cli in the process of the expo bin.

By letting Node resolve this, it should avoid issues with complex patterns such as isolated modules too.

Test Plan

  • $ yarn create expo ./test-bin -t tabs@beta
  • $ cd ./test-bin
  • $ rm -rf node_modules yarn.lock
  • Any of these commands should work:
    • $ yarn install && yarn expo --help (yarn v1)
    • $ npm install && npx expo --help (any npm version)
    • $ pnpm install && pnpm expo --help (any pnpm version)

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Jun 30, 2023
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Jun 30, 2023
Copy link
Contributor

@EvanBacon EvanBacon left a comment

Choose a reason for hiding this comment

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

will probably reveal a new set of issues related to expo/cli not being in the project, but this seems like a logical next step.

packages/expo/bin/cli Outdated Show resolved Hide resolved

# Forward all arguments to the local CLI (@expo/cli).
npm exec --no-install -- expo-internal "$@"
Copy link
Member

Choose a reason for hiding this comment

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

Are there any other remaining references to expo-internal?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this was the only one within expo. @expo/cli still exports the binary as expo-internal which might still be useful to keep around for dev.

Co-authored-by: James Ide <ide@users.noreply.github.com>
@byCedric
Copy link
Member Author

byCedric commented Jul 1, 2023

will probably reveal a new set of issues related to expo/cli not being in the project, but this seems like a logical next step.

As long as it's a dependency of expo, and expo is installed as project dep, there shouldn't be any. #thepoweroflettingNodedotheresolvework 😄

@byCedric byCedric merged commit 8fc62bb into main Jul 1, 2023
7 checks passed
@byCedric byCedric deleted the @bycedric/expo/fix-cli-resolve-issues branch July 1, 2023 19:36
byCedric added a commit that referenced this pull request Jul 1, 2023
…23220)

# Why

Fixes #23194

We've had reports of package managers being unable to resolve the
`@expo/cli` when executing from the `expo` package.

- #23193
- #23194

I've had a similar experience with pnpm and yarn v1 and workspaces with
`"noHoist": ["**"]`. This should fix some parts of that.

<details><summary>vscode-expo fixtures issue I ran into</summary>

<img width="754" alt="image"
src="https://github.com/expo/expo/assets/1203991/92324113-5a1a-44ae-a573-ba2582c5d2e9">

</details>

> **Note**
> I've tested this in:
https://github.com/byCedric/being-productive-can-have-many-reasons/blob/main/ISSUES.md
(a repository with fixes required for pnpm). You can clone that
repository, and try it yourself. Make sure you always install with `pnpm
install`, because the patches are only set for pnpm.

# How

Instead of creating a new process, either through `spawnAsync` or `npm
exec`, we just execute the `@expo/cli` in the process of the `expo` bin.

By letting Node resolve this, it should avoid issues with complex
patterns such as [isolated
modules](https://github.com/npm/rfcs/blob/main/accepted/0042-isolated-mode.md)
too.

# Test Plan

- `$ yarn create expo ./test-bin -t tabs@beta`
- `$ cd ./test-bin`
- `$ rm -rf node_modules yarn.lock`
- _Any of these commands should work:_
  - `$ yarn install && yarn expo --help` (yarn v1)
  - `$ npm install && npx expo --help` (any npm version)
  - `$ pnpm install && pnpm expo --help` (any pnpm version)

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Co-authored-by: James Ide <ide@users.noreply.github.com>
@byCedric
Copy link
Member Author

byCedric commented Jul 1, 2023

Backported the fix to sdk-49 (cc @brentvatne)

@byCedric
Copy link
Member Author

byCedric commented Jul 3, 2023

This really seems to make expo feel snappier too!

SDK 49 beta 3 (before) SDK 49 Beta 4 (after)
image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about published Changes from the PR have been published to npm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SDK 49 beta] SyntaxError: Invalid or unexpected token with yarn berry
6 participants