nx 19.6.0-canary.20240809-d3747e0 → 19.6.0-canary.20240814-6d83ae2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. package/bin/post-install.js +9 -0
  2. package/package.json +12 -12
  3. package/schemas/nx-schema.json +55 -4
  4. package/schemas/project-schema.json +7 -0
  5. package/src/adapter/compat.d.ts +1 -1
  6. package/src/adapter/compat.js +1 -0
  7. package/src/command-line/import/command-object.d.ts +2 -0
  8. package/src/command-line/import/command-object.js +38 -0
  9. package/src/command-line/import/import.d.ts +21 -0
  10. package/src/command-line/import/import.js +173 -0
  11. package/src/command-line/import/utils/merge-remote-source.d.ts +2 -0
  12. package/src/command-line/import/utils/merge-remote-source.js +14 -0
  13. package/src/command-line/import/utils/needs-install.d.ts +3 -0
  14. package/src/command-line/import/utils/needs-install.js +31 -0
  15. package/src/command-line/import/utils/prepare-source-repo.d.ts +2 -0
  16. package/src/command-line/import/utils/prepare-source-repo.js +104 -0
  17. package/src/command-line/init/init-v2.d.ts +7 -0
  18. package/src/command-line/init/init-v2.js +49 -16
  19. package/src/command-line/nx-commands.js +33 -28
  20. package/src/command-line/release/changelog.js +9 -9
  21. package/src/command-line/release/command-object.d.ts +12 -3
  22. package/src/command-line/release/command-object.js +16 -1
  23. package/src/command-line/release/config/config.js +4 -2
  24. package/src/command-line/release/config/filter-release-groups.d.ts +2 -2
  25. package/src/command-line/release/config/filter-release-groups.js +1 -1
  26. package/src/command-line/release/config/version-plans.d.ts +1 -1
  27. package/src/command-line/release/config/version-plans.js +12 -12
  28. package/src/command-line/release/plan-check.d.ts +4 -0
  29. package/src/command-line/release/plan-check.js +225 -0
  30. package/src/command-line/release/plan.js +1 -1
  31. package/src/command-line/release/release.js +3 -3
  32. package/src/command-line/release/version.js +1 -1
  33. package/src/command-line/sync/command-object.d.ts +6 -0
  34. package/src/command-line/sync/command-object.js +25 -0
  35. package/src/command-line/sync/sync.d.ts +6 -0
  36. package/src/command-line/sync/sync.js +30 -0
  37. package/src/command-line/yargs-utils/shared-options.d.ts +1 -1
  38. package/src/config/nx-json.d.ts +32 -2
  39. package/src/config/workspace-json-project-json.d.ts +5 -0
  40. package/src/core/graph/main.js +1 -1
  41. package/src/daemon/cache.d.ts +1 -0
  42. package/src/daemon/cache.js +25 -18
  43. package/src/daemon/client/client.d.ts +5 -0
  44. package/src/daemon/client/client.js +42 -1
  45. package/src/daemon/message-types/flush-sync-generator-changes-to-disk.d.ts +6 -0
  46. package/src/daemon/message-types/flush-sync-generator-changes-to-disk.js +11 -0
  47. package/src/daemon/message-types/force-shutdown.d.ts +5 -0
  48. package/src/daemon/message-types/force-shutdown.js +11 -0
  49. package/src/daemon/message-types/get-registered-sync-generators.d.ts +5 -0
  50. package/src/daemon/message-types/get-registered-sync-generators.js +11 -0
  51. package/src/daemon/message-types/get-sync-generator-changes.d.ts +6 -0
  52. package/src/daemon/message-types/get-sync-generator-changes.js +11 -0
  53. package/src/daemon/message-types/update-workspace-context.d.ts +8 -0
  54. package/src/daemon/message-types/update-workspace-context.js +11 -0
  55. package/src/daemon/server/handle-flush-sync-generator-changes-to-disk.d.ts +2 -0
  56. package/src/daemon/server/handle-flush-sync-generator-changes-to-disk.js +11 -0
  57. package/src/daemon/server/handle-force-shutdown.d.ts +5 -0
  58. package/src/daemon/server/handle-force-shutdown.js +18 -0
  59. package/src/daemon/server/handle-get-registered-sync-generators.d.ts +2 -0
  60. package/src/daemon/server/handle-get-registered-sync-generators.js +11 -0
  61. package/src/daemon/server/handle-get-sync-generator-changes.d.ts +2 -0
  62. package/src/daemon/server/handle-get-sync-generator-changes.js +17 -0
  63. package/src/daemon/server/handle-request-shutdown.js +2 -0
  64. package/src/daemon/server/handle-update-workspace-context.d.ts +2 -0
  65. package/src/daemon/server/handle-update-workspace-context.js +11 -0
  66. package/src/daemon/server/project-graph-incremental-recomputation.d.ts +1 -0
  67. package/src/daemon/server/project-graph-incremental-recomputation.js +20 -3
  68. package/src/daemon/server/server.d.ts +1 -0
  69. package/src/daemon/server/server.js +39 -0
  70. package/src/daemon/server/shutdown-utils.d.ts +2 -1
  71. package/src/daemon/server/shutdown-utils.js +11 -4
  72. package/src/daemon/server/sync-generators.d.ts +6 -0
  73. package/src/daemon/server/sync-generators.js +202 -0
  74. package/src/daemon/server/watcher.js +3 -0
  75. package/src/daemon/socket-utils.js +18 -5
  76. package/src/daemon/tmp-dir.js +2 -1
  77. package/src/native/nx.wasm32-wasi.wasm +0 -0
  78. package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +1 -1
  79. package/src/nx-cloud/models/onboarding-status.d.ts +1 -0
  80. package/src/nx-cloud/models/onboarding-status.js +2 -0
  81. package/src/nx-cloud/utilities/is-workspace-claimed.d.ts +1 -0
  82. package/src/nx-cloud/utilities/is-workspace-claimed.js +24 -0
  83. package/src/nx-cloud/utilities/onboarding.d.ts +5 -0
  84. package/src/nx-cloud/utilities/onboarding.js +28 -0
  85. package/src/project-graph/plugins/internal-api.js +16 -5
  86. package/src/project-graph/plugins/isolation/messaging.d.ts +5 -1
  87. package/src/project-graph/plugins/isolation/messaging.js +1 -0
  88. package/src/project-graph/plugins/isolation/plugin-pool.js +4 -6
  89. package/src/project-graph/plugins/isolation/plugin-worker.js +15 -0
  90. package/src/project-graph/utils/project-configuration-utils.js +5 -2
  91. package/src/tasks-runner/run-command.d.ts +1 -1
  92. package/src/tasks-runner/run-command.js +117 -2
  93. package/src/utils/command-line-utils.d.ts +1 -0
  94. package/src/utils/command-line-utils.js +6 -3
  95. package/src/utils/git-utils.d.ts +35 -0
  96. package/src/utils/git-utils.js +111 -0
  97. package/src/utils/package-manager.js +1 -1
  98. package/src/utils/plugins/output.js +1 -1
  99. package/src/utils/squash.d.ts +1 -0
  100. package/src/utils/squash.js +12 -0
  101. package/src/utils/sync-generators.d.ts +22 -0
  102. package/src/utils/sync-generators.js +161 -0
  103. package/src/utils/workspace-context.d.ts +2 -1
  104. package/src/utils/workspace-context.js +18 -1
  105. package/src/daemon/message-types/update-context-files.d.ts +0 -7
  106. package/src/daemon/message-types/update-context-files.js +0 -11
