@nx/devkit 20.0.8 → 20.1.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/devkit",
3
- "version": "20.0.8",
3
+ "version": "20.1.0-beta.0",
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": {
@@ -3,4 +3,10 @@ import { Tree } from 'nx/src/devkit-exports';
3
3
  * Formats all the created or updated files using Prettier
4
4
  * @param tree - the file system tree
5
5
  */
6
- export declare function formatFiles(tree: Tree): Promise<void>;
6
+ 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;
12
+ }): Promise<void>;
@@ -8,13 +8,21 @@ const devkit_internals_1 = require("nx/src/devkit-internals");
8
8
  * Formats all the created or updated files using Prettier
9
9
  * @param tree - the file system tree
10
10
  */
11
- async function formatFiles(tree) {
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
18
  let prettier;
13
19
  try {
14
20
  prettier = await Promise.resolve().then(() => require('prettier'));
15
21
  }
16
22
  catch { }
17
- sortTsConfig(tree);
23
+ if (options.sortRootTsconfigPaths) {
24
+ sortTsConfig(tree);
25
+ }
18
26
  if (!prettier)
19
27
  return;
20
28
  const files = new Set(tree.listChanges().filter((file) => file.type !== 'DELETE'));
@@ -34,4 +34,5 @@ export type ProjectNameAndRootOptions = {
34
34
  importPath?: string;
35
35
  };
36
36
  export declare function determineProjectNameAndRootOptions(tree: Tree, options: ProjectGenerationOptions): Promise<ProjectNameAndRootOptions>;
37
+ export declare function resolveImportPath(tree: Tree, projectName: string, projectRoot: string): string;
37
38
  export declare function ensureProjectName(tree: Tree, options: Omit<ProjectGenerationOptions, 'projectType'>, projectType: 'application' | 'library'): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.determineProjectNameAndRootOptions = determineProjectNameAndRootOptions;
4
+ exports.resolveImportPath = resolveImportPath;
4
5
  exports.ensureProjectName = ensureProjectName;
5
6
  const enquirer_1 = require("enquirer");
6
7
  const devkit_exports_1 = require("nx/src/devkit-exports");
@@ -45,20 +46,8 @@ async function determineProjectNameAndRootOptions(tree, options) {
45
46
  }
46
47
  let importPath = undefined;
47
48
  if (options.projectType === 'library') {
48
- importPath = options.importPath;
49
- if (!importPath) {
50
- if (name.startsWith('@')) {
51
- importPath = name;
52
- }
53
- else {
54
- const npmScope = getNpmScope(tree);
55
- importPath =
56
- projectRoot === '.'
57
- ? (0, devkit_exports_1.readJson)(tree, 'package.json').name ??
58
- getImportPath(npmScope, name)
59
- : getImportPath(npmScope, name);
60
- }
61
- }
49
+ importPath =
50
+ options.importPath ?? resolveImportPath(tree, name, projectRoot);
62
51
  }
63
52
  return {
64
53
  projectName: name,
@@ -70,6 +59,21 @@ async function determineProjectNameAndRootOptions(tree, options) {
70
59
  projectRoot,
71
60
  };
72
61
  }
62
+ function resolveImportPath(tree, projectName, projectRoot) {
63
+ let importPath;
64
+ if (projectName.startsWith('@')) {
65
+ importPath = projectName;
66
+ }
67
+ else {
68
+ const npmScope = getNpmScope(tree);
69
+ importPath =
70
+ projectRoot === '.'
71
+ ? (0, devkit_exports_1.readJson)(tree, 'package.json').name ??
72
+ getImportPath(npmScope, projectName)
73
+ : getImportPath(npmScope, projectName);
74
+ }
75
+ return importPath;
76
+ }
73
77
  async function ensureProjectName(tree, options, projectType) {
74
78
  if (!options.name) {
75
79
  if (options.directory === '.' && getRelativeCwd() === '') {
@@ -0,0 +1,2 @@
1
+ import { prompt } from 'enquirer';
2
+ export declare function promptWhenInteractive<T>(questions: Parameters<typeof prompt>[0], defaultValue: T): Promise<T>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promptWhenInteractive = promptWhenInteractive;
4
+ const enquirer_1 = require("enquirer");
5
+ const devkit_internals_1 = require("nx/src/devkit-internals");
6
+ async function promptWhenInteractive(questions, defaultValue) {
7
+ if (!isInteractive()) {
8
+ return defaultValue;
9
+ }
10
+ return await (0, enquirer_1.prompt)(questions);
11
+ }
12
+ function isInteractive() {
13
+ return (!(0, devkit_internals_1.isCI)() && !!process.stdout.isTTY && process.env.NX_INTERACTIVE === 'true');
14
+ }