@nx/devkit 21.3.0-canary.20250710-13551c9 → 21.3.0-canary.20250712-18e5d95

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/devkit",
3
- "version": "21.3.0-canary.20250710-13551c9",
3
+ "version": "21.3.0-canary.20250712-18e5d95",
4
4
  "private": false,
5
5
  "description": "The Nx Devkit is used to customize Nx for different technologies and use cases. It contains many utility functions for reading and writing files, updating configuration, working with Abstract Syntax Trees(ASTs), and more. Learn more about [extending Nx by leveraging the Nx Devkit](https://nx.dev/extending-nx/intro/getting-started) on our docs.",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "enquirer": "~2.3.6"
39
39
  },
40
40
  "peerDependencies": {
41
- "nx": "21.3.0-canary.20250710-13551c9"
41
+ "nx": "21.3.0-canary.20250712-18e5d95"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"
@@ -2,11 +2,8 @@ import { Tree } from 'nx/src/devkit-exports';
2
2
  /**
3
3
  * Formats all the created or updated files using Prettier
4
4
  * @param tree - the file system tree
5
+ * @param options - options for the formatFiles function
5
6
  */
6
7
  export declare function formatFiles(tree: Tree, options?: {
7
- /**
8
- * TODO(v21): Stop sorting tsconfig paths by default, paths are now less common/important
9
- * in Nx workspace setups, and the sorting causes comments to be lost.
10
- */
11
- sortRootTsconfigPaths: boolean;
8
+ sortRootTsconfigPaths?: boolean;
12
9
  }): Promise<void>;
@@ -1,20 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatFiles = formatFiles;
4
- const path = require("path");
5
4
  const devkit_exports_1 = require("nx/src/devkit-exports");
6
5
  const devkit_internals_1 = require("nx/src/devkit-internals");
6
+ const path = require("path");
7
7
  /**
8
8
  * Formats all the created or updated files using Prettier
9
9
  * @param tree - the file system tree
10
+ * @param options - options for the formatFiles function
10
11
  */
11
- async function formatFiles(tree, options = {
12
- /**
13
- * TODO(v21): Stop sorting tsconfig paths by default, paths are now less common/important
14
- * in Nx workspace setups, and the sorting causes comments to be lost.
15
- */
16
- sortRootTsconfigPaths: true,
17
- }) {
12
+ async function formatFiles(tree, options = {}) {
18
13
  let prettier;
19
14
  try {
20
15
  prettier = await Promise.resolve().then(() => require('prettier'));
@@ -27,6 +22,12 @@ async function formatFiles(tree, options = {
27
22
  }
28
23
  }
29
24
  catch { }
25
+ /**
26
+ * TODO(v22): Stop sorting tsconfig paths by default, paths are now less common/important
27
+ * in Nx workspace setups, and the sorting causes comments to be lost.
28
+ */
29
+ options.sortRootTsconfigPaths ??=
30
+ process.env.NX_FORMAT_SORT_TSCONFIG_PATHS !== 'false';
30
31
  if (options.sortRootTsconfigPaths) {
31
32
  sortTsConfig(tree);
32
33
  }
@@ -67,13 +68,18 @@ function sortTsConfig(tree) {
67
68
  if (!tsConfigPath) {
68
69
  return;
69
70
  }
70
- (0, devkit_exports_1.updateJson)(tree, tsConfigPath, (tsconfig) => ({
71
+ const tsconfig = (0, devkit_exports_1.readJson)(tree, tsConfigPath);
72
+ if (!tsconfig.compilerOptions?.paths) {
73
+ // no paths to sort
74
+ return;
75
+ }
76
+ (0, devkit_exports_1.writeJson)(tree, tsConfigPath, {
71
77
  ...tsconfig,
72
78
  compilerOptions: {
73
79
  ...tsconfig.compilerOptions,
74
80
  paths: (0, devkit_internals_1.sortObjectByKeys)(tsconfig.compilerOptions.paths),
75
81
  },
76
- }));
82
+ });
77
83
  }
78
84
  catch (e) {
79
85
  // catch noop