@@ -28,6 +28,7 @@ const logger_1 = require("../src/utils/logger");
28
28
  if ((0, nx_cloud_utils_1.isNxCloudUsed)((0, nx_json_1.readNxJson)())) {
29
29
  tasks.push((0, update_manager_1.verifyOrUpdateNxCloudClient)((0, get_cloud_options_1.getCloudOptions)()));
30
30
  }
31
+ process.env.NX_DAEMON = 'false';
31
32
  await Promise.all(tasks.map((promise) => {
32
33
  return promise.catch((e) => {
33
34
  if (process.env.NX_VERBOSE_LOGGING === 'true') {
@@ -53,3 +54,11 @@ function isMainNxPackage() {
53
54
  const thisNxPath = require.resolve('nx');
54
55
  return mainNxPath === thisNxPath;
55
56
  }
57
+ process.on('uncaughtException', (e) => {
58
+ logger_1.logger.verbose(e);
59
+ process.exit(0);
60
+ });
61
+ process.on('unhandledRejection', (e) => {
62
+ logger_1.logger.verbose(e);
63
+ process.exit(0);
64
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "19.6.0-canary.20240809-d3747e0",
3
+ "version": "19.6.0-canary.20240814-6d83ae2",
4
4
  "private": false,
5
5
  "description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
6
6
  "repository": {
@@ -71,7 +71,7 @@
71
71
  "yargs-parser": "21.1.1",
72
72
  "node-machine-id": "1.1.12",
73
73
  "ora": "5.3.0",
74
- "@nrwl/tao": "19.6.0-canary.20240809-d3747e0"
74
+ "@nrwl/tao": "19.6.0-canary.20240814-6d83ae2"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@swc-node/register": "^1.8.0",
@@ -86,16 +86,16 @@
86
86
  }
87
87
  },
88
88
  "optionalDependencies": {
89
- "@nx/nx-darwin-x64": "19.6.0-canary.20240809-d3747e0",
90
- "@nx/nx-darwin-arm64": "19.6.0-canary.20240809-d3747e0",
91
- "@nx/nx-linux-x64-gnu": "19.6.0-canary.20240809-d3747e0",
92
- "@nx/nx-linux-x64-musl": "19.6.0-canary.20240809-d3747e0",
93
- "@nx/nx-win32-x64-msvc": "19.6.0-canary.20240809-d3747e0",
94
- "@nx/nx-linux-arm64-gnu": "19.6.0-canary.20240809-d3747e0",
95
- "@nx/nx-linux-arm64-musl": "19.6.0-canary.20240809-d3747e0",
96
- "@nx/nx-linux-arm-gnueabihf": "19.6.0-canary.20240809-d3747e0",
97
- "@nx/nx-win32-arm64-msvc": "19.6.0-canary.20240809-d3747e0",
98
- "@nx/nx-freebsd-x64": "19.6.0-canary.20240809-d3747e0"
89
+ "@nx/nx-darwin-x64": "19.6.0-canary.20240814-6d83ae2",
90
+ "@nx/nx-darwin-arm64": "19.6.0-canary.20240814-6d83ae2",
91
+ "@nx/nx-linux-x64-gnu": "19.6.0-canary.20240814-6d83ae2",
92
+ "@nx/nx-linux-x64-musl": "19.6.0-canary.20240814-6d83ae2",
93
+ "@nx/nx-win32-x64-msvc": "19.6.0-canary.20240814-6d83ae2",
94
+ "@nx/nx-linux-arm64-gnu": "19.6.0-canary.20240814-6d83ae2",
95
+ "@nx/nx-linux-arm64-musl": "19.6.0-canary.20240814-6d83ae2",
96
+ "@nx/nx-linux-arm-gnueabihf": "19.6.0-canary.20240814-6d83ae2",
97
+ "@nx/nx-win32-arm64-msvc": "19.6.0-canary.20240814-6d83ae2",
98
+ "@nx/nx-freebsd-x64": "19.6.0-canary.20240814-6d83ae2"
99
99
  },
100
100
  "nx-migrations": {
101
101
  "migrations": "./migrations.json",
@@ -186,8 +186,15 @@
186
186
  "type": "string"
187
187
  },
188
188
  "versionPlans": {
189
- "type": "boolean",
190
- "description": "Enables using version plans as a specifier source for versioning and to determine changes for changelog generation."
189
+ "oneOf": [
190
+ {
191
+ "$ref": "#/definitions/NxReleaseVersionPlansConfiguration"
192
+ },
193
+ {
194
+ "type": "boolean",
195
+ "description": "Enables using version plans as a specifier source for versioning and to determine changes for changelog generation."
196
+ }
197
+ ]
191
198
  }
192
199
  },
193
200
  "required": ["projects"]
@@ -239,13 +246,45 @@
239
246
  "$ref": "#/definitions/NxReleaseVersionConfiguration"
240
247
  },
241
248
  "versionPlans": {
242
- "type": "boolean",
243
- "description": "Enables using version plans as a specifier source for versioning and to determine changes for changelog generation."
249
+ "oneOf": [
250
+ {
251
+ "$ref": "#/definitions/NxReleaseVersionPlansConfiguration"
252
+ },
253
+ {
254
+ "type": "boolean",
255
+ "description": "Enables using version plans as a specifier source for versioning and to determine changes for changelog generation."
256
+ }
257
+ ]
244
258
  },
245
259
  "releaseTagPattern": {
246
260
  "type": "string"
247
261
  }
248
262
  }
263
+ },
264
+ "sync": {
265
+ "type": "object",
266
+ "description": "Configuration for the `nx sync` command",
267
+ "properties": {
268
+ "globalGenerators": {
269
+ "type": "array",
270
+ "items": {
271
+ "type": "string"
272
+ },
273
+ "description": "List of workspace-wide sync generators to be run (not attached to targets)"
274
+ },
275
+ "generatorOptions": {
276
+ "type": "object",
277
+ "description": "Options for the sync generators.",
278
+ "additionalProperties": {
279
+ "type": "object"
280
+ }
281
+ },
282
+ "applyChanges": {
283
+ "type": "boolean",
284
+ "description": "Whether to automatically apply sync generator changes when running tasks. If not set, the user will be prompted. If set to `true`, the user will not be prompted and the changes will be applied. If set to `false`, the user will not be prompted and the changes will not be applied."
285
+ }
286
+ },
287
+ "additionalProperties": false
249
288
  }
250
289
  },
251
290
  "definitions": {
@@ -673,6 +712,18 @@
673
712
  }
674
713
  }
675
714
  },
715
+ "NxReleaseVersionPlansConfiguration": {
716
+ "type": "object",
717
+ "properties": {
718
+ "ignorePatternsForPlanCheck": {
719
+ "type": "array",
720
+ "items": {
721
+ "type": "string"
722
+ },
723
+ "description": "Changes to files matching any of these optional patterns will be excluded from the affected project logic within the `nx release plan:check` command. This is useful for ignoring files that are not relevant to the versioning process, such as documentation or configuration files."
724
+ }
725
+ }
726
+ },
676
727
  "ChangelogRenderOptions": {
677
728
  "type": "object",
678
729
  "additionalProperties": true
@@ -153,6 +153,13 @@
153
153
  }
154
154
  },
155
155
  "additionalProperties": true
156
+ },
157
+ "syncGenerators": {
158
+ "type": "array",
159
+ "items": {
160
+ "type": "string"
161
+ },
162
+ "description": "List of generators to run before the target to ensure the workspace is up to date"
156
163
  }
157
164
  }
158
165
  }
@@ -1,2 +1,2 @@
1
1
  export declare const allowedProjectExtensions: readonly ["tags", "implicitDependencies", "configFilePath", "$schema", "generators", "namedInputs", "name", "files", "root", "sourceRoot", "projectType", "release", "includedScripts", "metadata"];
