Skip to content

fix(core): ensure proper install for git dependency using Yarn classic and npm #4403

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

Merged

Conversation

colincasey
Copy link
Contributor

@colincasey colincasey commented Apr 27, 2022

What's the problem this PR addresses?
When a git dependency is specified that doesn't exist in the yarn cache it will be:

  • cloned to a temporary folder
  • the target package manager used will be detected
  • dependencies will be installed using the target package manager
  • the target package manager will then execute the pack command to create a tarball that can be installed
    • if any pack lifecycle scripts exist (i.e.; prepack, postpack) these will also be executed

If a pack lifecycle script depends on dev dependencies to be installed this process can fail in cases where environment variables like the following are present:

  • NODE_ENV=production (npm and Yarn classic)
  • NPM_CONFIG_PRODUCTION=true (npm)

This process of creating the installable tarball should guarantee that all dependencies are available and not allow environment variables to change what is installed.

How did you fix it?
This can be fixed by removing the environment variables described above from the subprocess spawned to handle the Yarn classic and npm install steps when preparing an external project.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@colincasey colincasey requested a review from arcanis as a code owner April 27, 2022 13:43
Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

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

We'll also need to do this for Yarn classic as well since it has the same behaviour.

@merceyz
Copy link
Member

merceyz commented Apr 29, 2022

Rejected to value: {"externalException": {"message": "Invalid or unexpected token"}}

That error is happening because the content of the file is

'module.exports
=
42;'

@colincasey
Copy link
Contributor Author

thanks @merceyz. i had to add that output temporarily to understand why windows was failing with the syntax error. next commit should sort things out 😅

@colincasey colincasey requested a review from merceyz April 30, 2022 17:22
@merceyz merceyz changed the title fix(core): ensure proper install for git dependency with npm prepack fix(core): ensure proper install for git dependency using Yarn classic and npm Apr 30, 2022
Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

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

Perfect, could you update the description to match the final state of the PR?

@colincasey colincasey requested a review from merceyz April 30, 2022 19:26
Copy link
Member

@merceyz merceyz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@arcanis arcanis merged commit 0c5974f into yarnpkg:master May 6, 2022
@colincasey colincasey deleted the fix/git_dependency_prepack_npm_install branch May 9, 2022 17:59
merceyz added a commit that referenced this pull request May 12, 2022
…c and npm (#4403)

* fix(core): ensure proper install for git dependency with npm prepack

* refactor: don't use variables outside of the test

* test: expect on the part that rejects

* chore: versions

* fix(core): ensure proper install for git dependency with prepack

* fix(core): ensure proper install for git dependency with prepack

* fix(core): ensure proper install for git dependency with prepack

* fix(core): ensure proper install for git dependency with prepack

* fix(core): ensure proper install for git dependency with prepack

* fix(core): ensure proper install for git dependency with prepack

* fix(core): ensure proper install for git dependency with prepack

* chore: style

Co-authored-by: merceyz <[email protected]>
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.

3 participants