@zukhruf/nx 0.8.30 → 0.8.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +378 -19
- package/dist/generators/add-keys.d.ts +7 -0
- package/dist/generators/add-keys.d.ts.map +1 -0
- package/dist/generators/add-keys.js +14 -0
- package/dist/generators/add-keys.js.map +1 -0
- package/dist/generators/add-lines.d.ts +8 -0
- package/dist/generators/add-lines.d.ts.map +1 -0
- package/dist/generators/add-lines.js +21 -0
- package/dist/generators/add-lines.js.map +1 -0
- package/dist/generators/app-directory.d.ts +17 -0
- package/dist/generators/app-directory.d.ts.map +1 -0
- package/dist/generators/app-directory.js +34 -0
- package/dist/generators/app-directory.js.map +1 -0
- package/dist/generators/dokploy/files.d.ts +21 -0
- package/dist/generators/dokploy/files.d.ts.map +1 -0
- package/dist/generators/dokploy/files.js +755 -0
- package/dist/generators/dokploy/files.js.map +1 -0
- package/dist/generators/dokploy/generator.d.ts +75 -0
- package/dist/generators/dokploy/generator.d.ts.map +1 -0
- package/dist/generators/dokploy/generator.js +139 -0
- package/dist/generators/dokploy/generator.js.map +1 -0
- package/dist/generators/dokploy/providers.d.ts +15 -0
- package/dist/generators/dokploy/providers.d.ts.map +1 -0
- package/dist/generators/dokploy/providers.js +114 -0
- package/dist/generators/dokploy/providers.js.map +1 -0
- package/dist/generators/init/files.js +3 -3
- package/dist/generators/init/files.js.map +1 -1
- package/dist/generators/init/generator.d.ts.map +1 -1
- package/dist/generators/init/generator.js +1 -16
- package/dist/generators/init/generator.js.map +1 -1
- package/dist/generators/init/nx-json.d.ts +16 -3
- package/dist/generators/init/nx-json.d.ts.map +1 -1
- package/dist/generators/init/nx-json.js +20 -5
- package/dist/generators/init/nx-json.js.map +1 -1
- package/dist/generators/init/root-package-json.d.ts +6 -0
- package/dist/generators/init/root-package-json.d.ts.map +1 -1
- package/dist/generators/init/root-package-json.js +15 -12
- package/dist/generators/init/root-package-json.js.map +1 -1
- package/dist/generators/node-app/files.d.ts +43 -0
- package/dist/generators/node-app/files.d.ts.map +1 -0
- package/dist/generators/node-app/files.js +522 -0
- package/dist/generators/node-app/files.js.map +1 -0
- package/dist/generators/node-app/generator.d.ts +17 -0
- package/dist/generators/node-app/generator.d.ts.map +1 -0
- package/dist/generators/node-app/generator.js +319 -0
- package/dist/generators/node-app/generator.js.map +1 -0
- package/dist/generators/nx-plugin.d.ts +16 -0
- package/dist/generators/nx-plugin.d.ts.map +1 -0
- package/dist/generators/nx-plugin.js +27 -0
- package/dist/generators/nx-plugin.js.map +1 -0
- package/dist/generators/pair/files.d.ts +4 -0
- package/dist/generators/pair/files.d.ts.map +1 -0
- package/dist/generators/pair/files.js +73 -0
- package/dist/generators/pair/files.js.map +1 -0
- package/dist/generators/pair/generator.d.ts +19 -0
- package/dist/generators/pair/generator.d.ts.map +1 -0
- package/dist/generators/pair/generator.js +70 -0
- package/dist/generators/pair/generator.js.map +1 -0
- package/dist/generators/prisma/files.d.ts +20 -0
- package/dist/generators/prisma/files.d.ts.map +1 -0
- package/dist/generators/prisma/files.js +183 -0
- package/dist/generators/prisma/files.js.map +1 -0
- package/dist/generators/prisma/generator.d.ts +17 -0
- package/dist/generators/prisma/generator.d.ts.map +1 -0
- package/dist/generators/prisma/generator.js +258 -0
- package/dist/generators/prisma/generator.js.map +1 -0
- package/dist/generators/react-app/files.d.ts +7 -0
- package/dist/generators/react-app/files.d.ts.map +1 -0
- package/dist/generators/react-app/files.js +188 -0
- package/dist/generators/react-app/files.js.map +1 -0
- package/dist/generators/react-app/generator.d.ts +12 -0
- package/dist/generators/react-app/generator.d.ts.map +1 -0
- package/dist/generators/react-app/generator.js +242 -0
- package/dist/generators/react-app/generator.js.map +1 -0
- package/dist/generators/react.d.ts +29 -0
- package/dist/generators/react.d.ts.map +1 -0
- package/dist/generators/react.js +64 -0
- package/dist/generators/react.js.map +1 -0
- package/dist/generators/root-dependencies.d.ts +21 -0
- package/dist/generators/root-dependencies.d.ts.map +1 -0
- package/dist/generators/root-dependencies.js +56 -0
- package/dist/generators/root-dependencies.js.map +1 -0
- package/dist/generators/ui-package/files.d.ts +37 -0
- package/dist/generators/ui-package/files.d.ts.map +1 -0
- package/dist/generators/ui-package/files.js +118 -0
- package/dist/generators/ui-package/files.js.map +1 -0
- package/dist/generators/ui-package/generator.d.ts +14 -0
- package/dist/generators/ui-package/generator.d.ts.map +1 -0
- package/dist/generators/ui-package/generator.js +111 -0
- package/dist/generators/ui-package/generator.js.map +1 -0
- package/dist/generators/versions.d.ts +49 -1
- package/dist/generators/versions.d.ts.map +1 -1
- package/dist/generators/versions.js +61 -1
- package/dist/generators/versions.js.map +1 -1
- package/generators.json +30 -0
- package/package.json +24 -5
- package/src/generators/dokploy/schema.json +48 -0
- package/src/generators/node-app/schema.json +22 -0
- package/src/generators/pair/schema.json +18 -0
- package/src/generators/prisma/schema.json +21 -0
- package/src/generators/react-app/schema.json +17 -0
- package/src/generators/ui-package/schema.json +22 -0
package/README.md
CHANGED
|
@@ -1,22 +1,117 @@
|
|
|
1
1
|
# @zukhruf/nx
|
|
2
2
|
|
|
3
|
-
This package is the Nx part of the monorepo standard. Each workspace copied the same Nx configuration into each project. This package gives that configuration one time, in areas. Each area has its own import path, and the package has no root entry point. Two [generators](#generators) write the root files of a workspace. The lint rules stay in `@zukhruf/eslint`, and the Git hooks stay in `@zukhruf/git-hooks`.
|
|
3
|
+
This package is the Nx part of the monorepo standard. Each workspace copied the same Nx configuration into each project. This package gives that configuration one time, in areas. Each area has its own import path, and the package has no root entry point. Two [generators](#generators) write the root files of a workspace, four [app generators](#app-generators) add its projects, the [prisma generator](#prisma-generator) adds a db package, and the [dokploy generator](#dokploy-generator) adds the delivery of a backend. The lint rules stay in `@zukhruf/eslint`, and the Git hooks stay in `@zukhruf/git-hooks`. [Monorepo standard](#monorepo-standard) says where each rule of the standard lives, and why.
|
|
4
4
|
|
|
5
5
|
The words in these documents have one meaning each. See the glossary in [CONTEXT.md](./CONTEXT.md).
|
|
6
6
|
|
|
7
7
|
## Areas
|
|
8
8
|
|
|
9
|
-
| Area | Import path | Status
|
|
10
|
-
| ---------------- | ---------------------- |
|
|
11
|
-
| format | `@zukhruf/nx/format` | This README
|
|
12
|
-
| test | `@zukhruf/nx/test` | This README
|
|
13
|
-
| lint | `@zukhruf/nx/lint` | This README
|
|
14
|
-
| portless | `@zukhruf/nx/portless` | Candidate (#3336): 14 projects in 3 repos
|
|
15
|
-
| opentofu, prisma | `@zukhruf/nx/<area>` | This README (#3339)
|
|
16
|
-
| generators | `@zukhruf/nx:<name>` | This README: `preset` and `init` (#3337);
|
|
9
|
+
| Area | Import path | Status |
|
|
10
|
+
| ---------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
11
|
+
| format | `@zukhruf/nx/format` | This README |
|
|
12
|
+
| test | `@zukhruf/nx/test` | This README |
|
|
13
|
+
| lint | `@zukhruf/nx/lint` | This README |
|
|
14
|
+
| portless | `@zukhruf/nx/portless` | Candidate (#3336): 14 projects in 3 repos |
|
|
15
|
+
| opentofu, prisma | `@zukhruf/nx/<area>` | This README (#3339) |
|
|
16
|
+
| generators | `@zukhruf/nx:<name>` | This README: `preset` and `init` (#3337); `node-app`, `react-app`, `pair`, `ui-package` (#3338); `dokploy` (#4603); `prisma` (#4604) |
|
|
17
17
|
|
|
18
18
|
The lint rules stay in `@zukhruf/eslint`. The `lint` area gives only the inputs of the `lint` target (#3335).
|
|
19
19
|
|
|
20
|
+
## monorepo standard
|
|
21
|
+
|
|
22
|
+
The monorepo standard is the set of rules that each new Nx repo follows. The generators of this package write it. The Nx plugins of this package, the rules of `@zukhruf/eslint` and the steps of `@zukhruf/git-hooks` check it. It started as `docs/monorepo-standard.md` in whatisgoingon, which moved here in #4605. This section keeps only what no generator writes and no check runs: where each rule lives, the decisions with their reasons, the rules that are still prose, and the pitfalls. To read a rule that a generator writes, read the generator's section or its source.
|
|
23
|
+
|
|
24
|
+
### Where each rule lives
|
|
25
|
+
|
|
26
|
+
| Part of the standard | Written by | Checked by |
|
|
27
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
28
|
+
| Tooling: npm workspaces, one exact version of the Nx family, TypeScript 7 with the TypeScript 6 API, exact root versions, `allowScripts`, peer `overrides` | `init` ([`root-package-json.ts`](./src/generators/init/root-package-json.ts), [`versions.ts`](./src/generators/versions.ts)); `preset` refuses another package manager; `node-app` adds the sdk-it peer `overrides` | `manifest/nx-family-pinned` ([`@zukhruf/eslint`](../eslint/README.md#every-other-manifest)); [`NpmrcPolicy`](../git-hooks/README.md#decide-how-npm-installs-in-the-repo) (`legacy-peer-deps=false`, `strict-allow-scripts=true`); [`LockfileSync`](../git-hooks/README.md#keep-package-lockjson-in-step-with-each-packagejson) |
|
|
29
|
+
| Versions as LTS aliases: `.nvmrc` `lts/*`, `node:lts-*` images, `npm@latest`, no `engines` and no `packageManager` | `init` ([`files.ts`](./src/generators/init/files.ts)); the Dockerfiles of `node-app` and `prisma`; the workflows of `dokploy` | [`NoNumericPins`](../git-hooks/README.md#refuse-a-node-or-npm-version-written-as-a-number) |
|
|
30
|
+
| Root files and the layout `apps/`, `packages/`, `tools/` | `init` and `preset`: [What the generators write](#what-the-generators-write) | the `Format` step for the root files; `NpmrcPolicy` for `.npmrc` |
|
|
31
|
+
| TypeScript: the Bundler base, and project tsconfigs that write to `out-tsc` with `rootDir: "src"` | `init` (base and solution file); the app generators and `prisma` (project tsconfigs) | `zukhruf/no-enum` |
|
|
32
|
+
| Nx: `nx.json` keys, plugins, target defaults, generator defaults; targets in the `nx` key of the project's `package.json` | `init` ([`nx-json.ts`](./src/generators/init/nx-json.ts)); each app generator adds its wiring: [What only an app generator writes](#what-only-an-app-generator-writes) | the `format`, `test` and `lint` areas, which no default may replace ([ADR 0001](./docs/adr/0001-inferred-targets-not-copied-defaults.md)) |
|
|
33
|
+
| Format: `.prettierrc` and `.prettierignore` | `init`; `react-app` adds `prettier-plugin-tailwindcss` | `format:check`; the `Format` step |
|
|
34
|
+
| Lint: the root and the project `eslint.config.mjs` | `init` (root); each app generator and `prisma` (project) | the `lint` area; the configs of `@zukhruf/eslint` |
|
|
35
|
+
| Git hooks: `Sync`, `Format`, the manifest steps, `Build` on pre-push, `NxReleaseScope` on commit-msg | `init` | — |
|
|
36
|
+
| Tests: `node:test` everywhere, Vitest in a Vite app, no lifecycle hooks, `test:docker` for Docker tests | the `test` area; `react-app` (the Vitest block and its `test` target); `prisma` (the Docker test and the tag) | `zukhruf/no-other-test-runner`, `zukhruf/no-test-lifecycle-hooks` |
|
|
37
|
+
| Backend: Hono, terminus, evlog, zod env, sdk-it client, one ESM bundle, Dockerfile, build sha | `node-app` | the `hono` and `env` configs; [`DockerfileInstallsFromLockfile`](../git-hooks/README.md#install-from-the-lockfile-in-a-dockerfile) |
|
|
38
|
+
| Web: React Router in data mode, Vite, Tailwind, React Compiler, Vitest; a UI library | `react-app`; `ui-package` | `@zukhruf/eslint/react`, the `react-router` and `tailwind` configs |
|
|
39
|
+
| Mobile: Expo | no generator: [Mobile with Expo](#mobile-with-expo) | [`@zukhruf/eslint/react-native`](../eslint/README.md#react-native-hermes) |
|
|
40
|
+
| Pair of a web app and a backend | `pair` | — |
|
|
41
|
+
| Database: a Prisma 7 package on Postgres | `prisma` | the `prisma` area |
|
|
42
|
+
| Agent workflow: the commands in `AGENTS.md` | `init` (`AGENTS.md`, `CLAUDE.md`) | — |
|
|
43
|
+
| Delivery: CI, deploy, encrypted OpenTofu state applied only by CI | `dokploy` | the `opentofu` area (`typecheck` with no secret, no `apply` target, [ADR 0007](./docs/adr/0007-opentofu-targets-from-environments-with-no-apply.md)) |
|
|
44
|
+
|
|
45
|
+
### Decisions and their reasons
|
|
46
|
+
|
|
47
|
+
| Topic | The sources disagreed | The standard | Why |
|
|
48
|
+
| --------------------- | ----------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
49
|
+
| Web tests | factory used Vitest and happy-dom; the zukhruf libraries used `node:test` only | Vitest in a Vite app, `node:test` everywhere else | The owner's decision of 2026-10-29. Vitest runs the app's own Vite config and transforms. |
|
|
50
|
+
| Vitest globals | factory set `globals: true` | `globals: false`, and RTL's `cleanup()` in the `finally` of each test | With `globals: true`, RTL registers an `afterEach`, which is a lifecycle hook. |
|
|
51
|
+
| Root scripts | factory had `build`, `check` and `lint` npm scripts; zukhruf, elt and context-compiler had only `prepare` | only `prepare` | Each command runs through an Nx target. |
|
|
52
|
+
| TypeScript | factory used `typescript@6.0.3`; elt and context-compiler used TypeScript 7 with the TypeScript 6 API alias | TypeScript 7, with the TypeScript 6 API for typescript-eslint and `@nx/js` | The newest setup (elt, 2026-10-10), and it follows the Nx guide `nx.dev/docs/kb/typescript-7`. typescript-eslint peers on TypeScript `<6.1`. |
|
|
53
|
+
| tsconfig base | factory used Bundler resolution; zukhruf and elt use NodeNext | Bundler for a workspace that bundles its apps | Different kinds of workspace. A workspace that Node runs from source uses `NodeNext` with `rewriteRelativeImportExtensions`; no generator writes it ([ADR 0009](./docs/adr/0009-a-preset-and-an-init-generator-start-a-repo-from-nothing.md)). |
|
|
54
|
+
| Expo | ipay used `@nx/expo` on Nx 21; bid and virtual-care wrote `run-commands` | `@nx/expo/plugin` | The official plugin, with inferred targets (2026-10-29). |
|
|
55
|
+
| Infrastructure | OpenTofu or Pulumi | OpenTofu with the state encrypted and committed, as text2sql v2 does | The pattern of text2sql v2. CI is the only writer of the state, and it commits the state back with `[skip ci]`. |
|
|
56
|
+
| Deploy trigger | text2sql deployed with a Dokploy webhook | the release job calls the Dokploy API with the panel key | The fewest long-lived credentials (2026-10-29): the apply needs the panel key in CI anyway, so the webhook URL and the PAT that wrote it into the Actions secrets go. |
|
|
57
|
+
| Delivery from day one | — | a new repo ships from `main` before its first feature | The owner's rule of 2026-10-29. Nobody runs a deploy, an apply or a build by hand. The owner runs each command that writes a secret. |
|
|
58
|
+
|
|
59
|
+
### Rules that are still prose
|
|
60
|
+
|
|
61
|
+
No generator writes these and no check runs them. Each one cost time once.
|
|
62
|
+
|
|
63
|
+
- Pass Nx flags through `npx nx`, never `npm exec`: npm eats the flags.
|
|
64
|
+
- Review each install script before you name it in `allowScripts`, and name a package with no version. The reasons so far: `esbuild: true`, because its postinstall links the native binary over the Node wrapper and downloads it when the platform package is missing; `nx: false`, because its postinstall only updates the Nx Cloud client and exits 0 on each error, and no repo uses Nx Cloud; `unrs-resolver`, `@parcel/watcher` and `fsevents` are native fallbacks. Some scripts block only on Linux (`dtrace-provider` under `eas-cli`, `protobufjs`), so read the list from a Linux install too: `docker run node:lts-bookworm-slim … npm ci`.
|
|
65
|
+
- Keep one copy of each shared runtime package, and run `npm ls <pkg>` after each generator. When tooling pins an older major (`zod` 3 for `@expo/cli`), declare the runtime major as a root `devDependency`, so npm hoists it and nests the old one.
|
|
66
|
+
- Add a package only for a real second caller.
|
|
67
|
+
- No `paths` aliases between projects. Projects import each other by package name, and `nx sync` writes the references.
|
|
68
|
+
- Never set the same key in a `project.json` and in the `nx` key of a `package.json`.
|
|
69
|
+
- A shell target sets a top-level `command`, or `executor: "nx:run-commands"`. `options.command` with no executor becomes `nx:noop`, and the target passes without running.
|
|
70
|
+
- Build order comes from the import graph. Write no `dependsOn` on a named project.
|
|
71
|
+
- Fix each lint finding; no `warn` for later. A ban that names one repo goes in that repo's config, and a rule for each repo goes in `@zukhruf/eslint`. An ESLint config does not read the project graph when it loads.
|
|
72
|
+
- No lint-staged: it put the files of other sessions into commits. Never `--no-verify` without asking.
|
|
73
|
+
- Test fixtures (a Docker database, an HTTP server, a temp folder, msw) come from `@zukhruf/testing`, and `await using` cleans them up.
|
|
74
|
+
- A React component of a library package is tested with `node:test`: the test registers a DOM with `@happy-dom/global-registrator`, then imports `react`, `react-dom/client` and the component from the built package. Node cannot load `.tsx`.
|
|
75
|
+
- `serve` of a backend runs the source, so its `ui.route.ts` answers `/` with `ui/build-missing`. In development the web app runs on the Vite dev server.
|
|
76
|
+
- CI installs each tool that a target runs, for example OpenTofu for the `typecheck` of the infra project. It passed locally only because Homebrew had `tofu`.
|
|
77
|
+
- On a paid GitHub plan, move the deploy secrets into a `production` environment that only `main` can use.
|
|
78
|
+
- The owner does each one-time step: `gh auth refresh -s workflow` (a push of a workflow file needs the scope) and the repository secrets.
|
|
79
|
+
|
|
80
|
+
### Mobile with Expo
|
|
81
|
+
|
|
82
|
+
No generator writes a mobile app yet. This is the Nx 24 shape of 2026-10-29:
|
|
83
|
+
|
|
84
|
+
- `nx g @nx/expo:app apps/<name>`, with `@nx/expo/plugin`. Set `buildTargetName: "eas-build"`: a target named `build` would run `eas build` in the cloud from `nx run-many -t build` and from the pre-push `Build` step.
|
|
85
|
+
- The latest Expo SDK and `expo-router` (`main: "expo-router/entry"`, routes in `src/app/`). Install Expo modules with the inferred `install` target, so the versions match the SDK.
|
|
86
|
+
- After the generator: move its root `dependencies` (Expo, React, React Native) into the app manifest with real versions (it writes `"*"`), delete `jest-expo` and `@testing-library/react-native`, and delete `tools/scripts/eas-build-{pre,post}-install.mjs`. The one EAS hook of the app is `eas-build-post-install`, which runs the `sdk` target of the generated client, because EAS installs from Git.
|
|
87
|
+
- Root `overrides` pin `react` and `react-dom` to the version of the Expo SDK, and each app declares it. Two copies fail with "Invalid hook call".
|
|
88
|
+
- `app.json`: set `slug` and `scheme` by hand (the scoped project name is not valid there), `owner`, `android.package`, `ios.bundleIdentifier`, and `ios.infoPlist.ITSAppUsesNonExemptEncryption: false`, or each build waits for an export-compliance answer. Then `eas init --non-interactive --force` from the app folder.
|
|
89
|
+
- `eas.json`: `cli.appVersionSource: "remote"`, and a `base` profile that each profile extends, with `node` as an exact version (EAS accepts no alias; `NoNumericPins` leaves `eas.json` out). The app's `eas-build-pre-install` runs `npm install -g npm@latest`. EAS uploads what Git tracks, so each profile sets its `EXPO_PUBLIC_*` values in `env`.
|
|
90
|
+
- `metro.config.js` wraps the config in `withNxMetro`. Keep the name: `@nx/expo/plugin` finds an Expo project only by that file. It is CommonJS, so turn off `@typescript-eslint/no-require-imports` for it.
|
|
91
|
+
- `tsconfig.app.json` extends `["../../tsconfig.base.json", "expo/tsconfig.base"]` with `noEmit: false`, `outDir: "out-tsc"`, `rootDir: "src"` and `types: ["expo/types"]`.
|
|
92
|
+
- `src/env.ts` reads each `process.env.EXPO_PUBLIC_<NAME>` by name: Expo inlines only those static reads, so the backend's `safeParse(process.env)` does not work.
|
|
93
|
+
- `ios/` and `android/` come from `prebuild` and are ignored by Git. `app.json` is the source of truth.
|
|
94
|
+
- The app calls the backend through the generated client with `baseUrl` from `EXPO_PUBLIC_API_URL`. The client builds URLs with `new URL(path, 'local://')`, which only the `URL` of the Expo runtime accepts, so the client does not work in bare React Native. `start`, `serve`, `run-ios`, `run-android` and `export` depend on `^sdk`.
|
|
95
|
+
- Verify with what CI runs (`expo export`, `eas build --local --non-interactive`). `grep -a` on the `.hbc` files shows whether a string made it into the bundle.
|
|
96
|
+
- TestFlight from CI: `eas build --auto-submit --non-interactive` needs `submit.production.ios.ascAppId`. The owner creates the App Store Connect app once in the web UI and runs `eas credentials -p ios` once (build credentials, then an App Store Connect API key; the App Manager role is enough). EAS then creates the internal TestFlight group. "Couldn't switch to provider" can be a stale Apple session: run it again.
|
|
97
|
+
|
|
98
|
+
### Pitfalls
|
|
99
|
+
|
|
100
|
+
- After you move a project: `nx reset`, then `nx sync`, then diff the tsconfigs. A stale graph makes `sync` delete valid references.
|
|
101
|
+
- A phantom TS2307 or TS6305 comes from a stale `.tsbuildinfo`. Run `nx reset`; do not edit the references.
|
|
102
|
+
- An incremental `typecheck` can miss a `.tsx` call-site error after a move, and `tsc` does not see a bundler break. Verify with the real build.
|
|
103
|
+
- After you delete a workspace, delete its `extraneous` entries from `package-lock.json`. A commit that adds a package carries its lockfile entries and its root tsconfig reference.
|
|
104
|
+
- `@nx/esbuild`: `thirdParty` decides what is bundled; `additionalEntryPoints` duplicate shared classes and break `instanceof`; an asset that the root `.gitignore` matches is dropped; a failed watch rebuild deletes the output. `generatePackageJson` throws in a TS solution workspace: use `prune-lockfile`.
|
|
105
|
+
- `nx migrate --create-commits` runs `git add -A`. Read `migrations.json` first. `parallel` in `nx.json` takes only a number.
|
|
106
|
+
- A generator of Nx rewrites root files through an AST: it can drop the comments of `eslint.config.mjs` and add `@swc/helpers` again. Stage before a generator of Nx, and diff after.
|
|
107
|
+
- Nx applies a sync only in an interactive run. A piped or CI run stops with "The workspace is out of sync": run `npx nx sync`.
|
|
108
|
+
- When Nx detects an AI agent, it holds the output of a task until the task ends. Add `--output-style=stream-without-prefixes` to read a server while it runs.
|
|
109
|
+
- With no green CI run yet, `nrwl/nx-set-shas` falls back to `HEAD~1`, and `affected` sees only the last commit. The generated CI runs `run-many` when `noPreviousBuild` is set.
|
|
110
|
+
- On a Mac, Microsoft Defender has killed the `commit-msg` and `pre-push` hooks. A `pre-push` that dies with SIGKILL is that, not the build.
|
|
111
|
+
- The macOS firewall in stealth mode drops LAN connections to `node`, even from the same Mac, so Expo's LAN URL times out in Expo Go. On the simulator, start with `-- --ios --localhost`.
|
|
112
|
+
- The Claude Code TypeScript LSP finds no `tsserver.js` under the TypeScript 6 alias, so it shows no diagnostics. Use `nx run <project>:typecheck`.
|
|
113
|
+
- zsh does not split an unquoted variable into words: `kill $pids` with `pids="1 2 3"` passes one argument.
|
|
114
|
+
|
|
20
115
|
## format
|
|
21
116
|
|
|
22
117
|
An Nx workspace formats its files with Prettier. The `format` area is an Nx inference plugin. It gives each project of the workspace two targets: `format`, which writes the files, and `format:check`, which only reads them. You list the plugin one time in `nx.json`. You do not copy targets into each project.
|
|
@@ -134,6 +229,7 @@ context-compiler already does this for `@nx/eslint/plugin`. See [ADR 0003](./doc
|
|
|
134
229
|
| whatisgoingon | #3321 |
|
|
135
230
|
| text2sql | #3322 |
|
|
136
231
|
| deepagents | #3323 |
|
|
232
|
+
| meddit | #4606 (written by `preset`) |
|
|
137
233
|
|
|
138
234
|
The umbrella item is #3317.
|
|
139
235
|
|
|
@@ -345,6 +441,7 @@ A `scripts.test` in a `package.json` replaces the inferred target. Nx runs it wi
|
|
|
345
441
|
| elt | uses it (#3366) |
|
|
346
442
|
| context-compiler | uses it (#3367) |
|
|
347
443
|
| text2sql | uses it (#3368) |
|
|
444
|
+
| meddit | #4606 (written by `preset`) |
|
|
348
445
|
|
|
349
446
|
The umbrella item is #3328.
|
|
350
447
|
|
|
@@ -493,6 +590,7 @@ The lockfile measured the edges on 2026-10-30. For factory, whatisgoingon, deepa
|
|
|
493
590
|
| text2sql | uses it (#3389) |
|
|
494
591
|
| elt | uses it (#3390) |
|
|
495
592
|
| context-compiler | uses it (#3391) |
|
|
593
|
+
| meddit | #4606 (written by `preset`) |
|
|
496
594
|
|
|
497
595
|
The umbrella item is #3335.
|
|
498
596
|
|
|
@@ -719,7 +817,7 @@ The backlog item of the area is #3339.
|
|
|
719
817
|
|
|
720
818
|
## generators
|
|
721
819
|
|
|
722
|
-
The root files of a workspace are the same in each repo: `package.json`, `nx.json`, the tsconfig files, `.npmrc`, the Git hooks and more (
|
|
820
|
+
The root files of a workspace are the same in each repo: `package.json`, `nx.json`, the tsconfig files, `.npmrc`, the Git hooks and more (see [monorepo standard](#monorepo-standard)). factory writes them with the `workspace` generator of its private package `@factory/foundation`. Other repos copy them by hand: 3 to 7 copies of each file. meddit is the third repo that starts from the standard, so the generator moves here (#3259).
|
|
723
821
|
|
|
724
822
|
The package gives two Nx generators:
|
|
725
823
|
|
|
@@ -844,21 +942,21 @@ type InitOptions = Record<string, never>;
|
|
|
844
942
|
| ------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
845
943
|
| `package.json` | `private: true`, `type: "module"`, `workspaces: ["apps/*", "packages/*", "tools/*"]` when missing, `scripts.prepare: "git config core.hooksPath .husky \|\| exit 0"` when missing, the root `devDependencies` (see [Versions](#versions-that-the-generators-write)), `allowScripts` for the packages it installs | merge keys | also deletes `packageManager`, the empty `dependencies` and `@nx/workspace`; moves `@zukhruf/nx` from `dependencies` to `devDependencies`; `name` stays `@<name>/source` |
|
|
846
944
|
| `nx.json` | `analytics: false`; `tui.enabled: false`; `namedInputs` `default`, `production` (with `{ "env": "NODE_ENV" }`, without the ESLint config, the tests and the test tsconfigs) and `sharedGlobals` (the root ESLint config, `tsconfig.base.json`); `plugins` in this order: `@nx/js/typescript`, `@nx/eslint/plugin`, `@zukhruf/nx/lint`, `@zukhruf/nx/format`, `@zukhruf/nx/test`; `targetDefaults` below; `sync.applyChanges: true` | merge keys | — |
|
|
847
|
-
| `tsconfig.base.json` | the base for bundled apps
|
|
945
|
+
| `tsconfig.base.json` | the base for bundled apps (`moduleResolution: "Bundler"`, `strict`, `verbatimModuleSyntax`, `erasableSyntaxOnly`), with `noUncheckedIndexedAccess`; `tsconfigBase` in [`files.ts`](./src/generators/init/files.ts) | create | — |
|
|
848
946
|
| `tsconfig.json` | the solution file: `extends` the base, `files: []`, `references: []`; `nx sync` writes the references | create | — |
|
|
849
947
|
| `.npmrc` | `legacy-peer-deps=false`, `save-exact=true`, `strict-allow-scripts=true` | add lines | — |
|
|
850
948
|
| `.nvmrc` | `lts/*` | create | — |
|
|
851
949
|
| `.gitattributes` | `* text=auto eol=lf` | create | — |
|
|
852
950
|
| `.editorconfig` | utf-8, lf, a final newline, 2 spaces, trim trailing whitespace except in `*.md` | create | replaces the file of `nx new` |
|
|
853
|
-
| `.gitignore` |
|
|
854
|
-
| `.prettierrc` | the
|
|
855
|
-
| `.prettierignore` |
|
|
951
|
+
| `.gitignore` | `gitignore` in [`files.ts`](./src/generators/init/files.ts) | add lines | replaces the file of `nx new` |
|
|
952
|
+
| `.prettierrc` | single quotes, the sort-imports plugin, `importOrder` with `./env` and `./startup` first and `^@<scope>/(.*)$`, and no Tailwind plugin | create | — |
|
|
953
|
+
| `.prettierignore` | `prettierignore` in [`files.ts`](./src/generators/init/files.ts) | add lines | — |
|
|
856
954
|
| `eslint.config.mjs` | `flat/base`, `flat/typescript` and `flat/javascript` of `@nx/eslint-plugin`; the build-output `ignores`; `@nx/enforce-module-boundaries`; the `base`, `tests`, `diagnostics`, `env` and `nx-project-json` configs of `@zukhruf/eslint`; `manifest.configs.recommended`; Modern Node for the config files and `.husky/*.ts`; `allowDefaultProject` for `*.config.ts` and `.husky/*.ts` | create | — |
|
|
857
|
-
| `.husky/pre-commit.ts`, `pre-push.ts`, `commit-msg.ts` |
|
|
955
|
+
| `.husky/pre-commit.ts`, `pre-push.ts`, `commit-msg.ts` | `Sync`, `Format`, `NoNumericPins`, `NpmrcPolicy`, `LockfileSync`, `DockerfileInstallsFromLockfile` and `DependencyChecks` on pre-commit, `Build` with `NODE_ENV=production` on pre-push, `NxReleaseScope` on commit-msg; mode `755` | create | — |
|
|
858
956
|
| `.husky/pre-commit`, `pre-push`, `commit-msg` | a link to the `.ts` file of the same name | create | — |
|
|
859
957
|
| `.vscode/settings.json` | file nesting, watcher and search excludes for `node_modules`, `.nx`, `tmp` | create | — |
|
|
860
958
|
| `.vscode/extensions.json` | `nrwl.angular-console`, `esbenp.prettier-vscode`, `dbaeumer.vscode-eslint` | create | replaces the file of `nx new` |
|
|
861
|
-
| `AGENTS.md`, `CLAUDE.md` | `AGENTS.md` holds the commands of
|
|
959
|
+
| `AGENTS.md`, `CLAUDE.md` | `AGENTS.md` holds the commands of the agent workflow; `CLAUDE.md` is one line, `@AGENTS.md` | create | — |
|
|
862
960
|
| `README.md` | `# <name>` and a link to `AGENTS.md` | — | replaces the file of `nx new` |
|
|
863
961
|
|
|
864
962
|
The `targetDefaults` that `init` writes:
|
|
@@ -891,7 +989,7 @@ The Git hooks are the same in each repo. `Sync` stages `**/tsconfig*.json` and `
|
|
|
891
989
|
|
|
892
990
|
- **The Nx family has one exact version.** `init` sets the root `nx` and each root `@nx/*` to `nxVersion`, also when the version is already there and is another one, a newer one included. Then npm installs one `nx` (#4532). An app generator adds its `@nx/*` packages at the same `nxVersion`. A test checks that the root `nx` equals `nxVersion` after `preset`, and that no root `@nx/*` has another version.
|
|
893
991
|
- **A missing `@zukhruf/*` package gets the version of `@zukhruf/nx` itself.** nx release gives each public package of zukhruf the same version, so the generator reads its own `package.json` and writes no list of versions. A version that is already there stays, for example a `file:` tarball in a smoke test.
|
|
894
|
-
- **The other root tools have exact versions** from one module, `src/generators/versions.ts`, that the app generators share: TypeScript 7 as `@typescript/native: "npm:typescript@7.x"` and the TypeScript 6 API as `typescript: "npm:@typescript/typescript6@6.x"` (
|
|
992
|
+
- **The other root tools have exact versions** from one module, `src/generators/versions.ts`, that the app generators share: TypeScript 7 as `@typescript/native: "npm:typescript@7.x"` and the TypeScript 6 API as `typescript: "npm:@typescript/typescript6@6.x"` (see [Decisions and their reasons](#decisions-and-their-reasons)), ESLint 10, Prettier 3, `@trivago/prettier-plugin-sort-imports`, and the peers of `@zukhruf/eslint` that the root config loads. `init` adds a missing package at that version, and keeps a version that is already there.
|
|
895
993
|
- **`allowScripts`** names each install script of a package that the generator installs: `nx: false` and `unrs-resolver: false`. `init` adds a missing name, and keeps a decision that is already there. The smoke test of 2026-11-18 proved the list: `npm install` with `strict-allow-scripts=true` passed.
|
|
896
994
|
|
|
897
995
|
### The workspace scope
|
|
@@ -915,7 +1013,7 @@ The `Tree` keeps a file mode, but it has no links:
|
|
|
915
1013
|
### What the generators do not do
|
|
916
1014
|
|
|
917
1015
|
- **They do not write CI, deploy or infra files.** The `dokploy` generator writes them (#4603).
|
|
918
|
-
- **They do not write a NodeNext base.** The base is the one for bundled apps
|
|
1016
|
+
- **They do not write a NodeNext base.** The base is the one for bundled apps. zukhruf and elt run code from source with NodeNext, and they do not use the generators.
|
|
919
1017
|
- **They do not change an ESLint config that is already there.** factory splices the configs of `@zukhruf/eslint` into an existing `eslint.config.mjs`. No consumer needs that now: the generator writes the file in a new repo, and factory and whatisgoingon already have their config.
|
|
920
1018
|
- **They do not commit.** create-nx-workspace commits only in a new folder. In an existing repo, you make the first commit.
|
|
921
1019
|
- **They do not delete a file or a folder** that the standard does not own. Only `preset` deletes, and only what `nx new` and `nx g` wrote a moment before: keys of `package.json`, `apps/.gitkeep` and `libs/.gitkeep`.
|
|
@@ -924,7 +1022,7 @@ The `Tree` keeps a file mode, but it has no links:
|
|
|
924
1022
|
|
|
925
1023
|
- The brand: the `@factory` scope fallback, the fonts, colors and favicons (#3338).
|
|
926
1024
|
- The mirror tests `tests/workspace-mirror.test.ts` and `tests/templates-mirror.test.ts`. They prove that factory's own root files equal the output of the generator. factory keeps them, and calls `@zukhruf/nx:init` (#4611).
|
|
927
|
-
- `--test-force-exit` for each project: factory sets it in the options of `@zukhruf/nx/test`. The standard adds it only for the tag `test:docker` (
|
|
1025
|
+
- `--test-force-exit` for each project: factory sets it in the options of `@zukhruf/nx/test`. The standard adds it only for the tag `test:docker` ([Docker tests](#docker-tests)), so `init` writes the plugin with no options.
|
|
928
1026
|
|
|
929
1027
|
### Tests of the generators
|
|
930
1028
|
|
|
@@ -951,4 +1049,265 @@ NX_E2E_PRESET_VERSION=file:<scratch>/zukhruf-nx-<version>.tgz \
|
|
|
951
1049
|
|
|
952
1050
|
Then check that `npm install` passes, that `npx nx run-many -t typecheck` and `npx nx run-many -t lint` pass, and that the first `git commit` passes the hooks. Delete the folder at the end. On 2026-11-18 both paths passed: a new folder (`acme`), and a folder with only `git init` (`.`). In the new folder, a demo package also passed `typecheck` (TypeScript 7.0.2) and `lint`, and its commit passed each hook. A second run of `npx nx g @zukhruf/nx:init` in the generated repo changed no file.
|
|
953
1051
|
|
|
1052
|
+
### Who uses the generators
|
|
1053
|
+
|
|
1054
|
+
| Workspace | Generators | Backlog item |
|
|
1055
|
+
| --------- | ----------------------------------------------------- | ------------ |
|
|
1056
|
+
| meddit | `preset`, `node-app`, `react-app`, `pair` | #4606 |
|
|
1057
|
+
| meddit | `prisma` | #4607 |
|
|
1058
|
+
| meddit | `dokploy` | #4608 |
|
|
1059
|
+
| factory | `init`, `node-app`, `react-app`, `pair`, `ui-package` | #4611 |
|
|
1060
|
+
|
|
954
1061
|
The decisions are in [ADR 0009](./docs/adr/0009-a-preset-and-an-init-generator-start-a-repo-from-nothing.md). The backlog item of the generators is #3337.
|
|
1062
|
+
|
|
1063
|
+
## app generators
|
|
1064
|
+
|
|
1065
|
+
Four generators add the projects of the standard: a backend, a web app, the pair of the two, and a UI package. factory wrote them in its private package `@factory/foundation`; whatisgoingon, text2sql and deepagents hold copies. meddit is the third repo of the same kinds, so they move here (#3338). Each runs [`init`](#add-the-standard-to-an-nx-workspace) first.
|
|
1066
|
+
|
|
1067
|
+
### Add a backend, a web app and their pair
|
|
1068
|
+
|
|
1069
|
+
```sh
|
|
1070
|
+
npx nx g @zukhruf/nx:node-app apps/backend
|
|
1071
|
+
npx nx g @zukhruf/nx:react-app apps/web
|
|
1072
|
+
npx nx g @zukhruf/nx:pair --api apps/backend --web apps/web
|
|
1073
|
+
npm install
|
|
1074
|
+
npx nx sync
|
|
1075
|
+
```
|
|
1076
|
+
|
|
1077
|
+
Then `npx nx run-many -t typecheck lint test build` passes, and `npx nx run @acme/backend:docker:build` builds the image of the backend with the web build in it. The image reports its commit:
|
|
1078
|
+
|
|
1079
|
+
```sh
|
|
1080
|
+
npx nx run @acme/backend:docker:run
|
|
1081
|
+
curl -s http://localhost:3000/api/healthz # {"status":"ok","sha":"<git rev-parse HEAD>"}
|
|
1082
|
+
```
|
|
1083
|
+
|
|
1084
|
+
### Add a UI package
|
|
1085
|
+
|
|
1086
|
+
```sh
|
|
1087
|
+
npx nx g @zukhruf/nx:ui-package packages/ui --importPath @acme/ui
|
|
1088
|
+
```
|
|
1089
|
+
|
|
1090
|
+
### Signature of the app generators
|
|
1091
|
+
|
|
1092
|
+
```ts
|
|
1093
|
+
// @zukhruf/nx:node-app
|
|
1094
|
+
interface NodeAppOptions {
|
|
1095
|
+
directory: string; // the project root, for example apps/backend
|
|
1096
|
+
port?: number; // 3000: PORT in .env.example, portless --app-port, EXPOSE
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// @zukhruf/nx:react-app
|
|
1100
|
+
interface ReactAppOptions {
|
|
1101
|
+
directory: string; // the project root, for example apps/web
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
// @zukhruf/nx:pair
|
|
1105
|
+
interface PairOptions {
|
|
1106
|
+
api: string; // the project root of a node-app
|
|
1107
|
+
web: string; // the project root of a react-app
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// @zukhruf/nx:ui-package
|
|
1111
|
+
interface UiPackageOptions {
|
|
1112
|
+
directory: string; // under packages/, for example packages/ui
|
|
1113
|
+
importPath: string; // a scoped package name, for example @acme/ui
|
|
1114
|
+
}
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
Each schema sets `additionalProperties: false`. The project name is the package name: `@<scope>/<last segment of directory>`, for example `@acme/backend`.
|
|
1118
|
+
|
|
1119
|
+
### What each app generator writes
|
|
1120
|
+
|
|
1121
|
+
| Generator | Files of the project | Root and nx.json |
|
|
1122
|
+
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1123
|
+
| `node-app` | `src/server.ts` (terminus, the `@nx-target-name: serve` header), `app.ts` (Hono on `/api`), `env.ts` (zod, `BUILD_SHA`), `logging.ts` (evlog), `startup.ts`, `routes/healthz.route.ts`, `app.test.ts`; `.env.example` (always) and `.env` (when missing); `Dockerfile`; `sdk-it.config.ts` and the client stub in `.sdk-it/`; the tsconfigs; `eslint.config.mjs` with `hono`, Modern Node and the env settings | `@nx/node`, `@nx/esbuild`, `esbuild`, `@sdk-it/cli`; `.dockerignore` when missing; the client in `workspaces`; the `.sdk-it` lines of `.gitignore` and `.prettierignore`; the `@nx/esbuild:esbuild` default; `^sdk` in `build`, `dev`, `typecheck` and `test` (`["...", "^sdk"]`); the sdk-it exclusion of `production`; `generators["@nx/node"]` |
|
|
1124
|
+
| `react-app` | `index.html`, `src/main.tsx` (React Router 8 in data mode), `src/app/app.tsx` and its test, `src/styles.css` (Tailwind with the sync markers), `vite.config.ts` (the React Compiler, Tailwind, brotli and gzip, the portless and `/api` dev proxy, the `test` block), `tsconfig.app.json` writing to `out-tsc`, `tsconfig.spec.json`, `eslint.config.mjs` with `@zukhruf/eslint/react`, `react-router` and `tailwind` | `@nx/react`, `@nx/vite`, `@nx/vitest` with `testMode: "run"`, Vite, Vitest, Testing Library, happy-dom, Tailwind, the 4 React lint plugins; `prettier-plugin-tailwindcss` in `.prettierrc`; the Tailwind sync generator in `sync` and in `build`, `dev`, `serve`; `generators["@nx/react"]`; the `test` default as it was |
|
|
1125
|
+
| `pair` | in the web: `src/api.ts` and the client, `zod` and `fast-content-type-parse` in its manifest; in the api: `src/routes/ui.route.ts`, its mount in `app.ts`, and the Dockerfile again with the web build | — |
|
|
1126
|
+
| `ui-package` | `package.json` with the `development` export of `src/index.ts`, `vite.config.ts` (a library with `vite-plugin-dts`), the tsconfigs, `eslint.config.mjs` with `@zukhruf/eslint/react` and `tailwind`, `tests/public-api.test.mjs` | the React root packages |
|
|
1127
|
+
|
|
1128
|
+
The targets of a project are in the `nx` key of its `package.json`: the generators pass `useProjectJson: false` and `addPlugin: true` to Nx, so Nx 23 and 24 write the same shape. `format`, `lint`, `test` (node) and `typecheck` come from the inference plugins; `node-app` writes `build` (one ESM esbuild bundle, each npm package external, with a `require` banner), `serve` (with `NODE_ENV=development`), `portless` (`<app>.<scope>`), `docker:build` and `docker:run`, and keeps `prune-lockfile` of `@nx/node`. `react-app` writes `portless` and the `test` target of the project (`^sdk`, `NODE_ENV=test`).
|
|
1129
|
+
|
|
1130
|
+
### The commit of an image
|
|
1131
|
+
|
|
1132
|
+
`docker:build` runs `docker build --file <root>/Dockerfile --build-arg BUILD_SHA=$(git rev-parse HEAD) --tag <scope>-<app> .` from the workspace root. The runtime stage has `ARG BUILD_SHA` and `ENV ... BUILD_SHA=$BUILD_SHA`, `env.ts` accepts a non-empty string or nothing, and `/api/healthz` returns `{ "status": "ok", "sha": <BUILD_SHA or null> }`. So a deploy can tell the new container from the old one. An image built without the build arg gets an empty `BUILD_SHA`, and `env.ts` stops it at start. terminus answers `/healthz` (no `/api`) for the `HEALTHCHECK`.
|
|
1133
|
+
|
|
1134
|
+
### Versions that the app generators write
|
|
1135
|
+
|
|
1136
|
+
- The packages of the apps have exact versions in `appPackageVersions` of `src/generators/versions.ts`, the latest on 2026-11-18: Hono 4.13, `@hono/node-server` 2.1, evlog 2.35, zod 4.6, sdk-it 0.46.11, esbuild 0.28, React 19.3, React Router 8.5, Vite 8.3, Vitest 5.1, Tailwind 4.3, `@vitejs/plugin-react` 6.3, `@rolldown/plugin-babel` 0.3, `vite-plugin-dts` 5.1.
|
|
1137
|
+
- An app generator reads the root package names before the generator of Nx runs. After it, a package of the app that was not there gets its pin, also over the version that Nx wrote; a version that was there stays. Each root `nx` and `@nx/*` gets `nxVersion`.
|
|
1138
|
+
- Residue goes when the run added it: the swc toolchain, `eslint-plugin-import`, `eslint-plugin-jsx-a11y` and `eslint-plugin-react` (they cap ESLint below 10), the root `react` and `react-dom` (each project declares its own), `@vitest/ui`, and for `ui-package` `@babel/core`, `@babel/preset-react`, `ajv` and the root `vite-plugin-dts`.
|
|
1139
|
+
- `allowScripts`: `esbuild: true`, `@parcel/watcher: false` and `fsevents: false` from `node-app`. A decision that is there stays.
|
|
1140
|
+
- `overrides`: `@juristr/nx-tailwind-sync` takes the one `@nx/devkit` (#4532); `@sdk-it/cli` and `@sdk-it/hono` take the root `typescript`, because sdk-it peers on `^6.0.3` and the TypeScript 6 alias is 6.0.2.
|
|
1141
|
+
|
|
1142
|
+
### Where the Nx plugins come from
|
|
1143
|
+
|
|
1144
|
+
`@nx/node`, `@nx/react`, `@nx/vite` and `@nx/vitest` are optional peers. An app generator requires the plugin from `@zukhruf/nx`, and else installs it at `nxVersion` into a temporary folder with `ensurePackage` of `@nx/devkit`, as the generators of Nx do. The plugin's own generator adds it to the root `package.json`. A repo with only a backend installs no React, Vite, Vitest or Tailwind package.
|
|
1145
|
+
|
|
1146
|
+
### Errors of the app generators
|
|
1147
|
+
|
|
1148
|
+
| Error | When |
|
|
1149
|
+
| ---------------------------------------------------------------------- | ------------------------------------------------------------- |
|
|
1150
|
+
| `The root package name "acme" has no scope.` | The root package is not named `@<scope>/source` (from `init`) |
|
|
1151
|
+
| `The directory "../x" is not a folder in the workspace.` | `directory` leaves the workspace or is empty |
|
|
1152
|
+
| `apps/backend has no sdk-it.config.ts, so it is not a node-app. Run …` | `pair --api` names a project that `node-app` did not write |
|
|
1153
|
+
| `apps/web has no vite.config.ts, so it is not a react-app. Run …` | `pair --web` names a project that `react-app` did not write |
|
|
1154
|
+
| `A UI package goes under packages/, not "…".` | `ui-package` outside `packages/` |
|
|
1155
|
+
| `<root> already belongs to <name>.` | `ui-package` on a folder of another package |
|
|
1156
|
+
|
|
1157
|
+
### What stays in factory after the move
|
|
1158
|
+
|
|
1159
|
+
The brand: the fonts, colors and favicons of `index.html`. The generated `index.html` has none of them; it keeps the theme script (light, dark or system, set before the first paint) and `styles.css` keeps the `dark` variant, because the standard puts them in each web app (ADR 0010). factory switches to these generators in #4611.
|
|
1160
|
+
|
|
1161
|
+
### Tests of the app generators
|
|
1162
|
+
|
|
1163
|
+
The tests run each generator on a virtual `Tree` with Nx 23.2.1, which zukhruf's root installs (`src/generators/*/generator.test.ts`, helpers in `src/testing/generator-tree.ts`). They port factory's `node-app`, `react-app`, `pair` and `ui-package` tests, and add the build sha, `testMode: "run"`, `test.dependsOn` after `node-app` and `react-app`, a backend-only workspace with no React, Vite, Vitest or Tailwind package, the workspace scope in the portless domain, and no brand in the web files. They drop factory's `modern-node.test.ts` and `root-vite.test.ts`, which write to disk and read zukhruf's installed versions; the smoke test below runs lint and a strict `npm install` instead. What Nx 24.0.6 writes itself is proven by the smoke test.
|
|
1164
|
+
|
|
1165
|
+
### Test the app generators before a release
|
|
1166
|
+
|
|
1167
|
+
After the steps of [Test the preset before a release](#test-the-preset-before-a-release), in the generated repo: run the 3 commands of [Add a backend, a web app and their pair](#add-a-backend-a-web-app-and-their-pair), then `npx nx run-many -t typecheck lint test build`, the first commit (each hook passes), `npx nx run @acme/backend:docker:build`, and a container whose `/api/healthz` reports `git rev-parse HEAD`.
|
|
1168
|
+
|
|
1169
|
+
The decisions are in [ADR 0010](./docs/adr/0010-the-app-generators-move-here-and-call-the-generators-of-nx.md). The backlog item of the app generators is #3338.
|
|
1170
|
+
|
|
1171
|
+
## prisma generator
|
|
1172
|
+
|
|
1173
|
+
`prisma` writes a Postgres db package on Prisma 7 and `@prisma/adapter-pg`, and can connect a node-app to it. text2sql holds 5 copies of the package and factory 1, and meddit is the next one, so the shape moves here (#4604). The targets come from the [prisma area](#prisma): the generator writes none.
|
|
1174
|
+
|
|
1175
|
+
### Add a db package
|
|
1176
|
+
|
|
1177
|
+
```sh
|
|
1178
|
+
npx nx g @zukhruf/nx:prisma packages/db --backend apps/backend
|
|
1179
|
+
npm install
|
|
1180
|
+
npx nx sync
|
|
1181
|
+
npx nx run @acme/db:generate
|
|
1182
|
+
```
|
|
1183
|
+
|
|
1184
|
+
Then `npx nx run-many -t typecheck lint test build` passes, and the tests of `@acme/db` and `@acme/backend` run against a Postgres of `@zukhruf/testing`. Leave out `--backend` for a package that no backend uses yet.
|
|
1185
|
+
|
|
1186
|
+
### Signature of the prisma generator
|
|
1187
|
+
|
|
1188
|
+
```ts
|
|
1189
|
+
// @zukhruf/nx:prisma
|
|
1190
|
+
interface PrismaOptions {
|
|
1191
|
+
directory: string; // the project root, for example packages/db
|
|
1192
|
+
backend?: string; // the project root of a node-app, for example apps/backend
|
|
1193
|
+
}
|
|
1194
|
+
```
|
|
1195
|
+
|
|
1196
|
+
The schema sets `additionalProperties: false`. The package name is `@<scope>/<last segment of directory>`, for example `@acme/db`.
|
|
1197
|
+
|
|
1198
|
+
### What the prisma generator writes
|
|
1199
|
+
|
|
1200
|
+
| File | Content |
|
|
1201
|
+
| ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1202
|
+
| `schema.prisma` | the `prisma-client` generator with `output = "src/prisma"` and `importFileExtension = "ts"`, and the `postgresql` datasource; the models go in `models/*.prisma` |
|
|
1203
|
+
| `prisma.config.ts` | `schema: '.'`, `migrations.path: 'migrations'`, `url` from `CONNECTION_STRING` and `shadowDatabaseUrl` from `SHADOW_CONNECTION_STRING`, each read only when set, so `generate` runs with none; no dotenv |
|
|
1204
|
+
| `migrations/migration_lock.toml` | `provider = "postgresql"` |
|
|
1205
|
+
| `models/.gitkeep` | the image copies `models/`, so the folder is in Git before the first model |
|
|
1206
|
+
| `src/index.ts` | `createPrisma({ connectionString })` on the Postgres adapter, and each export of the generated client; it reads no environment |
|
|
1207
|
+
| `src/testing.ts` | `applySchema(connectionString)`: runs each `migrations/*/migration.sql` in order with `pg`, with no `_prisma_migrations` record, for a test database that is thrown away |
|
|
1208
|
+
| `src/index.test.ts` | a query on a database of `@zukhruf/testing/postgres` after `applySchema`; the project has the tag `test:docker` |
|
|
1209
|
+
| `package.json` | the `.` and `./testing` exports (`development` the source, `import` `dist`); `@prisma/client`, `@prisma/adapter-pg`, `pg` and `tslib` in `dependencies`; `prisma` and `@types/pg` in `devDependencies` |
|
|
1210
|
+
| `tsconfig.lib.json` | the build: JavaScript and declarations into `dist`, with `rewriteRelativeImportExtensions`, because the generated client imports `.ts` files |
|
|
1211
|
+
| `tsconfig.json`, `tsconfig.test.json` | the solution file and the tests, as in node-app |
|
|
1212
|
+
| `eslint.config.mjs` | ignores `src/prisma`; Modern Node; `allowDefaultProject` for `prisma.config.ts` |
|
|
1213
|
+
| `.env.example`, `.env` | `CONNECTION_STRING=` and `SHADOW_CONNECTION_STRING=`; `.env` only when missing |
|
|
1214
|
+
| `Dockerfile.migration` | `npm ci --workspace=<package>` installs the CLI from the lockfile, and `CMD npx prisma migrate deploy` applies the migrations to the `CONNECTION_STRING` of the container |
|
|
1215
|
+
|
|
1216
|
+
At the root: `@zukhruf/nx/prisma` in `plugins`; `generate` in the `dependsOn` of the `typecheck` and `build` defaults, with `...`; `<root>/src/prisma` in `.gitignore` and `.prettierignore`; `.dockerignore` when missing; the package root in `workspaces` when no `<parent>/*` glob holds it; `@zukhruf/testing`; and `@prisma/engines: true`, `prisma: false`, `ssh2: false`, `cpu-features: false` in `allowScripts`. A second run keeps the files of the package and adds no line or key twice.
|
|
1217
|
+
|
|
1218
|
+
With `--backend`, the node-app gets:
|
|
1219
|
+
|
|
1220
|
+
- `CONNECTION_STRING: z.string().min(1)` in `src/env.ts`, and the key in `.env.example` and in a `.env` that has none.
|
|
1221
|
+
- In `src/startup.ts`, the client and one `SELECT 1` before the app serves, so a database that refuses the connection stops the boot. `$connect()` alone opens no connection on a driver adapter.
|
|
1222
|
+
- `await prisma.$disconnect()` in the terminus `onSignal` of `src/server.ts`.
|
|
1223
|
+
- `src/database.test.ts`, which imports the package through its exports, and the tag `test:docker`.
|
|
1224
|
+
- The npm packages of the db package in its `dependencies`, not the package: the bundle inlines the package and leaves them external, so `prune-lockfile` puts them in the image.
|
|
1225
|
+
|
|
1226
|
+
### Versions that the prisma generator writes
|
|
1227
|
+
|
|
1228
|
+
`prisma`, `@prisma/client` and `@prisma/adapter-pg` have one exact version, 7.10.1, in `appPackageVersions`. The `latest` tag of `prisma` is a release candidate of 8 (8.0.0-rc.34 on 2026-11-18) while the other two are at 7.10.1, so no version comes from `latest`, and a test checks that the three are equal and stable.
|
|
1229
|
+
|
|
1230
|
+
### Migrations
|
|
1231
|
+
|
|
1232
|
+
Write a migration by hand, or with `npx prisma migrate diff --from-empty --to-schema . --script` in the package for the first one, into `migrations/<timestamp>_<name>/migration.sql`. Apply it with `nx run @acme/db:deploy`, or with the image. `migrate dev` needs a TTY, so an agent does not run it, and nothing runs `migrate reset` on a shared database.
|
|
1233
|
+
|
|
1234
|
+
### Errors of the prisma generator
|
|
1235
|
+
|
|
1236
|
+
| Error | When |
|
|
1237
|
+
| ---------------------------------------------------------------------- | --------------------------------------------------------- |
|
|
1238
|
+
| `apps/api has no sdk-it.config.ts, so it is not a node-app. Run …` | `--backend` names a project that `node-app` did not write |
|
|
1239
|
+
| `packages/db already belongs to @acme/other.` | `directory` holds another package |
|
|
1240
|
+
| `apps/backend/src/server.ts has no "import './startup.ts';", so the …` | a backend file lost the line that the wiring changes |
|
|
1241
|
+
|
|
1242
|
+
### Test the prisma generator before a release
|
|
1243
|
+
|
|
1244
|
+
After the steps of [Test the preset before a release](#test-the-preset-before-a-release): `node-app apps/backend`, the 4 commands of [Add a db package](#add-a-db-package), and `npx nx run-many -t typecheck lint test build`. Then add a model and a first migration, put `@zukhruf/nx` back on the registry version (`npm ci` in an image cannot read a `file:` tarball), build `Dockerfile.migration`, and run its container against a new `postgres:18-alpine`: `prisma migrate deploy` applies the migration. On 2026-11-18 each step passed, and the backend image served `/api/healthz` with one database session and stopped at start with a wrong password.
|
|
1245
|
+
|
|
1246
|
+
The decisions are in [ADR 0012](./docs/adr/0012-the-prisma-generator-writes-a-postgres-db-package-and-wires-a-backend.md). The backlog item is #4604.
|
|
1247
|
+
|
|
1248
|
+
## dokploy generator
|
|
1249
|
+
|
|
1250
|
+
`dokploy` writes the GitOps delivery of a node-app on Dokploy: an OpenTofu project in `infra/` that stores the compose in Dokploy, and the workflows that build the images, apply the stack and roll it out. text2sql (v2, authx) and whatisgoingon hold copies, and meddit is the third repo, so the shape moves here (#4603). The workflows call zukhruf's kit at `@main`: the reusable `tofu-apply.yml`, and the `dokploy-deploy` and `wait-for-health` actions.
|
|
1251
|
+
|
|
1252
|
+
### Deliver a backend
|
|
1253
|
+
|
|
1254
|
+
```sh
|
|
1255
|
+
npx nx g @zukhruf/nx:dokploy --api apps/backend --owner <github-owner>
|
|
1256
|
+
npx nx run @acme/infra:typecheck
|
|
1257
|
+
```
|
|
1258
|
+
|
|
1259
|
+
With Postgres, a Prisma package, a private GHCR and a DNS name:
|
|
1260
|
+
|
|
1261
|
+
```sh
|
|
1262
|
+
npx nx g @zukhruf/nx:dokploy --api apps/backend --owner Phi-Science \
|
|
1263
|
+
--database packages/db --registryUser <github-user> --host app.example.com
|
|
1264
|
+
```
|
|
1265
|
+
|
|
1266
|
+
Then add the repository secrets `TF_ENCRYPTION_PASSPHRASE`, `DOKPLOY_API_KEY` and `HCLOUD_TOKEN`, and `GHCR_PULL_TOKEN` with `--registryUser`. A push to `main` runs CI, and a green CI run deploys.
|
|
1267
|
+
|
|
1268
|
+
### Signature of the dokploy generator
|
|
1269
|
+
|
|
1270
|
+
```ts
|
|
1271
|
+
// @zukhruf/nx:dokploy
|
|
1272
|
+
interface DokployOptions {
|
|
1273
|
+
api: string; // the project root of a node-app
|
|
1274
|
+
owner: string; // the GitHub owner; the images are ghcr.io/<owner, lowercase>/<name>-<app>
|
|
1275
|
+
name?: string; // the Dokploy project and the image prefix; the workspace scope
|
|
1276
|
+
dokployHost?: string; // https://dokploy.limerence.sh/api
|
|
1277
|
+
server?: string; // the Hetzner server that runs Dokploy: limerence-dokploy
|
|
1278
|
+
host?: string; // a DNS name in a Hetzner zone; without it, <name>.<server ipv4>.sslip.io
|
|
1279
|
+
zone?: string; // the Hetzner zone of host: host without its first label
|
|
1280
|
+
database?: string; // the project root of a Prisma package: adds Postgres and the migrate service
|
|
1281
|
+
registryUser?: string; // the GitHub user of GHCR_PULL_TOKEN: adds a Dokploy registry for private images
|
|
1282
|
+
}
|
|
1283
|
+
```
|
|
1284
|
+
|
|
1285
|
+
### What the dokploy generator writes
|
|
1286
|
+
|
|
1287
|
+
| File | What it holds |
|
|
1288
|
+
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1289
|
+
| `infra/project.json` | `@<scope>/infra`; `@zukhruf/nx/opentofu` gives its targets, and the generator lists that plugin after `@zukhruf/nx/format` in `nx.json` |
|
|
1290
|
+
| `infra/compose.dokploy.yml` | the app image on `dokploy-network` with the Traefik labels (`web` redirects, `websecure` with Let's Encrypt); with `database`, `postgres:18-alpine` and the one-shot `migrate`, which the app waits for |
|
|
1291
|
+
| `infra/.env.example`, `infra/.gitignore` | the secrets of a local run, `TF_VAR_dokploy_api_key=${DOKPLOY_API_KEY}` (and `TF_VAR_ghcr_pull_token`); the plaintext backups, `.terraform/` and `tfplan` |
|
|
1292
|
+
| `src/environments/production/*.tf` | `versions`, `backend` (local, the encrypted state committed), `encryption` (pbkdf2 and aes_gcm, enforced), `providers`, `dns`, `main`, `outputs` (`dokploy_api`, `compose_id`, `host`), `variables`, `registry` |
|
|
1293
|
+
| `.terraform.lock.hcl` | the providers for `linux_amd64` and `darwin_arm64`, so `typecheck` (`-lockfile=readonly`) passes on CI and a Mac |
|
|
1294
|
+
| `.github/workflows/deploy.yml` | gate, image (a matrix: the app and `migrate`), promote to `:latest`, infra (`tofu-apply.yml`), release (`dokploy-deploy`, `wait-for-health`) |
|
|
1295
|
+
| `.github/workflows/ci.yml` | only when missing: setup-workspace, OpenTofu, nx-set-shas, `sync:check` and `prettier --check` in parallel, then `nx affected -t lint typecheck test build` |
|
|
1296
|
+
|
|
1297
|
+
The compose reads `PUBLIC_HOST`, and with `database` `POSTGRES_PASSWORD` and `CONNECTION_STRING`, from the env that `main.tf` stores with it. Postgres 18 keeps its data under `/var/lib/postgresql/18/docker`, so the volume is mounted at `/var/lib/postgresql`. Each variable refuses an empty value, because CI renders an unset secret as `""`. The stack has no `terraform_data` deployment: the release job deploys after a new image, after an apply that changed the stack, and while the infra project is affected since the last successful deploy, and it checks the build sha only after a new image. `.prettierignore` gets `.terraform`, `tfplan` and the state.
|
|
1298
|
+
|
|
1299
|
+
### Errors of the dokploy generator
|
|
1300
|
+
|
|
1301
|
+
| Error | When |
|
|
1302
|
+
| ------------------------------------------------------------------------------- | -------------------------------------------------------- |
|
|
1303
|
+
| `apps/backend has no Dockerfile, so it is not a node-app. Run …` | `--api` names a project that `node-app` did not write |
|
|
1304
|
+
| `packages/db has no Dockerfile.migration, so it is not a Prisma package. Run …` | `--database` names a project that `prisma` did not write |
|
|
1305
|
+
| `The zone "example.com" needs a host in it.` | `--zone` without `--host` |
|
|
1306
|
+
| `The host "app.example.org" is not a name in the zone "example.com".` | `--host` outside `--zone` |
|
|
1307
|
+
| `The name "My App" is not a lowercase name that starts with a letter.` | `--name`, or the scope, is not a lowercase name |
|
|
1308
|
+
|
|
1309
|
+
### Test the dokploy generator before a release
|
|
1310
|
+
|
|
1311
|
+
After the steps of [Test the app generators before a release](#test-the-app-generators-before-a-release), run `prisma` and then `dokploy` with `--database`, `--registryUser` and no `--host`, then `npm install`, `npx nx sync`, `npx nx run @acme/infra:typecheck`, `actionlint .github/workflows/*.yml`, `npx nx run-many -t typecheck lint`, `npx prettier --check .`, and `docker compose -f infra/compose.dokploy.yml config`. actionlint 1.7.12 does not know the `parallel:` step of `ci.yml`, which GitHub runs. On 2026-11-18 each passed, also after a run with `--host` and no `--database` or `--registryUser`; after that, two runs with the first options passed again, and the second of them changed no file.
|
|
1312
|
+
|
|
1313
|
+
The decisions are in [ADR 0011](./docs/adr/0011-the-dokploy-generator-writes-the-gitops-delivery-of-a-node-app.md). The backlog item of the dokploy generator is #4603.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds each key of `defaults` that `record` does not have, after the keys
|
|
3
|
+
* that are there. A key that is there keeps its value and its place, so a run
|
|
4
|
+
* on a repo that has the keys in another order writes the same file.
|
|
5
|
+
*/
|
|
6
|
+
export declare function addMissingKeys<T>(record: Record<string, T> | undefined, defaults: Record<string, T>): Record<string, T>;
|
|
7
|
+
//# sourceMappingURL=add-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-keys.d.ts","sourceRoot":"","sources":["../../src/generators/add-keys.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,EACrC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAC1B,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAMnB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds each key of `defaults` that `record` does not have, after the keys
|
|
3
|
+
* that are there. A key that is there keeps its value and its place, so a run
|
|
4
|
+
* on a repo that has the keys in another order writes the same file.
|
|
5
|
+
*/
|
|
6
|
+
export function addMissingKeys(record, defaults) {
|
|
7
|
+
const merged = { ...record };
|
|
8
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
9
|
+
if (!Object.hasOwn(merged, key))
|
|
10
|
+
merged[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return merged;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=add-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-keys.js","sourceRoot":"","sources":["../../src/generators/add-keys.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAqC,EACrC,QAA2B;IAE3B,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACvD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|