Skip to content

Latest commit

 

History

History
132 lines (87 loc) · 3.43 KB

HACKING.md

File metadata and controls

132 lines (87 loc) · 3.43 KB

Contributing

Project info

Canonical react-components is developed with TypeScript, but built with babel and @babel/preset-typescript. Type declarations are generated post build with tsc.

Pull Requests

Pull request titles need to follow conventional commits specification.

Developing components with Storybook

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.

Using with another project that runs on yarn 3

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",
    "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.

Using with another project that runs on an older version of yarn

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

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.

Developing integration tests with cypress

Running against a local storybook

Start storybook with:

PORT=<PORT> yarn docs

Start the interactive cypress environment with:

yarn cypress:open --env port=<PORT>

Running cypress tests in CI

PORT=<PORT> yarn test-cypress