@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,29 @@
1
+ export declare enum Preset {
2
+ Apps = "apps",
3
+ /** @deprecated Use Apps instead
4
+ */
5
+ Empty = "empty",
6
+ /** @deprecated Use NPM instead
7
+ */
8
+ Core = "core",
9
+ NPM = "npm",
10
+ TS = "ts",
11
+ WebComponents = "web-components",
12
+ AngularMonorepo = "angular-monorepo",
13
+ AngularStandalone = "angular-standalone",
14
+ ReactMonorepo = "react-monorepo",
15
+ ReactStandalone = "react-standalone",
16
+ NextJsStandalone = "nextjs-standalone",
17
+ ReactNative = "react-native",
18
+ VueMonorepo = "vue-monorepo",
19
+ VueStandalone = "vue-standalone",
20
+ Nuxt = "nuxt",
21
+ NuxtStandalone = "nuxt-standalone",
22
+ Expo = "expo",
23
+ NextJs = "next",
24
+ Nest = "nest",
25
+ Express = "express",
26
+ NodeStandalone = "node-standalone",
27
+ NodeMonorepo = "node-monorepo",
28
+ TsStandalone = "ts-standalone"
29
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Preset = void 0;
4
+ var Preset;
5
+ (function (Preset) {
6
+ Preset["Apps"] = "apps";
7
+ // TODO(v19): Remove Empty and Core presets
8
+ /** @deprecated Use Apps instead
9
+ */
10
+ Preset["Empty"] = "empty";
11
+ /** @deprecated Use NPM instead
12
+ */
13
+ Preset["Core"] = "core";
14
+ Preset["NPM"] = "npm";
15
+ Preset["TS"] = "ts";
16
+ Preset["WebComponents"] = "web-components";
17
+ Preset["AngularMonorepo"] = "angular-monorepo";
18
+ Preset["AngularStandalone"] = "angular-standalone";
19
+ Preset["ReactMonorepo"] = "react-monorepo";
20
+ Preset["ReactStandalone"] = "react-standalone";
21
+ Preset["NextJsStandalone"] = "nextjs-standalone";
22
+ Preset["ReactNative"] = "react-native";
23
+ Preset["VueMonorepo"] = "vue-monorepo";
24
+ Preset["VueStandalone"] = "vue-standalone";
25
+ Preset["Nuxt"] = "nuxt";
26
+ Preset["NuxtStandalone"] = "nuxt-standalone";
27
+ Preset["Expo"] = "expo";
28
+ Preset["NextJs"] = "next";
29
+ Preset["Nest"] = "nest";
30
+ Preset["Express"] = "express";
31
+ Preset["NodeStandalone"] = "node-standalone";
32
+ Preset["NodeMonorepo"] = "node-monorepo";
33
+ Preset["TsStandalone"] = "ts-standalone";
34
+ })(Preset || (exports.Preset = Preset = {}));
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function splitConfigurationIntoProjectJsonFiles(tree: Tree): Promise<void>;
3
+ export default splitConfigurationIntoProjectJsonFiles;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitConfigurationIntoProjectJsonFiles = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const convert_to_nx_project_1 = require("../../generators/convert-to-nx-project/convert-to-nx-project");
6
+ async function splitConfigurationIntoProjectJsonFiles(tree) {
7
+ await (0, convert_to_nx_project_1.default)(tree, { all: true });
8
+ await (0, devkit_1.formatFiles)(tree);
9
+ }
10
+ exports.splitConfigurationIntoProjectJsonFiles = splitConfigurationIntoProjectJsonFiles;
11
+ exports.default = splitConfigurationIntoProjectJsonFiles;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): void;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ function update(tree) {
5
+ const projects = (0, devkit_1.getProjects)(tree);
6
+ const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
7
+ // In case user installed as prod dep.
8
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
9
+ // If web package is installed, skip update.
10
+ if (deps['@nrwl/web'] || deps['@nx/web']) {
11
+ return;
12
+ }
13
+ projects.forEach((config, name) => {
14
+ const babelRcPath = (0, devkit_1.joinPathFragments)(config.root, '.babelrc');
15
+ if (!tree.exists(babelRcPath))
16
+ return;
17
+ const babelRc = (0, devkit_1.readJson)(tree, babelRcPath);
18
+ const nrwlWebBabelPresetIdx = babelRc.presets?.findIndex((p) =>
19
+ // Babel preset could be specified as a string or a tuple with options.
20
+ // Account for rescope migration running before or after this one.
21
+ Array.isArray(p)
22
+ ? p[0] === '@nrwl/web/babel' || p[0] === '@nx/web/babel'
23
+ : p === '@nrwl/web/babel' || p === '@nx/web/babel');
24
+ if (nrwlWebBabelPresetIdx === undefined || nrwlWebBabelPresetIdx === -1) {
25
+ return;
26
+ }
27
+ if (deps['@nrwl/js'] || deps['@nx/js']) {
28
+ // If JS plugin is installed, then rename to @nx/js/babel.
29
+ const found = babelRc.presets[nrwlWebBabelPresetIdx];
30
+ babelRc.presets[nrwlWebBabelPresetIdx] = Array.isArray(found)
31
+ ? ['@nx/js/babel', found[1]]
32
+ : '@nx/js/babel';
33
+ }
34
+ else {
35
+ // Otherwise, remove from config.
36
+ babelRc.presets.splice(nrwlWebBabelPresetIdx, 1);
37
+ }
38
+ (0, devkit_1.writeJson)(tree, babelRcPath, babelRc);
39
+ });
40
+ }
41
+ exports.default = update;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<() => void>;
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ // nx-ignore-next-line
5
+ const path = require("path");
6
+ const move_1 = require("../../generators/move/move");
7
+ const versions_1 = require("../../utils/versions");
8
+ const path_1 = require("path");
9
+ const get_import_path_1 = require("../../utilities/get-import-path");
10
+ const PROJECT_NAME = 'workspace-plugin';
11
+ const DESTINATION = `tools/${PROJECT_NAME}`;
12
+ async function default_1(tree) {
13
+ if (!tree.exists('tools/generators')) {
14
+ return;
15
+ }
16
+ const tasks = [];
17
+ if (hasWorkspaceGenerators(tree)) {
18
+ tasks.push(...(await moveWorkspaceGeneratorsToLocalPlugin(tree)));
19
+ }
20
+ removeToolsGeneratorsIfEmpty(tree);
21
+ await (0, devkit_1.formatFiles)(tree);
22
+ return () => {
23
+ for (const task of tasks) {
24
+ task();
25
+ }
26
+ };
27
+ }
28
+ exports.default = default_1;
29
+ async function moveWorkspaceGeneratorsToLocalPlugin(tree) {
30
+ const tasks = [];
31
+ let project = (0, devkit_1.getProjects)(tree).get(PROJECT_NAME);
32
+ if (!project) {
33
+ await createNewPlugin(tree);
34
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
35
+ '@nx/plugin': versions_1.nxVersion,
36
+ }));
37
+ project = (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME);
38
+ }
39
+ updateExistingPlugin(tree, project);
40
+ return tasks;
41
+ }
42
+ function hasWorkspaceGenerators(tree) {
43
+ const children = tree.children('tools/generators');
44
+ return (children.length > 0 &&
45
+ !(children.length === 1 && children[0] === '.gitkeep'));
46
+ }
47
+ function removeToolsGeneratorsIfEmpty(tree) {
48
+ if (!hasWorkspaceGenerators(tree)) {
49
+ tree.delete('tools/generators');
50
+ }
51
+ }
52
+ // Inspired by packages/nx/src/command-line/workspace-generators.ts
53
+ function collectAndMoveGenerators(tree, destinationProjectRoot) {
54
+ const generators = {};
55
+ const generatorsDir = 'tools/generators';
56
+ const destinationDir = (0, devkit_1.joinPathFragments)(destinationProjectRoot, 'src', 'generators');
57
+ for (const c of tree.children('tools/generators')) {
58
+ const childDir = path.join(generatorsDir, c);
59
+ const schemaPath = (0, devkit_1.joinPathFragments)(childDir, 'schema.json');
60
+ if (tree.exists(schemaPath)) {
61
+ const schema = (0, devkit_1.readJson)(tree, schemaPath);
62
+ generators[c] = {
63
+ implementation: `./src/generators/${c}`,
64
+ schema: `./src/generators/${(0, devkit_1.joinPathFragments)(c, 'schema.json')}`,
65
+ description: schema.description ?? `Generator ${c}`,
66
+ };
67
+ moveFilesInDirectory(tree, childDir, (0, devkit_1.joinPathFragments)(destinationDir, c));
68
+ }
69
+ }
70
+ return generators;
71
+ }
72
+ function moveFilesInDirectory(tree, source, destination) {
73
+ const relative = path_1.posix.relative(source, path_1.posix.dirname(destination));
74
+ if (!relative.startsWith('../')) {
75
+ // If the destination is in the same directory or a subdirectory of the source
76
+ // we can just move the files. If it is not, we need to update the relative imports.
77
+ return;
78
+ }
79
+ let offsetLevel = 0;
80
+ const pathParts = relative.split('/');
81
+ for (const part of pathParts) {
82
+ if (part === '..') {
83
+ offsetLevel++;
84
+ }
85
+ else {
86
+ break;
87
+ }
88
+ }
89
+ for (const c of tree.children(source)) {
90
+ if (!tree.isFile(c)) {
91
+ moveFilesInDirectory(tree, (0, devkit_1.joinPathFragments)(source, c), (0, devkit_1.joinPathFragments)(destination, c));
92
+ }
93
+ tree.rename((0, devkit_1.joinPathFragments)(source, c), (0, devkit_1.joinPathFragments)(destination, c));
94
+ // If its a TS file we can update relative imports with find + replace
95
+ // This could be done with AST, but since we are only looking at relative
96
+ // imports its easy to do via string replace. We replace any strings starting
97
+ // with a relative path outside of their own directory.
98
+ if (c.endsWith('.ts')) {
99
+ let content = tree.read((0, devkit_1.joinPathFragments)(destination, c)).toString();
100
+ // +2 is a bit of a magic number here - represents extra directory levels in a normal
101
+ // plugin structure compared to the workspace-generator layout
102
+ const extraDirectoriesInPluginStructure = 2;
103
+ content = content.replace(new RegExp(`'` + `\.\.\/`.repeat(offsetLevel), 'g'), "'" + '../'.repeat(offsetLevel + extraDirectoriesInPluginStructure));
104
+ content = content.replace(new RegExp(`"` + `\.\.\/`.repeat(offsetLevel), 'g'), '"' + '../'.repeat(offsetLevel + extraDirectoriesInPluginStructure));
105
+ // We write it back in the same spot, since it is moved as if it was a regular file after this
106
+ tree.write((0, devkit_1.joinPathFragments)(source, c), content);
107
+ }
108
+ tree.rename((0, devkit_1.joinPathFragments)(source, c), (0, devkit_1.joinPathFragments)(destination, c));
109
+ }
110
+ }
111
+ async function createNewPlugin(tree) {
112
+ (0, devkit_1.ensurePackage)('@nx/plugin', versions_1.nxVersion);
113
+ const { pluginGenerator } =
114
+ // nx-ignore-next-line
115
+ require('@nx/plugin/src/generators/plugin/plugin');
116
+ // nx-ignore-next-line
117
+ const { Linter } = (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
118
+ const npmScope = (0, get_import_path_1.getNpmScope)(tree);
119
+ const importPath = npmScope ? `@${npmScope}/${PROJECT_NAME}` : PROJECT_NAME;
120
+ await pluginGenerator(tree, {
121
+ minimal: true,
122
+ name: PROJECT_NAME,
123
+ importPath: importPath,
124
+ skipTsConfig: false,
125
+ compiler: 'tsc',
126
+ linter: Linter.EsLint,
127
+ skipFormat: true,
128
+ skipLintChecks: false,
129
+ unitTestRunner: 'jest',
130
+ e2eTestRunner: 'none',
131
+ publishable: false,
132
+ });
133
+ await getCreateGeneratorsJson()(tree, (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME).root, PROJECT_NAME);
134
+ await moveGeneratedPlugin(tree, DESTINATION, importPath);
135
+ }
136
+ function moveGeneratedPlugin(tree, destination, importPath) {
137
+ const config = (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME);
138
+ if (config.root !== DESTINATION) {
139
+ return (0, move_1.moveGenerator)(tree, {
140
+ destination,
141
+ projectName: PROJECT_NAME,
142
+ newProjectName: PROJECT_NAME,
143
+ updateImportPath: true,
144
+ importPath: importPath,
145
+ projectNameAndRootFormat: 'as-provided',
146
+ });
147
+ }
148
+ }
149
+ function updateExistingPlugin(tree, project) {
150
+ const packageJson = (0, devkit_1.readJson)(tree, (0, devkit_1.joinPathFragments)(project.root, 'package.json'));
151
+ const defaultGeneratorsPath = (0, devkit_1.joinPathFragments)(project.root, 'generators.json');
152
+ let generatorsJsonPath = packageJson.generators ||
153
+ packageJson.schematics ||
154
+ tree.exists(defaultGeneratorsPath)
155
+ ? defaultGeneratorsPath
156
+ : null;
157
+ if (!generatorsJsonPath) {
158
+ getCreateGeneratorsJson()(tree, (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME).root, PROJECT_NAME);
159
+ generatorsJsonPath = defaultGeneratorsPath;
160
+ }
161
+ (0, devkit_1.updateJson)(tree, generatorsJsonPath, (json) => {
162
+ const generators = collectAndMoveGenerators(tree, project.root);
163
+ json.generators ??= {};
164
+ for (const generator in generators) {
165
+ if (json.generators[generator]) {
166
+ devkit_1.output.warn({
167
+ title: `Generator ${generator} already exists in ${project.name}`,
168
+ bodyLines: [
169
+ 'Since you have a generator with the same name in your plugin, the generator from workspace-generators has been discarded.',
170
+ ],
171
+ });
172
+ }
173
+ else {
174
+ json.generators[generator] = generators[generator];
175
+ }
176
+ }
177
+ return json;
178
+ });
179
+ }
180
+ function getCreateGeneratorsJson() {
181
+ // We cant use `as typeof import('@nx/plugin/src/generators/generator/generator');` here
182
+ // because it will cause a typescript error at build time.
183
+ const { createGeneratorsJson } =
184
+ // nx-ignore-next-line
185
+ require('@nx/plugin/src/generators/generator/generator');
186
+ return createGeneratorsJson;
187
+ }
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function replacePackage(tree: Tree): Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/workspace', '@nx/workspace');
7
+ await (0, devkit_1.formatFiles)(tree);
8
+ }
9
+ exports.default = replacePackage;
@@ -0,0 +1 @@
1
+ export { CachedResult, TaskWithCachedResult, Cache, } from 'nx/src/tasks-runner/cache';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cache = void 0;
4
+ var cache_1 = require("nx/src/tasks-runner/cache");
5
+ Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return cache_1.Cache; } });
@@ -0,0 +1 @@
1
+ export * from 'nx/src/tasks-runner/default-tasks-runner';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("nx/src/tasks-runner/default-tasks-runner"), exports);
@@ -0,0 +1 @@
1
+ export { CompositeLifeCycle, TaskMetadata, TaskResult, LifeCycle, } from 'nx/src/tasks-runner/life-cycle';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompositeLifeCycle = void 0;
4
+ var life_cycle_1 = require("nx/src/tasks-runner/life-cycle");
5
+ Object.defineProperty(exports, "CompositeLifeCycle", { enumerable: true, get: function () { return life_cycle_1.CompositeLifeCycle; } });
@@ -0,0 +1 @@
1
+ export * from 'nx/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("nx/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle"), exports);
@@ -0,0 +1,2 @@
1
+ export * from 'nx/src/tasks-runner/tasks-runner';
2
+ export { Task } from '@nx/devkit';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("nx/src/tasks-runner/tasks-runner"), exports);
@@ -0,0 +1 @@
1
+ export * from 'nx/src/tasks-runner/utils';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("nx/src/tasks-runner/utils"), exports);
@@ -0,0 +1 @@
1
+ export * from 'nx/src/utils/workspace-root';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("nx/src/utils/workspace-root"), exports);
@@ -0,0 +1 @@
1
+ export declare function deduceDefaultBase(): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deduceDefaultBase = void 0;
4
+ const child_process_1 = require("child_process");
5
+ function deduceDefaultBase() {
6
+ const nxDefaultBase = 'main';
7
+ try {
8
+ return ((0, child_process_1.execSync)('git config --get init.defaultBranch').toString().trim() ||
9
+ nxDefaultBase);
10
+ }
11
+ catch {
12
+ return nxDefaultBase;
13
+ }
14
+ }
15
+ exports.deduceDefaultBase = deduceDefaultBase;
@@ -0,0 +1,13 @@
1
+ import { fileExists, directoryExists, isRelativePath, createDirectory } from 'nx/src/utils/fileutils';
2
+ export { fileExists, directoryExists, isRelativePath, createDirectory };
3
+ /**
4
+ * This method is specifically for updating a JSON file using the filesystem
5
+ *
6
+ * @remarks
7
+ * If you are looking to update a JSON file in a tree, look for ./ast-utils#updateJsonInTree
8
+ * @param path Path of the JSON file on the filesystem
9
+ * @param callback Manipulation of the JSON data
10
+ */
11
+ export declare function updateJsonFile(path: string, callback: (a: any) => any): void;
12
+ export declare function copyFile(file: string, target: string): void;
13
+ export declare function renameSync(from: string, to: string, cb: (err: Error | null) => void): void;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renameSync = exports.copyFile = exports.updateJsonFile = exports.createDirectory = exports.isRelativePath = exports.directoryExists = exports.fileExists = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const fileutils_1 = require("nx/src/utils/fileutils");
7
+ Object.defineProperty(exports, "fileExists", { enumerable: true, get: function () { return fileutils_1.fileExists; } });
8
+ Object.defineProperty(exports, "directoryExists", { enumerable: true, get: function () { return fileutils_1.directoryExists; } });
9
+ Object.defineProperty(exports, "isRelativePath", { enumerable: true, get: function () { return fileutils_1.isRelativePath; } });
10
+ Object.defineProperty(exports, "createDirectory", { enumerable: true, get: function () { return fileutils_1.createDirectory; } });
11
+ /**
12
+ * This method is specifically for updating a JSON file using the filesystem
13
+ *
14
+ * @remarks
15
+ * If you are looking to update a JSON file in a tree, look for ./ast-utils#updateJsonInTree
16
+ * @param path Path of the JSON file on the filesystem
17
+ * @param callback Manipulation of the JSON data
18
+ */
19
+ function updateJsonFile(path, callback) {
20
+ const json = (0, fileutils_1.readJsonFile)(path);
21
+ callback(json);
22
+ (0, fileutils_1.writeJsonFile)(path, json);
23
+ }
24
+ exports.updateJsonFile = updateJsonFile;
25
+ function copyFile(file, target) {
26
+ const f = (0, path_1.basename)(file);
27
+ const source = (0, fs_1.createReadStream)(file);
28
+ const dest = (0, fs_1.createWriteStream)((0, path_1.resolve)(target, f));
29
+ source.pipe(dest);
30
+ source.on('error', (e) => console.error(e));
31
+ }
32
+ exports.copyFile = copyFile;
33
+ function renameSync(from, to, cb) {
34
+ try {
35
+ if (!(0, fs_1.existsSync)(from)) {
36
+ throw new Error(`Path: ${from} does not exist`);
37
+ }
38
+ else if ((0, fs_1.existsSync)(to)) {
39
+ throw new Error(`Path: ${to} already exists`);
40
+ }
41
+ // Make sure parent path exists
42
+ const parentPath = (0, path_1.resolve)(to, '..');
43
+ (0, fileutils_1.createDirectory)(parentPath);
44
+ (0, fs_1.renameSync)(from, to);
45
+ cb(null);
46
+ }
47
+ catch (e) {
48
+ cb(e);
49
+ }
50
+ }
51
+ exports.renameSync = renameSync;
@@ -0,0 +1,3 @@
1
+ import { Tree } from 'nx/src/generators/tree';
2
+ export declare function getImportPath(tree: Tree, projectDirectory: string): string;
3
+ export declare function getNpmScope(tree: Tree): string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNpmScope = exports.getImportPath = void 0;
4
+ const json_1 = require("nx/src/generators/utils/json");
5
+ function getImportPath(tree, projectDirectory) {
6
+ const npmScope = getNpmScope(tree);
7
+ return npmScope
8
+ ? `${npmScope === '@' ? '' : '@'}${npmScope}/${projectDirectory}`
9
+ : projectDirectory;
10
+ }
11
+ exports.getImportPath = getImportPath;
12
+ function getNpmScope(tree) {
13
+ const { name } = tree.exists('package.json')
14
+ ? (0, json_1.readJson)(tree, 'package.json')
15
+ : { name: null };
16
+ if (name?.startsWith('@')) {
17
+ return name.split('/')[0].substring(1);
18
+ }
19
+ }
20
+ exports.getNpmScope = getNpmScope;
@@ -0,0 +1 @@
1
+ export * from 'nx/src/utils/output';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("nx/src/utils/output"), exports);
@@ -0,0 +1,7 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import type { Node, SyntaxKind } from 'typescript';
3
+ export declare function readTsConfig(tsConfigPath: string): import("typescript").ParsedCommandLine;
4
+ export declare function getRootTsConfigPathInTree(tree: Tree): string | null;
5
+ export declare function getRelativePathToRootTsConfig(tree: Tree, targetPath: string): string;
6
+ export declare function getRootTsConfigFileName(): string | null;
7
+ export declare function findNodes(node: Node, kind: SyntaxKind | SyntaxKind[], max?: number): Node[];
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findNodes = exports.getRootTsConfigFileName = exports.getRelativePathToRootTsConfig = exports.getRootTsConfigPathInTree = exports.readTsConfig = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ const typescript_1 = require("./typescript");
8
+ let tsModule;
9
+ function readTsConfig(tsConfigPath) {
10
+ if (!tsModule) {
11
+ tsModule = (0, typescript_1.ensureTypescript)();
12
+ }
13
+ const readResult = tsModule.readConfigFile(tsConfigPath, tsModule.sys.readFile);
14
+ return tsModule.parseJsonConfigFileContent(readResult.config, tsModule.sys, (0, path_1.dirname)(tsConfigPath));
15
+ }
16
+ exports.readTsConfig = readTsConfig;
17
+ function getRootTsConfigPathInTree(tree) {
18
+ for (const path of ['tsconfig.base.json', 'tsconfig.json']) {
19
+ if (tree.exists(path)) {
20
+ return path;
21
+ }
22
+ }
23
+ return 'tsconfig.base.json';
24
+ }
25
+ exports.getRootTsConfigPathInTree = getRootTsConfigPathInTree;
26
+ function getRelativePathToRootTsConfig(tree, targetPath) {
27
+ return (0, devkit_1.offsetFromRoot)(targetPath) + getRootTsConfigPathInTree(tree);
28
+ }
29
+ exports.getRelativePathToRootTsConfig = getRelativePathToRootTsConfig;
30
+ function getRootTsConfigFileName() {
31
+ for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) {
32
+ const tsConfigPath = (0, path_1.join)(devkit_1.workspaceRoot, tsConfigName);
33
+ if ((0, fs_1.existsSync)(tsConfigPath)) {
34
+ return tsConfigName;
35
+ }
36
+ }
37
+ return null;
38
+ }
39
+ exports.getRootTsConfigFileName = getRootTsConfigFileName;
40
+ function findNodes(node, kind, max = Infinity) {
41
+ if (!node || max == 0) {
42
+ return [];
43
+ }
44
+ const arr = [];
45
+ const hasMatch = Array.isArray(kind)
46
+ ? kind.includes(node.kind)
47
+ : node.kind === kind;
48
+ if (hasMatch) {
49
+ arr.push(node);
50
+ max--;
51
+ }
52
+ if (max > 0) {
53
+ for (const child of node.getChildren()) {
54
+ findNodes(child, kind, max).forEach((node) => {
55
+ if (max > 0) {
56
+ arr.push(node);
57
+ }
58
+ max--;
59
+ });
60
+ if (max <= 0) {
61
+ break;
62
+ }
63
+ }
64
+ }
65
+ return arr;
66
+ }
67
+ exports.findNodes = findNodes;
@@ -0,0 +1,22 @@
1
+ import type * as ts from 'typescript';
2
+ import type { CustomTransformers, Diagnostic, Program } from 'typescript';
3
+ export interface TypeScriptCompilationOptions {
4
+ outputPath: string;
5
+ projectName: string;
6
+ projectRoot: string;
7
+ tsConfig: string;
8
+ deleteOutputPath?: boolean;
9
+ rootDir?: string;
10
+ watch?: boolean;
11
+ getCustomTransformers?(program: Program): CustomTransformers;
12
+ }
13
+ export interface TypescriptWatchChangeEvent {
14
+ diagnostic: ts.Diagnostic;
15
+ newLine: string;
16
+ options: ts.CompilerOptions;
17
+ errorCount: number;
18
+ }
19
+ export declare function compileTypeScript(options: TypeScriptCompilationOptions): {
20
+ success: boolean;
21
+ };
22
+ export declare function compileTypeScriptWatcher(options: TypeScriptCompilationOptions, callback: (diagnostic: Diagnostic, newLine: string, options: ts.CompilerOptions, errorCount: number) => void | Promise<void>): ts.WatchOfFilesAndCompilerOptions<ts.BuilderProgram>;