-
Notifications
You must be signed in to change notification settings - Fork 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
Framework: Add lerna to publish @automattic/simple-components (Take Two) #24788
Conversation
5ab80af
to
c76a26b
Compare
lerna.json
Outdated
@@ -0,0 +1,7 @@ | |||
{ | |||
"lerna": "2.0.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.
2.11.0
according to package? (latest version)
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 spot!
package.json
Outdated
"docker": "docker run -it --name wp-calypso --rm -p 80:3000 wp-calypso", | ||
"env": "cross-env-shell NODE_PATH=$NODE_PATH:server:client:.", | ||
"eslint-branch": "node bin/eslint-branch.js", | ||
"install-if-deps-outdated": "node bin/install-if-deps-outdated.js", | ||
"install-if-no-packages": "node bin/install-if-no-packages.js", | ||
"postinstall": "npx lerna bootstrap --hoist", |
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.
Maybe we should move it to prebuild
...
would this still work with greenkeeper? greenkeeperio/greenkeeper#139 |
This looks promising: greenkeeperio/greenkeeper#139 (comment) |
c6d7b65
to
8b44db8
Compare
d77849b
to
d588545
Compare
I'm not sure we want to publish untranspiled code, ever. That pushes the burden of transpiling and the associated babel config down to a client, who may be running a different version of babel with different presets. I think publishing es5 with modules is likely fine, this is what lodash and a bunch of others are doing with the |
client/components/package.json
Outdated
"version": "0.1.0-alpha.5", | ||
"description": "React components, as used on WordPress.com", | ||
"scripts": { | ||
"build": "npx babel --only ./index.js,./button/,./main/ --out-dir cjs .", |
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.
with the babel 7 beta 53 upgrade, this is going to get more complicated. babel will now pull the config from the root of the repo, in babel.config.js
instead of looking for the closest .babelrc.js
. So far we don't have a .babelrc.js
, but we may want one.
How does this package handle polyfills? We're generating them at the entry point in calypso, but for a package like this, we probably want them polyfill'd at the usage point? Or not at all and we require the client to polyfill what we need?
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 does this package handle polyfills?
Badly 😆 Just been struggling with the following error
ERROR in ./client/boot/polyfills.js
Module not found: Error: Can't resolve 'core-js/modules/es6.array.sort' in '~/src/wp-calypso/client/boot'
So yeah, generating at entry point is probably the least desirable...
Or not at all and we require the client to polyfill what we need?
That seems kinda reasonable...
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 filed #26094 which should fix the polyfill issue.
client/components/package.json
Outdated
], | ||
"dependencies": { | ||
"classnames": "2.2.6", | ||
"lodash": "4.17.10", |
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 we make sure these don't get out of sync with calypso proper? They should probably be ^
revs like ^4.17.10
, as this is a library, not an app.
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 could use a wrapper script that makes sure versions are identical across Calypso + modules during pre-push.
Idea from:
https://github.com/wix/lerna-script/tree/master/tasks/modules & https://youtu.be/MCOmdxJ6qTU
89043a2
to
aaf4c51
Compare
There's a precedent in several npm packages to publish with multiple copies of the same code, including commonjs, minified bundle, and even the original es2015+ code. While I agree that the |
}, | ||
"homepage": "https://github.com/Automattic/wp-calypso/blob/master/docs/components.md", | ||
"main": "./cjs/index.js", | ||
"esnext": "./index.js", |
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 mirror the Gutenberg lerna config (build scripts etc...)?
We do publish two versions per module as well:
main
which corresponds to the transpiled versionmodule
which is a transpiled version but still using ES6 modules which guarantee tree shaking etc...
Is it a common usage to use an esnext
property for untranspiled code? Also, how do we (package consumers) know what babel config or transpiling is needed with this field if it's not normalized?
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.
+1 on using main
and module
as you said.
the latest i've seen on publishing es6+ is https://babeljs.io/blog/2018/06/26/on-consuming-and-publishing-es2015+-packages
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.
See react-router
as an example:
https://unpkg.com/react-router@4.3.1/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.
Should we mirror the Gutenberg lerna config (build scripts etc...)?
I didn't want to necessarily introduce build scripts yet since that seemed overblown for the little amount of transpilation we're doing at this point (YAGNI -- might add them later as needed tho).
We do publish two versions per module as well:
main
which corresponds to the transpiled versionmodule
which is a transpiled version but still using ES6 modules which guarantee tree shaking etc...Is it a common usage to use an
esnext
property for untranspiled code? Also, how do we (package consumers) know what babel config or transpiling is needed with this field if it's not normalized?
I picked up esnext
from the 2ality blog, see PR desc:
http://2ality.com/2017/07/npm-packages-via-babel.html, and for more information, http://2ality.com/2017/04/transpiling-dependencies-babel.html and http://2ality.com/2017/06/pkg-esnext.html.
Granted, this is far from standardized, so I'm happy to reconsider.
Some good reading on the possible future of transpiling dependencies https://babeljs.io/blog/2018/06/26/on-consuming-and-publishing-es2015+-packages |
If you want to get closer to the setup Gutenberg uses, you can use this tool: You can also override some config values provided by default using: |
client/components/package.json
Outdated
"version": "0.1.0-alpha.6", | ||
"description": "React components, as used on WordPress.com", | ||
"scripts": { | ||
"build": "npx babel --only ./index.js,./badge/,./button/,./main/,./notice/ --out-dir cjs .", |
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 super simple when you compare to what we offer in Gutenberg:
https://github.com/WordPress/gutenberg/blob/master/bin/packages/build.js
We might want to sync on this and expose one general script.
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 like simple 😁 TBH, those build scripts looked a bit... overblown? 😁 To me, it seemed like the most relevant config options were (declarative) .babelrc
material (rather than -- imperative -- script material). I think I'd like us at least to wait for the Babel 7-beta.53 upgrade (#26020) to see how far we can get using Babel configs.
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.
Our build scripts are inspired by Jest and they are built the way they are mainly because we want quick "watch" support, which means if there's a change in a file we only transpile this file. Maybe it's possible to simplify this as well but yeah let's try to align once the project matures.
4a7d3a5
to
8f1e0ee
Compare
a9a6e0d
to
6599b3c
Compare
I pushed a fix for the bug where As But there is package The transpiled Fixed by adding I also pushed a revert of #26094, as it's no longer interesting. |
)" (#26192) This reverts commit ed6beaa. [Rationale](#26094 (comment)): > This PR [increased](http://iscalypsofastyet.com/push/ed6beaa5e0b54f6ddbe11360c8ad8a572b83a32f/e3642614723d88c353e5d768969d8f877d7472c4) the bundle size and [reverted](http://iscalypsofastyet.com/push/acef9fa493cc06a9fefece7ff00759997af8ca8a/03502467b044464e191c9746c510c6a10a7930e0) the improvements achieved in #25961. > > It's because `babel-preset-env` used to transform the `@babel/polyfill` import into a list that excludes the polyfills that are not needed on the target browser list. In the new location of `@babel/polyfill`, the plugin doesn't get the opportunity to do that transform and all polyfills are bundled again. I filed #26094 in the first place to get #24788 to work. Fortunately, @jsnajdr found [another way](#24788 (comment)).
Pins the version in top-level `node_modules` to 2.5.7, not a random version that happens to be promoted by NPM Install to the top-level directory. Fixes a bug where `import from 'core-js'` statements generated by `babel-preset-env` started using an old 1.x version suddenly.
Add `lerna` (a monorepo tool) to Calypso, and use it to publish [`@automattic/simple-components`](https://www.npmjs.com/package/@automattic/simple-components) as a separate npm. This involves adding a `package.json`, `.gitignore`, and `.npmignore` to `client/components`, and an `alias` field to Calypso's webpack configs. Since we want Calypso (and possibly other consumers) to continue to use untranspiled code (to benefit from features such as tree-shaking), the npms we produce should contain both transpiled and untranspiled versions of the code. See http://2ality.com/2017/07/npm-packages-via-babel.html, and for more information, http://2ality.com/2017/04/transpiling-dependencies-babel.html and http://2ality.com/2017/06/pkg-esnext.html.
ec181d0
to
850c496
Compare
@@ -0,0 +1 @@ | |||
node_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.
I believe node_modules
is redundant here: https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package
Closing. We're using |
Add
lerna
(a monorepo tool) to Calypso, and use it to publish@automattic/simple-components
as a separate npm.This involves adding a
package.json
,.gitignore
, and.npmignore
toclient/components
, and analias
field to Calypso's webpack configs.Since we want Calypso (and possibly other consumers) to continue to use untranspiled code (to benefit from features such as tree-shaking), the npms we produce should contain both transpiled and untranspiled versions of the code. See http://2ality.com/2017/07/npm-packages-via-babel.html, and for more information, http://2ality.com/2017/04/transpiling-dependencies-babel.html and http://2ality.com/2017/06/pkg-esnext.html.
Please note #16782 (comment)!
To test:
npm run distclean && npm start
node_modules/@automattic/simple-components
is a symlink toclient/components/
!npm run build-docker
) and running (npm run docker
) the Docker container still works (see PCYsg-5XR-p2).To publish the npm (only if you know what you're doing! 😛):
npx lerna publish --skip-git
NPM_CONFIG_OTP=<your2FAcode>
to that command -- and be quick before it expires while attempting to publish! Related: Support 2FA--otp=123456
lerna/lerna#1091Prerelease
for@automattic/simple-components
!)Related (but not required for this PR!): #19698.
Take One was #16782.