yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.34k stars 1.1k forks source link

[Feature] Support `yarnclean` functionality via resolutions or config #1629

Open darthtrevino opened 4 years ago

darthtrevino commented 4 years ago

Describe the user story

Some important dependencies have malformed dependency lists and bring in transitive packages that can break builds. The example I have in mind is @types/styled-components, which brings in @types/react-native, which clashes with DOM typings built into TypeScript.

In Yarn v1, I could add @types/react-native to .yarnclean, and that dependency would not be be installed. This only makes a single repository work though.

Describe the solution you'd like

Perhaps there's a way to block dependencies from being included in the current package and downstream dependencies

e.g.

"dependencies": {
   "@types/styled-components": "^5.3.1",
},
"resolutions": {
   "@types/react-native": null
}

or

"dependencies": {
   "@types/styled-components": "^5.3.1",
},
"excludeDependencies": ["@types/react-native"]

Describe the drawbacks of your solution

An extension like this would be yarn-specific, and npm clients would still have that extension drawn into their workspace.

Additional context

https://github.com/DefinitelyTyped/DefinitelyTyped/issues/33015

merceyz commented 4 years ago

I guess you could try with aliasing it to the normal react types.

"resolutions": {
  "@types/react-native": "npm:@types/react@*"
},

Is this a problem in both PnP and node_modules or?

darthtrevino commented 4 years ago

My personal use case is with node_modules, but this affects both linkers. Edit: that workaround did not effectively remove @types/react-native

merceyz commented 4 years ago

My personal use case is with node_modules, but this affects both linkers.

Assumed the PnP linker would scope it to just @types/styled-components but I guess it overwrites the global interfaces

Edit: that workaround did not effectively remove @types/react-native

I didn't write it correctly, updated, try again please

darthtrevino commented 4 years ago

Tried the update, no effect

merceyz commented 4 years ago

Do you have a reproduction for that? Setting that resolution and running yarn add @types/react-native shows that node_modules/@types/react-native contains the source for @types/react

darthtrevino commented 4 years ago

https://github.com/darthtrevino/yarn-berry-1629

I do see that if I move the "resolutions" field to the top-level monorepo root, then that does what you're suggesting. I'll try that out in my app

merceyz commented 4 years ago

I do see that if I move the "resolutions" field to the top-level monorepo root, then that does what you're suggesting

Yes, resolutions only work from the the root package.json, Yarn also tells you this when you run an install

$ yarn
➤ YN0000: ┌ Validation step
➤ YN0057: │ a: Resolutions field will be ignored
➤ YN0000: └ Completed
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 0.16s
darthtrevino commented 4 years ago

lol, derp - I must've missed that

darthtrevino commented 4 years ago

The workaround did work in my projects - it's not the most straightforward of configs, but it lets me use the types I want to use. I'll leave this issue open as a suggestion for more direct approaches to problems like that