| 1 |
# Cockpit Javascript Dependencies |
| 2 |
|
| 3 |
Cockpit uses [Node.js](https://nodejs.org) and the |
| 4 |
[npm](https://docs.npmjs.com/cli/) package manager to build its code and run |
| 5 |
browser integration tests. These are not used at runtime or when |
| 6 |
building/installing from a release tarball. |
| 7 |
|
| 8 |
[package.json](../package.json) has two [npmjs](https://www.npmjs.com/) package |
| 9 |
lists: runtime `dependencies` like PatternFly or React which are included into |
| 10 |
Cockpit's pages and run in the browser; and `devDependencies` like esbuild or linters |
| 11 |
which are only used at build/test time. |
| 12 |
|
| 13 |
## Git builds |
| 14 |
|
| 15 |
When building from Git, the `node_modules/` directory is managed as a git |
| 16 |
submodule from the `node-cache` repository in the same project as the main |
| 17 |
repository (ie: `cockpit-project/node-cache`). That means that normal builds |
| 18 |
won't need to run `npm install`. Checking out the correct version of the |
| 19 |
`node_modules` directory is managed by the script `tools/node-modules`, which |
| 20 |
is automatically invoked from the build system on an as-needed basis, and has |
| 21 |
good caching. You can also do a recursive git checkout, if you'd prefer to |
| 22 |
build in a no-network environment, but you'll lose the caching benefits. |
| 23 |
|
| 24 |
The gitlink for `node_modules/` is always kept in sync with the `package.json` |
| 25 |
file used to fetch that set of modules with `npm install`. |
| 26 |
|
| 27 |
## Making changes |
| 28 |
|
| 29 |
If you modify `package.json`, the `node_modules` will need to be regenerated, |
| 30 |
and a new commit recorded. That can be managed locally by running |
| 31 |
|
| 32 |
``` |
| 33 |
tools/node_modules install |
| 34 |
``` |
| 35 |
|
| 36 |
which will produce a commit which is available for local testing. |
| 37 |
|
| 38 |
When you are ready to open a pull request with your changes, push the newly |
| 39 |
created `node_modules` commit to the cache by running |
| 40 |
|
| 41 |
``` |
| 42 |
tools/node_modules push |
| 43 |
``` |
| 44 |
|
| 45 |
Then create a pull request with your `package.json` and `node_modules` changes. |
| 46 |
|
| 47 |
Each pull request runs the [reposchutz](.github/workflows/reposchutz.yml) |
| 48 |
workflow to ensure that the branch is consistent wrt. package.json and |
| 49 |
node_modules/. This is purely read-only and does not need any secrets. |
| 50 |
|
| 51 |
## GitHub setup notes (documentation for project admins) |
| 52 |
|
| 53 |
This section documents the way to setup the |
| 54 |
[node-cache](https://github.com/cockpit-project/node-cache/) repository on |
| 55 |
GitHub. All projects in the cockpit-project organization share the same |
| 56 |
repository. |
| 57 |
|
| 58 |
Each project's "release" and "dependabot" workflows need write access to the node-cache |
| 59 |
repository for taggging releases or rebuilding node_modules/ respectively. |
| 60 |
These happen via workflow environments, whose deploy keys are set up in bot's |
| 61 |
[setup-deploy-keys](https://github.com/cockpit-project/bots/blob/main/setup-deploy-keys) |
| 62 |
script. |
| 63 |
|
| 64 |
For other projects/orgs or forks, you can create a node-cache repository from |
| 65 |
scratch manually (unless you want to fork/re-use `setup-deploy-keys`): |
| 66 |
|
| 67 |
- create the `node-cache` repository under the same project as the main |
| 68 |
repository (or fork it) |
| 69 |
- add a commit to that repository with a `README`. At least one commit on a |
| 70 |
named branch needs to be present in order for the GitHub web UI to function |
| 71 |
properly (eg: generate diffs, show tree contents, etc.) |
| 72 |
- generate an SSH key locally, without a passphrase, without touching the disk: |
| 73 |
`ssh-keygen -t ed25519 -C 'node-cache deploy' -f "${XDG_RUNTIME_DIR}/deploy-key" -N ''` |
| 74 |
- create an environment called `node-cache upload` in the "environments" settings of the |
| 75 |
primary repository. |
| 76 |
- add the content of the private key `deploy-key` to the `node-cache upload` |
| 77 |
environment as a secret with the name `NODE_CACHE_DEPLOY_KEY` |
| 78 |
- upload the public key `deploy-key.pub` as a deploy key to `node-cache` with |
| 79 |
write access enabled: |
| 80 |
https://github.com/cockpit-project/node-cache/settings/keys/new |
| 81 |
- destroy the local copy: `rm ${XDG_RUNTIME_DIR}/deploy-key*` |