@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,7 @@
1
+ import { Schema } from '../schema';
2
+ /**
3
+ * Check whether the project to be removed is depended on by another project
4
+ *
5
+ * Throws an error if the project is in use, unless the `--forceRemove` option is used.
6
+ */
7
+ export declare function checkDependencies(_: any, schema: Schema): Promise<void>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ /**
6
+ * Check whether the project to be removed is depended on by another project
7
+ *
8
+ * Throws an error if the project is in use, unless the `--forceRemove` option is used.
9
+ */
10
+ async function checkDependencies(_, schema) {
11
+ if (schema.forceRemove) {
12
+ return;
13
+ }
14
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
15
+ const reverseGraph = (0, devkit_1.reverse)(graph);
16
+ const deps = reverseGraph.dependencies[schema.projectName] || [];
17
+ if (deps.length > 0) {
18
+ throw new Error(`${schema.projectName} is still a dependency of the following projects:\n${deps
19
+ .map((x) => x.target)
20
+ .join('\n')}`);
21
+ }
22
+ }
23
+ exports.checkDependencies = checkDependencies;
@@ -0,0 +1,3 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { Schema } from '../schema';
3
+ export declare function checkProjectIsSafeToRemove(tree: Tree, schema: Schema, project: ProjectConfiguration): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkProjectIsSafeToRemove = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ function checkProjectIsSafeToRemove(tree, schema, project) {
7
+ if (project.root === '.') {
8
+ throw new Error(`"${schema.projectName}" is the root project. Running this would delete every file in your workspace.`);
9
+ }
10
+ if (schema.forceRemove) {
11
+ devkit_1.logger.warn(`You have passed --forceRemove`);
12
+ return;
13
+ }
14
+ const containedProjects = [];
15
+ for (const [_, p] of (0, devkit_1.getProjects)(tree)) {
16
+ if (project.name !== p.name &&
17
+ !(0, devkit_1.normalizePath)((0, path_1.relative)(project.root, p.root)).startsWith('..')) {
18
+ containedProjects.push(p.name);
19
+ }
20
+ }
21
+ if (containedProjects.length > 0) {
22
+ throw new Error(`"${schema.projectName}" is a project that has nested projects within it. Removing this project would remove the following projects as well:\n - ${containedProjects.join('\n - ')}\nPass --forceRemove to remove all of the above projects`);
23
+ }
24
+ }
25
+ exports.checkProjectIsSafeToRemove = checkProjectIsSafeToRemove;
@@ -0,0 +1,10 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { Schema } from '../schema';
3
+ /**
4
+ * Check whether the project to be removed has builders targetted by another project
5
+ *
6
+ * Throws an error if the project is in use, unless the `--forceRemove` option is used.
7
+ *
8
+ * @param schema The options provided to the schematic
9
+ */
10
+ export declare function checkTargets(tree: Tree, schema: Schema): Promise<void>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkTargets = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ /**
6
+ * Check whether the project to be removed has builders targetted by another project
7
+ *
8
+ * Throws an error if the project is in use, unless the `--forceRemove` option is used.
9
+ *
10
+ * @param schema The options provided to the schematic
11
+ */
12
+ async function checkTargets(tree, schema) {
13
+ if (schema.forceRemove) {
14
+ return;
15
+ }
16
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
17
+ const errors = [];
18
+ (0, devkit_1.getProjects)(tree).forEach((projectConfig, projectName) => {
19
+ if (projectName === schema.projectName) {
20
+ return;
21
+ }
22
+ Object.entries(projectConfig.targets || {}).forEach(([, targetConfig]) => {
23
+ checkIfProjectIsUsed(targetConfig, (value) => {
24
+ try {
25
+ const { project } = (0, devkit_1.parseTargetString)(value, graph);
26
+ if (project === schema.projectName) {
27
+ errors.push(`"${value}" is used by "${projectName}"`);
28
+ }
29
+ }
30
+ catch (err) {
31
+ /**
32
+ * It threw because the target string was not
33
+ * in the format of project:target:configuration
34
+ *
35
+ * In that case, we don't care about it.
36
+ * So we can ignore this error.
37
+ */
38
+ }
39
+ });
40
+ });
41
+ });
42
+ if (errors.length > 0) {
43
+ let message = `${schema.projectName} is still targeted by some projects:\n\n`;
44
+ for (let error of errors) {
45
+ message += `${error}\n`;
46
+ }
47
+ throw new Error(message);
48
+ }
49
+ }
50
+ exports.checkTargets = checkTargets;
51
+ function checkIfProjectIsUsed(config, callback) {
52
+ function recur(obj, key, value) {
53
+ if (typeof value === 'string') {
54
+ callback(value);
55
+ }
56
+ else if (Array.isArray(value)) {
57
+ value.forEach((x, idx) => recur(value, idx, x));
58
+ }
59
+ else if (typeof value === 'object') {
60
+ Object.entries(value).forEach(([k, v]) => {
61
+ recur(value, k, v);
62
+ });
63
+ }
64
+ }
65
+ Object.entries(config).forEach(([k, v]) => {
66
+ recur(config, k, v);
67
+ });
68
+ }
@@ -0,0 +1,3 @@
1
+ import { Schema } from '../schema';
2
+ import { Tree } from '@nx/devkit';
3
+ export declare function removeProjectReferencesInConfig(tree: Tree, schema: Schema): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeProjectReferencesInConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function removeProjectReferencesInConfig(tree, schema) {
6
+ // Unset default project if deleting the default project
7
+ const nxJson = (0, devkit_1.readNxJson)(tree);
8
+ if (nxJson.defaultProject && nxJson.defaultProject === schema.projectName) {
9
+ delete nxJson.defaultProject;
10
+ (0, devkit_1.updateNxJson)(tree, nxJson);
11
+ }
12
+ // Remove implicit dependencies onto removed project
13
+ (0, devkit_1.getProjects)(tree).forEach((project, projectName) => {
14
+ if (project.implicitDependencies &&
15
+ project.implicitDependencies.some((projectName) => projectName === schema.projectName)) {
16
+ project.implicitDependencies = project.implicitDependencies.filter((projectName) => projectName !== schema.projectName);
17
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
18
+ }
19
+ });
20
+ }
21
+ exports.removeProjectReferencesInConfig = removeProjectReferencesInConfig;
@@ -0,0 +1,5 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ /**
3
+ * Removes (deletes) a project's files from the folder tree
4
+ */
5
+ export declare function removeProject(tree: Tree, project: ProjectConfiguration): void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeProject = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ /**
6
+ * Removes (deletes) a project's files from the folder tree
7
+ */
8
+ function removeProject(tree, project) {
9
+ (0, devkit_1.visitNotIgnoredFiles)(tree, project.root, (file) => {
10
+ tree.delete(file);
11
+ });
12
+ tree.delete(project.root);
13
+ }
14
+ exports.removeProject = removeProject;
@@ -0,0 +1,6 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { Schema } from '../schema';
3
+ /**
4
+ * Updates the root jest config projects array and removes the project.
5
+ */
6
+ export declare function updateJestConfig(tree: Tree, schema: Schema, projectConfig: ProjectConfiguration): void;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateJestConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const get_source_nodes_1 = require("../../../utilities/typescript/get-source-nodes");
6
+ const path_1 = require("path");
7
+ const typescript_1 = require("../../../utilities/typescript");
8
+ const jest_config_1 = require("../../utils/jest-config");
9
+ let tsModule;
10
+ function isUsingUtilityFunction(host) {
11
+ const rootConfigPath = (0, jest_config_1.findRootJestConfig)(host);
12
+ if (!rootConfigPath) {
13
+ return false;
14
+ }
15
+ const rootConfig = host.read(rootConfigPath, 'utf-8');
16
+ return (rootConfig.includes('getJestProjects()') ||
17
+ rootConfig.includes('getJestProjectsAsync()'));
18
+ }
19
+ /**
20
+ * in a standalone project, the root jest.config.ts is a project config instead
21
+ * of multi-project config.
22
+ * in that case we do not need to edit it to remove it
23
+ **/
24
+ function isMonorepoConfig(tree) {
25
+ const rootConfigPath = (0, jest_config_1.findRootJestConfig)(tree);
26
+ if (!rootConfigPath) {
27
+ return false;
28
+ }
29
+ return tree.read(rootConfigPath, 'utf-8').includes('projects:');
30
+ }
31
+ /**
32
+ * Updates the root jest config projects array and removes the project.
33
+ */
34
+ function updateJestConfig(tree, schema, projectConfig) {
35
+ if (!tsModule) {
36
+ tsModule = (0, typescript_1.ensureTypescript)();
37
+ }
38
+ const { createSourceFile, ScriptTarget, isPropertyAssignment, isArrayLiteralExpression, isStringLiteral, } = tsModule;
39
+ const projectToRemove = schema.projectName;
40
+ const rootConfigPath = (0, jest_config_1.findRootJestConfig)(tree);
41
+ if (!tree.exists(rootConfigPath) ||
42
+ !tree.exists((0, path_1.join)(projectConfig.root, 'jest.config.ts')) ||
43
+ isUsingUtilityFunction(tree) ||
44
+ !isMonorepoConfig(tree)) {
45
+ return;
46
+ }
47
+ const contents = tree.read(rootConfigPath, 'utf-8');
48
+ const sourceFile = createSourceFile(rootConfigPath, contents, ScriptTarget.Latest);
49
+ const sourceNodes = (0, get_source_nodes_1.getSourceNodes)(sourceFile);
50
+ const projectsAssignment = sourceNodes.find((node) => isPropertyAssignment(node) &&
51
+ node.name.getText(sourceFile) === 'projects' &&
52
+ isArrayLiteralExpression(node.initializer));
53
+ if (!projectsAssignment) {
54
+ throw Error(`Could not remove ${projectToRemove} from projects in /jest.config.ts. Please remove ${projectToRemove} from your projects.`);
55
+ }
56
+ const projectsArray = projectsAssignment.initializer;
57
+ const project = projectsArray.elements.find((item) => isStringLiteral(item) &&
58
+ item.text.startsWith(`<rootDir>/${projectConfig.root}`));
59
+ if (!project) {
60
+ console.warn(`Could not find ${projectToRemove} in projects in /jest.config.ts.`);
61
+ return;
62
+ }
63
+ const previousProject = projectsArray.elements[projectsArray.elements.indexOf(project) - 1];
64
+ const start = previousProject
65
+ ? previousProject.getEnd()
66
+ : project.getStart(sourceFile);
67
+ tree.write(rootConfigPath, (0, devkit_1.applyChangesToString)(contents, [
68
+ {
69
+ type: devkit_1.ChangeType.Delete,
70
+ start,
71
+ length: project.getEnd() - start,
72
+ },
73
+ ]));
74
+ }
75
+ exports.updateJestConfig = updateJestConfig;
@@ -0,0 +1,8 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { Schema } from '../schema';
3
+ /**
4
+ * Updates the tsconfig paths to remove the project.
5
+ *
6
+ * @param schema The options provided to the schematic
7
+ */
8
+ export declare function updateTsconfig(tree: Tree, schema: Schema): Promise<void>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateTsconfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const ts_config_1 = require("../../../utilities/ts-config");
6
+ const find_project_for_path_1 = require("nx/src/project-graph/utils/find-project-for-path");
7
+ /**
8
+ * Updates the tsconfig paths to remove the project.
9
+ *
10
+ * @param schema The options provided to the schematic
11
+ */
12
+ async function updateTsconfig(tree, schema) {
13
+ const tsConfigPath = (0, ts_config_1.getRootTsConfigPathInTree)(tree);
14
+ if (tree.exists(tsConfigPath)) {
15
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
16
+ const projectMapping = (0, find_project_for_path_1.createProjectRootMappings)(graph.nodes);
17
+ (0, devkit_1.updateJson)(tree, tsConfigPath, (json) => {
18
+ for (const importPath in json.compilerOptions.paths) {
19
+ for (const path of json.compilerOptions.paths[importPath]) {
20
+ const project = (0, find_project_for_path_1.findProjectForPath)((0, devkit_1.normalizePath)(path), projectMapping);
21
+ if (project === schema.projectName) {
22
+ delete json.compilerOptions.paths[importPath];
23
+ break;
24
+ }
25
+ }
26
+ }
27
+ return json;
28
+ });
29
+ }
30
+ }
31
+ exports.updateTsconfig = updateTsconfig;
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function removeGenerator(tree: Tree, schema: Schema): Promise<void>;
4
+ export default removeGenerator;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const check_project_is_safe_to_remove_1 = require("./lib/check-project-is-safe-to-remove");
6
+ const check_dependencies_1 = require("./lib/check-dependencies");
7
+ const check_targets_1 = require("./lib/check-targets");
8
+ const remove_project_1 = require("./lib/remove-project");
9
+ const update_tsconfig_1 = require("./lib/update-tsconfig");
10
+ const remove_project_references_in_config_1 = require("./lib/remove-project-references-in-config");
11
+ const update_jest_config_1 = require("./lib/update-jest-config");
12
+ async function removeGenerator(tree, schema) {
13
+ const project = (0, devkit_1.readProjectConfiguration)(tree, schema.projectName);
14
+ await (0, check_project_is_safe_to_remove_1.checkProjectIsSafeToRemove)(tree, schema, project);
15
+ await (0, check_dependencies_1.checkDependencies)(tree, schema);
16
+ await (0, check_targets_1.checkTargets)(tree, schema);
17
+ (0, update_jest_config_1.updateJestConfig)(tree, schema, project);
18
+ (0, remove_project_references_in_config_1.removeProjectReferencesInConfig)(tree, schema);
19
+ (0, remove_project_1.removeProject)(tree, project);
20
+ await (0, update_tsconfig_1.updateTsconfig)(tree, schema);
21
+ if (!schema.skipFormat) {
22
+ await (0, devkit_1.formatFiles)(tree);
23
+ }
24
+ }
25
+ exports.removeGenerator = removeGenerator;
26
+ exports.default = removeGenerator;
@@ -0,0 +1,10 @@
1
+ export interface Json {
2
+ [k: string]: any;
3
+ }
4
+
5
+ export interface Schema extends Json {
6
+ projectName: string;
7
+ skipFormat: boolean;
8
+ forceRemove: boolean;
9
+ importPath?: string;
10
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxWorkspaceRemove",
4
+ "cli": "nx",
5
+ "title": "Nx Remove",
6
+ "description": "Remove a project from the workspace.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g @nx/workspace:remove my-feature-lib",
11
+ "description": "Remove `my-feature-lib` from the workspace"
12
+ },
13
+ {
14
+ "command": "nx g @nx/workspace:remove my-feature-lib --forceRemove",
15
+ "description": "Force removal of `my-feature-lib` from the workspace"
16
+ }
17
+ ],
18
+ "properties": {
19
+ "projectName": {
20
+ "type": "string",
21
+ "alias": "project",
22
+ "description": "The name of the project to remove.",
23
+ "$default": {
24
+ "$source": "argv",
25
+ "index": 0
26
+ }
27
+ },
28
+ "forceRemove": {
29
+ "type": "boolean",
30
+ "aliases": ["force-remove"],
31
+ "description": "When `true`, forces removal even if the project is still in use.",
32
+ "default": false
33
+ },
34
+ "skipFormat": {
35
+ "type": "boolean",
36
+ "aliases": ["skip-format"],
37
+ "description": "Skip formatting files.",
38
+ "default": false,
39
+ "x-priority": "internal"
40
+ },
41
+ "importPath": {
42
+ "type": "string",
43
+ "description": "The library name used at creation time"
44
+ }
45
+ },
46
+ "required": ["projectName"]
47
+ }
@@ -0,0 +1,4 @@
1
+ import { Schema } from './schema';
2
+ import { Tree } from '@nx/devkit';
3
+ export declare function runCommandsGenerator(host: Tree, schema: Schema): Promise<void>;
4
+ export default runCommandsGenerator;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCommandsGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ async function runCommandsGenerator(host, schema) {
6
+ const project = (0, devkit_1.readProjectConfiguration)(host, schema.project);
7
+ project.targets = project.targets || {};
8
+ project.targets[schema.name] = {
9
+ executor: 'nx:run-commands',
10
+ outputs: schema.outputs
11
+ ? schema.outputs
12
+ .split(',')
13
+ .map((s) => (0, devkit_1.joinPathFragments)('{workspaceRoot}', s.trim()))
14
+ : [],
15
+ options: {
16
+ command: schema.command,
17
+ cwd: schema.cwd,
18
+ envFile: schema.envFile,
19
+ },
20
+ };
21
+ (0, devkit_1.updateProjectConfiguration)(host, schema.project, project);
22
+ await (0, devkit_1.formatFiles)(host);
23
+ }
24
+ exports.runCommandsGenerator = runCommandsGenerator;
25
+ exports.default = runCommandsGenerator;
@@ -0,0 +1,8 @@
1
+ export interface Schema {
2
+ name: string;
3
+ command: string;
4
+ project: string;
5
+ cwd?: string;
6
+ outputs?: string;
7
+ envFile?: string;
8
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "SchematicsRunCommands",
4
+ "title": "Create a custom target to run any command",
5
+ "description": "Create a custom target to run any command.",
6
+ "type": "object",
7
+ "cli": "nx",
8
+ "examples": [
9
+ {
10
+ "command": "nx g @nx/workspace:run-commands printhello --project my-feature-lib --command 'echo hello'",
11
+ "description": "Add the `printhello` target to `my-feature-lib`"
12
+ }
13
+ ],
14
+ "properties": {
15
+ "name": {
16
+ "type": "string",
17
+ "description": "Target name.",
18
+ "$default": {
19
+ "$source": "argv",
20
+ "index": 0
21
+ },
22
+ "x-prompt": "What name would you like to use to invoke the command?"
23
+ },
24
+ "project": {
25
+ "description": "Project name.",
26
+ "type": "string",
27
+ "x-prompt": "What project does the target belong to?",
28
+ "x-dropdown": "projects"
29
+ },
30
+ "command": {
31
+ "description": "Command to run.",
32
+ "type": "string",
33
+ "x-prompt": "What command would you like to run?"
34
+ },
35
+ "cwd": {
36
+ "description": "Current working directory of the command.",
37
+ "type": "string"
38
+ },
39
+ "outputs": {
40
+ "description": "Allows you to specify where the build artifacts are stored. This allows Nx Cloud to pick them up correctly, in the case that the build artifacts are placed somewhere other than the top level dist folder.",
41
+ "type": "string"
42
+ },
43
+ "envFile": {
44
+ "description": "Env files to be loaded before executing the commands.",
45
+ "type": "string"
46
+ }
47
+ },
48
+ "required": ["name", "command", "project"]
49
+ }
@@ -0,0 +1 @@
1
+ export declare function getNpmPackageVersion(packageName: string, packageVersion?: string): string | null;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNpmPackageVersion = void 0;
4
+ function getNpmPackageVersion(packageName, packageVersion) {
5
+ try {
6
+ const version = require('child_process').execSync(`npm view ${packageName}${packageVersion ? '@' + packageVersion : ''} version --json`, { stdio: ['pipe', 'pipe', 'ignore'] });
7
+ if (version) {
8
+ // package@1.12 => ["1.12.0", "1.12.1"]
9
+ // package@1.12.1 => "1.12.1"
10
+ // package@latest => "1.12.1"
11
+ const versionOrArray = JSON.parse(version.toString());
12
+ if (typeof versionOrArray === 'string') {
13
+ return versionOrArray;
14
+ }
15
+ return versionOrArray.pop();
16
+ }
17
+ }
18
+ catch (err) { }
19
+ return packageVersion ?? null;
20
+ }
21
+ exports.getNpmPackageVersion = getNpmPackageVersion;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function insertImport(tree: Tree, path: string, name: string, modulePath: string): void;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.insertImport = void 0;
4
+ const insert_statement_1 = require("./insert-statement");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const typescript_1 = require("../../utilities/typescript");
7
+ let tsModule;
8
+ function insertImport(tree, path, name, modulePath) {
9
+ if (!tsModule) {
10
+ tsModule = (0, typescript_1.ensureTypescript)();
11
+ }
12
+ const { createSourceFile, ScriptTarget, isStringLiteral, isImportDeclaration, isNamedImports, } = tsModule;
13
+ const contents = tree.read(path, 'utf-8');
14
+ const sourceFile = createSourceFile(path, contents, ScriptTarget.ESNext);
15
+ const importStatements = sourceFile.statements.filter(isImportDeclaration);
16
+ const existingImport = importStatements.find((statement) => isStringLiteral(statement.moduleSpecifier) &&
17
+ statement.moduleSpecifier
18
+ .getText(sourceFile)
19
+ .replace(/['"`]/g, '')
20
+ .trim() === modulePath &&
21
+ statement.importClause.namedBindings &&
22
+ isNamedImports(statement.importClause.namedBindings));
23
+ if (!existingImport) {
24
+ (0, insert_statement_1.insertStatement)(tree, path, `import { ${name} } from '${modulePath}';`);
25
+ return;
26
+ }
27
+ // TODO: Also check if the namedImport already exists
28
+ const namedImports = existingImport.importClause
29
+ .namedBindings;
30
+ const index = namedImports.getEnd() - 1;
31
+ let text;
32
+ if (namedImports.elements.hasTrailingComma) {
33
+ text = `${name},`;
34
+ }
35
+ else {
36
+ text = `,${name}`;
37
+ }
38
+ const newContents = (0, devkit_1.applyChangesToString)(contents, [
39
+ {
40
+ type: devkit_1.ChangeType.Insert,
41
+ index,
42
+ text,
43
+ },
44
+ ]);
45
+ tree.write(path, newContents);
46
+ }
47
+ exports.insertImport = insertImport;
@@ -0,0 +1,5 @@
1
+ import { Tree } from '@nx/devkit';
2
+ /**
3
+ * Insert a statement after the last import statement in a file
4
+ */
5
+ export declare function insertStatement(tree: Tree, path: string, statement: string): void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.insertStatement = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const typescript_1 = require("../../utilities/typescript");
6
+ let tsModule;
7
+ /**
8
+ * Insert a statement after the last import statement in a file
9
+ */
10
+ function insertStatement(tree, path, statement) {
11
+ if (!tsModule) {
12
+ tsModule = (0, typescript_1.ensureTypescript)();
13
+ }
14
+ const { createSourceFile, isImportDeclaration, ScriptTarget } = tsModule;
15
+ const contents = tree.read(path, 'utf-8');
16
+ const sourceFile = createSourceFile(path, contents, ScriptTarget.ESNext);
17
+ const importStatements = sourceFile.statements.filter(isImportDeclaration);
18
+ const index = importStatements.length > 0
19
+ ? importStatements[importStatements.length - 1].getEnd()
20
+ : 0;
21
+ if (importStatements.length > 0) {
22
+ statement = `\n${statement}`;
23
+ }
24
+ const newContents = (0, devkit_1.applyChangesToString)(contents, [
25
+ {
26
+ type: devkit_1.ChangeType.Insert,
27
+ index,
28
+ text: statement,
29
+ },
30
+ ]);
31
+ tree.write(path, newContents);
32
+ }
33
+ exports.insertStatement = insertStatement;
@@ -0,0 +1,2 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ export declare function findRootJestConfig(tree: Tree): string | null;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findRootJestConfig = void 0;
4
+ function findRootJestConfig(tree) {
5
+ if (tree.exists('jest.config.js')) {
6
+ return 'jest.config.js';
7
+ }
8
+ if (tree.exists('jest.config.ts')) {
9
+ return 'jest.config.ts';
10
+ }
11
+ return null;
12
+ }
13
+ exports.findRootJestConfig = findRootJestConfig;