Canonical react-components
is developed with TypeScript, but built with babel
and @babel/preset-typescript
. Type declarations are generated post build with tsc
.
Pull request titles need to follow conventional commits specification, which will be used by semantic-release to determine if a release will be published on merging your pull request into the main branch. You can refer to this FAQ for details regarding rules for triggering a release.
You can run Storybook locally to develop new components. You may also need to validate that they work with other projects, in which case see the instructions below.
Run Storybook with dotrun:
dotrun
Or directly with Yarn:
yarn install
yarn docs
And remember to dotrun test
and dotrun lint
.
Both projects will need to be running on the same machine/container.
In react-components
run:
yarn clean
yarn install
yarn build
yarn build-watch
In your project run:
yarn clean
yarn install
yarn link path_to_react_components
At this point, you might get errors about mismatched versions of specific dependencies between react-components
and your project. To fix these errors, change the versions of those dependencies in react-components
to match the versions in your project. Once done, rerun the previously mentioned steps.
Finally, in your project, add the resolutions for react
and react-dom
to package.json
. The added bit of code should be:
"resolutions": {
"@canonical/react-components": "portal:path_to_react_components",
"formik": "portal:path_to_react_components/node_modules/formik",
"react": "portal:path_to_react_components/node_modules/react",
"react-dom": "portal:path_to_react_components/node_modules/react-dom"
}
Note: Before pushing changes to @canonical/react-components
, don't forget to change the mismatched versions of dependencies in react-components
to the ones before the change.
Both projects will need to be running on the same machine/container.
In react-components
run:
dotrun link-package
You may want to watch and build files as you change them.
dotrun build-watch
This command links React to prevent multiple copies of React being loaded.
In the project you're working on:
dotrun clean
dotrun exec yarn link "@canonical/react-components"
dotrun exec yarn link "react"
dotrun exec yarn install
dotrun
If using a monorepo you'll need to run those commands at the top level (not inside a workspace).
You'll then need to start you project with yarn, not ./run
.
Then when you're finished, in your project run:
dotrun exec yarn unlink react
dotrun exec yarn unlink "@canonical/react-components"
Then in react-components
run:
dotrun unlink-package
When using yarn link from a project using Vite you may need to temporarily set the following option in your vite.config.ts:
resolve: {
dedupe: ["react", "react-dom", "formik"],
preserveSymlinks: true,
},
If you do not wish do use dotrun then replace dotrun in the command above. Note that you must use dotrun or yarn on one project you must use the same command on the other project so that they both link the same node modules.
Start storybook with:
PORT=<PORT> yarn docs
Start the interactive cypress environment with:
yarn cypress:open --env port=<PORT>
PORT=<PORT> yarn test-cypress