-
Notifications
You must be signed in to change notification settings - Fork 405
Better support for Yarn workspaces #1225
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
Conversation
988136b to
a22809e
Compare
|
@sghoweri @bmuenzenmeyer
patternlab-node/packages/core/src/lib/loaduikits.js Lines 55 to 60 in 831c8b0
In Yarn v2, you can only load dependencies which are explicitly in your If I do it this way, am I covering the same behaviour then? |
yes all future work should read the config explictly and look for those only - the |
|
@bmuenzenmeyer I moved my resolver code from the I don't understand what I'm missing. Any idea? |
e0cdb11 to
201014d
Compare
|
@bmuenzenmeyer in commit 04df565, you can see the rewritten version to load the uikits. Without too much effort, the |
JosefBredereck
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When those 3 things are resolved or clearified. I'm appy to approve this PR.
| if ('package' in uikitConfig) { | ||
| try { | ||
| uikitLocation = resolvePackageFolder(uikitConfig.package); | ||
| } catch (ex) { | ||
| logger.warning( | ||
| `Could not find uikit with package name ${uikitConfig.package}. Did you add it to the 'dependencies' section in your 'package.json' file?` | ||
| ); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide an example patternlab-config.json for that or change the given ones. The user shouldn't get warnings for a freshly installed pattern-lab after we merge this.
Most Important
- packages/core/patternlab-config.json (used within getDefaultConfig)
- packages/edition-node/patternlab-config.json
- packages/edition-node-gulp/patternlab-config.json
- packages/edition-twig/patternlab-config.json
Less Important or Internal
- packages/core/test/util/patternlab-config.json
- packages/cli/test/fixtures/patternlab-config.json
- packages/development-edition-engine-handlebars/patternlab-config.json
- packages/development-edition-engine-react/patternlab-config.json
- packages/development-edition-engine-twig/patternlab-config.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/core/test/util/patternlab-config.json is left as is intentionally because it is used in the tests for checking the warning messages.
Question back: packages/development-edition-engine-react/patternlab-config.json doesn't have a uikits block, but does point to ./node_modules/@pattern-lab/uikit-workshop files inside the paths section. With my change, this won't work in Yarn v2. I don't know if this is anything specific to React but I would need some help here on what to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave it out then. I'm not shure which engines are used anymore. Some feel depreacated / outdated anyway.
| const resolveFileInPackage = (packageName, ...pathElements) => { | ||
| return require.resolve(path.join(packageName, ...pathElements)); | ||
| }; | ||
|
|
||
| /** | ||
| * @func resolveDirInPackage | ||
| * Resolves a file inside a package | ||
| */ | ||
| const resolveDirInPackage = (packageName, ...pathElements) => { | ||
| return path.dirname(resolveFileInPackage(packageName, ...pathElements)); | ||
| }; | ||
|
|
||
| /** | ||
| * @func resolvePackageFolder | ||
| * Resolves the location of a package on disc | ||
| */ | ||
| const resolvePackageFolder = packageName => { | ||
| return path.dirname(resolveFileInPackage(packageName, 'package.json')); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question for this. The whole concept is working without process.cwd() is that correct?
When it tries to resolve the given files/directories it will walk from the resolver location through the filesystem or where would it start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Patternlab loads files from installed NodeJS packages. It starts loading via whatever resolver a package manager could configure inside the Node runtime. In my case, I want to support Yarn v2 with PnP active eventually. In such a setup, no node_modules folder is used at all and every package is stored as a zip file. Here is an example how files inside a package are to be found:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it does not interfere with other resolvers like npm or yarn v1 everything is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JosefBredereck if uikit resolution works via require.resolve, the updated code ought to work under any other setup. If it doesn't it is a bug and needs to be fixed, which I'm glad to provide a fix for.
|
Also, you will need to update the branch from |
|
@JosefBredereck will process your requests next week. I'm on holiday this week. ;-) |
7ed5244 to
e694c37
Compare
e694c37 to
4b18d43
Compare
|
@JosefBredereck can you review again? Please focus on the
so these also use the new resolver instead of calculating paths into |
JosefBredereck
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good changes. Also, I like that you keep the old way in place and notify the user to update the config.
Closes: #1136
The code has too many places where locations are calculated into a package inside the
node_modulesfolder. The assumption is made here that the thenode_modulesfolder is in the current working directory (process.cwd()). But with Yarn workspaces, this is not always the case: thenode_modulescan be one or two levels higher in the folder structure.Summary of changes:
require.resolve.