question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Support yarn 2's PnP natively in ngcc

See original GitHub issue

šŸš€ feature request

Relevant Package

Mainly @angular/compiler-cli

Description

It is currently impossible to use the ivy renderer in a workspace managed by yarn 2 with the pnp linker, unless using yarnā€™s pnpify command.

There are two blocking issues and one thatā€™s more of a nuisance, all of which can be tackled by angular.

The blockers:

  • ngcc requires the node_modules folder to exist.
  • ngcc uses a custom implementation of the node module resolution algorithm, which is not supported in PnP.

The nuisance:

  • All angular packages that need to be run through ngcc have to be unplugged manually (e.g. yarn unplug @angular/core), as ngcc writes to these package folders.

Iā€™ve created a proof-of-concept repository where @angular/compiler-cli supports PnP natively: https://github.com/bgotink/angular-pnp-ivy-poc

Describe the solution youā€™d like

Native support for pnp in ngcc. I donā€™t necessarily mean any code specific to pnp. A removal of the custom node_modules resolution algorithm and replacing it with calls to require.resolve with the paths option or via module.createRequire should work in all environments.

For the unplugging: the ideal solution (from yarnā€™s point of view) would be to not write to the package folders (see also #33395). Unplugging the packages works fine though, so this is a nuisance rather than a blocker. Angular could help alleviate this a bit by indicating to yarn that the relevant packages need to be unplugged using a "preferUnplugged: true flag in the package.json files. That way developers using angular donā€™t need to worry about unplugging, and if angular ever moves away from writing to the package folders, that flag can be removed and developers will automatically get an improved developer experience when they update. Of course this only applies to angularā€™s own packages. Third party angular libraries will still need to be unplugged (either by having their own package marked as preferUnplugged or by manually unplugging).

The @angular/compiler-cli package also needs to be unplugged because it tries to write a lockfile in its own location. If this could be moved to e.g. node_modules/.cache/ thatā€™d make unplugging no longer necessary. Thatā€™s the same folder used by babel, terser, nyc and others to store their caches in, e.g. using find-cache-dir. Yarn 2 supports this behaviour by explicitly keeping node_modules/.cache folders around (the install command removes any other file or folder in node_modules).

Describe alternatives youā€™ve considered

  • Yarn 2 supports patching installed packages. The repo mentioned in the description contains a patch for @angular/compiler-cli that replaces the custom node module resolution algorithm with calls to require.resolve. Of course itā€™s hardly ideal that packages are patched. This is more of a temporary solution to work around issues until they are patched upstream.
  • Yarn has a pnpify package that, when wrapped around another command, will mock the node_modules folder. This works already, but it introduces overhead. The time difference in building the PoC repo: 2 seconds real time, from 9.84 to 11.85 seconds; 3 seconds user time, from 13.67 to 16.62 seconds. These times are the average of five builds each for yarn ng build and yarn pnpify ng build.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:21
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
petebacondarwincommented, Sep 25, 2020

Yes, we are currently implementing the ā€œlinkerā€ approach set out in the RFC. You can follow progress here https://github.com/orgs/angular/projects/2

4reactions
petebacondarwincommented, Jul 20, 2020

@bgotink - thank you for this detailed and well thought out feature-request. And also for the proof-of-concept - this sort of thing is invaluable.

We are currently looking into the future of ngcc and where we go next to avoid some of the constraints that ngcc has. This may well involve a different strategy that would avoid having to modify published library code in the way that ngcc does right now. We will be publishing our ideas (probably in the form of an RFC) in the near future. So I think it would be better to consider this PR in the light of that, since I would rather focus our efforts on a long term solution rather than continuing to fix up ngcc.

Letā€™s come back to this issue in a few weeks when we are in a position to compare the cost of doing it with the other options on the table.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plug'n'Play | Yarn - Package Manager
Initializing PnP. PnP loose mode. Caveat. Alternatives. Compatibility Table. Native support; Support via plugins; Incompatible. Frequently Asked Questions.
Read more >
How to use Yarn 3 with React Native | by Tom McIntosh
This article will explain what PnP is, why React Native does not support it, and how we can work around this to enjoy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found