2
- export declare const allowedWorkspaceExtensions: readonly ["implicitDependencies", "affected", "defaultBase", "tasksRunnerOptions", "workspaceLayout", "plugins", "targetDefaults", "files", "generators", "namedInputs", "extends", "cli", "pluginsConfig", "defaultProject", "installation", "release", "nxCloudAccessToken", "nxCloudId", "nxCloudUrl", "nxCloudEncryptionKey", "parallel", "cacheDirectory", "useDaemonProcess", "useInferencePlugins", "neverConnectToCloud"];
2
+ export declare const allowedWorkspaceExtensions: readonly ["implicitDependencies", "affected", "defaultBase", "tasksRunnerOptions", "workspaceLayout", "plugins", "targetDefaults", "files", "generators", "namedInputs", "extends", "cli", "pluginsConfig", "defaultProject", "installation", "release", "nxCloudAccessToken", "nxCloudId", "nxCloudUrl", "nxCloudEncryptionKey", "parallel", "cacheDirectory", "useDaemonProcess", "useInferencePlugins", "neverConnectToCloud", "sync"];
@@ -62,6 +62,7 @@ exports.allowedWorkspaceExtensions = [
62
62
  'useDaemonProcess',
63
63
  'useInferencePlugins',
64
64
  'neverConnectToCloud',
65
+ 'sync',
65
66
  ];
