@nx/devkit 21.3.0-beta.5 → 21.3.0-canary.20250613-18155f4

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-beta.5",
3
+ "version": "21.3.0-canary.20250613-18155f4",
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-beta.5"
41
+ "nx": "21.3.0-canary.20250613-18155f4"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"
@@ -2,8 +2,11 @@ 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
6
5
  */
7
6
  export declare function formatFiles(tree: Tree, options?: {
8
- sortRootTsconfigPaths?: boolean;
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;
9
12
  }): Promise<void>;
@@ -1,15 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatFiles = formatFiles;
4
+ const path = require("path");
4
5
  const devkit_exports_1 = require("nx/src/devkit-exports");
5
6
  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
11
10
  */
12
- async function formatFiles(tree, options = {}) {
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
+ }) {
13
18
  let prettier;
14
19
  try {
15
20
  prettier = await Promise.resolve().then(() => require('prettier'));
@@ -22,12 +27,6 @@ async function formatFiles(tree, options = {}) {
22
27
  }
23
28
  }
24
29
  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';
31
30
  if (options.sortRootTsconfigPaths) {
32
31
  sortTsConfig(tree);
33
32
  }
@@ -68,18 +67,13 @@ function sortTsConfig(tree) {
68
67
  if (!tsConfigPath) {
69
68
  return;
70
69
  }
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, {
70
+ (0, devkit_exports_1.updateJson)(tree, tsConfigPath, (tsconfig) => ({
77
71
  ...tsconfig,
78
72
  compilerOptions: {
79
73
  ...tsconfig.compilerOptions,
80
74
  paths: (0, devkit_internals_1.sortObjectByKeys)(tsconfig.compilerOptions.paths),
81
75
  },
82
- });
76
+ }));
83
77
  }
84
78
  catch (e) {
85
79
  // catch noop
@@ -1,5 +1,5 @@
1
1
  export declare let dynamicImport: Function;
2
- export declare function loadConfigFile<T extends object = any>(configFilePath: string, tsconfigFileNames?: string[]): Promise<T>;
2
+ export declare function loadConfigFile<T extends object = any>(configFilePath: string): Promise<T>;
3
3
  export declare function getRootTsConfigPath(): string | null;
4
4
  export declare function getRootTsConfigFileName(): string | null;
5
5
  export declare function clearRequireCache(): void;
@@ -11,22 +11,22 @@ const devkit_exports_1 = require("nx/src/devkit-exports");
11
11
  const devkit_internals_1 = require("nx/src/devkit-internals");
12
12
  const path_1 = require("path");
13
13
  exports.dynamicImport = new Function('modulePath', 'return import(modulePath);');
14
- async function loadConfigFile(configFilePath, tsconfigFileNames) {
14
+ async function loadConfigFile(configFilePath) {
15
15
  const extension = (0, path_1.extname)(configFilePath);
16
- const module = await loadModule(configFilePath, extension, tsconfigFileNames);
16
+ const module = await loadModule(configFilePath, extension);
17
17
  return module.default ?? module;
18
18
  }
19
- async function loadModule(path, extension, tsconfigFileNames) {
19
+ async function loadModule(path, extension) {
20
20
  if (isTypeScriptFile(extension)) {
21
- return await loadTypeScriptModule(path, extension, tsconfigFileNames);
21
+ return await loadTypeScriptModule(path, extension);
22
22
  }
23
23
  return await loadJavaScriptModule(path, extension);
24
24
  }
25
25
  function isTypeScriptFile(extension) {
26
26
  return extension.endsWith('ts');
27
27
  }
28
- async function loadTypeScriptModule(path, extension, tsconfigFileNames) {
29
- const tsConfigPath = getTypeScriptConfigPath(path, tsconfigFileNames);
28
+ async function loadTypeScriptModule(path, extension) {
29
+ const tsConfigPath = getTypeScriptConfigPath(path);
30
30
  if (tsConfigPath) {
31
31
  const unregisterTsProject = (0, devkit_internals_1.registerTsProject)(tsConfigPath);
32
32
  try {
@@ -38,11 +38,10 @@ async function loadTypeScriptModule(path, extension, tsconfigFileNames) {
38
38
  }
39
39
  return await loadModuleByExtension(path, extension);
40
40
  }
41
- function getTypeScriptConfigPath(path, tsconfigFileNames) {
41
+ function getTypeScriptConfigPath(path) {
42
42
  const siblingFiles = (0, fs_1.readdirSync)((0, path_1.dirname)(path));
43
- const tsConfigFileName = (tsconfigFileNames ?? ['tsconfig.json']).find((name) => siblingFiles.includes(name));
44
- return tsConfigFileName
45
- ? (0, path_1.join)((0, path_1.dirname)(path), tsConfigFileName)
43
+ return siblingFiles.includes('tsconfig.json')
44
+ ? (0, path_1.join)((0, path_1.dirname)(path), 'tsconfig.json')
46
45
  : getRootTsConfigPath();
47
46
  }
48
47
  async function loadJavaScriptModule(path, extension) {