Skip to content

Commit

Permalink
chore: add more doc
Browse files Browse the repository at this point in the history
  • Loading branch information
kasir-barati committed Oct 31, 2024
1 parent dde752b commit 879bac2
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/docs/monorepo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ In [VCS](https://en.wikipedia.org/wiki/Version_control), a monorepo is:
- Are usually technology specific.
- Increases productivity by removing any friction of integrating different tools with each other and by providing utilities to keep them up to date.
- Use the `@nx/plugin` package to easily scaffold a new plugin or even just automate your local workspace.
- [`@nx/js:node`](./nx-js-node-executor.md).

#### Webpack plugin -- `@nx/webpack/plugin`

- **The basic plugin** works with a standard webpack configuration file, and adds them to the plugins option.
- `NxAppWebpackPlugin`provides common confs for the build. Thins like TypeScript support and linking workspace libraries (via `paths` conf declared in `tsconfig.json`).

### Devkit

Expand Down Expand Up @@ -121,6 +127,10 @@ In [VCS](https://en.wikipedia.org/wiki/Version_control), a monorepo is:

![project.json](./project-build-docker.png)

> [!IMPORTANT]
>
> Learn more about `project.json` [here](./project-json.md).
### Caching

- Battle-tested computation caching system.
Expand Down
32 changes: 32 additions & 0 deletions .github/docs/monorepo/nx-js-node-executor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# [`@nx/js:node`](https://nx.dev/nx-api/js/executors/node)

- NodeJS app executor.

```json
{
"targets": {
"serve": {
"executor": "@nx/js:node",
"options": {
// Use `runtimeArgs` to pass args to the underlying nodejs command (NodeJS CLI arguments)
"runtimeArgs": ["--no-warnings"],
// Nx build automatically all deps of your app.
// E.g. when your build have to consumes a library from its output, not its source.
"runBuildTargetDependencies": true,
// Extra args when starting the app.
"args": ["--job", "worker"],
// Ensures the app is starting with debugging.
"inspect": "inspect",
// The host to inspect the process on.
// Default: localhost
"host": "localhost",
// The port to inspect the process on. Setting port to 0 will assign random free ports to all forked processes.
// Default: 9229
"port": 108
}
}
}
}
```

- Learn more about other available options [here](https://nx.dev/nx-api/js/executors/node#options-playground).
Binary file added .github/docs/monorepo/project-conf-def.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
199 changes: 199 additions & 0 deletions .github/docs/monorepo/project-json.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# Project Configuration

![Project configuration definition](./project-conf-def.png)

- See project detailed view in your browser: `nx show project my-huawei --web`
- Tasks that use executors must be defined in a `project.json`.
- Example `libs/mylib/project.json`:

```json
{
"root": "libs/mylib/",
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {
/* ... */
}
},
"build": {
"executor": "@nx/js:tsc",
"options": {
/* ... */
}
}
}
}
```

```shell
$ nx build mylib
$ nx test mylib
```

- Different settings:

- Orchestration settings: how Nx runs tasks.

```json
{
"tags": ["scope:myteam"],
"implicitDependencies": ["anotherlib"],
"targets": {
"test": {
"dependsOn": ["build"]
},
"build": {
"dependsOn": ["^build"]
}
}
}
```

- Execution settings: how the actual task is executed.

```json
{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"options": {}
},
"build": {
"dependsOn": ["^build"],
"executor": "@nx/js:tsc",
"options": {}
}
}
}
```

- Caching settings: when Nx caches a task and what is actually cached.

```json
{
"namedInputs": {
"default": ["{projectRoot}/**/*"],
"production": ["!{projectRoot}/**/*.spec.tsx"]
},
"targets": {
"test": {
"inputs": ["default", "^production"],
"outputs": []
},
"build": {
"inputs": ["production", "^production"],
"outputs": ["{workspaceRoot}/dist/libs/mylib"]
}
}
}
```

## Task definitions/targets

```ts
{
// defines a keyword, thus when you're using default or production Nx knows which files do you mean.
"namedInputs": {
"default": [
// every file in the project
"{projectRoot}/**/*"
],
"production": [
"default",
// Exclude test files from production files.
"!{projectRoot}/**/*.spec.tsx"
]
},
"targets": {
"e2e": {
// Cache the results of a given target
"cache": boolean,
// By default, tasks are run in parallel
"parallelism": boolean,
"dependsOn": [
// Nx before running e2e test make sure to build mylib first.
// Note lack of "^" inside the string.
"build"
]
},
"build": {
"inputs": [
// Uses the production keyword defined in namedInputs.
"production",
{ "externalDependencies": ["vite"] }
],
// Tells Nx where the target is going to create file artifacts that Nx should cache.
"outputs": [
// Caches the whole dist/libs/mylib dir
"{workspaceRoot}/dist/libs/mylib",
// Caches only files inside dist/libs/mylib with css extension.
"{workspaceRoot}/dist/libs/mylib/**/*.css",
/*
Usually not needed as Nx has some defaults:
- "{workspaceRoot}/dist/{projectRoot}".
- "{projectRoot}/build".
- "{projectRoot}/dist".
- "{projectRoot}/public".
*/
],
"dependsOn": [
// Nx before building mylib make sure to build mylib's dependencies as well.
// This is configured by that "^" character.
"^build"
],
"options": {
// statically pass some extra args to the underlying executor
// args as options
"assetsInlineLimit": 2048,
"assetsDir": "static/assets"
// Or you can do this:
// This will take precedence over the ones defined as option.
"args": ["--assetsInlineLimit=2048", "--assetsDir=static/assets"]
}
},
"serve": {
// Define which command or executor should be executed.
// In here let's assume "build" is inferred task, meaning its executor is defined in nx.json and we are just changing some minor confs.
"executor": "nx:run-commands",
"dependsOn": [
{
// Build "my-app-in-cpp" project first.
"projects": ["my-app-in-cpp"],
// Which target does it depend on?
"target": "build",
// How to handle the params passed to the target. here we are talking about param1 & param2: nx openapi:create --param1 value1 --param2 value2
// "forward" | "ignore".
// Defaults to "ignore".
"params": "ignore"
}
]
},
"lint": {
// Using a plugin as my executor
"executor": "@nx/eslint:lint",
// Metadata for our task.
"metadata": {
"description": "Lint the application"
}
}
},
// Can be used in lint to make sure that libs in productA do not depend on libs in productB
"tags": ["scope:productA"],
// Nx usually can deduce what area project's deps but if it failed to do so we can specify it manually here.
"implicitDependencies": [
// This's added as dep.
"auth",
// Removed from dep.
"!core"
],
// Metadata for our little project
"metadata": {
"description": "This is the admin application"
}
}
```

> [!NOTE]
>
> `namedInputs` can be defined in both `nx.json` and `project.json`.

0 comments on commit 879bac2

Please sign in to comment.