Skip to content
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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cjs
node_modules
1 change: 1 addition & 0 deletions client/components/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Copy link
Member

@simison simison Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9 changes: 9 additions & 0 deletions client/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @format */

// Keep in sync with the `files` field in package.json!
// TODO: Can we auto-generate at build time?

export { Badge } from './badge';
export { Button } from './button';
export { Main } from './main';
export { Notice } from './notice';
45 changes: 45 additions & 0 deletions client/components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@automattic/simple-components",
"version": "0.1.0-alpha.7",
"description": "React components, as used on WordPress.com",
"scripts": {
"build": "npx babel --only ./index.js,./badge/,./button/,./main/,./notice/ --out-dir cjs .",
"prepublishOnly": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/automattic/wp-calypso.git"
},
"keywords": [
"wordpress",
"react",
"components"
],
"author": "Automattic",
"license": "GPL-2.0+",
"bugs": {
"url": "https://github.com/automattic/wp-calypso/issues"
},
"homepage": "https://github.com/Automattic/wp-calypso/blob/master/docs/components.md",
"main": "./cjs/index.js",
"esnext": "./index.js",
Copy link
Contributor

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 version
  • module 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?

Copy link
Contributor

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

Copy link
Member

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

Copy link
Contributor Author

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 version
  • module 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.

"files": [
"index.js",
"cjs/",
"badge/",
"button/",
"main/",
"notice"
],
"dependencies": {
"classnames": "^2.2.6",
"gridicons": "^3.0.1",
"i18n-calypso": "^1.9.1",
"lodash": "^4.17.10",
"prop-types": "^15.6.2",
"react": "^16.4.1"
},
"publishConfig": {
"access": "public"
}
}
6 changes: 6 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"packages": [
"client/components"
],
"version": "independent"
}
Loading