@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,41 @@
1
+ image: node:20
2
+
3
+ clone:
4
+ depth: full
5
+
6
+ pipelines:
7
+ pull-requests:
8
+ '**':
9
+ - step:
10
+ name: 'Build and test affected apps on Pull Requests'
11
+ script:
12
+ - export NX_BRANCH=$BITBUCKET_PR_ID
13
+
14
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
15
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
16
+ # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
17
+
18
+ <% if(packageManager == 'pnpm'){ %>
19
+ - npm install --prefix=$HOME/.local -g pnpm@8
20
+ <% } %>
21
+ - <%= packageManagerInstall %>
22
+
23
+ - <%= packageManagerPrefix %> nx-cloud record -- nx format:check
24
+ - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %> --base=origin/<%= mainBranch %>
25
+
26
+ branches:
27
+ main:
28
+ - step:
29
+ name: 'Build and test affected apps on "<%= mainBranch %>" branch changes'
30
+ script:
31
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
32
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
33
+ # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
34
+
35
+ <% if(packageManager == 'pnpm'){ %>
36
+ - npm install --prefix=$HOME/.local -g pnpm@8
37
+ <% } %>
38
+ - <%= packageManagerInstall %>
39
+
40
+ - <%= packageManagerPrefix %> nx-cloud record -- nx format:check
41
+ - <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %> --base=HEAD~1
@@ -0,0 +1,33 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ nx: nrwl/nx@1.6.2
5
+
6
+ jobs:
7
+ main:
8
+ docker:
9
+ - image: cimg/node:lts-browsers
10
+ steps:
11
+ - checkout
12
+
13
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
14
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
15
+ # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
16
+
17
+ <% if(packageManager == 'pnpm'){ %>
18
+ - run:
19
+ name: Install PNPM
20
+ command: npm install --prefix=$HOME/.local -g pnpm@8
21
+ <% } %>- run: <%= packageManagerInstall %>
22
+ - nx/set-shas:
23
+ main-branch-name: '<%= mainBranch %>'
24
+
25
+ - run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
26
+ - run: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
27
+
28
+ workflows:
29
+ version: 2
30
+
31
+ <%= workflowFileName %>:
32
+ jobs:
33
+ - main
@@ -0,0 +1,38 @@
1
+ name: <%= workflowName %>
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - <%= mainBranch %>
7
+ pull_request:
8
+
9
+ permissions:
10
+ actions: read
11
+ contents: read
12
+
13
+ jobs:
14
+ main:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ with:
19
+ fetch-depth: 0
20
+
21
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
22
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
23
+ # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
24
+
25
+ <% if(packageManager == 'pnpm'){ %>
26
+ - uses: pnpm/action-setup@v2
27
+ with:
28
+ version: 8
29
+ <% } %># Cache node_modules
30
+ - uses: actions/setup-node@v3
31
+ with:
32
+ node-version: 20
33
+ cache: '<%= packageManager %>'
34
+ - run: <%= packageManagerInstall %>
35
+ - uses: nrwl/nx-set-shas@v4
36
+
37
+ - run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check
38
+ - run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
@@ -0,0 +1,24 @@
1
+ image: node:20
2
+ variables:
3
+ CI: 'true'
4
+
5
+ # Main job
6
+ <%= workflowName %>:
7
+ interruptible: true
8
+ only:
9
+ - main
10
+ - merge_requests
11
+ script:
12
+ # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
13
+ # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested
14
+ # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>"
15
+
16
+ <% if(packageManager == 'pnpm'){ %>
17
+ - npm install --prefix=$HOME/.local -g pnpm@8
18
+ <% } %>
19
+ - <%= packageManagerInstall %>
20
+ - NX_HEAD=$CI_COMMIT_SHA
21
+ - NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}
22
+
23
+ - <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
24
+ - <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
@@ -0,0 +1,38 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxWorkspaceCIWorkflow",
4
+ "title": "Generate a CI workflow.",
5
+ "description": "Generate a CI workflow.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "properties": {
9
+ "ci": {
10
+ "type": "string",
11
+ "description": "CI provider.",
12
+ "enum": ["github", "circleci", "azure", "bitbucket-pipelines", "gitlab"],
13
+ "x-prompt": {
14
+ "message": "What is your target CI provider?",
15
+ "type": "list",
16
+ "items": [
17
+ { "value": "github", "label": "GitHub Actions" },
18
+ { "value": "circleci", "label": "Circle CI" },
19
+ { "value": "azure", "label": "Azure DevOps" },
20
+ { "value": "bitbucket-pipelines", "label": "BitBucket Pipelines" },
21
+ { "value": "gitlab", "label": "Gitlab" }
22
+ ]
23
+ }
24
+ },
25
+ "name": {
26
+ "type": "string",
27
+ "description": "Workflow name.",
28
+ "$default": {
29
+ "$source": "argv",
30
+ "index": 0
31
+ },
32
+ "default": "CI",
33
+ "x-prompt": "How should we name your workflow?",
34
+ "pattern": "^[a-zA-Z].*$"
35
+ }
36
+ },
37
+ "required": ["ci", "name"]
38
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function monorepoGenerator(tree: Tree, options: {}): Promise<void>;
3
+ export default monorepoGenerator;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.monorepoGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const move_1 = require("../move/move");
6
+ async function monorepoGenerator(tree, options) {
7
+ const projects = (0, devkit_1.getProjects)(tree);
8
+ const nxJson = (0, devkit_1.readNxJson)(tree);
9
+ (0, devkit_1.updateNxJson)(tree, nxJson);
10
+ let rootProject;
11
+ const projectsToMove = [];
12
+ // Need to determine libs vs packages directory base on the type of root project.
13
+ for (const [, project] of projects) {
14
+ if (project.root === '.') {
15
+ rootProject = project;
16
+ }
17
+ else {
18
+ projectsToMove.push(project);
19
+ }
20
+ }
21
+ projectsToMove.unshift(rootProject); // move the root project 1st
22
+ // Currently, Nx only handles apps+libs or packages. You cannot mix and match them.
23
+ // If the standalone project is an app (React, Angular, etc), then use apps+libs.
24
+ // Otherwise, for TS standalone (lib), use packages.
25
+ const isRootProjectApp = rootProject.projectType === 'application';
26
+ const appsDir = isRootProjectApp ? 'apps' : 'packages';
27
+ const libsDir = isRootProjectApp ? 'libs' : 'packages';
28
+ for (const project of projectsToMove) {
29
+ await (0, move_1.moveGenerator)(tree, {
30
+ projectName: project.name,
31
+ newProjectName: project.name,
32
+ destination: project.projectType === 'application'
33
+ ? (0, devkit_1.joinPathFragments)(appsDir, project.root === '.' ? project.name : project.root)
34
+ : (0, devkit_1.joinPathFragments)(libsDir, project.root === '.' ? project.name : project.root),
35
+ updateImportPath: project.projectType === 'library',
36
+ projectNameAndRootFormat: 'as-provided',
37
+ });
38
+ }
39
+ }
40
+ exports.monorepoGenerator = monorepoGenerator;
41
+ exports.default = monorepoGenerator;
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "NxWorkspaceConvertToMonorepo",
4
+ "cli": "nx",
5
+ "title": "Nx Convert to Monorepo",
6
+ "description": "Convert an Nx project to a monorepo.",
7
+ "type": "object",
8
+ "examples": [
9
+ {
10
+ "command": "nx g @nx/workspace:monorepo",
11
+ "description": "Convert an Nx standalone project to a monorepo."
12
+ }
13
+ ],
14
+ "properties": {},
15
+ "required": []
16
+ }
@@ -0,0 +1,5 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function validateSchema(schema: Schema, configName: string): Promise<void>;
4
+ export declare function convertToNxProjectGenerator(host: Tree, schema: Schema): Promise<void>;
5
+ export default convertToNxProjectGenerator;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToNxProjectGenerator = exports.validateSchema = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const angular_json_1 = require("nx/src/adapter/angular-json");
7
+ const output_1 = require("../../utils/output");
8
+ async function validateSchema(schema, configName) {
9
+ if (schema.project && schema.all) {
10
+ throw new Error('--project and --all are mutually exclusive');
11
+ }
12
+ if (schema.project && schema.reformat) {
13
+ throw new Error('--project and --reformat are mutually exclusive');
14
+ }
15
+ if (schema.all && schema.reformat) {
16
+ throw new Error('--all and --reformat are mutually exclusive');
17
+ }
18
+ if ((configName === 'workspace.json' && schema.project) ||
19
+ (configName === 'workspace.json' && schema.reformat)) {
20
+ throw new Error('workspace.json is no longer supported. Please pass --all to convert all projects and remove workspace.json.');
21
+ }
22
+ if (!schema.project && !schema.all && !schema.reformat) {
23
+ schema.all = true;
24
+ }
25
+ }
26
+ exports.validateSchema = validateSchema;
27
+ async function convertToNxProjectGenerator(host, schema) {
28
+ const configName = host.exists('angular.json')
29
+ ? 'angular.json'
30
+ : 'workspace.json';
31
+ if (!host.exists(configName))
32
+ return;
33
+ await validateSchema(schema, configName);
34
+ const projects = (0, angular_json_1.toNewFormat)((0, devkit_1.readJson)(host, configName)).projects;
35
+ const leftOverProjects = {};
36
+ for (const projectName of Object.keys(projects)) {
37
+ const config = projects[projectName];
38
+ if ((!schema.project || schema.project === projectName) &&
39
+ !schema.reformat) {
40
+ if (typeof config === 'string') {
41
+ // configuration is in project.json
42
+ const projectConfig = (0, devkit_1.readJson)(host, (0, path_1.join)(config, 'project.json'));
43
+ if (projectConfig.name !== projectName) {
44
+ projectConfig.name = projectName;
45
+ projectConfig.root = config;
46
+ (0, devkit_1.updateProjectConfiguration)(host, projectName, projectConfig);
47
+ }
48
+ }
49
+ else {
50
+ // configuration is an object in workspace.json
51
+ const path = (0, path_1.join)(config.root, 'project.json');
52
+ if (!host.exists(path)) {
53
+ projects[projectName].name = projectName;
54
+ (0, devkit_1.addProjectConfiguration)(host, path, projects[projectName]);
55
+ }
56
+ }
57
+ }
58
+ else {
59
+ leftOverProjects[projectName] = config;
60
+ }
61
+ }
62
+ if (Object.keys(leftOverProjects).length > 0) {
63
+ (0, devkit_1.writeJson)(host, 'angular.json', (0, angular_json_1.toOldFormat)({ version: 1, projects: leftOverProjects }));
64
+ }
65
+ else {
66
+ host.delete(configName);
67
+ }
68
+ if (!schema.skipFormat) {
69
+ await (0, devkit_1.formatFiles)(host);
70
+ }
71
+ output_1.output.note({
72
+ title: 'Use "nx show projects" to read the list of projects.',
73
+ bodyLines: [
74
+ `If you read the list of projects from ${configName}, use "nx show projects" instead.`,
75
+ ],
76
+ });
77
+ }
78
+ exports.convertToNxProjectGenerator = convertToNxProjectGenerator;
79
+ exports.default = convertToNxProjectGenerator;
@@ -0,0 +1,7 @@
1
+ export interface Schema {
2
+ project?: string;
3
+ all?: boolean;
4
+
5
+ reformat?: boolean;
6
+ skipFormat?: boolean;
7
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "$id": "SchematicsConvertToNxProject",
4
+ "title": "@nx/workspace:fix-configuration",
5
+ "description": "Migrates v1 config to v2 standalone configuration.",
6
+ "type": "object",
7
+ "cli": "nx",
8
+ "examples": [
9
+ {
10
+ "command": "nx g @nx/workspace:convert-to-nx-project --project my-feature-lib",
11
+ "description": "Convert the `my-feature-lib` project to use `project.json` file instead of `workspace.json`"
12
+ },
13
+ {
14
+ "command": "nx g @nx/workspace:convert-to-nx-project --all",
15
+ "description": "Convert all projects in `workspace.json` to separate `project.json` files"
16
+ }
17
+ ],
18
+ "properties": {
19
+ "project": {
20
+ "description": "Convert a single project",
21
+ "type": "string"
22
+ },
23
+ "all": {
24
+ "description": "Convert all projects",
25
+ "type": "boolean"
26
+ },
27
+ "reformat": {
28
+ "description": "Just reformats the configuration",
29
+ "type": "boolean"
30
+ },
31
+ "skipFormat": {
32
+ "description": "Skip formatting files",
33
+ "type": "boolean",
34
+ "default": false,
35
+ "x-priority": "internal"
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,11 @@
1
+ import type { Tree } from '@nx/devkit';
2
+ import type { NormalizedSchema } from '../schema';
3
+ /**
4
+ * Checks whether the destination folder is valid
5
+ *
6
+ * - must not be outside the workspace
7
+ * - must be a new folder
8
+ *
9
+ * @param schema The options provided to the schematic
10
+ */
11
+ export declare function checkDestination(tree: Tree, schema: NormalizedSchema, providedDestination: string): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkDestination = void 0;
4
+ /**
5
+ * Checks whether the destination folder is valid
6
+ *
7
+ * - must not be outside the workspace
8
+ * - must be a new folder
9
+ *
10
+ * @param schema The options provided to the schematic
11
+ */
12
+ function checkDestination(tree, schema, providedDestination) {
13
+ const INVALID_DESTINATION = `Invalid destination: [${providedDestination}]`;
14
+ if (providedDestination.includes('..')) {
15
+ throw new Error(`${INVALID_DESTINATION} - Please specify explicit path.`);
16
+ }
17
+ if (tree.children(schema.relativeToRootDestination).length > 0) {
18
+ throw new Error(`${INVALID_DESTINATION} - Path is not empty.`);
19
+ }
20
+ }
21
+ exports.checkDestination = checkDestination;
@@ -0,0 +1,3 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ export declare function createProjectConfigurationInNewDestination(tree: Tree, schema: NormalizedSchema, projectConfig: ProjectConfiguration): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createProjectConfigurationInNewDestination = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function createProjectConfigurationInNewDestination(tree, schema, projectConfig) {
6
+ projectConfig.name = schema.newProjectName;
7
+ const isRootProject = projectConfig.root === '.';
8
+ // Subtle bug if project name === path, where the updated name was being overridden.
9
+ const { name, ...rest } = projectConfig;
10
+ // replace old root path with new one
11
+ let newProjectString = JSON.stringify(rest);
12
+ if (isRootProject) {
13
+ // Don't replace . with new root since it'll match all characters.
14
+ // Only look for "./" and replace with new root.
15
+ newProjectString = newProjectString.replace(/\.\//g, schema.relativeToRootDestination + '/');
16
+ newProjectString = newProjectString.replace(/"((tsconfig|jest|webpack|vite)\..*?\.(ts|js|json))"/g, `"${schema.relativeToRootDestination}/$1"`);
17
+ newProjectString = newProjectString.replace(/"(\.\/)?src\/(.*?)"/g, `"${schema.relativeToRootDestination}/src/$2"`);
18
+ }
19
+ else {
20
+ // There's another issue if project name === path, where the target
21
+ // string (my-app:build:production) was being replaced
22
+ // and resulting in my-destination/my-new-name:build:production
23
+ // Change anything but target strings (my-app:build:production).
24
+ // Target string are going to be updated in the updateBuildTargets function
25
+ newProjectString = newProjectString.replace(new RegExp(projectConfig.root + '(?!:)', 'g'), schema.relativeToRootDestination);
26
+ }
27
+ const newProject = {
28
+ name,
29
+ ...JSON.parse(newProjectString),
30
+ };
31
+ newProject.root = schema.relativeToRootDestination;
32
+ // Correct "e2e" target and config since part of the rename will be wrong unless we make the project name "e2e" more unique.
33
+ // e.g. my-app-e2e is safer to search and replace than "e2e".
34
+ if (projectConfig.name === 'e2e') {
35
+ for (const [targetName, targetConfig] of Object.entries(newProject.targets)) {
36
+ const wrongName = schema.relativeToRootDestination;
37
+ if (targetName !== wrongName)
38
+ continue;
39
+ if (targetConfig.options?.testingType === wrongName) {
40
+ targetConfig.options.testingType = 'e2e';
41
+ }
42
+ newProject.targets['e2e'] = targetConfig;
43
+ delete newProject.targets[targetName];
44
+ }
45
+ }
46
+ // Original sourceRoot is typically 'src' or 'app', but it could be any folder.
47
+ // Make sure it is updated to be under the new destination.
48
+ if (isRootProject && projectConfig.sourceRoot) {
49
+ newProject.sourceRoot = (0, devkit_1.joinPathFragments)(schema.relativeToRootDestination, projectConfig.sourceRoot);
50
+ }
51
+ // Create a new project with the root replaced
52
+ (0, devkit_1.addProjectConfiguration)(tree, schema.newProjectName, newProject);
53
+ }
54
+ exports.createProjectConfigurationInNewDestination = createProjectConfigurationInNewDestination;
@@ -0,0 +1,4 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ export declare function maybeExtractTsConfigBase(tree: Tree): void;
3
+ export declare function maybeExtractJestConfigBase(tree: Tree): Promise<void>;
4
+ export declare function maybeMigrateEslintConfigIfRootProject(tree: Tree, rootProject: ProjectConfiguration): void;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maybeMigrateEslintConfigIfRootProject = exports.maybeExtractJestConfigBase = exports.maybeExtractTsConfigBase = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function maybeExtractTsConfigBase(tree) {
6
+ let extractTsConfigBase;
7
+ try {
8
+ extractTsConfigBase = require('@nx/' + 'js').extractTsConfigBase;
9
+ }
10
+ catch {
11
+ // Not installed, skip
12
+ return;
13
+ }
14
+ extractTsConfigBase(tree);
15
+ }
16
+ exports.maybeExtractTsConfigBase = maybeExtractTsConfigBase;
17
+ async function maybeExtractJestConfigBase(tree) {
18
+ let jestInitGenerator;
19
+ try {
20
+ jestInitGenerator = require('@nx/' + 'jest').jestInitGenerator;
21
+ }
22
+ catch {
23
+ // Not installed, skip
24
+ return;
25
+ }
26
+ await jestInitGenerator(tree, {});
27
+ }
28
+ exports.maybeExtractJestConfigBase = maybeExtractJestConfigBase;
29
+ function maybeMigrateEslintConfigIfRootProject(tree, rootProject) {
30
+ let migrateConfigToMonorepoStyle;
31
+ try {
32
+ migrateConfigToMonorepoStyle = require('@nx/' +
33
+ 'eslint/src/generators/init/init-migration').migrateConfigToMonorepoStyle;
34
+ }
35
+ catch {
36
+ // eslint not installed
37
+ }
38
+ migrateConfigToMonorepoStyle?.(Array.from((0, devkit_1.getProjects)(tree).values()), tree, tree.exists((0, devkit_1.joinPathFragments)(rootProject.root, 'jest.config.ts')) ||
39
+ tree.exists((0, devkit_1.joinPathFragments)(rootProject.root, 'jest.config.js'))
40
+ ? 'jest'
41
+ : 'none');
42
+ }
43
+ exports.maybeMigrateEslintConfigIfRootProject = maybeMigrateEslintConfigIfRootProject;
@@ -0,0 +1,8 @@
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ /**
4
+ * Moves a project to the given destination path
5
+ *
6
+ * @param schema The options provided to the schematic
7
+ */
8
+ export declare function moveProjectFiles(tree: Tree, schema: NormalizedSchema, project: ProjectConfiguration): void;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.moveProjectFiles = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ /**
7
+ * Moves a project to the given destination path
8
+ *
9
+ * @param schema The options provided to the schematic
10
+ */
11
+ function moveProjectFiles(tree, schema, project) {
12
+ // We don't want to move configuration files and other folders that we don't know about.
13
+ // Moving the wrong files is worse than not moving them, because there might be
14
+ // a lot of work to undo it.
15
+ const knownRootProjectFiles = [
16
+ // Config files
17
+ 'project.json',
18
+ 'tsconfig.json',
19
+ 'tsconfig.app.json',
20
+ 'tsconfig.lib.json',
21
+ 'tsconfig.spec.json',
22
+ '.babelrc',
23
+ '.eslintrc.json',
24
+ 'eslint.config.js',
25
+ /^jest\.config\.((app|lib)\.)?[jt]s$/,
26
+ 'vite.config.ts',
27
+ /^webpack.*\.js$/,
28
+ 'index.html', // Vite
29
+ ];
30
+ const knownRootProjectFolders = [
31
+ 'src', // Most apps/libs
32
+ 'app', // Remix, Next.js
33
+ 'pages', // Next.js
34
+ 'public', // Vite, Remix, Next.js
35
+ ];
36
+ const isKnownRootProjectFile = (file) => {
37
+ const baseDir = (0, path_1.dirname)(file).split(path_1.sep)[0];
38
+ if (baseDir === '.') {
39
+ // Not nested, check file matches
40
+ return knownRootProjectFiles.some((stringOrRegex) => typeof stringOrRegex === 'string'
41
+ ? file === stringOrRegex
42
+ : stringOrRegex.test(file));
43
+ }
44
+ else {
45
+ // Nested, check base dir matches
46
+ return knownRootProjectFolders.includes(baseDir);
47
+ }
48
+ };
49
+ (0, devkit_1.visitNotIgnoredFiles)(tree, project.root, (file) => {
50
+ if (project.root === '.' && !isKnownRootProjectFile(file))
51
+ return;
52
+ // This is a rename but Angular Devkit isn't capable of writing to a file after it's renamed so this is a workaround
53
+ const relativeFromOriginalSource = (0, path_1.relative)(project.root, file);
54
+ const newFilePath = (0, path_1.join)(schema.relativeToRootDestination, relativeFromOriginalSource);
55
+ const content = tree.read(file);
56
+ tree.write(newFilePath, content);
57
+ tree.delete(file);
58
+ });
59
+ }
60
+ exports.moveProjectFiles = moveProjectFiles;
@@ -0,0 +1,3 @@
1
+ import { type ProjectConfiguration, type Tree } from '@nx/devkit';
2
+ import type { NormalizedSchema, Schema } from '../schema';
3
+ export declare function normalizeSchema(tree: Tree, schema: Schema, projectConfiguration: ProjectConfiguration): Promise<NormalizedSchema>;