-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Declare singleton-ish packages as peer dependencies #26954
Conversation
89e6408
to
9340e51
Compare
Size Change: 0 B Total Size: 1.19 MB ℹ️ View Unchanged
|
"@wordpress/dom-ready": "file:../dom-ready" | ||
}, | ||
"peerDependencies": { | ||
"@wordpress/i18n": "^3.16.0" |
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 to make sure I understand properly, when we work locally on the repo, these will use the local versions right and not install things from npm registry?
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.
Because @wordpress/i18n
is already declared in the root package.json
as a file:package/i18n
link, there will be a symlink to packages/i18n
in node_modules/@wordpress/i18n
. The package from NPM registry will never be installed there, because that would directly contradict what the root package.json
says.
NPM 6 (and also Yarn) will never try to install any peer dependency. It only checks if someone else installed it into node_modules
already, and will check that the semver matches. And because the package is required by the root package.json
, and the version
field in the symlinked package's package.json
matches, it will be happy.
NPM 7 will also find the dependency satisfied by the symlink in root node_modules
.
Only if we removed the i18n
dependency from the root package.json
(or forgot to add a new package there), that's the only case where unwanted things can happen. NPM 6 will issue a warning that peer dependency was not found. And NPM 7 will install it into root node_modules
from the NPM registry.
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.
Is the intention to allow only the same major version of peer dependencies?
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, in this case, the a11y
package uses the 3.16
version of the i18n
API. 3.15
probably lacks some feature that we make use of, so it's not compatible. Version 2
could have completely different API that is not compatible, and 4
might also break everything.
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.
Any thoughts on how this impacts the release package process?
While working on this PR and auditing the dependencies, I found some React Native components that should probably be in other packages:
|
That's something to figure out. I have limited knowledge about how even the existing release process works. For example, @gziolo recently released a few packages in 3523f7e. How did you know that Peer dependencies should not be bumped automatically whenever a new version of the package is released. Bugfix/patch releases never need a peer bump. If a package declares dependency on And if there is a minor release with new features, consumers should bump the peer dependency only if they really use the new API and can't work with the older version. Bumping the peer dependency means a major version bump for the consumer. Just like many NPM packages release a major version just because they removed support for old versions of Node.js. This "package new API -> consumer major release" transition could have a ripple effect through several packages, triggering many major updates in one release cycle. |
Thank you @jsnajdr for opening this proposal. It's a lot to process in terms of publishing packages. I'll do my best to explain but it might require some follow-ups 😅
In this particular case, I might selected version bumps manually as it was a bug fix release 😄 Usually, it's automated. There is a very naive implementation that picks version bumps for modified packages based on entries in gutenberg/bin/plugin/commands/packages.js Lines 113 to 155 in 9db42e0
The same script also updates gutenberg/bin/plugin/commands/packages.js Lines 218 to 226 in 9db42e0
In general, it seems like it could be extended to update also
It might be really difficult to verify if a new API is used in the package. It would be also problematic when during the release I think it's essential to have a way to automate peer dependencies updates because otherwise, they won't be very useful when consuming packages from npm. |
Indeed, I addressed this in a PR which targets this branch: #26969
About |
Had a look at |
Hey there 👋
For the components |
Hello everyone. What is the next step for this PR? |
@paaljoachim I think the next step is here is to upgrade Gutenberg to NPM 7 which has a better algorithm for installing peer dependencies. This comment contains a detailed analysis of how NPM 6 and 7 and Yarn work with peer deps: #8981 (comment) |
Thank you @jsnajdr Jarda. I will ping @ockham and @noahtallen and let them know about this PR. |
My understanding is that PR prevents a wild uncontrolled upgrade to npm 7 rather than intending to stay on 6 for a prolonged period of time. If you wanted to point out that npm should be spelled in all lowercase -- thank you, I didn't know that and was always little bit confused when typing the three letters 🙂 Now I know that npm is just like webpack -- no capital letters. |
@jsnajdr that's a good reflection, but I think the PR is trying to downgrade npm version to 6 to avoid failures with installing dependencies for Gutenberg when using npm 7 😄 |
@gziolo The @paaljoachim's comment originally linked to this specific comment: #29204 (comment) That's why I was not sure if it's about npm 6 or about spelling 😄 |
Is this still something we want to do? Probably better to close the PR and reopen if needed anyway? |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @Tug. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
I think this is still a desirable thing to do, but the actual diff is hopelessly outdated. It will be easier to create it from scratch than trying to rebase the existing one. Back in 2020 we were still using old Node 14 and NPM 6, nowadays |
Implements proposal from #8981 that declares singleton-ish packages as peer dependencies, to make consumers'
node_modules
trees easier to maintain and less prone to package duplication. Which, in case of singletons inside packages, leads to broken apps.Any package that contains a singleton is eligible:
data
: has the store registry andregisterStore
method.i18n
: stores translations set withsetLocaleData
and consumed with__
et al.hooks
: has registry of filters and actions, methods to register and apply them.rich-text
: registers thecore/rich-text
store that contains registry of format types.plugins
: has registry of plugins andregisterPlugin
,unregisterPlugin
methods.edit-post
: exposes API for plugins like thePluginPrePublishPanel
slot that plugins can fill.block-editor
: registers and exposes thecore/block-editor
store.blocks
: exposes thecore/blocks
store.editor
: exposes thecore/editor
store and also statically registers hooks and loops throughcore/blocks
to callshimAttributeSource
notices
: exposes thecore/notices
store.core-data
: exposes thecore
data store.reusable-blocks
: exposes acore/reusable-blocks
that manages theisEditingReusableBlock
flags for the reusable block editor.keyboard-shortcuts
: exposes thecore/keyboard-shortcuts
store where component can register these.interface
: exposes thecore/interface
store that manages enabled/disabled state for sidebar items.viewport
: exposes thecore/viewport
store that watches the browser viewport and fires change events to subscribers.As peer dependencies need to be declared with version numbers instead of
file:
links that Lerna would automatically replace, I used the latest version in the repo for each declaration.In future, we'll need to be more careful about maintaining the semver versions of each package whenever a new API is added, maintaining the
CHANGELOG.md
files (many are neglected and many versions behind), and about tracking which dependent packages are using the new API, updating the peer dependencies and semver versions accordingly.