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

Support resolution with Yarn PnP. #80

Merged
merged 5 commits into from
Jan 7, 2019
Merged

Support resolution with Yarn PnP. #80

merged 5 commits into from
Jan 7, 2019

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Jan 2, 2019

Yarn 1.12.x supports the new PnP system to allow folks to avoid having a node_modules/ folder in each project. To implement this, they create a static file mapping table for each package and then require them directly from the global Yarn cache.

Since a PnP project is no longer following the "normal" node module resolution rules changes were needed in the resolve package. Those changes landed in resolve@1.9.0 and are leveraged by Yarn 1.13.0+.

In the mean time (throughout the Yarn 1.12.x lifespan), a simple resolve.sync isn't quite good enough so we now detect if we are running in a PnP scenario (by attempting to require the pnpapi module). If we are, we use the public API provided by Yarn's pnpapi module to resolve the package being checked for relative to the provided root.

Fixes #78.
Related to ember-cli/ember-cli#8164.

@rwjblue rwjblue requested a review from Turbo87 January 2, 2019 23:45
tests/index.js Outdated Show resolved Hide resolved
src/npm-dependency-version-checker.js Outdated Show resolved Hide resolved
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
if (ALLOWED_ERROR_CODES.includes(e.code)) {
Copy link
Member

Choose a reason for hiding this comment

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

we should probably use debug or heimdall-logger here to make this easier to debug

Copy link
Member Author

Choose a reason for hiding this comment

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

Ya, good point. I'll do that in a separate PR then rebase this one...

@rwjblue
Copy link
Member Author

rwjblue commented Jan 3, 2019

CI failure is due to not running recent enough yarn version in CI. #81 should fix.

@rwjblue rwjblue force-pushed the pnp-support branch 3 times, most recently from 6a17cbf to 83cb1c1 Compare January 3, 2019 15:19
Yarn 1.12.x supports the new PnP system to allow folks to avoid having a
`node_modules/` folder in _each_ project. To implement this, they create
a static file mapping table for each package and then require them
directly from the global Yarn cache.

Since a PnP project is no longer following the "normal" node module
resolution rules changes were needed in the `resolve` package. Those
changes landed in `resolve@1.9.0` and are leveraged by Yarn 1.13.0+.

In the mean time (throughout the Yarn 1.12.x lifespan), a simple
`resolve.sync` isn't quite good enough so we now detect if we are
running in a PnP scenario (by attempting to require the `pnpapi`
module). If we are, we use the public API provided by Yarn's `pnpapi`
module to resolve the package being checked for relative to the provided
root.
@rwjblue
Copy link
Member Author

rwjblue commented Jan 4, 2019

@Turbo87 - no, you are right it was a node 6 issue

@rwjblue rwjblue merged commit f71925a into master Jan 7, 2019
@rwjblue rwjblue deleted the pnp-support branch January 7, 2019 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yarn PnP Support
2 participants