build(workspaces): implement src as workspace package#1178
build(workspaces): implement src as workspace package#1178nickofthyme merged 10 commits intoelastic:alphafrom
Conversation
- move `./src/**` to `./packages/elastic-charts/**` - correct all paths due to file sturcture changes - fix bad docs paths and config options - create top-level mono package, move lib package - simplify lib tsconfig.json files - fix errors in linking package, cleanup paths - fix linting config to reflect file structure changes - update semantic release to point at new lib package - add lerna to facilitate running workspace scripts
nickofthyme
left a comment
There was a problem hiding this comment.
A few code comments to explain some of the key changes.
| @import '../../../node_modules/@elastic/eui/src/themes/eui/eui_colors_dark'; | ||
| @import 'style/themes/colors_dark'; | ||
| @import '../../../node_modules/@elastic/eui/src/global_styling/functions/index'; | ||
| @import '../../../node_modules/@elastic/eui/src/global_styling/variables/index'; | ||
| @import '../../../node_modules/@elastic/eui/src/global_styling/mixins/index'; | ||
| @import '../../../node_modules/@elastic/eui/src/global_styling/reset/index'; |
There was a problem hiding this comment.
git could not track this rename, but this is the same file as src/reset_dark.scss. Only the path changed to point at top node_modules folder.
| const cwd = path.join(libDir, 'dist'); | ||
| const nodeModulesDir = path.join(libDir, 'node_modules'); | ||
| const re = new RegExp(`require\\("(?:.*?\\/)*(${linkedPackages.join('|')})"\\)`, 'g'); |
There was a problem hiding this comment.
Now this simply converts to relative path require('react') -> require('../react'). Previously went into library like require('../../kibana/node_modules/react')
Now when linked elsewhere the dist files will use the relative node_modules depending on where the package is linked.
| @import '../node_modules/@elastic/eui/src/global_styling/functions/index'; | ||
| @import '../node_modules/@elastic/eui/src/global_styling/variables/index'; | ||
| @import '../node_modules/@elastic/eui/src/global_styling/mixins/index'; |
There was a problem hiding this comment.
Not delete only moved to packages/elastic-charts/src
| extends: | ||
| - tslint:recommended | ||
| # - tslint-microsoft-contrib | ||
|
|
||
| rulesDirectory: | ||
| # - node_modules/tslint-microsoft-contrib | ||
|
|
||
| rules: | ||
| object-literal-sort-keys: false | ||
| interface-name: false | ||
| no-default-export: true | ||
| no-irregular-whitespace: true | ||
| no-unused-expression: true | ||
| quotemark: [true, 'single', 'jsx-double'] | ||
| member-access: [true, 'no-public'] |
There was a problem hiding this comment.
We have not used tslint since I can recall
| @@ -21,5 +20,5 @@ | |||
| "resolveJsonModule": true, | |||
| "typeRoots": ["./node_modules/@types", "./**/*.d.ts", "./scripts/custom_matchers.ts"] | |||
| }, | |||
| "exclude": ["**/tmp"] | |||
| "exclude": ["**/tmp", "**/dist"] | |||
There was a problem hiding this comment.
prevents IDE from attempting to auto import from dist directory
There was a problem hiding this comment.
isn't that excluded with .gitignore?
There was a problem hiding this comment.
I kept getting this dist import suggestions, maybe but I think dist was already gitignored
| "scripts": { | ||
| "autoprefix:css": "echo 'Autoprefixing...' && yarn postcss dist/*.css --no-map --use autoprefixer -d dist", | ||
| "api:check": "yarn build:ts && yarn api:extract", | ||
| "api:check:local": "yarn api:check --local", | ||
| "api:extract": "yarn api-extractor run --verbose", | ||
| "autoprefix:css": "lerna run --loglevel=silent --scope @elastic/charts autoprefix:css", | ||
| "api:check": "lerna run --loglevel=silent --scope @elastic/charts api:check", | ||
| "api:check:local": "lerna run --loglevel=silent --scope @elastic/charts api:check:local", | ||
| "api:extract": "lerna run --loglevel=silent --scope @elastic/charts api:extract", |
There was a problem hiding this comment.
Kept all previous scripts, except for watch which I never used as it's faster to just saw yarn test -w.
Now repo-wide scripts are run from here and library scripts are run using @lerna/run
I think we can cleanup these scripts more in the future or even have a cli much like yarn kbn <action>
| "module": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "private": "true", | ||
| "repository": "git@github.com:elastic/elastic-charts.git", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "files": [ | ||
| "dist/**/*" | ||
| "workspaces": [ | ||
| "packages/*" |
There was a problem hiding this comment.
must be private to add workspaces
| "name": "elastic-charts-mono", | ||
| "description": "Mono repo for @elastic/charts", |
There was a problem hiding this comment.
Open to a better name or description her just cannot be @elastic/charts
| ...(isDryRun | ||
| ? [] | ||
| : [ | ||
| 'semantic-release-slack-bot', | ||
| { | ||
| notifyOnSuccess: true, | ||
| notifyOnFail: true, | ||
| markdownReleaseNotes: true, | ||
| }, | ||
| ]), |
There was a problem hiding this comment.
This always fails when running in dry-run mode
| [ | ||
| '@semantic-release/npm', | ||
| { | ||
| // must point to the child package | ||
| pkgRoot: 'packages/elastic-charts', | ||
| }, | ||
| ], |
There was a problem hiding this comment.
I'm pretty sure this will work and is the only change needed to point to the now nested library. 🤞🏼 See @semantic-release/npm
If this does not work, we can move this config to packages/elastic-charts.
We could update the git and github assets to only include the dist but I didn't see other orgs like react doing this on github.
|
What's the reason for putting If I understand, I'll put it on today's agenda to learn more |
@monfera most of the benefits are described clearly in the PR description and in the 2 linked issues and can be resumed in a cleaner set of dependencies for the library and a clear distinction between library and the docs+storybook infrastructure. This monorepo can be exploited in the future to exposing multiple independent packages within the same repo. One example could be: split the React Chart API from the Chart implementation and rendering whenever we have defined a clean JSON, JSON like API, so that one can just import the chart implementation and use the JSON API, or someone wants to use the react API bridge to build charts. You are probably right about the folder naming: calling them |
|
Thanks @markov00!
That's great, if it is a monorepo indeed. We've been talking about a decomposition anyway, so at some point, |
@monfera You are right It is a little deeper but the idea is that we have now the ability to have independent packages that are either coupled with But the beauty about yarn workspaces is that they automatically symlink all dependent packages across the repo. Thus if I am in
Yes it is a single thing, at least for the moment, but this not only allows for adding more packages in the future but also clearly defining boundaries of the library and the other apps. This includes moving all our application code such as
Exactly! Similarly, we could even have separate rending packages for |
@nickofthyme this is a great thing, it helps a lot with the testing as we isolate the lib from Storybook and help us identifying missing exposed types easily. |
|
@nickofthyme I've pull down this PR and run Why is the |
Interesting, might be related to yarnpkg/yarn#3209. I'll use |
Key changes: - move `./src/**` to `./packages/elastic-charts/**` - correct all paths due to file sturcture changes - fix bad docs paths and config options - create top-level mono package, move lib package - simplify lib tsconfig.json files - fix errors in linking package, cleanup paths - fix linting config to reflect file structure changes - update semantic release to point at new lib package - add lerna to facilitate running workspace scripts
Key changes: - move `./src/**` to `./packages/elastic-charts/**` - correct all paths due to file sturcture changes - fix bad docs paths and config options - create top-level mono package, move lib package - simplify lib tsconfig.json files - fix errors in linking package, cleanup paths - fix linting config to reflect file structure changes - update semantic release to point at new lib package - add lerna to facilitate running workspace scripts
# [30.1.0-alpha.1](v30.0.0...v30.1.0-alpha.1) (2021-06-08) ### Features * **workspaces:** implement src as workspace package ([#1178](#1178)) ([0cdf3b4](0cdf3b4))
Key changes: - move `./src/**` to `./packages/elastic-charts/**` - correct all paths due to file sturcture changes - fix bad docs paths and config options - create top-level mono package, move lib package - simplify lib tsconfig.json files - fix errors in linking package, cleanup paths - fix linting config to reflect file structure changes - update semantic release to point at new lib package - add lerna to facilitate running workspace scripts
Summary
Implement
@elastic/charts/srcas yarn workspace. Benefits of this are mostly internal but could improve productivity. These changes will have no effect on the library consumers.Details
Step towards closing #378. Ensured all npm scripts function as before, some even better 😏 🎉
List of benefits
package.json.srcfiles.List of key changes
src/**topackages/elastic-charts/**tsconfig.jsonfileslink_kibanapackage, cleanup path logiclernaand@lerna/runto facilitate running workspace/package scriptsFile Structure
As you may have noticed, there are now two
package.jsonfiles. The main top-levelpackage.json(namedelastic-charts-mono) is needed to control the repo and all its apps and libraries viaworkspaces. The other one atpackages/elastic-charts/package.jsonis the package for the library itself, moved from the top-level.One of the beauties of this new approach is offloading all of the
devDependenciesto the top levelpackage.jsonthat can be used across all workspaces.Limitations
Currently semantic release assumes a
1:1relation between repo and packages (see semantic-release/semantic-release#193). This is fine for now with only one external package, but this could be addressed when we have more packages to release.Checklist
src/index.ts(and stories only import from../srcexcept for test data & storybook)