@nx/devkit 16.9.0-beta.4 → 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.4",
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": {
@@ -2,10 +2,11 @@
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.`;
@@ -89,11 +90,28 @@ function getProjectNameAndRootFormats(tree, options) {
89
90
  ? normalizePath(options.directory.replace(/^\.?\//, ''))
90
91
  : undefined;
91
92
  const asProvidedProjectName = name;
92
- const asProvidedProjectDirectory = directory
93
- ? (0, names_1.names)(directory).fileName
94
- : options.rootProject
95
- ? '.'
96
- : 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
+ }
97
115
  if (name.startsWith('@')) {
98
116
  const nameWithoutScope = asProvidedProjectName.split('/')[1];
99
117
  return {
@@ -194,3 +212,14 @@ function getNpmScope(tree) {
194
212
  function isTTY() {
195
213
  return !!process.stdout.isTTY && process.env['CI'] !== 'true';
196
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
+ }