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

feat(cli): add monorepo and Yarn PnP support #1418

Merged
merged 7 commits into from
Apr 13, 2021

Conversation

merceyz
Copy link
Contributor

@merceyz merceyz commented Sep 13, 2020

What kind of change does this PR introduce?

bugfix, feature

Did you add tests for your changes?

Added an e2e test that will test preact-cli for undeclared dependencies and incorrect assumptions about the node_modules layout using Yarn PnP's strict dependency checks.

Summary

preact-cli doesn't work with Yarn PnP and monorepos using node_modules due to its incorrect assumptions about the node_modules layout, various undeclared dependencies, and not resolving dependencies it provides.

Fixes #1046
Fixes #1105
Fixes #1043

Does this PR introduce a breaking change?
No

Other information

N/A

@merceyz merceyz requested a review from a team as a code owner September 13, 2020 23:33
@changeset-bot
Copy link

changeset-bot bot commented Sep 13, 2020

🦋 Changeset detected

Latest commit: d9df4d7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
preact-cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@merceyz merceyz force-pushed the pnp branch 5 times, most recently from 02be2b9 to 8d78546 Compare September 14, 2020 00:18
@merceyz merceyz marked this pull request as draft September 15, 2020 06:39
@merceyz merceyz marked this pull request as ready for review September 15, 2020 21:43
@prateekbh
Copy link
Member

This is awesome. Thanks @merceyz .
Can you add a test case where one of the pages uses any hook? Thats where i guess this broke earlierr

@merceyz merceyz force-pushed the pnp branch 3 times, most recently from 4c0399d to ae12eaf Compare September 16, 2020 15:58
@merceyz
Copy link
Contributor Author

merceyz commented Sep 16, 2020

Can you add a test case where one of the pages uses any hook? Thats where i guess this broke earlierr

In normal repos the behaviour should be the same, and hopefully already covered by tests

@merceyz merceyz force-pushed the pnp branch 2 times, most recently from 09e56c4 to a83f767 Compare January 9, 2021 15:06
Comment on lines -97 to -105
let modules = resolve(cwd, 'node_modules');

if (!isDir(modules)) {
return error(
'No `node_modules` found! Please run `npm install` before continuing.',
1
);
}

Copy link
Contributor Author

@merceyz merceyz Jan 9, 2021

Choose a reason for hiding this comment

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

When run in a monorepo where the hoisting is good this folder wont exist so checking if the project is installed like this is not correct

@ljharb
Copy link

ljharb commented Jan 9, 2021

Note that adding peer deps is a breaking change, even when optional, for clients that don’t support optional peer deps - which includes most of npm 6, and some versions of yarn.

@merceyz merceyz changed the title feat(cli): add Yarn PnP support feat(cli): add monorepo and Yarn PnP support Jan 9, 2021
@merceyz merceyz force-pushed the pnp branch 3 times, most recently from 4f2dbeb to 8c95b73 Compare January 9, 2021 16:34
@merceyz
Copy link
Contributor Author

merceyz commented Jan 9, 2021

Note that adding peer deps is a breaking change, even when optional, for clients that don’t support optional peer deps - which includes most of npm 6, and some versions of yarn.

@ljharb To prevent old package managers from freaking out while letting newer package mangers know about them Yarn and pnpm (unsure about npm) supports just setting peerDependenciesMeta.optional, so the entries in peerDependencies can be removed if that's what the Preact team wants

@ljharb
Copy link

ljharb commented Jan 9, 2021

@merceyz yes, i'm saying that support for peerDependenciesMeta itself isn't in older versions of yarn, pnpm, or npm, which makes it a breaking change, because prior to peerDependenciesMeta.optional, all peer deps are and have always been required.

You can mitigate this by adding engines entries for yarn and npm (and pnpm, i suppose) - but doing so is also a breaking change.

@merceyz
Copy link
Contributor Author

merceyz commented Jan 9, 2021

@merceyz yes, i'm saying that support for peerDependenciesMeta itself isn't in older versions of yarn, pnpm, or npm, which makes it a breaking change, because prior to peerDependenciesMeta.optional, all peer deps are and have always been required.

I know, that's why I said only specifying that field is the solution to that problem

[...] just setting peerDependenciesMeta.optional, so the entries in peerDependencies can be removed if that's what the Preact team wants

@ljharb
Copy link

ljharb commented Jan 9, 2021

I’m under the impression that peer deps are invalid if they are only listed in peerDependenciesMeta - Meta is a modifier, not a declaration.

@merceyz
Copy link
Contributor Author

merceyz commented Jan 9, 2021

Yarn and pnpm (again, unsure about npm) treats them as an implicit peer dependency to allow projects to declare their dependencies without messing with older package managers

@sumanthratna sumanthratna mentioned this pull request Mar 16, 2021
18 tasks
@ForsakenHarmony ForsakenHarmony merged commit 4b81641 into preactjs:master Apr 13, 2021
@preact-bot preact-bot mentioned this pull request Apr 13, 2021
@merceyz merceyz deleted the pnp branch April 13, 2021 20:24
@osdiab
Copy link

osdiab commented Apr 20, 2021

I can really use this at the moment - any idea when the next preact-cli release to npm might be released? thanks!

@rschristian
Copy link
Member

This breaks the getLoadersByName helper as loaders will now have their full path in the file system as the name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants