-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
fix: make Docusaurus PnP strict mode compatible #6047
Conversation
✔️ [V2] 🔨 Explore the source changes: a700cf1 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/61ab35a4c5711b000749956d 😎 Browse the preview: https://deploy-preview-6047--docusaurus-2.netlify.app |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-6047--docusaurus-2.netlify.app/ |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Kristoffer K. <[email protected]>
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.
Thanks, that's really great to get rid of these cycles!
Just asked a few questions to be sure
@@ -12,17 +12,17 @@ exports[`transformImage plugin pathname protocol 1`] = ` | |||
exports[`transformImage plugin transform md images to <img /> 1`] = ` | |||
"![img](https://example.com/img.png) | |||
|
|||
<img src={require(\\"!url-loader?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=file-loader!./static/img.png\\").default} /> | |||
<img src={require(\\"![CWD]/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[hash].[ext]&fallback=[CWD]/node_modules/file-loader/dist/cjs.js!./static/img.png\\").default} /> |
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.
wonder if this snapshot is normal? What is this new syntax?
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.
It's just require.resolve('url-loader')
+ replacing CWD with placeholder so the absolute path isn't hardcoded in the snapshot
return result.toString(); | ||
return result | ||
.toString() | ||
.replace(new RegExp(posixPath(process.cwd()), 'g'), '[CWD]'); |
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.
I don't understand that part.
Is the goal to make tests insensitive to local FS?
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.
Yes, indeed
@@ -7,7 +7,7 @@ | |||
|
|||
import {PluginOptions, RedirectOption, UserPluginOptions} from './types'; | |||
import {Joi, PathnameSchema} from '@docusaurus/utils-validation'; | |||
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants'; | |||
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils'; |
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.
I was wondering if we shouldn't have a dedicated @docusaurus/constants
package? any thought 🤷♂️ ?
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.
Hmmm, I don't like little packages everywhere... @docusaurus/utils
serves a very clear purpose as a general util to be consumed by any Node code, so I think it makes sense to put server-side constants here
@@ -29,10 +28,12 @@ | |||
"react-live": "2.2.3" | |||
}, | |||
"devDependencies": { | |||
"@docusaurus/core": "2.0.0-beta.9", |
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.
how do you choose if it's needed in devDependencies? If there are tests?
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.
This is a hack so that lerna correctly figures out the dependency graph and builds the core before building those that still implicitly depend on the core's internal APIs (that's still bad, we need to further refactor that)
LGTM 👍 |
Okay, this is slightly problematic 😅 @slorber lerna doesn't seem to bump peerDeps during publish: lerna/lerna#955 this doesn't cause installation errors but still triggers some warnings. Maybe we want to use caret ranges for peerDeps? |
I'm not sure to know what to do here What kind of warning will users have? Will all package managers work? I've seen some tools using React seems to use a fixed version like us for react/react-dom: https://github.com/facebook/react/blob/main/packages/react-dom/package.json 🤷♂️ What is the advantages of using peerDeps in this case compared to what we had before? Does reverting this change prevent the usage of PnP strict mode? (You see, this is exactly why changes like upgrading to Yarn 3 can unexpectedly become a time sink 😄) |
This is for a project on Yarn v3.
This is in our own repo. (The only Docusaurus project on Yarn v1 that I have.) It doesn't prevent PnP; it just makes package managers frown. I haven't seen any of them error. But I know that pnpm is stricter about peer deps and they may be unhappy.
Yes, a fixed peer dependency does make sense; the only problem being that lerna refuses to bump peer dependencies, which I can also sympathize with. Still, we have runtime checks so it's not strictly necessary.
No; I'm fine with reverting back to hard dep. As I said, it's just semantically better because plugins should work in isolation from the core.
It's not about Yarn v3, but exactly about lerna which we hope to ditch in the Yarn v3 migration. Basically, what package manager we use should minimally affect the end users. |
Motivation
Close #2576. This PR did the following changes
getFileLoaderUtils
function fromcore/webpack/utils
to@docusaurus/utils
so that the mdx loader doesn't depend on the core which will cause circular dependencies otherwise.require.resolve
so that all the extra loader dependencies can be safely removed from the init templates.core/constants
to@docusaurus/utils
so that constants are not duplicated.@docusaurus/core
the peer dependency instead of hard dependency of any plugin.Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Tested locally & updated the E2E test script