Skip to content

Commit

Permalink
Merge pull request #1373 from KyleBastien/master
Browse files Browse the repository at this point in the history
Update Nx documentation
  • Loading branch information
samchon authored Nov 23, 2024
2 parents af0cf1b + fcb5ef9 commit a48e876
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions website/pages/docs/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ Additionally, if you're using `typia` in the NodeJS project especially for the b



### NX
### Nx
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" copy showLineNumbers
Expand Down Expand Up @@ -534,27 +534,41 @@ bun typia setup --manager bun
</Tab>
</Tabs>

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 <package-name>: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/<package-name>/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 <package-name>: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
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
Expand Down

0 comments on commit a48e876

Please sign in to comment.