Monorepo for Guardian UIs
The following packages live in libs/@guardian/*
and are published to NPM:
- @guardian/ab-core
- @guardian/ab-react
- @guardian/browserslist-config
- @guardian/core-web-vitals
- @guardian/eslint-config
- @guardian/eslint-config-typescript
- @guardian/eslint-plugin-source-foundations
- @guardian/eslint-plugin-source-react-components
- @guardian/identity-auth
- @guardian/identity-auth-frontend
- @guardian/libs
- @guardian/newsletter-types
- @guardian/prettier
- @guardian/source-foundations
- @guardian/source-react-components
- @guardian/source-react-components-development-kitchen
- @guardian/tsconfig
- Clone the repo
- Run a task.
You'll be prompted to install any missing requirements if they are needed...
Tasks that apply to all projects are defined in the Makefile
:
make build
builds all projectsmake build:storybooks
builds all storybooksmake changeset
creates a new changesetmake clean
removes all build artifactsmake dev
runs the dev targets for all projects in single instancemake e2e
runs the e2e tests for all projectsmake fix
attemps to fix lint errors across all projectsmake formatting:check
check repo for formatting errorsmake lint
checks all projects for lint errorsmake ls
lists availablemake
targetsmake storybooks
runs storybook for all projects in single instancemake test
runs the unit tests for all projectsmake validate
makes sure absolutely everything is workingmake verify-dist
runs unit tests against dist for all projects
Project-specific tasks are defined as scripts
in a package.json
or targets
in a project.json
files, and can be run with make <project>:<script>
/make <project>:<target>
:
make @guardian/ab-core:build
make @guardian/ab-core:dev
make @guardian/ab-core:fix
make @guardian/ab-core:lint
make @guardian/ab-core:test
make @guardian/ab-core:verify-dist
make @guardian/ab-react:build
make @guardian/ab-react:dev
make @guardian/ab-react:fix
make @guardian/ab-react:lint
make @guardian/ab-react:test
make @guardian/ab-react:verify-dist
make @guardian/browserslist-config:fix
make @guardian/browserslist-config:lint
make @guardian/browserslist-config:update-readme
make @guardian/cobalt-plugin-ts:fix
make @guardian/cobalt-plugin-ts:lint
make @guardian/core-web-vitals:build
make @guardian/core-web-vitals:dev
make @guardian/core-web-vitals:fix
make @guardian/core-web-vitals:lint
make @guardian/core-web-vitals:test
make @guardian/core-web-vitals:verify-dist
make @guardian/design-tokens:build
make @guardian/design-tokens:fix
make @guardian/design-tokens:lint
make @guardian/eslint-config:fix
make @guardian/eslint-config:lint
make @guardian/eslint-config-typescript:fix
make @guardian/eslint-config-typescript:lint
make @guardian/eslint-plugin-source-foundations:build
make @guardian/eslint-plugin-source-foundations:dev
make @guardian/eslint-plugin-source-foundations:fix
make @guardian/eslint-plugin-source-foundations:lint
make @guardian/eslint-plugin-source-foundations:test
make @guardian/eslint-plugin-source-foundations:verify-dist
make @guardian/eslint-plugin-source-react-components:build
make @guardian/eslint-plugin-source-react-components:dev
make @guardian/eslint-plugin-source-react-components:fix
make @guardian/eslint-plugin-source-react-components:lint
make @guardian/eslint-plugin-source-react-components:test
make @guardian/eslint-plugin-source-react-components:verify-dist
make @guardian/identity-auth:build
make @guardian/identity-auth:dev
make @guardian/identity-auth:fix
make @guardian/identity-auth:lint
make @guardian/identity-auth:test
make @guardian/identity-auth:verify-dist
make @guardian/identity-auth-frontend:build
make @guardian/identity-auth-frontend:dev
make @guardian/identity-auth-frontend:fix
make @guardian/identity-auth-frontend:lint
make @guardian/identity-auth-frontend:test
make @guardian/identity-auth-frontend:verify-dist
make @guardian/libs:build
make @guardian/libs:dev
make @guardian/libs:e2e
make @guardian/libs:fix
make @guardian/libs:lint
make @guardian/libs:test
make @guardian/libs:verify-dist
make @guardian/newsletter-types:build
make @guardian/newsletter-types:dev
make @guardian/newsletter-types:fix
make @guardian/newsletter-types:lint
make @guardian/prettier:fix
make @guardian/prettier:lint
make @guardian/source-foundations:build
make @guardian/source-foundations:build-storybook
make @guardian/source-foundations:build-type-presets
make @guardian/source-foundations:dev
make @guardian/source-foundations:fix
make @guardian/source-foundations:lint
make @guardian/source-foundations:storybook
make @guardian/source-foundations:test
make @guardian/source-foundations:verify-dist
make @guardian/source-react-components:build
make @guardian/source-react-components:build-storybook
make @guardian/source-react-components:create-icons
make @guardian/source-react-components:dev
make @guardian/source-react-components:fix
make @guardian/source-react-components:lint
make @guardian/source-react-components:storybook
make @guardian/source-react-components:test
make @guardian/source-react-components:verify-dist
make @guardian/source-react-components-development-kitchen:build
make @guardian/source-react-components-development-kitchen:build-storybook
make @guardian/source-react-components-development-kitchen:dev
make @guardian/source-react-components-development-kitchen:fix
make @guardian/source-react-components-development-kitchen:lint
make @guardian/source-react-components-development-kitchen:storybook
make @guardian/source-react-components-development-kitchen:test
make @guardian/source-react-components-development-kitchen:verify-dist
make @guardian/tsconfig:fix
make @guardian/tsconfig:lint
make github-pages:build
make github-pages:dev
make github-pages:start
make storybooks:dev
Tasks are managed by Nx.
Nx remotely caches the output of build
, lint
, test
, and verify-dist
.
This means only one full iteration of these tasks runs for a given state of a project – ever – which makes them extremely fast to re-run.
For example, you're working on something, run the tests and they pass. Nx remotely caches the result. You push your changes to CI. When CI runs the tests, nothing has changed, so Nx fetches the (passing) cached results, the build goes green and you can merge.
When I pull your changes, my copy of the code is identical to what you pushed and merged, so I also get the cached results. If I then change the code, Nx re-runs the tests and, again, caches the results.
This happens per project. So if you change project-a
but not project-b
, Nx will get the cached results for project-b
, but still run the tests for project-a
. From then on, until project-a
changes again, Nx will always use the cached results for both.
This includes between development and CI, between machines, pulls etc.
To force the tasks in the Makefile
to skip the Nx cache, set SKIP_NX_CACHE=true
, e.g.
SKIP_NX_CACHE=true make test
CSNX uses Chromatic for visual regression testing, and all PRs require the Chromatic checks to pass before merging.
However, each run costs money, so we only want to run Chromatic when a PR is ready to merge (rather than for every push, for example).
Therefore, initially, Chromatic checks will not run.
When your PR is ready, add the run_chromatic
label. This will starts Chromatic checks.
Note
Each push while the label is applied will trigger new checks, so you may want to remove the label if you're making more changes.
Once all checks pass, you're good to merge.
Libs within CSNX are available as NPM packages. We use Changesets to automate this release process.
To publish your changes to NPM, run make changeset
. This will open the Changesets CLI, and you will be offered a list of packages to release. Once you've selected the changed package/s you'll be given the option of major
, minor
or patch
release. Select one of these and add a description.
This will create a "changeset": a .md
file containing the release information. When you merge your branch, the changeset will be picked up by the Changests GHA, which will in turn create a release PR. To complete the NPM release merge this second PR.
You will be prompted to install the recommended extensions when you open the repo.
There is also a suggested settings file (./.vscode/settings.json.default) with some defaults you may useful. It covers project-specific enhancements, useful settings for common extensions etc.
If you want to use any/all of them, create a copy of the file and remove the .default
extension.
n.b. these are your personal settings for this repo, so add anything else you find useful and remove/change anything you don't like.
If you get a command not found
error or a message saying you're using the wrong version of Node when commiting using a GUI (VSCode, GitHub desktop etc), add a ~/.config/husky/init.sh
file and load your Node version manager there.
Note
This used be located in ~/.huskyrc
. If you set that up before, you will need to recreate it at ~/.config/husky/init.sh
.
mkdir -p ~/.config/husky && cp ~/.huskyrc $_/init.sh
For example, if you use fnm
:
# ~/.config/husky/init.sh
eval "$(fnm env)"
fnm use
Or for asdf
:
# ~/.config/husky/init.sh (installed with git)
. $HOME/.asdf/asdf.sh
# ~/.config/husky/init.sh (installed with brew on intel macs)
. /usr/local/opt/asdf/libexec/asdf.sh
# ~/.config/husky/init.sh (installed with brew on apple silicon)
. /opt/homebrew/opt/asdf/asdf.sh
Or for nvm
:
# ~/.config/husky/init.sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && nvm use
See https://typicode.github.io/husky/how-to.html for more info.