From fcb5ef95b39f3bad0fba95e958e0e20b353610ff Mon Sep 17 00:00:00 2001 From: Kyle-Bastien Date: Fri, 22 Nov 2024 16:27:40 -0800 Subject: [PATCH] Update Nx documentation --- website/pages/docs/setup.mdx | 38 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/website/pages/docs/setup.mdx b/website/pages/docs/setup.mdx index 64d244fd46..5693414447 100644 --- a/website/pages/docs/setup.mdx +++ b/website/pages/docs/setup.mdx @@ -505,7 +505,7 @@ Additionally, if you're using `typia` in the NodeJS project especially for the b -### NX +### Nx ```bash filename="Terminal" copy showLineNumbers @@ -534,27 +534,41 @@ bun typia setup --manager bun -After install `typia` like above, you have to modify `project.json` on each app like below. +After installing `typia` like above, and ensuring the `prepare` script is something similar to `ts-patch install && typia patch` you have to modify the `tsconfig.lib.json` on each `@nx/js` package to be similar to the below. -```javascript filename="project.json" showLineNumbers copy +```json filename="tsconfig.lib.json" showLineNumbers copy +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": [], + "plugins": [{ "transform": "typia/lib/transform" }] + }, + "include": ["**/*.ts"], + "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"] +} +``` + +After this, when running `nx :build` it _should_ now output with the Typia transforms applied. But if Typia fails for any reasons (for example it considers some type you have to be invalid), this error is not reported back via Nx. Nx will silent swallow these errors from ts-patch/typia, and you will just not get the output you expect. To debug this, you can create a new task in your `project.json` file similar to the below. + +```json filename="project.json" showLineNumbers copy "targets": { - "build": { - ... + "build:validate:typia": { + "executor": "nx:run-commands", "options": { - ... - "target": "node", - "compiler": "tsc", - "transformers": [ - "typia/lib/transform", - ] + "commands": [ + "tsc --project packages//tsconfig.lib.json --outDir dist/packages/typiaTest" + ], } }, ... } ``` +Running this task will show you the errors from Typia, and allow you to correct them, meaning that using the standard `nx :build` task should now work the way you expect. - +Note: While Nx has a `transformers` feature on the `@nx/js` plugin, that won't work with Typia. The reason is because Nx is expecting a transformer to export a `before` hook, which Nx then plugs directly into TypeScript via the compiler API. Typia doesn't export that kind of hook, because Typia only works with ts-patch, which abstracts the need for creating a specific before hook in the way Nx wants. ## Generation