@nx/devkit 16.9.0-beta.3 → 16.9.0-rc.0

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": "16.9.0-beta.3",
3
+ "version": "16.9.0-rc.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.",
6
6
  "repository": {
@@ -28,13 +28,13 @@
28
28
  },
29
29
  "homepage": "https://nx.dev",
30
30
  "dependencies": {
31
- "@nrwl/devkit": "16.9.0-beta.3",
32
31
  "ejs": "^3.1.7",
33
32
  "enquirer": "~2.3.6",
34
33
  "ignore": "^5.0.4",
35
- "semver": "7.5.3",
36
34
  "tmp": "~0.2.1",
37
- "tslib": "^2.3.0"
35
+ "tslib": "^2.3.0",
36
+ "semver": "7.5.3",
37
+ "@nrwl/devkit": "*"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "nx": ">= 15 <= 17"
@@ -45,6 +45,5 @@
45
45
  "nx-migrations": {
46
46
  "migrations": "./migrations.json"
47
47
  },
48
- "type": "commonjs",
49
- "gitHead": "d5692528c089a75c76b21d2d1235d8cc5dbb1d26"
48
+ "type": "commonjs"
50
49
  }
@@ -2,22 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.determineProjectNameAndRootOptions = void 0;
4
4
  const enquirer_1 = require("enquirer");
5
+ const path_1 = require("path");
5
6
  const nx_1 = require("../../nx");
6
7
  const get_workspace_layout_1 = require("../utils/get-workspace-layout");
7
8
  const names_1 = require("../utils/names");
8
- const { joinPathFragments, normalizePath, logger, readJson, readNxJson, updateNxJson, stripIndents, } = (0, nx_1.requireNx)();
9
+ const { joinPathFragments, normalizePath, logger, readJson, readNxJson, updateNxJson, stripIndents, workspaceRoot, } = (0, nx_1.requireNx)();
9
10
  const deprecationWarning = stripIndents `
10
11
  In Nx 18, generating projects will no longer derive the name and root.
11
12
  Please provide the exact project name and root in the future.`;
12
13
  async function determineProjectNameAndRootOptions(tree, options) {
13
14
  validateName(options.name, options.projectNameAndRootFormat);
14
15
  const formats = getProjectNameAndRootFormats(tree, options);
15
- const configuredDefault = getDefaultProjectNameAndRootFormat(tree);
16
- if (configuredDefault === 'derived') {
17
- logger.warn(deprecationWarning + '\n' + getExample(options.callingGenerator, formats));
18
- }
19
16
  const format = options.projectNameAndRootFormat ??
20
- configuredDefault ??
21
17
  (await determineFormat(tree, formats, options.callingGenerator));
22
18
  return {
23
19
  ...formats[format],
@@ -82,47 +78,40 @@ async function determineFormat(tree, formats, callingGenerator) {
82
78
  ],
83
79
  initial: 'as-provided',
84
80
  }).then(({ format }) => format === asProvidedSelectedValue ? 'as-provided' : 'derived');
85
- if (result === 'as-provided' && callingGenerator) {
86
- const { saveDefault } = await (0, enquirer_1.prompt)({
87
- type: 'confirm',
88
- message: `Would you like to configure Nx to always take project name and root as provided for ${callingGenerator}?`,
89
- name: 'saveDefault',
90
- initial: true,
91
- });
92
- if (saveDefault) {
93
- setProjectNameAndRootFormatDefault(tree);
94
- }
95
- else {
96
- logger.warn(deprecationWarning);
97
- }
98
- }
99
- else {
81
+ if (result === 'derived' && callingGenerator) {
100
82
  const example = getExample(callingGenerator, formats);
101
83
  logger.warn(deprecationWarning + '\n' + example);
102
84
  }
103
85
  return result;
104
86
  }
105
- function setProjectNameAndRootFormatDefault(tree) {
106
- const nxJson = readNxJson(tree);
107
- nxJson.workspaceLayout ??= {};
108
- nxJson.workspaceLayout.projectNameAndRootFormat = 'as-provided';
109
- updateNxJson(tree, nxJson);
110
- }
111
- function getDefaultProjectNameAndRootFormat(tree) {
112
- const nxJson = readNxJson(tree);
113
- return nxJson.workspaceLayout?.projectNameAndRootFormat;
114
- }
115
87
  function getProjectNameAndRootFormats(tree, options) {
116
88
  const name = (0, names_1.names)(options.name).fileName;
117
89
  const directory = options.directory
118
90
  ? normalizePath(options.directory.replace(/^\.?\//, ''))
119
91
  : undefined;
120
92
  const asProvidedProjectName = name;
121
- const asProvidedProjectDirectory = directory
122
- ? (0, names_1.names)(directory).fileName
123
- : options.rootProject
124
- ? '.'
125
- : asProvidedProjectName;
93
+ let asProvidedProjectDirectory;
94
+ const relativeCwd = normalizePath((0, path_1.relative)(workspaceRoot, getCwd())).replace(/\/$/, '');
95
+ if (directory) {
96
+ // append the directory to the current working directory if it doesn't start with it
97
+ if (directory === relativeCwd || directory.startsWith(`${relativeCwd}/`)) {
98
+ asProvidedProjectDirectory = (0, names_1.names)(directory).fileName;
99
+ }
100
+ else {
101
+ asProvidedProjectDirectory = joinPathFragments(relativeCwd, (0, names_1.names)(directory).fileName);
102
+ }
103
+ }
104
+ else if (options.rootProject) {
105
+ asProvidedProjectDirectory = '.';
106
+ }
107
+ else {
108
+ asProvidedProjectDirectory = relativeCwd;
109
+ // append the project name to the current working directory if it doesn't end with it
110
+ if (!relativeCwd.endsWith(asProvidedProjectName) &&
111
+ !relativeCwd.endsWith(options.name)) {
112
+ asProvidedProjectDirectory = joinPathFragments(relativeCwd, asProvidedProjectName);
113
+ }
114
+ }
126
115
  if (name.startsWith('@')) {
127
116
  const nameWithoutScope = asProvidedProjectName.split('/')[1];
128
117
  return {
@@ -223,3 +212,14 @@ function getNpmScope(tree) {
223
212
  function isTTY() {
224
213
  return !!process.stdout.isTTY && process.env['CI'] !== 'true';
225
214
  }
215
+ /**
216
+ * When running a script with the package manager (e.g. `npm run`), the package manager will
217
+ * traverse the directory tree upwards until it finds a `package.json` and will set `process.cwd()`
218
+ * to the folder where it found it. The actual working directory is stored in the INIT_CWD
219
+ * environment variable (see here: https://docs.npmjs.com/cli/v9/commands/npm-run-script#description).
220
+ */
221
+ function getCwd() {
222
+ return process.env.INIT_CWD?.startsWith(workspaceRoot)
223
+ ? process.env.INIT_CWD
224
+ : process.cwd();
225
+ }
package/CHANGELOG.md DELETED
@@ -1,8 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
-
7
-
8
- **Note:** Version bump only for package @nx/devkit