Skip to content

Commit b5d406d

Browse files
authored
fix(core): allow opting out of sorting root tsconfig path mappings with an env var (#31763)
## Current Behavior Currently, users can opt out of sorting the root tsconfig file path mappings by providing `--sort-root-tsconfig-paths=false` to the `nx format` commands, or by providing `{ sortRootTsconfigPaths: false }` to the `formatFiles` function when invoked programmatically. Still, Nx generators sort the root tsconfig file path mappings by default, and the only way to bypass that is to run two different commands: ```bash nx g component path/to/component --skip-format nx format:write --sort-root-tsconfig-paths=false ``` ## Expected Behavior Users should be able to easily opt out of sorting the root tsconfig file path mappings by setting the `NX_FORMAT_SORT_TSCONFIG_PATHS` environment variable to `false`. With that set, all the relevant commands, including `nx generate` will respect it. ## Related Issue(s) Fixes #29043
1 parent 3782d7e commit b5d406d

File tree

8 files changed

+96
-81
lines changed

8 files changed

+96
-81
lines changed

docs/generated/cli/format-check.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`
1717

1818
## Options
1919

20-
| Option | Type | Description |
21-
| ---------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
22-
| `--all` | boolean | Format all projects. |
23-
| `--base` | string | Base of the current branch (usually main). |
24-
| `--exclude` | string | Exclude certain projects from being processed. |
25-
| `--files` | string | Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces. |
26-
| `--head` | string | Latest commit of the current branch (usually HEAD). |
27-
| `--help` | boolean | Show help. |
28-
| `--libs-and-apps` | boolean | Format only libraries and applications files. |
29-
| `--projects` | string | Projects to format (comma/space delimited). |
30-
| `--sort-root-tsconfig-paths` | boolean | Ensure the workspace's tsconfig compilerOptions.paths are sorted. Warning: This will cause comments in the tsconfig to be lost. (Default: `true`) |
31-
| `--uncommitted` | boolean | Uncommitted changes. |
32-
| `--untracked` | boolean | Untracked changes. |
33-
| `--version` | boolean | Show version number. |
20+
| Option | Type | Description |
21+
| ---------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
22+
| `--all` | boolean | Format all projects. |
23+
| `--base` | string | Base of the current branch (usually main). |
24+
| `--exclude` | string | Exclude certain projects from being processed. |
25+
| `--files` | string | Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces. |
26+
| `--head` | string | Latest commit of the current branch (usually HEAD). |
27+
| `--help` | boolean | Show help. |
28+
| `--libs-and-apps` | boolean | Format only libraries and applications files. |
29+
| `--projects` | string | Projects to format (comma/space delimited). |
30+
| `--sort-root-tsconfig-paths` | boolean | Ensure the workspace's tsconfig compilerOptions.paths are sorted. Warning: This will cause comments in the tsconfig to be lost. The default value is "true" unless NX_FORMAT_SORT_TSCONFIG_PATHS is set to "false". |
31+
| `--uncommitted` | boolean | Uncommitted changes. |
32+
| `--untracked` | boolean | Untracked changes. |
33+
| `--version` | boolean | Show version number. |

docs/generated/cli/format-write.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`
1717

1818
## Options
1919

20-
| Option | Type | Description |
21-
| ---------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
22-
| `--all` | boolean | Format all projects. |
23-
| `--base` | string | Base of the current branch (usually main). |
24-
| `--exclude` | string | Exclude certain projects from being processed. |
25-
| `--files` | string | Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces. |
26-
| `--head` | string | Latest commit of the current branch (usually HEAD). |
27-
| `--help` | boolean | Show help. |
28-
| `--libs-and-apps` | boolean | Format only libraries and applications files. |
29-
| `--projects` | string | Projects to format (comma/space delimited). |
30-
| `--sort-root-tsconfig-paths` | boolean | Ensure the workspace's tsconfig compilerOptions.paths are sorted. Warning: This will cause comments in the tsconfig to be lost. (Default: `true`) |
31-
| `--uncommitted` | boolean | Uncommitted changes. |
32-
| `--untracked` | boolean | Untracked changes. |
33-
| `--version` | boolean | Show version number. |
20+
| Option | Type | Description |
21+
| ---------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
22+
| `--all` | boolean | Format all projects. |
23+
| `--base` | string | Base of the current branch (usually main). |
24+
| `--exclude` | string | Exclude certain projects from being processed. |
25+
| `--files` | string | Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas or spaces. |
26+
| `--head` | string | Latest commit of the current branch (usually HEAD). |
27+
| `--help` | boolean | Show help. |
28+
| `--libs-and-apps` | boolean | Format only libraries and applications files. |
29+
| `--projects` | string | Projects to format (comma/space delimited). |
30+
| `--sort-root-tsconfig-paths` | boolean | Ensure the workspace's tsconfig compilerOptions.paths are sorted. Warning: This will cause comments in the tsconfig to be lost. The default value is "true" unless NX_FORMAT_SORT_TSCONFIG_PATHS is set to "false". |
31+
| `--uncommitted` | boolean | Uncommitted changes. |
32+
| `--untracked` | boolean | Untracked changes. |
33+
| `--version` | boolean | Show version number. |

docs/generated/devkit/formatFiles.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Formats all the created or updated files using Prettier
66

77
#### Parameters
88

9-
| Name | Type | Description |
10-
| :------------------------------ | :-------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- |
11-
| `tree` | [`Tree`](/reference/core-api/devkit/documents/Tree) | the file system tree |
12-
| `options?` | `Object` | - |
13-
| `options.sortRootTsconfigPaths` | `boolean` | TODO(v21): Stop sorting tsconfig paths by default, paths are now less common/important in Nx workspace setups, and the sorting causes comments to be lost. |
9+
| Name | Type | Description |
10+
| :------------------------------- | :-------------------------------------------------- | :----------------------------------- |
11+
| `tree` | [`Tree`](/reference/core-api/devkit/documents/Tree) | the file system tree |
12+
| `options?` | `Object` | options for the formatFiles function |
13+
| `options.sortRootTsconfigPaths?` | `boolean` | - |
1414

1515
#### Returns
1616

0 commit comments

Comments
 (0)