-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Build: Move date module to packages maintained by Lerna #6658
Conversation
components/date-time/date.js
Outdated
/** | ||
* WordPress dependencies | ||
*/ | ||
import { moment } from '@wordpress/date'; |
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.
The usage of the regular moment
was intentional here. The idea is that we don't need any locale set, we just use moment as an utility function without global locale. (this avoids a dependency between components
and date
which I think would be nice to keep independent.)
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.
Reverting those changes 👍
I wasn't aware of this. It still would be useful to wrap those moment
calls with some higher level API to make it possible to replace moment
with something else as soon as there is good alternative for it :)
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.
The exporting of moment
from our package strikes me as strange and I'm finding it hard to separate out the package change from it conceptually 😅
The issue with losing package locking is just for our internal dependencies, which are in the repo already, right? If that's the case it's probably fine. 🤷♂️
components/date-time/date.js
Outdated
/** | ||
* WordPress dependencies | ||
*/ | ||
import { moment } from '@wordpress/date'; |
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'm confused about the utility of importing this package from @wordpress/date
when it's already available as a regular dependency. It seems like more stuff we have to manage to export the same API (and if we aren't exposing moment
's exact API we should maybe call it something different). Why do this?
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 agree with this, the idea is that it absorbs the WP locale and timezone settings. But the downside is that this forces us somehow to stay compatible with the current moment version. We should definitely try to remove moment
from the date
module entirely, but let's leave it for a separate PR.
webpack.config.js
Outdated
@@ -123,7 +127,12 @@ const config = { | |||
memo[ name ] = `./${ path }`; | |||
return memo; | |||
}, {} ), | |||
packageNames.reduce( ( memo, packageName ) => { | |||
gutenbergPackages.reduce( ( memo, path ) => { |
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 reason to rename packageName
to path
? It's still just using the packageName
and I like the explicitness of the variable name. Plus it will hopefully discourage someone from including more nested paths.
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 guess it's copy and paste thing. Will fix :)
webpack.config.js
Outdated
packageNames.reduce( ( memo, packageName ) => { | ||
gutenbergPackages.reduce( ( memo, path ) => { | ||
const name = camelCaseDash( path ); | ||
memo[ name ] = `./packages/${ path }`; |
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.
should we add an src
folder here (and move the files) ./packages/${ path }/src
to match the packages repository setup?
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 have it locally, need to push. I thought the same when I saw diff on GitHub :)
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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 believe this is lacking the main/module
configs to make the modules ready for npm. This would probably have an impact on the webpack config (separate dist folder) than the one currently used for the remaining modules
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.
Which brings us back to having a dedicated build folder per package maybe 🤷♂️
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 seems like we need to have independent build folders for npm, because we use very specific Webpack config which does some additional work like exposing wp.
globals. We also need to expose two version:
- es5 friendly
- import/export friendly
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've always found a dedicated build folder much easier to grok when I first explore a package
it's for |
Maintaining both, manually, if that is what is required would be my suggestion, the latest npm releases heavily depend on lock files when installing, so either no lock file, or an up to date lock file is pretty much required. |
Let's try to keep lock file as it is and maintain duplicates. If this is too much hassle we can always use package linter we are about to roll out for packages repository :) |
"lerna": "2.11.0", | ||
"commands": { | ||
"publish": { | ||
"message": "chore(release): publish %s" |
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 the packages are going to be independently released as they are currently with the packages repo the %s
here will be ignored and should be dropped here, see https://github.com/lerna/lerna#--message--m-msg
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 thought we keep one version aligned with Gutenberg release version. I need to collect all my thoughts and move to description :)
So the idea I had is that every time we publish a new version of the plugin to .org, we publish also the same version of npm packages. We will have to revisit after 5.0 mission is accomplished.
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, makes sense 👍
On the %s
issue, did you run lerna init
with the --independent
flag? If so %s
will be ignored, I'll take a closer look tomorrow, its a pretty minor thing that we will see if it is or is not when lerna publish
is run for th first time 😏
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.
lerna init
only :)
Now's a good time to add a |
return settings; | ||
} | ||
|
||
function setupWPTimezone() { |
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'd love to get rid of moment config entirely and just export simple functions but let's do this separately. The date module is still usable in a generic way using get/setSettings
at the moment
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.
We can now remove all those date
related logic from the default Jest config. I will take care of it separately.
"pot-to-php": "./bin/pot-to-php.js", | ||
"publish:check": "lerna updated", | ||
"publish:dev": "lerna publish --npm-tag next", | ||
"publish:prod": "lerna publish", |
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.
Adding docs to the RELEASE.md would be good (or contributing) to explain how to use these things :), could be done later once the config is more battle-tested.
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.
Copied https://github.com/WordPress/gutenberg/blob/37a722322327ee45f0510e0c7fa9a2ec2f793db2/CONTRIBUTING.md#releasing-packages from the existing docs in WordPress/packages
:)
Props to @youknowriad and @pento 🙇
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.
What process do you propose we adopt for cutting releases? |
@aduth, I briefly described it as follows:
To expand on it, once this PR is merged, we publish |
19de1fa
to
37a7223
Compare
See: lerna/lerna#850 (comment)
Let's test it in |
So not SemVer ? |
Not using SemVer is a 👎 from me; it makes it difficult to consume the packages and make sense of changes, which is the point of doing releases 😄 |
This is what the cause of breaking SemVer would be due to, by setting this configuration option in Lerna every package in this repo would use the same version, but this doesn't have to mean semantic versioning is not used. Rather, it would add SemVer to the Gutenberg releases, so if there is a breaking API change made later today, then the next release of Gutenberg would be The alternative with Lerna is to use the |
That makes the most sense to me; Gutenberg's versioning is not SemVer, but we shouldn't condemn our packages to the same fate 😉 |
Let's fly with |
37a7223
to
8f022b8
Compare
"packages": [ | ||
"packages/*" | ||
], | ||
"version": "independent" |
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'm merging this PR in the current shape with the intention to the follow-up work:
|
Description
Related issues: #3955, #6594.
This PR tries to provide Lerna setup similar to what we have in
WordPress/packages
. This would allow publishing source code of individual modules to npm to make them available for all plugin developers.I started small with the
date
module to start the discussion.The version number would be maintained in Lerna config instead of
package.json
. So the idea I had is that every time we publish a new version of the plugin to .org, we publish also the same version of npm packages. We will have to revisit after 5.0 mission is accomplished.In the first iteration, we would release
date
with2.8-alpha
version as a development release. Once it is confirmed it works as expected, and we havebuild
andbuild-module
distributions we could switch to regular releases.Issues discovered
We are using
package-lock.json
for Gutenberg. I disabled it fordate
package because it isn't required there at all. However when using--hoist
flag with Lerna (to avoid duplicatednode_modules
) I noticed thatpackage-lock.json
doesn't get dependencies from packages included in the lock flag. To mitigate it I had to duplicate the same dependencies in both package and rootpackage.json
file. Question is if we should maintain it in both places or is fine to have it outside of lock file control?How has this been tested?
Manually:
node_modules
folder.npm install
npm test
npm run dev
npm run build
npm run package-plugin
New commands introduced:
npm run publish:check
npm run publish:dev
npm run publish:prod
It mirros what we have in
WordPress/packages
.Types of changes
Refactoring.
Checklist: