@nx/workspace 0.0.0-pr-22179-271588f

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.
Files changed (190) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +66 -0
  3. package/executors.json +11 -0
  4. package/generators.d.ts +5 -0
  5. package/generators.js +13 -0
  6. package/generators.json +59 -0
  7. package/index.d.ts +12 -0
  8. package/index.js +33 -0
  9. package/migrations.json +90 -0
  10. package/package.json +76 -0
  11. package/presets/core.json +11 -0
  12. package/presets/npm.json +7 -0
  13. package/src/core/file-utils.d.ts +1 -0
  14. package/src/core/file-utils.js +4 -0
  15. package/src/core/project-graph.d.ts +1 -0
  16. package/src/core/project-graph.js +4 -0
  17. package/src/executors/counter/counter.impl.d.ts +12 -0
  18. package/src/executors/counter/counter.impl.js +40 -0
  19. package/src/executors/counter/schema.json +20 -0
  20. package/src/generators/ci-workflow/ci-workflow.d.ts +6 -0
  21. package/src/generators/ci-workflow/ci-workflow.js +60 -0
  22. package/src/generators/ci-workflow/files/azure/azure-pipelines.yml__tmpl__ +54 -0
  23. package/src/generators/ci-workflow/files/bitbucket-pipelines/bitbucket-pipelines.yml__tmpl__ +41 -0
  24. package/src/generators/ci-workflow/files/circleci/.circleci/config.yml__tmpl__ +33 -0
  25. package/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml__tmpl__ +38 -0
  26. package/src/generators/ci-workflow/files/gitlab/.gitlab-ci.yml__tmpl__ +24 -0
  27. package/src/generators/ci-workflow/schema.json +38 -0
  28. package/src/generators/convert-to-monorepo/convert-to-monorepo.d.ts +3 -0
  29. package/src/generators/convert-to-monorepo/convert-to-monorepo.js +41 -0
  30. package/src/generators/convert-to-monorepo/schema.json +16 -0
  31. package/src/generators/convert-to-nx-project/convert-to-nx-project.d.ts +5 -0
  32. package/src/generators/convert-to-nx-project/convert-to-nx-project.js +79 -0
  33. package/src/generators/convert-to-nx-project/schema.d.ts +7 -0
  34. package/src/generators/convert-to-nx-project/schema.json +38 -0
  35. package/src/generators/move/lib/check-destination.d.ts +11 -0
  36. package/src/generators/move/lib/check-destination.js +21 -0
  37. package/src/generators/move/lib/create-project-configuration-in-new-destination.d.ts +3 -0
  38. package/src/generators/move/lib/create-project-configuration-in-new-destination.js +54 -0
  39. package/src/generators/move/lib/extract-base-configs.d.ts +4 -0
  40. package/src/generators/move/lib/extract-base-configs.js +43 -0
  41. package/src/generators/move/lib/move-project-files.d.ts +8 -0
  42. package/src/generators/move/lib/move-project-files.js +60 -0
  43. package/src/generators/move/lib/normalize-schema.d.ts +3 -0
  44. package/src/generators/move/lib/normalize-schema.js +183 -0
  45. package/src/generators/move/lib/run-angular-plugin.d.ts +3 -0
  46. package/src/generators/move/lib/run-angular-plugin.js +19 -0
  47. package/src/generators/move/lib/update-build-targets.d.ts +6 -0
  48. package/src/generators/move/lib/update-build-targets.js +53 -0
  49. package/src/generators/move/lib/update-cypress-config.d.ts +10 -0
  50. package/src/generators/move/lib/update-cypress-config.js +40 -0
  51. package/src/generators/move/lib/update-default-project.d.ts +10 -0
  52. package/src/generators/move/lib/update-default-project.js +20 -0
  53. package/src/generators/move/lib/update-eslint-config.d.ts +8 -0
  54. package/src/generators/move/lib/update-eslint-config.js +33 -0
  55. package/src/generators/move/lib/update-implicit-dependencies.d.ts +6 -0
  56. package/src/generators/move/lib/update-implicit-dependencies.js +19 -0
  57. package/src/generators/move/lib/update-imports.d.ts +8 -0
  58. package/src/generators/move/lib/update-imports.js +182 -0
  59. package/src/generators/move/lib/update-jest-config.d.ts +10 -0
  60. package/src/generators/move/lib/update-jest-config.js +49 -0
  61. package/src/generators/move/lib/update-package-json.d.ts +8 -0
  62. package/src/generators/move/lib/update-package-json.js +24 -0
  63. package/src/generators/move/lib/update-project-root-files.d.ts +12 -0
  64. package/src/generators/move/lib/update-project-root-files.js +87 -0
  65. package/src/generators/move/lib/update-readme.d.ts +8 -0
  66. package/src/generators/move/lib/update-readme.js +21 -0
  67. package/src/generators/move/lib/update-storybook-config.d.ts +10 -0
  68. package/src/generators/move/lib/update-storybook-config.js +43 -0
  69. package/src/generators/move/lib/utils.d.ts +22 -0
  70. package/src/generators/move/lib/utils.js +49 -0
  71. package/src/generators/move/move.d.ts +5 -0
  72. package/src/generators/move/move.js +63 -0
  73. package/src/generators/move/schema.d.ts +15 -0
  74. package/src/generators/move/schema.json +59 -0
  75. package/src/generators/new/files-integrated-repo/__dot__editorconfig +13 -0
  76. package/src/generators/new/files-integrated-repo/__dot__gitignore +41 -0
  77. package/src/generators/new/files-integrated-repo/__dot__vscode/extensions.json__tmpl__ +9 -0
  78. package/src/generators/new/files-integrated-repo/package.json__tmpl__ +14 -0
  79. package/src/generators/new/files-package-based-repo/__dot__gitignore +41 -0
  80. package/src/generators/new/files-package-based-repo/__dot__vscode/extensions.json__tmpl__ +8 -0
  81. package/src/generators/new/files-package-based-repo/package.json__tmpl__ +13 -0
  82. package/src/generators/new/files-readme/README.md.template +89 -0
  83. package/src/generators/new/files-root-app/__dot__gitignore +41 -0
  84. package/src/generators/new/files-root-app/__dot__vscode/extensions.json__tmpl__ +6 -0
  85. package/src/generators/new/files-root-app/package.json__tmpl__ +17 -0
  86. package/src/generators/new/generate-preset.d.ts +4 -0
  87. package/src/generators/new/generate-preset.js +162 -0
  88. package/src/generators/new/generate-workspace-files.d.ts +3 -0
  89. package/src/generators/new/generate-workspace-files.js +190 -0
  90. package/src/generators/new/new.d.ts +30 -0
  91. package/src/generators/new/new.js +84 -0
  92. package/src/generators/new/schema.json +92 -0
  93. package/src/generators/npm-package/files/index.js.template +1 -0
  94. package/src/generators/npm-package/npm-package.d.ts +9 -0
  95. package/src/generators/npm-package/npm-package.js +53 -0
  96. package/src/generators/npm-package/schema.json +31 -0
  97. package/src/generators/preset/preset.d.ts +4 -0
  98. package/src/generators/preset/preset.js +301 -0
  99. package/src/generators/preset/schema.d.ts +22 -0
  100. package/src/generators/preset/schema.json +109 -0
  101. package/src/generators/remove/lib/__fixtures__/jest-project.config.d.ts +14 -0
  102. package/src/generators/remove/lib/__fixtures__/jest-project.config.js +17 -0
  103. package/src/generators/remove/lib/__fixtures__/jest.config.d.ts +0 -0
  104. package/src/generators/remove/lib/__fixtures__/jest.config.js +8 -0
  105. package/src/generators/remove/lib/check-dependencies.d.ts +7 -0
  106. package/src/generators/remove/lib/check-dependencies.js +23 -0
  107. package/src/generators/remove/lib/check-project-is-safe-to-remove.d.ts +3 -0
  108. package/src/generators/remove/lib/check-project-is-safe-to-remove.js +25 -0
  109. package/src/generators/remove/lib/check-targets.d.ts +10 -0
  110. package/src/generators/remove/lib/check-targets.js +68 -0
  111. package/src/generators/remove/lib/remove-project-references-in-config.d.ts +3 -0
  112. package/src/generators/remove/lib/remove-project-references-in-config.js +21 -0
  113. package/src/generators/remove/lib/remove-project.d.ts +5 -0
  114. package/src/generators/remove/lib/remove-project.js +14 -0
  115. package/src/generators/remove/lib/update-jest-config.d.ts +6 -0
  116. package/src/generators/remove/lib/update-jest-config.js +75 -0
  117. package/src/generators/remove/lib/update-tsconfig.d.ts +8 -0
  118. package/src/generators/remove/lib/update-tsconfig.js +31 -0
  119. package/src/generators/remove/remove.d.ts +4 -0
  120. package/src/generators/remove/remove.js +26 -0
  121. package/src/generators/remove/schema.d.ts +10 -0
  122. package/src/generators/remove/schema.json +47 -0
  123. package/src/generators/run-commands/run-commands.d.ts +4 -0
  124. package/src/generators/run-commands/run-commands.js +25 -0
  125. package/src/generators/run-commands/schema.d.ts +8 -0
  126. package/src/generators/run-commands/schema.json +49 -0
  127. package/src/generators/utils/get-npm-package-version.d.ts +1 -0
  128. package/src/generators/utils/get-npm-package-version.js +21 -0
  129. package/src/generators/utils/insert-import.d.ts +2 -0
  130. package/src/generators/utils/insert-import.js +47 -0
  131. package/src/generators/utils/insert-statement.d.ts +5 -0
  132. package/src/generators/utils/insert-statement.js +33 -0
  133. package/src/generators/utils/jest-config.d.ts +2 -0
  134. package/src/generators/utils/jest-config.js +13 -0
  135. package/src/generators/utils/presets.d.ts +29 -0
  136. package/src/generators/utils/presets.js +34 -0
  137. package/src/migrations/update-15-7-0/split-configuration-into-project-json-files.d.ts +3 -0
  138. package/src/migrations/update-15-7-0/split-configuration-into-project-json-files.js +11 -0
  139. package/src/migrations/update-16-0-0/fix-invalid-babelrc.d.ts +2 -0
  140. package/src/migrations/update-16-0-0/fix-invalid-babelrc.js +41 -0
  141. package/src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin.d.ts +2 -0
  142. package/src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin.js +187 -0
  143. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  144. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  145. package/src/tasks-runner/cache.d.ts +1 -0
  146. package/src/tasks-runner/cache.js +5 -0
  147. package/src/tasks-runner/default-tasks-runner.d.ts +1 -0
  148. package/src/tasks-runner/default-tasks-runner.js +4 -0
  149. package/src/tasks-runner/life-cycle.d.ts +1 -0
  150. package/src/tasks-runner/life-cycle.js +5 -0
  151. package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.d.ts +1 -0
  152. package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +4 -0
  153. package/src/tasks-runner/tasks-runner.d.ts +2 -0
  154. package/src/tasks-runner/tasks-runner.js +4 -0
  155. package/src/tasks-runner/utils.d.ts +1 -0
  156. package/src/tasks-runner/utils.js +4 -0
  157. package/src/utilities/app-root.d.ts +1 -0
  158. package/src/utilities/app-root.js +4 -0
  159. package/src/utilities/default-base.d.ts +1 -0
  160. package/src/utilities/default-base.js +15 -0
  161. package/src/utilities/fileutils.d.ts +13 -0
  162. package/src/utilities/fileutils.js +51 -0
  163. package/src/utilities/get-import-path.d.ts +3 -0
  164. package/src/utilities/get-import-path.js +20 -0
  165. package/src/utilities/output.d.ts +1 -0
  166. package/src/utilities/output.js +4 -0
  167. package/src/utilities/ts-config.d.ts +7 -0
  168. package/src/utilities/ts-config.js +67 -0
  169. package/src/utilities/typescript/compilation.d.ts +22 -0
  170. package/src/utilities/typescript/compilation.js +120 -0
  171. package/src/utilities/typescript/get-source-nodes.d.ts +5 -0
  172. package/src/utilities/typescript/get-source-nodes.js +21 -0
  173. package/src/utilities/typescript.d.ts +13 -0
  174. package/src/utilities/typescript.js +55 -0
  175. package/src/utils/ast-utils.d.ts +1 -0
  176. package/src/utils/ast-utils.js +5 -0
  177. package/src/utils/cli-config-utils.d.ts +16 -0
  178. package/src/utils/cli-config-utils.js +29 -0
  179. package/src/utils/lint.d.ts +4 -0
  180. package/src/utils/lint.js +2 -0
  181. package/src/utils/output.d.ts +52 -0
  182. package/src/utils/output.js +133 -0
  183. package/src/utils/perf-logging.d.ts +1 -0
  184. package/src/utils/perf-logging.js +10 -0
  185. package/src/utils/project-type.d.ts +5 -0
  186. package/src/utils/project-type.js +17 -0
  187. package/src/utils/versions.d.ts +3 -0
  188. package/src/utils/versions.js +8 -0
  189. package/tasks-runners/default.d.ts +1 -0
  190. package/tasks-runners/default.js +5 -0
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeSchema = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const enquirer_1 = require("enquirer");
6
+ const get_import_path_1 = require("../../../utilities/get-import-path");
7
+ const utils_1 = require("./utils");
8
+ async function normalizeSchema(tree, schema, projectConfiguration) {
9
+ const { destination, newProjectName, importPath } = await determineProjectNameAndRootOptions(tree, schema, projectConfiguration);
10
+ return {
11
+ ...schema,
12
+ destination: (0, utils_1.normalizePathSlashes)(schema.destination),
13
+ importPath,
14
+ newProjectName,
15
+ relativeToRootDestination: destination,
16
+ };
17
+ }
18
+ exports.normalizeSchema = normalizeSchema;
19
+ async function determineProjectNameAndRootOptions(tree, options, projectConfiguration) {
20
+ if (!options.projectNameAndRootFormat &&
21
+ (process.env.NX_INTERACTIVE !== 'true' || !isTTY())) {
22
+ options.projectNameAndRootFormat = 'derived';
23
+ }
24
+ validateName(options.newProjectName, options.projectNameAndRootFormat, projectConfiguration);
25
+ const formats = getProjectNameAndRootFormats(tree, options, projectConfiguration);
26
+ const format = options.projectNameAndRootFormat ?? (await determineFormat(formats));
27
+ if (format === 'derived') {
28
+ logDeprecationMessage(formats, options);
29
+ }
30
+ return formats[format];
31
+ }
32
+ function validateName(name, projectNameAndRootFormat, projectConfiguration) {
33
+ if (!name) {
34
+ return;
35
+ }
36
+ if (projectNameAndRootFormat === 'derived' && name.startsWith('@')) {
37
+ throw new Error(`The new project name "${name}" cannot start with "@" when the "projectNameAndRootFormat" is "derived".`);
38
+ }
39
+ /**
40
+ * Matches two types of project names:
41
+ *
42
+ * 1. Valid npm package names (e.g., '@scope/name' or 'name').
43
+ * 2. Names starting with a letter and can contain any character except whitespace and ':'.
44
+ *
45
+ * The second case is to support the legacy behavior (^[a-zA-Z].*$) with the difference
46
+ * that it doesn't allow the ":" character. It was wrong to allow it because it would
47
+ * conflict with the notation for tasks.
48
+ */
49
+ const libraryPattern = '(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$';
50
+ const appPattern = '^[a-zA-Z][^:]*$';
51
+ if (projectConfiguration.projectType === 'application') {
52
+ const validationRegex = new RegExp(appPattern);
53
+ if (!validationRegex.test(name)) {
54
+ throw new Error(`The new project name should match the pattern "${appPattern}". The provided value "${name}" does not match.`);
55
+ }
56
+ }
57
+ else if (projectConfiguration.projectType === 'library') {
58
+ const validationRegex = new RegExp(libraryPattern);
59
+ if (!validationRegex.test(name)) {
60
+ throw new Error(`The new project name should match the pattern "${libraryPattern}". The provided value "${name}" does not match.`);
61
+ }
62
+ }
63
+ }
64
+ function getProjectNameAndRootFormats(tree, options, projectConfiguration) {
65
+ let destination = (0, utils_1.normalizePathSlashes)(options.destination);
66
+ if (options.newProjectName &&
67
+ options.newProjectName.includes('/') &&
68
+ !options.newProjectName.startsWith('@')) {
69
+ throw new Error(`You can't specify a new project name with a directory path (${options.newProjectName}). ` +
70
+ `Please provide a valid name without path segments and the full destination with the "--destination" option.`);
71
+ }
72
+ const asProvidedOptions = getAsProvidedOptions(tree, { ...options, destination }, projectConfiguration);
73
+ if (options.projectNameAndRootFormat === 'as-provided') {
74
+ return {
75
+ 'as-provided': asProvidedOptions,
76
+ derived: undefined,
77
+ };
78
+ }
79
+ if (asProvidedOptions.newProjectName.startsWith('@')) {
80
+ if (!options.projectNameAndRootFormat) {
81
+ devkit_1.output.warn({
82
+ title: `The provided new project name "${asProvidedOptions.newProjectName}" is a scoped project name and this is not supported by the move generator when using the "derived" format.`,
83
+ bodyLines: [
84
+ `The generator will try to move the project using the "as-provided" format with the new name "${asProvidedOptions.newProjectName}" located at "${asProvidedOptions.destination}".`,
85
+ ],
86
+ });
87
+ return {
88
+ 'as-provided': asProvidedOptions,
89
+ derived: undefined,
90
+ };
91
+ }
92
+ throw new Error(`The provided new project name "${options.newProjectName}" is a scoped project name and this is not supported by the move generator when using the "derived" format. ` +
93
+ `Please provide a name without "@" or use the "as-provided" format.`);
94
+ }
95
+ const derivedOptions = getDerivedOptions(tree, { ...options, destination }, projectConfiguration);
96
+ return {
97
+ 'as-provided': asProvidedOptions,
98
+ derived: derivedOptions,
99
+ };
100
+ }
101
+ async function determineFormat(formats) {
102
+ if (!formats.derived) {
103
+ return 'as-provided';
104
+ }
105
+ const asProvidedDescription = `As provided:
106
+ Name: ${formats['as-provided'].newProjectName}
107
+ Destination: ${formats['as-provided'].destination}`;
108
+ const asProvidedSelectedValue = `${formats['as-provided'].newProjectName} @ ${formats['as-provided'].destination}`;
109
+ const derivedDescription = `Derived:
110
+ Name: ${formats['derived'].newProjectName}
111
+ Destination: ${formats['derived'].destination}`;
112
+ const derivedSelectedValue = `${formats['derived'].newProjectName} @ ${formats['derived'].destination}`;
113
+ const result = await (0, enquirer_1.prompt)({
114
+ type: 'select',
115
+ name: 'format',
116
+ message: 'What should be the new project name and where should it be moved to?',
117
+ choices: [
118
+ {
119
+ message: asProvidedDescription,
120
+ name: asProvidedSelectedValue,
121
+ },
122
+ {
123
+ message: derivedDescription,
124
+ name: derivedSelectedValue,
125
+ },
126
+ ],
127
+ initial: 0,
128
+ }).then(({ format }) => format === asProvidedSelectedValue ? 'as-provided' : 'derived');
129
+ return result;
130
+ }
131
+ function logDeprecationMessage(formats, options) {
132
+ const callingGenerator = process.env.NX_ANGULAR_MOVE_INVOKED === 'true'
133
+ ? '@nx/angular:move'
134
+ : '@nx/workspace:move';
135
+ devkit_1.logger.warn((0, devkit_1.stripIndents) `
136
+ In Nx 19, the project name and destination will no longer be derived.
137
+ Please provide the exact new project name and destination in the future.
138
+ Example: nx g ${callingGenerator} --projectName ${options.projectName} --destination ${formats['derived'].destination}` +
139
+ (options.projectName !== formats['derived'].newProjectName
140
+ ? ` --newProjectName ${formats['derived'].newProjectName}`
141
+ : ''));
142
+ }
143
+ function getAsProvidedOptions(tree, options, projectConfiguration) {
144
+ const newProjectName = options.newProjectName ?? options.projectName;
145
+ const destination = options.destination;
146
+ if (projectConfiguration.projectType !== 'library') {
147
+ return { destination, newProjectName };
148
+ }
149
+ let importPath = options.importPath;
150
+ if (importPath) {
151
+ return { destination, newProjectName, importPath };
152
+ }
153
+ if (options.newProjectName?.startsWith('@')) {
154
+ // keep the existing import path if the name didn't change
155
+ importPath =
156
+ options.newProjectName && options.projectName !== options.newProjectName
157
+ ? newProjectName
158
+ : undefined;
159
+ }
160
+ else if (options.newProjectName) {
161
+ const npmScope = (0, get_import_path_1.getNpmScope)(tree);
162
+ importPath = npmScope
163
+ ? `${npmScope === '@' ? '' : '@'}${npmScope}/${newProjectName}`
164
+ : newProjectName;
165
+ }
166
+ return { destination, newProjectName, importPath };
167
+ }
168
+ function getDerivedOptions(tree, options, projectConfiguration) {
169
+ const newProjectName = options.newProjectName
170
+ ? (0, devkit_1.names)(options.newProjectName).fileName
171
+ : (0, utils_1.getNewProjectName)(options.destination);
172
+ const destination = (0, utils_1.getDestination)(tree, options, projectConfiguration);
173
+ let importPath;
174
+ if (projectConfiguration.projectType === 'library') {
175
+ importPath =
176
+ options.importPath ??
177
+ (0, utils_1.normalizePathSlashes)((0, get_import_path_1.getImportPath)(tree, options.destination));
178
+ }
179
+ return { destination, newProjectName, importPath };
180
+ }
181
+ function isTTY() {
182
+ return !!process.stdout.isTTY && process.env['CI'] !== 'true';
183
+ }
@@ -0,0 +1,3 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { Schema } from '../schema';
3
+ export declare function runAngularPlugin(tree: Tree, schema: Schema): Promise<void>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runAngularPlugin = void 0;
4
+ async function runAngularPlugin(tree, schema) {
5
+ let move;
6
+ try {
7
+ // nx-ignore-next-line
8
+ move = require('@nx/angular/src/generators/move/move-impl').move;
9
+ }
10
+ catch { }
11
+ if (!move) {
12
+ return;
13
+ }
14
+ await move(tree, {
15
+ oldProjectName: schema.projectName,
16
+ newProjectName: schema.newProjectName,
17
+ });
18
+ }
19
+ exports.runAngularPlugin = runAngularPlugin;
@@ -0,0 +1,6 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ /**
4
+ * Update other references to the source project's targets
5
+ */
6
+ export declare function updateBuildTargets(tree: Tree, schema: NormalizedSchema): void;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateBuildTargets = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ /**
6
+ * Update other references to the source project's targets
7
+ */
8
+ function updateBuildTargets(tree, schema) {
9
+ (0, devkit_1.getProjects)(tree).forEach((projectConfig, project) => {
10
+ let changed = false;
11
+ Object.entries(projectConfig.targets || {}).forEach(([target, targetConfig]) => {
12
+ changed =
13
+ updateJsonValue(targetConfig, (value) => {
14
+ const [project, target, configuration] = value.split(':');
15
+ if (project === schema.projectName && target) {
16
+ return configuration
17
+ ? `${schema.newProjectName}:${target}:${configuration}`
18
+ : `${schema.newProjectName}:${target}`;
19
+ }
20
+ }) || changed;
21
+ });
22
+ if (changed) {
23
+ (0, devkit_1.updateProjectConfiguration)(tree, project, projectConfig);
24
+ }
25
+ });
26
+ }
27
+ exports.updateBuildTargets = updateBuildTargets;
28
+ function updateJsonValue(config, callback) {
29
+ function recur(obj, key, value) {
30
+ let changed = false;
31
+ if (typeof value === 'string') {
32
+ const result = callback(value);
33
+ if (result && obj[key] !== result) {
34
+ obj[key] = result;
35
+ changed = true;
36
+ }
37
+ }
38
+ else if (Array.isArray(value)) {
39
+ value.forEach((x, idx) => recur(value, idx, x));
40
+ }
41
+ else if (typeof value === 'object') {
42
+ Object.entries(value).forEach(([k, v]) => {
43
+ changed = recur(value, k, v) || changed;
44
+ });
45
+ }
46
+ return changed;
47
+ }
48
+ let changed = false;
49
+ Object.entries(config).forEach(([k, v]) => {
50
+ changed = recur(config, k, v) || changed;
51
+ });
52
+ return changed;
53
+ }
@@ -0,0 +1,10 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ /**
4
+ * Updates the videos and screenshots folders in the cypress.json/cypress.config.ts if it exists (i.e. we're moving an e2e project)
5
+ *
6
+ * (assume relative paths have been updated previously)
7
+ *
8
+ * @param schema The options provided to the schematic
9
+ */
10
+ export declare function updateCypressConfig(tree: Tree, schema: NormalizedSchema, project: ProjectConfiguration): Tree;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateCypressConfig = void 0;
4
+ const path = require("path");
5
+ /**
6
+ * Updates the videos and screenshots folders in the cypress.json/cypress.config.ts if it exists (i.e. we're moving an e2e project)
7
+ *
8
+ * (assume relative paths have been updated previously)
9
+ *
10
+ * @param schema The options provided to the schematic
11
+ */
12
+ function updateCypressConfig(tree, schema, project) {
13
+ const cypressJsonPath = path.join(schema.relativeToRootDestination, 'cypress.json');
14
+ if (tree.exists(cypressJsonPath)) {
15
+ const cypressJson = JSON.parse(tree.read(cypressJsonPath).toString('utf-8'));
16
+ // videosFolder is not required because videos can be turned off - it also has a default
17
+ if (cypressJson.videosFolder) {
18
+ cypressJson.videosFolder = cypressJson.videosFolder.replace(project.root, schema.relativeToRootDestination);
19
+ }
20
+ // screenshotsFolder is not required as it has a default
21
+ if (cypressJson.screenshotsFolder) {
22
+ cypressJson.screenshotsFolder = cypressJson.screenshotsFolder.replace(project.root, schema.relativeToRootDestination);
23
+ }
24
+ tree.write(cypressJsonPath, JSON.stringify(cypressJson));
25
+ return tree;
26
+ }
27
+ const cypressConfigPath = path.join(schema.relativeToRootDestination, 'cypress.config.ts');
28
+ // Search and replace for "e2e" directory is not safe, and will result in an invalid config file.
29
+ // Leave it and let users fix the config if needed.
30
+ if (project.root !== 'e2e' && tree.exists(cypressConfigPath)) {
31
+ const oldContent = tree.read(cypressConfigPath, 'utf-8');
32
+ const findName = new RegExp(`'${schema.projectName}'`, 'g');
33
+ const findDir = new RegExp(project.root, 'g');
34
+ const newContent = oldContent
35
+ .replace(findName, `'${schema.newProjectName}'`)
36
+ .replace(findDir, schema.relativeToRootDestination);
37
+ tree.write(cypressConfigPath, newContent);
38
+ }
39
+ }
40
+ exports.updateCypressConfig = updateCypressConfig;
@@ -0,0 +1,10 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ /**
4
+ * Updates the project in the workspace file
5
+ *
6
+ * - update all references to the old root path
7
+ * - change the project name
8
+ * - change target references
9
+ */
10
+ export declare function updateDefaultProject(tree: Tree, schema: NormalizedSchema): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateDefaultProject = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ /**
6
+ * Updates the project in the workspace file
7
+ *
8
+ * - update all references to the old root path
9
+ * - change the project name
10
+ * - change target references
11
+ */
12
+ function updateDefaultProject(tree, schema) {
13
+ const nxJson = (0, devkit_1.readNxJson)(tree);
14
+ // update default project (if necessary)
15
+ if (nxJson.defaultProject && nxJson.defaultProject === schema.projectName) {
16
+ nxJson.defaultProject = schema.newProjectName;
17
+ (0, devkit_1.updateNxJson)(tree, nxJson);
18
+ }
19
+ }
20
+ exports.updateDefaultProject = updateDefaultProject;
@@ -0,0 +1,8 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ /**
4
+ * Update the .eslintrc file of the project if it exists.
5
+ *
6
+ * @param schema The options provided to the schematic
7
+ */
8
+ export declare function updateEslintConfig(tree: Tree, schema: NormalizedSchema, project: ProjectConfiguration): void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateEslintConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ /**
6
+ * Update the .eslintrc file of the project if it exists.
7
+ *
8
+ * @param schema The options provided to the schematic
9
+ */
10
+ function updateEslintConfig(tree, schema, project) {
11
+ // if there is no suitable eslint config, we don't need to do anything
12
+ if (!tree.exists('.eslintrc.json') &&
13
+ !tree.exists('eslint.config.js') &&
14
+ !tree.exists('.eslintrc.base.json') &&
15
+ !tree.exists('eslint.base.config.js')) {
16
+ return;
17
+ }
18
+ try {
19
+ const { updateRelativePathsInConfig,
20
+ // nx-ignore-next-line
21
+ } = require('@nx/eslint/src/generators/utils/eslint-file');
22
+ updateRelativePathsInConfig(tree, project.root, schema.relativeToRootDestination);
23
+ }
24
+ catch {
25
+ devkit_1.output.warn({
26
+ title: `Could not update the eslint config file.`,
27
+ bodyLines: [
28
+ 'The @nx/eslint package could not be loaded. Please update the paths in eslint config manually.',
29
+ ],
30
+ });
31
+ }
32
+ }
33
+ exports.updateEslintConfig = updateEslintConfig;
@@ -0,0 +1,6 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { NormalizedSchema } from '../schema';
3
+ /**
4
+ * @param schema The options provided to the schematic
5
+ */
6
+ export declare function updateImplicitDependencies(tree: Tree, schema: NormalizedSchema): void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateImplicitDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ /**
6
+ * @param schema The options provided to the schematic
7
+ */
8
+ function updateImplicitDependencies(tree, schema) {
9
+ for (const [projectName, project] of (0, devkit_1.getProjects)(tree)) {
10
+ if (project.implicitDependencies) {
11
+ const index = project.implicitDependencies.indexOf(schema.projectName);
12
+ if (index !== -1) {
13
+ project.implicitDependencies[index] = schema.newProjectName;
14
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
15
+ }
16
+ }
17
+ }
18
+ }
19
+ exports.updateImplicitDependencies = updateImplicitDependencies;
@@ -0,0 +1,8 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ /**
4
+ * Updates all the imports in the workspace and modifies the tsconfig appropriately.
5
+ *
6
+ * @param schema The options provided to the schematic
7
+ */
8
+ export declare function updateImports(tree: Tree, schema: NormalizedSchema, project: ProjectConfiguration): void;
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateImports = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const get_import_path_1 = require("../../../utilities/get-import-path");
7
+ const ts_config_1 = require("../../../utilities/ts-config");
8
+ const typescript_1 = require("../../../utilities/typescript");
9
+ const utils_1 = require("./utils");
10
+ let tsModule;
11
+ /**
12
+ * Updates all the imports in the workspace and modifies the tsconfig appropriately.
13
+ *
14
+ * @param schema The options provided to the schematic
15
+ */
16
+ function updateImports(tree, schema, project) {
17
+ if (project.projectType !== 'library') {
18
+ return;
19
+ }
20
+ const { libsDir } = (0, devkit_1.getWorkspaceLayout)(tree);
21
+ const projects = (0, devkit_1.getProjects)(tree);
22
+ // use the source root to find the from location
23
+ // this attempts to account for libs that have been created with --importPath
24
+ const tsConfigPath = (0, ts_config_1.getRootTsConfigPathInTree)(tree);
25
+ let tsConfig;
26
+ let mainEntryPointImportPath;
27
+ let secondaryEntryPointImportPaths;
28
+ if (tree.exists(tsConfigPath)) {
29
+ tsConfig = (0, devkit_1.readJson)(tree, tsConfigPath);
30
+ const sourceRoot = project.sourceRoot ?? (0, devkit_1.joinPathFragments)(project.root, 'src');
31
+ mainEntryPointImportPath = Object.keys(tsConfig.compilerOptions?.paths ?? {}).find((path) => tsConfig.compilerOptions.paths[path].some((x) => x.startsWith(ensureTrailingSlash(sourceRoot))));
32
+ secondaryEntryPointImportPaths = Object.keys(tsConfig.compilerOptions?.paths ?? {}).filter((path) => tsConfig.compilerOptions.paths[path].some((x) => x.startsWith(ensureTrailingSlash(project.root)) &&
33
+ !x.startsWith(ensureTrailingSlash(sourceRoot))));
34
+ }
35
+ mainEntryPointImportPath ??= (0, utils_1.normalizePathSlashes)((0, get_import_path_1.getImportPath)(tree, project.root.slice(libsDir.length).replace(/^\/|\\/, '')));
36
+ const projectRefs = [
37
+ {
38
+ from: mainEntryPointImportPath,
39
+ to: schema.importPath,
40
+ },
41
+ ...secondaryEntryPointImportPaths.map((p) => ({
42
+ from: p,
43
+ // if the import path doesn't start with the main entry point import path,
44
+ // it's a custom import path we don't know how to update the name, we keep
45
+ // it as-is, but we'll update the path it points to
46
+ to: schema.importPath && p.startsWith(mainEntryPointImportPath)
47
+ ? p.replace(mainEntryPointImportPath, schema.importPath)
48
+ : null,
49
+ })),
50
+ ];
51
+ for (const projectRef of projectRefs) {
52
+ if (schema.updateImportPath && projectRef.to) {
53
+ const replaceProjectRef = new RegExp(projectRef.from, 'g');
54
+ for (const [name, definition] of Array.from(projects.entries())) {
55
+ if (name === schema.projectName) {
56
+ continue;
57
+ }
58
+ (0, devkit_1.visitNotIgnoredFiles)(tree, definition.root, (file) => {
59
+ const contents = tree.read(file, 'utf-8');
60
+ replaceProjectRef.lastIndex = 0;
61
+ if (!replaceProjectRef.test(contents)) {
62
+ return;
63
+ }
64
+ updateImportPaths(tree, file, projectRef.from, projectRef.to);
65
+ });
66
+ }
67
+ }
68
+ const projectRoot = {
69
+ from: project.root,
70
+ to: schema.relativeToRootDestination,
71
+ };
72
+ if (tsConfig) {
73
+ const path = tsConfig.compilerOptions.paths[projectRef.from];
74
+ if (!path) {
75
+ throw new Error([
76
+ `unable to find "${projectRef.from}" in`,
77
+ `${tsConfigPath} compilerOptions.paths`,
78
+ ].join(' '));
79
+ }
80
+ const updatedPath = path.map((x) => (0, devkit_1.joinPathFragments)(projectRoot.to, (0, path_1.relative)(projectRoot.from, x)));
81
+ if (schema.updateImportPath && projectRef.to) {
82
+ tsConfig.compilerOptions.paths[projectRef.to] = updatedPath;
83
+ if (projectRef.from !== projectRef.to) {
84
+ delete tsConfig.compilerOptions.paths[projectRef.from];
85
+ }
86
+ }
87
+ else {
88
+ tsConfig.compilerOptions.paths[projectRef.from] = updatedPath;
89
+ }
90
+ }
91
+ (0, devkit_1.writeJson)(tree, tsConfigPath, tsConfig);
92
+ }
93
+ }
94
+ exports.updateImports = updateImports;
95
+ function ensureTrailingSlash(path) {
96
+ return path.endsWith('/') ? path : `${path}/`;
97
+ }
98
+ /**
99
+ * Changes imports in a file from one import to another
100
+ */
101
+ function updateImportPaths(tree, path, from, to) {
102
+ if (!tsModule) {
103
+ tsModule = (0, typescript_1.ensureTypescript)();
104
+ }
105
+ const contents = tree.read(path, 'utf-8');
106
+ const sourceFile = tsModule.createSourceFile(path, contents, tsModule.ScriptTarget.Latest, true);
107
+ // Apply changes on the various types of imports
108
+ const newContents = (0, devkit_1.applyChangesToString)(contents, [
109
+ ...updateImportDeclarations(sourceFile, from, to),
110
+ ...updateDynamicImports(sourceFile, from, to),
111
+ ]);
112
+ tree.write(path, newContents);
113
+ }
114
+ /**
115
+ * Update the module specifiers on static imports
116
+ */
117
+ function updateImportDeclarations(sourceFile, from, to) {
118
+ if (!tsModule) {
119
+ tsModule = (0, typescript_1.ensureTypescript)();
120
+ }
121
+ const importDecls = (0, ts_config_1.findNodes)(sourceFile, [
122
+ tsModule.SyntaxKind.ImportDeclaration,
123
+ tsModule.SyntaxKind.ExportDeclaration,
124
+ ]);
125
+ const changes = [];
126
+ for (const { moduleSpecifier } of importDecls) {
127
+ if (tsModule.isStringLiteral(moduleSpecifier)) {
128
+ changes.push(...updateModuleSpecifier(moduleSpecifier, from, to));
129
+ }
130
+ }
131
+ return changes;
132
+ }
133
+ /**
134
+ * Update the module specifiers on dynamic imports and require statements
135
+ */
136
+ function updateDynamicImports(sourceFile, from, to) {
137
+ if (!tsModule) {
138
+ tsModule = (0, typescript_1.ensureTypescript)();
139
+ }
140
+ const expressions = (0, ts_config_1.findNodes)(sourceFile, tsModule.SyntaxKind.CallExpression);
141
+ const changes = [];
142
+ for (const { expression, arguments: args } of expressions) {
143
+ const moduleSpecifier = args[0];
144
+ // handle dynamic import statements
145
+ if (expression.kind === tsModule.SyntaxKind.ImportKeyword &&
146
+ moduleSpecifier &&
147
+ tsModule.isStringLiteral(moduleSpecifier)) {
148
+ changes.push(...updateModuleSpecifier(moduleSpecifier, from, to));
149
+ }
150
+ // handle require statements
151
+ if (tsModule.isIdentifier(expression) &&
152
+ expression.text === 'require' &&
153
+ moduleSpecifier &&
154
+ tsModule.isStringLiteral(moduleSpecifier)) {
155
+ changes.push(...updateModuleSpecifier(moduleSpecifier, from, to));
156
+ }
157
+ }
158
+ return changes;
159
+ }
160
+ /**
161
+ * Replace the old module specifier with a the new path
162
+ */
163
+ function updateModuleSpecifier(moduleSpecifier, from, to) {
164
+ if (moduleSpecifier.text === from ||
165
+ moduleSpecifier.text.startsWith(`${from}/`)) {
166
+ return [
167
+ {
168
+ type: devkit_1.ChangeType.Delete,
169
+ start: moduleSpecifier.getStart() + 1,
170
+ length: moduleSpecifier.text.length,
171
+ },
172
+ {
173
+ type: devkit_1.ChangeType.Insert,
174
+ index: moduleSpecifier.getStart() + 1,
175
+ text: moduleSpecifier.text.replace(new RegExp(from, 'g'), to),
176
+ },
177
+ ];
178
+ }
179
+ else {
180
+ return [];
181
+ }
182
+ }
@@ -0,0 +1,10 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ /**
4
+ * Updates the project name and coverage folder in the jest.config.js if it exists
5
+ *
6
+ * (assume relative paths have been updated previously)
7
+ *
8
+ * @param schema The options provided to the schematic
9
+ */
10
+ export declare function updateJestConfig(tree: Tree, schema: NormalizedSchema, project: ProjectConfiguration): void;