@ui-kit/*
@sewan/ui-kit
@sewan/ui-kit
@ui-kit/avatar
@ui-kit/form
Google Material Components (aka. MDC)
npm 7+
Rollup
Lerna
used by
· The world
reduce the ui-kit coupling
v1
v2
I want that upgrade
But not this one
I didn't want it (yet)
@sewan/ui-kit
@sewan/ui-kit
App
App
App
App
v1.0
v1.1
I want that upgrade
@ui-kit/triangle
@ui-kit/triangle
v2.6
v3.0
But not this one (yet)
@ui-kit/circle
@ui-kit/circle
@ui-kit/triangle
@ui-kit/circle
INDEPENDENT - UNAWARE
OF EACH OTHERS
A package owns:
making them:
v2
v5
v1
v2
v6
multiple packages
front-ui-kit ├── ... ├── packages │ ├── Avatar │ ├── Icon │ ├── ... │ └── ui-kit └── ...
@sewan/ui-kit
@ui-kit/*
meta-package
individuals
import Avatar from '@ui-kit/avatar'
import { Avatar } from '@sewan/ui-kit'
or
individually
globally (backward compatible)
├── packages │ ├── Avatar/package.json │ ├── Icon/package.json │ ├── ... │ └── ui-kit/package.json ├── ... └── package.json
individuals
project-wide (dev)
├── packages │ ├── Avatar/README.md │ ├── Icon/README.md │ ├── ... │ └── ui-kit/README.md ├── ... └── README.md
individuals
project-wide (dev)
├── packages │ ├── Avatar/package.json │ ├── Icon/package.json │ ├── ... │ └── ui-kit/package.json ├── ... └── package.json
{ "name": "@ui-kit/avatar", "version": "1.6.2", ... }
{ "name": "@sewan/ui-kit", "version": "1.2.5", "dependencies": { "@ui-kit/avatar": "^1.6.2", ... } }
├── node_modules │ ├── @ui-kit/avatar -> ../packages/Avatar │ ├── @ui-kit/icon -> ../packages/Icon │ ├── ... │ └── @sewan/ui-kit -> ../packages/ui-kit └── ...
import Icon from '@ui-kit/icon' const ico = <Icon name="FranceFlagIcon" />
thx to npm --version 7
package.json
{
...
"workspaces": [...],
...
}
├── packages │ ├── Avatar/dist │ ├── Icon/dist │ ├── ... │ └── ui-kit/dist └── ...
JS compiled version
(ie: not JSX)
├── packages │ ├── Avatar/dist │ │ ├── index.cjs.js │ │ └── index.es.js │ ├── Icon/dist │ ├── ... │ └── ui-kit/dist └── ...
{ "name": "@ui-kit/avatar", "version": "1.6.2", "main": "dist/index.cjs.js", "module": "dist/index.es.js", ... }
const Avatar = require('@ui-kit/avatar')
import Avatar from '@ui-kit/avatar'
a unique script to bundle all
$ npx @sewan/ui-rollup
#!/bin/sh
index.js
dist/index.es.js dist/index.cjs.js
{
...
"src": "index.js",
...
}
package.json
#!/bin/sh
foo/index.js
bar/dist/index.es.js bar/dist/index.cjs.js
bar/index.js
foo/dist/index.es.js foo/dist/index.cjs.js
$ npx @sewan/ui-rollup \
<input1> <input2> ...
#!/bin/sh
foo/index.js
bar/dist/index.es.js bar/dist/index.cjs.js
bar/index.js
foo/dist/index.es.js foo/dist/index.cjs.js
$ npx @sewan/ui-rollup foo/index.js bar/index.js \
--watch
$ npx @sewan/ui-rollup --help
$ lerna run dist
packages/*
{
...,
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"scripts": {
"dist": "sewan-ui-rollup",
...
}
}
npm run dist
aka.
packages/*/dist
package.json
aka. dev mode
npm start
aka.
$ npx start-storybook
// .storybook/main.js if (config.mode !== 'production') { config.plugins.push(onFirstBuildDonePlugin(() => { spawn('npm', ['run', 'dist-packages-watch'], {stdio: "inherit"}) })) }
Storybook +
Dependencies graph
$ ./bin/list-packages --toposort
/home/abernier/sewan/front-ui-kit/packages/Icon/index.js /home/abernier/sewan/front-ui-kit/packages/core/index.js /home/abernier/sewan/front-ui-kit/packages/Avatar/index.js /home/abernier/sewan/front-ui-kit/packages/ui-kit/index.js
1
2
3
4
npm run dist-watch
aka.
$ npx @sewan/ui-rollup \
$(./bin/list-packages --toposort) \
--watch
1
@ui-kit/icon
2
@ui-kit/core
3
@ui-kit/avatar
4
@sewan/ui-kit
$ npx @sewan/ui-rollup \
$(./bin/list-packages --toposort --scope @ui-kit/*) \
--watch
npm run dist-packages-watch
aka.
1
@ui-kit/icon
2
@ui-kit/core
3
@ui-kit/avatar
for any packages/*
$ git commit
feat(avatar): new comment
BREAKING CHANGE: this is huge
$ lerna changed/diff
$ npx lerna changed lerna notice cli v4.0.0 lerna info versioning independent lerna info Looking for changed packages since @sewan/ui-kit@1.2.8 @ui-kit/avatar @sewan/ui-kit lerna success found 2 packages ready to publish
$ npx lerna diff lerna notice cli v4.0.0 lerna info versioning independent diff --git a/packages/Avatar/index.js b/packages/Avatar/index.js index 649e010..554e401 100644 --- a/packages/Avatar/index.js +++ b/packages/Avatar/index.js @@ -1,3 +1,4 @@ export { default } from './Avatar'; export { default as AvatarGroup } from './AvatarGroup'; export { AvatarSet } from './styled'; +// breaking change
$ lerna version
npm run release
aka.
$ lerna publish from-git
If versioning implicitly, run all version lifecycle scripts
Run prepublish lifecycle in root, if enabled
Run prepare lifecycle in root
Run prepublishOnly lifecycle in root
Run prepack lifecycle in root
For each changed package, in topological order (all dependencies before dependents):
Run postpack lifecycle in root
For each changed package, in topological order (all dependencies before dependents):
Run publish lifecycle in root
To avoid recursive calls, don't use this root lifecycle to run lerna publish
Run postpublish lifecycle in root
Update temporary dist-tag to latest, if enabled
postversion lifecycle
{
...,
"scripts": {
"prepack": "npm run dist",
...
}
}
package.json
by modifying
@ui-kit/avatar
pre-commit hook → npx lint-staged
eslint-config-airbnb + eslint-config-prettier
both now run on built version of the packages (confidence)
no more storyshots (time saving ~300%)
lint included (pretest lifecycle)
npm-ci: image: $DOCKER_REGISTRY/$DOCKER_NODE_IMAGE stage: intro variables: FF_USE_FASTZIP: 'true' CACHE_COMPRESSION_LEVEL: 'fastest' cache: key: files: [package-lock.json] paths: [node_modules/] policy: push script: - npm ci --no-audit --no-optional only: changes: - package-lock.json
-300%
FROM node:15.14.0-alpine
that comes with
node --version
7.7.6
FROM node:15.14.0-alpine
node-ci:15.14.0
of all @ui-kit/*