66
67
  if (!patched) {
67
68
  Module.prototype.require = function () {
@@ -0,0 +1,2 @@
1
+ import { CommandModule } from 'yargs';
2
+ export declare const yargsImportCommand: CommandModule;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.yargsImportCommand = void 0;
4
+ const documentation_1 = require("../yargs-utils/documentation");
5
+ const shared_options_1 = require("../yargs-utils/shared-options");
6
+ const params_1 = require("../../utils/params");
7
+ exports.yargsImportCommand = {
8
+ command: 'import [sourceRemoteUrl] [destination]',
9
+ describe: false,
10
+ builder: (yargs) => (0, documentation_1.linkToNxDevAndExamples)((0, shared_options_1.withVerbose)(yargs
11
+ .positional('sourceRemoteUrl', {
12
+ type: 'string',
13
+ description: 'The remote URL of the source to import',
14
+ })
15
+ .positional('destination', {
16
+ type: 'string',
17
+ description: 'The directory in the current workspace to import into',
18
+ })
19
+ .option('source', {
20
+ type: 'string',
21
+ description: 'The directory in the source repository to import from',
22
+ })
23
+ .option('ref', {
24
+ type: 'string',
25
+ description: 'The branch from the source repository to import',
26
+ })
27
+ .option('interactive', {
28
+ type: 'boolean',
29
+ description: 'Interactive mode',
30
+ default: true,
31
+ })), 'import'),
32
+ handler: async (args) => {
33
+ const exitCode = await (0, params_1.handleErrors)(args.verbose ?? process.env.NX_VERBOSE_LOGGING === 'true', async () => {
34
+ return (await Promise.resolve().then(() => require('./import'))).importHandler(args);
35
+ });
36
+ process.exit(exitCode);
37
+ },
38
+ };
@@ -0,0 +1,21 @@
1
+ export interface ImportOptions {
2
+ /**
3
+ * The remote URL of the repository to import
4
+ */
5
+ sourceRemoteUrl: string;
6
+ /**
7
+ * The branch or reference to import
8
+ */
9
+ ref: string;
10
+ /**
11
+ * The directory in the source repo to import
12
+ */
13
+ source: string;
14
+ /**
15
+ * The directory in the destination repo to import into
16
+ */
17
+ destination: string;
18
+ verbose: boolean;
19
+ interactive: boolean;
20
+ }
21
+ export declare function importHandler(options: ImportOptions): Promise<void>;
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.importHandler = importHandler;
4
+ const path_1 = require("path");
5
+ const git_utils_1 = require("../../utils/git-utils");
6
+ const promises_1 = require("node:fs/promises");
7
+ const tmp_1 = require("tmp");
8
+ const enquirer_1 = require("enquirer");
9
+ const output_1 = require("../../utils/output");
10
+ const createSpinner = require("ora");
11
+ const init_v2_1 = require("../init/init-v2");
12
+ const nx_json_1 = require("../../config/nx-json");
13
+ const workspace_root_1 = require("../../utils/workspace-root");
14
+ const package_manager_1 = require("../../utils/package-manager");
15
+ const workspace_context_1 = require("../../utils/workspace-context");
16
+ const utils_1 = require("../init/implementation/utils");
17
+ const command_line_utils_1 = require("../../utils/command-line-utils");
18
+ const prepare_source_repo_1 = require("./utils/prepare-source-repo");
19
+ const merge_remote_source_1 = require("./utils/merge-remote-source");
20
+ const needs_install_1 = require("./utils/needs-install");
21
+ const importRemoteName = '__tmp_nx_import__';
22
+ async function importHandler(options) {
23
+ let { sourceRemoteUrl, ref, source, destination } = options;
24
+ output_1.output.log({
25
+ title: 'Nx will walk you through the process of importing code from another repository into this workspace:',
26
+ bodyLines: [
27
+ `1. Nx will clone the other repository into a temporary directory`,
28
+ `2. Code to be imported will be moved to the same directory it will be imported into on a temporary branch`,
29
+ `3. The code will be merged into the current branch in this workspace`,
30
+ `4. Nx will recommend plugins to integrate tools used in the imported code with Nx`,
31
+ `5. The code will be successfully imported into this workspace`,
32
+ '',
33
+ `Git history will be preserved during this process`,
34
+ ],
35
+ });
36
+ const tempImportDirectory = (0, path_1.join)(tmp_1.tmpdir, 'nx-import');
37
+ if (!sourceRemoteUrl) {
38
+ sourceRemoteUrl = (await (0, enquirer_1.prompt)([
39
+ {
40
+ type: 'input',
41
+ name: 'sourceRemoteUrl',
42
+ message: 'What is the URL of the repository you want to import? (This can be a local git repository or a git remote URL)',
43
+ required: true,
44
+ },
45
+ ])).sourceRemoteUrl;
46
+ }
47
+ try {
48
+ const maybeLocalDirectory = await (0, promises_1.stat)(sourceRemoteUrl);
49
+ if (maybeLocalDirectory.isDirectory()) {
50
+ sourceRemoteUrl = (0, path_1.resolve)(sourceRemoteUrl);
51
+ }
52
+ }
53
+ catch (e) {
54
+ // It's a remote url
55
+ }
56
+ const sourceRepoPath = (0, path_1.join)(tempImportDirectory, 'repo');
57
+ const spinner = createSpinner(`Cloning ${sourceRemoteUrl} into a temporary directory: ${sourceRepoPath}`).start();
58
+ try {
59
+ await (0, promises_1.rm)(tempImportDirectory, { recursive: true });
60
+ }
61
+ catch { }
62
+ await (0, promises_1.mkdir)(tempImportDirectory, { recursive: true });
63
+ let sourceGitClient;
64
+ try {
65
+ sourceGitClient = await (0, git_utils_1.cloneFromUpstream)(sourceRemoteUrl, sourceRepoPath, {
66
+ originName: importRemoteName,
67
+ });
68
+ }
69
+ catch (e) {
70
+ spinner.fail(`Failed to clone ${sourceRemoteUrl} into ${sourceRepoPath}`);
71
+ let errorMessage = `Failed to clone ${sourceRemoteUrl} into ${sourceRepoPath}. Please double check the remote and try again.\n${e.message}`;
72
+ throw new Error(errorMessage);
73
+ }
74
+ spinner.succeed(`Cloned into ${sourceRepoPath}`);
75
+ if (!ref) {
76
+ const branchChoices = await sourceGitClient.listBranches();
77
+ ref = (await (0, enquirer_1.prompt)([
78
+ {
79
+ type: 'autocomplete',
80
+ name: 'ref',
81
+ message: `Which branch do you want to import?`,
82
+ choices: branchChoices,
83
+ /**
84
+ * Limit the number of choices so that it fits on screen
85
+ */
86
+ limit: process.stdout.rows - 3,
87
+ required: true,
88
+ },
89
+ ])).ref;
90
+ }
91
+ if (!source) {
92
+ source = (await (0, enquirer_1.prompt)([
93
+ {
94
+ type: 'input',
95
+ name: 'source',
96
+ message: `Which directory do you want to import into this workspace? (leave blank to import the entire repository)`,
97
+ },
98
+ ])).source;
99
+ }
100
+ if (!destination) {
101
+ destination = (await (0, enquirer_1.prompt)([
102
+ {
103
+ type: 'input',
104
+ name: 'destination',
105
+ message: 'Where in this workspace should the code be imported into?',
106
+ required: true,
107
+ },
108
+ ])).destination;
109
+ }
110
+ const absSource = (0, path_1.join)(sourceRepoPath, source);
111
+ const absDestination = (0, path_1.join)(process.cwd(), destination);
112
+ try {
113
+ await (0, promises_1.stat)(absSource);
114
+ }
115
+ catch (e) {
116
+ throw new Error(`The source directory ${source} does not exist in ${sourceRemoteUrl}. Please double check to make sure it exists.`);
117
+ }
118
+ const destinationGitClient = new git_utils_1.GitRepository(process.cwd());
119
+ await assertDestinationEmpty(destinationGitClient, absDestination);
120
+ const tempImportBranch = getTempImportBranch(ref);
121
+ const packageManager = (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot);
122
+ const originalPackageWorkspaces = await (0, needs_install_1.getPackagesInPackageManagerWorkspace)(packageManager);
123
+ const relativeDestination = (0, path_1.relative)(destinationGitClient.root, absDestination);
124
+ await (0, prepare_source_repo_1.prepareSourceRepo)(sourceGitClient, ref, source, relativeDestination, tempImportBranch, sourceRemoteUrl, importRemoteName);
125
+ await createTemporaryRemote(destinationGitClient, (0, path_1.join)(sourceRepoPath, '.git'), importRemoteName);
126
+ await (0, merge_remote_source_1.mergeRemoteSource)(destinationGitClient, sourceRemoteUrl, tempImportBranch, destination, importRemoteName, ref);
127
+ spinner.start('Cleaning up temporary files and remotes');
128
+ await (0, promises_1.rm)(tempImportDirectory, { recursive: true });
129
+ await destinationGitClient.deleteGitRemote(importRemoteName);
130
+ spinner.succeed('Cleaned up temporary files and remotes');
131
+ const pmc = (0, package_manager_1.getPackageManagerCommand)();
132
+ const nxJson = (0, nx_json_1.readNxJson)(workspace_root_1.workspaceRoot);
133
+ (0, workspace_context_1.resetWorkspaceContext)();
134
+ const { plugins, updatePackageScripts } = await (0, init_v2_1.detectPlugins)(nxJson, options.interactive);
135
+ if (plugins.length > 0) {
136
+ output_1.output.log({ title: 'Installing Plugins' });
137
+ (0, init_v2_1.installPlugins)(workspace_root_1.workspaceRoot, plugins, pmc, updatePackageScripts);
138
+ await destinationGitClient.amendCommit();
139
+ }
140
+ else if (await (0, needs_install_1.needsInstall)(packageManager, originalPackageWorkspaces)) {
141
+ output_1.output.log({
142
+ title: 'Installing dependencies for imported code',
143
+ });
144
+ (0, utils_1.runInstall)(workspace_root_1.workspaceRoot, (0, package_manager_1.getPackageManagerCommand)(packageManager));
145
+ await destinationGitClient.amendCommit();
146
+ }
147
+ console.log(await destinationGitClient.showStat());
148
+ output_1.output.log({
149
+ title: `Merging these changes into ${(0, command_line_utils_1.getBaseRef)(nxJson)}`,
150
+ bodyLines: [
151
+ `MERGE these changes when merging these changes.`,
152
+ `Do NOT squash and do NOT rebase these changes when merging these changes.`,
153
+ `If you would like to UNDO these changes, run "git reset HEAD~1 --hard"`,
154
+ ],
155
+ });
156
+ }
157
+ async function assertDestinationEmpty(gitClient, absDestination) {
158
+ const files = await gitClient.getGitFiles(absDestination);
159
+ if (files.length > 0) {
160
+ throw new Error(`Destination directory ${absDestination} is not empty. Please make sure it is empty before importing into it.`);
161
+ }
162
+ }
163
+ function getTempImportBranch(sourceBranch) {
164
+ return `__nx_tmp_import__/${sourceBranch}`;
165
+ }
166
+ async function createTemporaryRemote(destinationGitClient, sourceRemoteUrl, remoteName) {
167
+ try {
168
+ await destinationGitClient.deleteGitRemote(remoteName);
169
+ }
170
+ catch { }
171
+ await destinationGitClient.addGitRemote(remoteName, sourceRemoteUrl);
172
+ await destinationGitClient.fetch(remoteName);
173
+ }
@@ -0,0 +1,2 @@
1
+ import { GitRepository } from '../../../utils/git-utils';
2
+ export declare function mergeRemoteSource(destinationGitClient: GitRepository, sourceRemoteUrl: string, tempBranch: string, destination: string, remoteName: string, branchName: string): Promise<void>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeRemoteSource = mergeRemoteSource;
4
+ const createSpinner = require("ora");
5
+ async function mergeRemoteSource(destinationGitClient, sourceRemoteUrl, tempBranch, destination, remoteName, branchName) {
6
+ const spinner = createSpinner();
7
+ spinner.start(`Merging ${branchName} from ${sourceRemoteUrl} into ${destination}`);
8
+ spinner.start(`Fetching ${tempBranch} from ${remoteName}`);
9
+ await destinationGitClient.fetch(remoteName, tempBranch);
10
+ spinner.succeed(`Fetched ${tempBranch} from ${remoteName}`);
11
+ spinner.start(`Merging files and git history from ${branchName} from ${sourceRemoteUrl} into ${destination}`);
12
+ await destinationGitClient.mergeUnrelatedHistories(`${remoteName}/${tempBranch}`, `feat(repo): merge ${branchName} from ${sourceRemoteUrl}`);
13
+ spinner.succeed(`Merged files and git history from ${branchName} from ${sourceRemoteUrl} into ${destination}`);
14
+ }
@@ -0,0 +1,3 @@
1
+ import { PackageManager } from '../../../utils/package-manager';
2
+ export declare function getPackagesInPackageManagerWorkspace(packageManager: PackageManager): Promise<Set<string>>;
3
+ export declare function needsInstall(packageManager: PackageManager, originalPackagesInPackageManagerWorkspaces: Set<string>): Promise<boolean>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackagesInPackageManagerWorkspace = getPackagesInPackageManagerWorkspace;
4
+ exports.needsInstall = needsInstall;
5
+ const package_manager_1 = require("../../../utils/package-manager");
6
+ const workspace_root_1 = require("../../../utils/workspace-root");
7
+ const package_json_1 = require("../../../plugins/package-json");
8
+ const workspace_context_1 = require("../../../utils/workspace-context");
9
+ async function getPackagesInPackageManagerWorkspace(packageManager) {
10
+ if (!(0, package_manager_1.isWorkspacesEnabled)(packageManager, workspace_root_1.workspaceRoot)) {
11
+ return new Set();
12
+ }
13
+ const patterns = (0, package_json_1.getGlobPatternsFromPackageManagerWorkspaces)(workspace_root_1.workspaceRoot);
14
+ return new Set(await (0, workspace_context_1.globWithWorkspaceContext)(workspace_root_1.workspaceRoot, patterns));
15
+ }
16
+ async function needsInstall(packageManager, originalPackagesInPackageManagerWorkspaces) {
17
+ if (!(0, package_manager_1.isWorkspacesEnabled)(packageManager, workspace_root_1.workspaceRoot)) {
18
+ return false;
19
+ }
20
+ const updatedPackagesInPackageManagerWorkspaces = await getPackagesInPackageManagerWorkspace(packageManager);
21
+ if (updatedPackagesInPackageManagerWorkspaces.size !==
22
+ originalPackagesInPackageManagerWorkspaces.size) {
23
+ return true;
24
+ }
25
+ for (const pkg of updatedPackagesInPackageManagerWorkspaces) {
26
+ if (!originalPackagesInPackageManagerWorkspaces.has(pkg)) {
27
+ return true;
28
+ }
29
+ }
30
+ return false;
31
+ }
@@ -0,0 +1,2 @@
1
+ import { GitRepository } from '../../../utils/git-utils';
2
+ export declare function prepareSourceRepo(gitClient: GitRepository, ref: string, source: string, relativeDestination: string, tempImportBranch: string, sourceRemoteUrl: string, originName: string): Promise<void>;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareSourceRepo = prepareSourceRepo;
4
+ const createSpinner = require("ora");
5
+ const path_1 = require("path");
6
+ const promises_1 = require("node:fs/promises");
7
+ async function prepareSourceRepo(gitClient, ref, source, relativeDestination, tempImportBranch, sourceRemoteUrl, originName) {
8
+ const spinner = createSpinner().start(`Fetching ${ref} from ${sourceRemoteUrl}`);
9
+ await gitClient.addFetchRemote(originName, ref);
10
+ await gitClient.fetch(originName, ref);
11
+ spinner.succeed(`Fetched ${ref} from ${sourceRemoteUrl}`);
12
+ spinner.start(`Checking out a temporary branch, ${tempImportBranch} based on ${ref}`);
13
+ await gitClient.checkout(tempImportBranch, {
14
+ new: true,
15
+ base: `${originName}/${ref}`,
16
+ });
17
+ spinner.succeed(`Created a ${tempImportBranch} branch based on ${ref}`);
18
+ const relativeSourceDir = (0, path_1.relative)(gitClient.root, (0, path_1.join)(gitClient.root, source));
19
+ const destinationInSource = (0, path_1.join)(gitClient.root, relativeDestination);
20
+ spinner.start(`Moving files and git history to ${destinationInSource}`);
21
+ if (relativeSourceDir === '') {
22
+ const files = await gitClient.getGitFiles('.');
23
+ try {
24
+ await (0, promises_1.rm)(destinationInSource, {
25
+ recursive: true,
26
+ });
27
+ }
28
+ catch { }
29
+ await (0, promises_1.mkdir)(destinationInSource, { recursive: true });
30
+ const gitignores = new Set();
31
+ for (const file of files) {
32
+ if ((0, path_1.basename)(file) === '.gitignore') {
33
+ gitignores.add(file);
34
+ continue;
35
+ }
36
+ spinner.start(`Moving files and git history to ${destinationInSource}: ${file}`);
37
+ const newPath = (0, path_1.join)(destinationInSource, file);
38
+ await (0, promises_1.mkdir)((0, path_1.dirname)(newPath), { recursive: true });
39
+ try {
40
+ await gitClient.move(file, newPath);
41
+ }
42
+ catch {
43
+ await wait(100);
44
+ await gitClient.move(file, newPath);
45
+ }
46
+ }
47
+ await gitClient.commit(`chore(repo): move ${source} to ${relativeDestination} to prepare to be imported`);
48
+ for (const gitignore of gitignores) {
49
+ await gitClient.move(gitignore, (0, path_1.join)(destinationInSource, gitignore));
50
+ }
51
+ await gitClient.amendCommit();
52
+ for (const gitignore of gitignores) {
53
+ await (0, promises_1.copyFile)((0, path_1.join)(destinationInSource, gitignore), (0, path_1.join)(gitClient.root, gitignore));
54
+ }
55
+ }
56
+ else {
57
+ let needsSquash = false;
58
+ const needsMove = destinationInSource !== (0, path_1.join)(gitClient.root, source);
59
+ if (needsMove) {
60
+ try {
61
+ await (0, promises_1.rm)(destinationInSource, {
62
+ recursive: true,
63
+ });
64
+ await gitClient.commit('chore(repo): prepare for import');
65
+ needsSquash = true;
66
+ }
67
+ catch { }
68
+ await (0, promises_1.mkdir)(destinationInSource, { recursive: true });
69
+ }
70
+ const files = await gitClient.getGitFiles('.');
71
+ for (const file of files) {
72
+ if (file === '.gitignore') {
73
+ continue;
74
+ }
75
+ spinner.start(`Moving files and git history to ${destinationInSource}: ${file}`);
76
+ if (!(0, path_1.relative)(source, file).startsWith('..')) {
77
+ if (needsMove) {
78
+ const newPath = (0, path_1.join)(destinationInSource, file);
79
+ await (0, promises_1.mkdir)((0, path_1.dirname)(newPath), { recursive: true });
80
+ try {
81
+ await gitClient.move(file, newPath);
82
+ }
83
+ catch {
84
+ await wait(100);
85
+ await gitClient.move(file, newPath);
86
+ }
87
+ }
88
+ }
89
+ else {
90
+ await (0, promises_1.rm)((0, path_1.join)(gitClient.root, file), {
91
+ recursive: true,
92
+ });
93
+ }
94
+ }
95
+ await gitClient.commit('chore(repo): prepare for import 2');
96
+ if (needsSquash) {
97
+ await gitClient.squashLastTwoCommits();
98
+ }
99
+ }
100
+ spinner.succeed(`${sourceRemoteUrl} has been prepared to be imported into this workspace on a temporary branch: ${tempImportBranch} in ${gitClient.root}`);
101
+ }
102
+ function wait(ms) {
103
+ return new Promise((resolve) => setTimeout(resolve, ms));
104
+ }
@@ -1,7 +1,14 @@
1
+ import { PackageManagerCommands } from '../../utils/package-manager';
2
+ import { NxJsonConfiguration } from '../../config/nx-json';
1
3
  export interface InitArgs {
2
4
  interactive: boolean;
3
5
  nxCloud?: boolean;
4
6
  useDotNxInstallation?: boolean;
5
7
  integrated?: boolean;
6
8
  }
9
+ export declare function installPlugins(repoRoot: string, plugins: string[], pmc: PackageManagerCommands, updatePackageScripts: boolean): void;
7
10
  export declare function initHandler(options: InitArgs): Promise<void>;
11
+ export declare function detectPlugins(nxJson: NxJsonConfiguration, interactive: boolean): Promise<{
12
+ plugins: string[];
13
+ updatePackageScripts: boolean;
14
+ }>;