-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add missing package dependencies #55178
base: trunk
Are you sure you want to change the base?
Conversation
Build code transformations can introduce dependencies on packages such as `react` and `@babel/runtime`. These need to be declared if the package is to function correctly with yarn's p'n'p or pnpm with hoisting disabled. After WordPress#54494, `@wordpress/icons`, `@wordpress/interactivity`, and `@wordpress/react-i18n` are now lacking peer dependencies on react. `@wordpress/interactivity` also appears to be lacking a dependency or peer dependency on `@babel/runtime`. Fixes WordPress#55171
It looks good for |
Indeed, Why does it need |
See the file defined as the main entry point in package.json: https://unpkg.com/@wordpress/interactivity@2.4.0/build/index.js There is the following line: var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); |
This is also an interesting example: https://unpkg.com/browse/@wordpress/interactivity@2.4.0/build-module/hooks.js The first line is: import { createElement } from "react"; |
This is typical for files transpiled by Babel. Many transforms use a helper function, and either a copy of that helper function is pasted into each transpiled file, leading to hundreds of copies, or it's imported from a runtime package. There is a
That's certainly a bug, probably a regression introduced by #54494. This import is auto-inserted by the JSX transform. For interactivity files, the transform should be configured to import from |
That's what we are doing, so it looks like a bug. I'll take a look. https://github.com/WordPress/gutenberg/blob/trunk/tools/webpack/interactivity.js#L45-L46
Ok. It looks like we could avoid default exports then, although we will move to modules in the near future, so those webpack runtime patches won't be necessary: https://unpkg.com/browse/@wordpress/interactivity@2.4.0/build-module/index.js |
https://github.com/WordPress/gutenberg/blob/trunk/tools/webpack/interactivity.js#L45-L46 I think this should override |
Ok. This problem was not introduced in #54494 because previous to that, the This is what is happening: Gutenberg is doing two transpilation passes. The first one generates the We're ignoring the build folders for the So we are generating the bundle using the module.exports = {
...baseConfig,
entry: {
index: {
import: `./packages/interactivity/src/index.js`, That also explains why there's not When I was integrating the private version of the resolve: {
alias: {
'@wordpress/interactivity': normalizeJoin( baseDir, 'node_modules/@wordpress/interactivity/src/index.js' ),
},
}, As I'm currently working on migrating this package to ES modules, I don't think it makes sense to improve how things work today in this regard. So feel free to add the I'll make sure to refactor all this once this package is using only ES modules. |
That doesn't feel ideal to me. I think core and Gutenberg should consume the package in the exact same way any third party application does. |
I agree, but I don't think that it makes sense to do this work now because I have started working on the ES module migration so the bundling configuration will change. I'll make sure to fix this before the package is publicly available. |
Looks like in that case #54494 changed the problem from "missing Anyway, if you all want to update this PR once you've figured out what exactly needs updating for So far it's only |
What?
Add missing peer dependencies of
@wordpress/icons
,@wordpress/interactivity
, and@wordpress/react-i18n
onreact
.Add missing dependency of
@wordpress/interactivity
on@babel/runtime
.Why?
Build code transformations can introduce dependencies on packages such as
react
and@babel/runtime
. These need to be declared if the package is to function correctly with yarn's p'n'p or pnpm with hoisting disabled.Fixes #55171
How?
Adding the missing dependencies. Normally I'd probably have done the
@babel/runtime
dep as a peer dep, but I see you use a normal dependency everywhere else so I followed along.Testing Instructions
yarn add <package>@file:/path/to/gutenberg/packages/<package>
orpnpm add <package>@file:/path/to/gutenberg/packages/<package>
to point yarn or pnpm at the locally built version of the package.