nx 19.2.0-canary.20240605-5a06daa → 19.2.0-rc.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "19.2.0-canary.20240605-5a06daa",
3
+ "version": "19.2.0-rc.1",
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": {
@@ -70,7 +70,7 @@
70
70
  "yargs-parser": "21.1.1",
71
71
  "node-machine-id": "1.1.12",
72
72
  "ora": "5.3.0",
73
- "@nrwl/tao": "19.2.0-canary.20240605-5a06daa"
73
+ "@nrwl/tao": "19.2.0-rc.1"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "@swc-node/register": "^1.8.0",
@@ -85,16 +85,16 @@
85
85
  }
86
86
  },
87
87
  "optionalDependencies": {
88
- "@nx/nx-darwin-x64": "19.2.0-canary.20240605-5a06daa",
89
- "@nx/nx-darwin-arm64": "19.2.0-canary.20240605-5a06daa",
90
- "@nx/nx-linux-x64-gnu": "19.2.0-canary.20240605-5a06daa",
91
- "@nx/nx-linux-x64-musl": "19.2.0-canary.20240605-5a06daa",
92
- "@nx/nx-win32-x64-msvc": "19.2.0-canary.20240605-5a06daa",
93
- "@nx/nx-linux-arm64-gnu": "19.2.0-canary.20240605-5a06daa",
94
- "@nx/nx-linux-arm64-musl": "19.2.0-canary.20240605-5a06daa",
95
- "@nx/nx-linux-arm-gnueabihf": "19.2.0-canary.20240605-5a06daa",
96
- "@nx/nx-win32-arm64-msvc": "19.2.0-canary.20240605-5a06daa",
97
- "@nx/nx-freebsd-x64": "19.2.0-canary.20240605-5a06daa"
88
+ "@nx/nx-darwin-x64": "19.2.0-rc.1",
89
+ "@nx/nx-darwin-arm64": "19.2.0-rc.1",
90
+ "@nx/nx-linux-x64-gnu": "19.2.0-rc.1",
91
+ "@nx/nx-linux-x64-musl": "19.2.0-rc.1",
92
+ "@nx/nx-win32-x64-msvc": "19.2.0-rc.1",
93
+ "@nx/nx-linux-arm64-gnu": "19.2.0-rc.1",
94
+ "@nx/nx-linux-arm64-musl": "19.2.0-rc.1",
95
+ "@nx/nx-linux-arm-gnueabihf": "19.2.0-rc.1",
96
+ "@nx/nx-win32-arm64-msvc": "19.2.0-rc.1",
97
+ "@nx/nx-freebsd-x64": "19.2.0-rc.1"
98
98
  },
99
99
  "nx-migrations": {
100
100
  "migrations": "./migrations.json",
@@ -5,6 +5,7 @@ const output_1 = require("../../utils/output");
5
5
  const configuration_1 = require("../../config/configuration");
6
6
  const tree_1 = require("../../generators/tree");
7
7
  const connect_to_nx_cloud_1 = require("../../nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud");
8
+ const url_shorten_1 = require("../../nx-cloud/utilities/url-shorten");
8
9
  const nx_cloud_utils_1 = require("../../utils/nx-cloud-utils");
9
10
  const child_process_1 = require("../../utils/child-process");
10
11
  const ab_testing_1 = require("../../utils/ab-testing");
@@ -43,20 +44,38 @@ exports.connectToNxCloudIfExplicitlyAsked = connectToNxCloudIfExplicitlyAsked;
43
44
  async function connectToNxCloudCommand() {
44
45
  const nxJson = (0, configuration_1.readNxJson)();
45
46
  if ((0, nx_cloud_utils_1.isNxCloudUsed)(nxJson)) {
46
- output_1.output.log({
47
- title: '✔ This workspace already has Nx Cloud set up',
48
- bodyLines: [
49
- 'If you have not done so already, connect your workspace to your Nx Cloud account:',
50
- `- Login at ${(0, nx_cloud_utils_1.getNxCloudUrl)(nxJson)} to connect your repository`,
51
- ],
52
- });
47
+ if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') {
48
+ output_1.output.log({
49
+ title: '✔ This workspace already has Nx Cloud set up',
50
+ bodyLines: [
51
+ 'If you have not done so already, connect your workspace to your Nx Cloud account:',
52
+ `- Login at ${(0, nx_cloud_utils_1.getNxCloudUrl)(nxJson)} to connect your repository`,
53
+ ],
54
+ });
55
+ }
56
+ else {
57
+ const token = process.env.NX_CLOUD_ACCESS_TOKEN || nxJson.nxCloudAccessToken;
58
+ if (!token) {
59
+ throw new Error(`Unable to authenticate. Either define accessToken in nx.json or set the NX_CLOUD_ACCESS_TOKEN env variable.`);
60
+ }
61
+ const connectCloudUrl = await (0, url_shorten_1.shortenedCloudUrl)('nx-connect', token);
62
+ output_1.output.log({
63
+ title: '✔ This workspace already has Nx Cloud set up',
64
+ bodyLines: [
65
+ 'If you have not done so already, connect your workspace to your Nx Cloud account:',
66
+ `- Connect with Nx Cloud at:
67
+
68
+ ${connectCloudUrl}`,
69
+ ],
70
+ });
71
+ }
53
72
  return false;
54
73
  }
55
74
  const tree = new tree_1.FsTree(workspace_root_1.workspaceRoot, false, 'connect-to-nx-cloud');
56
75
  const callback = await (0, connect_to_nx_cloud_1.connectToNxCloud)(tree, {});
57
76
  tree.lock();
58
77
  (0, tree_1.flushChanges)(workspace_root_1.workspaceRoot, tree.listChanges());
59
- callback();
78
+ await callback();
60
79
  return true;
61
80
  }
62
81
  exports.connectToNxCloudCommand = connectToNxCloudCommand;
@@ -11,6 +11,7 @@ const util_1 = require("util");
11
11
  const tree_1 = require("../../generators/tree");
12
12
  const fileutils_1 = require("../../utils/fileutils");
13
13
  const logger_1 = require("../../utils/logger");
14
+ const git_utils_1 = require("../../utils/git-utils");
14
15
  const package_json_1 = require("../../utils/package-json");
15
16
  const package_manager_1 = require("../../utils/package-manager");
16
17
  const params_1 = require("../../utils/params");
@@ -925,7 +926,7 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
925
926
  installDepsIfChanged();
926
927
  const commitMessage = `${commitPrefix}${m.name}`;
927
928
  try {
928
- const committedSha = commitChanges(commitMessage);
929
+ const committedSha = (0, git_utils_1.commitChanges)(commitMessage);
929
930
  if (committedSha) {
930
931
  logger_1.logger.info(chalk.dim(`- Commit created for changes: ${committedSha}`));
931
932
  }
@@ -1007,31 +1008,6 @@ function getStringifiedPackageJsonDeps(root) {
1007
1008
  return '';
1008
1009
  }
1009
1010
  }
1010
- function commitChanges(commitMessage) {
1011
- try {
1012
- (0, child_process_1.execSync)('git add -A', { encoding: 'utf8', stdio: 'pipe' });
1013
- (0, child_process_1.execSync)('git commit --no-verify -F -', {
1014
- encoding: 'utf8',
1015
- stdio: 'pipe',
1016
- input: commitMessage,
1017
- });
1018
- }
1019
- catch (err) {
1020
- throw new Error(`Error committing changes:\n${err.stderr}`);
1021
- }
1022
- return getLatestCommitSha();
1023
- }
1024
- function getLatestCommitSha() {
1025
- try {
1026
- return (0, child_process_1.execSync)('git rev-parse HEAD', {
1027
- encoding: 'utf8',
1028
- stdio: 'pipe',
1029
- }).trim();
1030
- }
1031
- catch {
1032
- return null;
1033
- }
1034
- }
1035
1011
  async function runNxMigration(root, collectionPath, collection, name) {
1036
1012
  const { path: implPath, fnSymbol } = getImplementationPath(collection, collectionPath, name);
1037
1013
  const fn = require(implPath)[fnSymbol];
@@ -10,12 +10,14 @@ function getNativeFileCacheLocation() {
10
10
  return process.env.NX_NATIVE_FILE_CACHE_DIRECTORY;
11
11
  }
12
12
  else {
13
- const shortHash = (0, crypto_1.createHash)('sha256')
14
- .update((0, os_1.userInfo)().username)
15
- .update(workspace_root_1.workspaceRoot)
16
- .digest('hex')
17
- .substring(0, 7);
18
- return (0, path_1.join)((0, os_1.tmpdir)(), `nx-native-file-cache-${shortHash}`);
13
+ const hash = (0, crypto_1.createHash)('sha256').update(workspace_root_1.workspaceRoot);
14
+ try {
15
+ hash.update((0, os_1.userInfo)().username);
16
+ }
17
+ catch (e) {
18
+ // if there's no user, we only use the workspace root for the hash and move on
19
+ }
20
+ return (0, path_1.join)((0, os_1.tmpdir)(), `nx-native-file-cache-${hash.digest('hex').substring(0, 7)}`);
19
21
  }
20
22
  }
21
23
  exports.getNativeFileCacheLocation = getNativeFileCacheLocation;
@@ -3,6 +3,7 @@ interface ConnectToNxCloudOptions {
3
3
  analytics?: boolean;
4
4
  installationSource?: string;
5
5
  hideFormatLogs?: boolean;
6
+ github?: boolean;
6
7
  }
7
8
  export declare function connectToNxCloud(tree: Tree, schema: ConnectToNxCloudOptions): Promise<() => void>;
8
9
  export default connectToNxCloud;
@@ -7,6 +7,7 @@ const output_1 = require("../../../utils/output");
7
7
  const json_1 = require("../../../generators/utils/json");
8
8
  const nx_json_1 = require("../../../generators/utils/nx-json");
9
9
  const format_changed_files_with_prettier_if_available_1 = require("../../../generators/internal-utils/format-changed-files-with-prettier-if-available");
10
+ const url_shorten_1 = require("../../utilities/url-shorten");
10
11
  function printCloudConnectionDisabledMessage() {
11
12
  output_1.output.error({
12
13
  title: `Connections to Nx Cloud are disabled for this workspace`,
@@ -56,20 +57,36 @@ async function createNxCloudWorkspace(workspaceName, installationSource, nxInitD
56
57
  }
57
58
  return response.data;
58
59
  }
59
- function printSuccessMessage(url) {
60
- let origin = 'https://nx.app';
61
- try {
62
- origin = new node_url_1.URL(url).origin;
60
+ async function printSuccessMessage(url, token, installationSource, github) {
61
+ if (process.env.NX_NEW_CLOUD_ONBOARDING !== 'true') {
62
+ let origin = 'https://nx.app';
63
+ try {
64
+ origin = new node_url_1.URL(url).origin;
65
+ }
66
+ catch (e) { }
67
+ output_1.output.note({
68
+ title: `Your Nx Cloud workspace is public`,
69
+ bodyLines: [
70
+ `To restrict access, connect it to your Nx Cloud account:`,
71
+ `- Push your changes`,
72
+ `- Login at ${origin} to connect your repository`,
73
+ ],
74
+ });
75
+ }
76
+ else {
77
+ const connectCloudUrl = await (0, url_shorten_1.shortenedCloudUrl)(installationSource, token, github);
78
+ output_1.output.note({
79
+ title: `Your Nx Cloud workspace is ready.`,
80
+ bodyLines: [
81
+ `To claim it, connect it to your Nx Cloud account:`,
82
+ `- Commit and push your changes.`,
83
+ `- Create a pull request for the changes.`,
84
+ `- Go to the following URL to connect your workspace to Nx Cloud:
85
+
86
+ ${connectCloudUrl}`,
87
+ ],
88
+ });
63
89
  }
64
- catch (e) { }
65
- output_1.output.note({
66
- title: `Your Nx Cloud workspace is public`,
67
- bodyLines: [
68
- `To restrict access, connect it to your Nx Cloud account:`,
69
- `- Push your changes`,
70
- `- Login at ${origin} to connect your repository`,
71
- ],
72
- });
73
90
  }
74
91
  function addNxCloudOptionsToNxJson(tree, nxJson, token) {
75
92
  nxJson ??= {
@@ -97,7 +114,7 @@ async function connectToNxCloud(tree, schema) {
97
114
  await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree, {
98
115
  silent: schema.hideFormatLogs,
99
116
  });
100
- return () => printSuccessMessage(r.url);
117
+ return async () => await printSuccessMessage(r.url, r.token, schema.installationSource, schema.github);
101
118
  }
102
119
  }
103
120
  exports.connectToNxCloud = connectToNxCloud;
@@ -20,6 +20,11 @@
20
20
  "type": "boolean",
21
21
  "description": "Hide formatting logs",
22
22
  "x-priority": "internal"
23
+ },
24
+ "github": {
25
+ "type": "boolean",
26
+ "description": "If the user will be using GitHub as their git hosting provider",
27
+ "default": false
23
28
  }
24
29
  },
25
30
  "additionalProperties": false,
@@ -0,0 +1 @@
1
+ export declare function shortenedCloudUrl(installationSource: string, accessToken: string, github?: boolean): Promise<string>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shortenedCloudUrl = void 0;
4
+ const devkit_exports_1 = require("../../devkit-exports");
5
+ const git_utils_1 = require("../../utils/git-utils");
6
+ async function shortenedCloudUrl(installationSource, accessToken, github) {
7
+ const githubSlug = (0, git_utils_1.getGithubSlugOrNull)();
8
+ const apiUrl = removeTrailingSlash(process.env.NX_CLOUD_API || process.env.NRWL_API || `https://cloud.nx.app`);
9
+ const installationSupportsGitHub = await getInstallationSupportsGitHub(apiUrl);
10
+ const usesGithub = (githubSlug || github) &&
11
+ (apiUrl.includes('cloud.nx.app') ||
12
+ apiUrl.includes('eu.nx.app') ||
13
+ installationSupportsGitHub);
14
+ const source = getSource(installationSource);
15
+ try {
16
+ const response = await require('axios').post(`${apiUrl}/nx-cloud/onboarding`, {
17
+ type: usesGithub ? 'GITHUB' : 'MANUAL',
18
+ source,
19
+ accessToken: usesGithub ? null : accessToken,
20
+ selectedRepositoryName: githubSlug,
21
+ });
22
+ if (!response?.data || response.data.message) {
23
+ throw new Error(response?.data?.message ?? 'Failed to shorten Nx Cloud URL');
24
+ }
25
+ return `${apiUrl}/connect/${response.data}`;
26
+ }
27
+ catch (e) {
28
+ devkit_exports_1.logger.verbose(`Failed to shorten Nx Cloud URL.
29
+ ${e}`);
30
+ return getURLifShortenFailed(usesGithub, githubSlug, apiUrl, accessToken, source);
31
+ }
32
+ }
33
+ exports.shortenedCloudUrl = shortenedCloudUrl;
34
+ function removeTrailingSlash(apiUrl) {
35
+ return apiUrl[apiUrl.length - 1] === '/' ? apiUrl.slice(0, -1) : apiUrl;
36
+ }
37
+ function getSource(installationSource) {
38
+ if (installationSource.includes('nx-init')) {
39
+ return 'nx-init';
40
+ }
41
+ else if (installationSource.includes('nx-connect')) {
42
+ return 'nx-connect';
43
+ }
44
+ else if (installationSource.includes('create-nx-workspace')) {
45
+ return 'create-nx-workspace';
46
+ }
47
+ else {
48
+ return 'other';
49
+ }
50
+ }
51
+ function getURLifShortenFailed(usesGithub, githubSlug, apiUrl, accessToken, source) {
52
+ if (usesGithub) {
53
+ if (githubSlug) {
54
+ return `${apiUrl}/setup/connect-workspace/vcs?provider=GITHUB&selectedRepositoryName=${encodeURIComponent(githubSlug)}&source=${source}`;
55
+ }
56
+ else {
57
+ return `${apiUrl}/setup/connect-workspace/vcs?provider=GITHUB&source=${source}`;
58
+ }
59
+ }
60
+ return `${apiUrl}/setup/connect-workspace/manual?accessToken=${accessToken}&source=${source}`;
61
+ }
62
+ async function getInstallationSupportsGitHub(apiUrl) {
63
+ try {
64
+ const response = await require('axios').get(`${apiUrl}/vcs-integrations`);
65
+ if (!response?.data || response.data.message) {
66
+ throw new Error(response?.data?.message ?? 'Failed to shorten Nx Cloud URL');
67
+ }
68
+ return !!response.data.github;
69
+ }
70
+ catch (e) {
71
+ if (process.env.NX_VERBOSE_LOGGING) {
72
+ devkit_exports_1.logger.warn(`Failed to access vcs-integrations endpoint.
73
+ ${e}`);
74
+ }
75
+ return false;
76
+ }
77
+ }
@@ -9,12 +9,12 @@ import { LoadedNxPlugin } from '../plugins/internal-api';
9
9
  * @param nxJson
10
10
  */
11
11
  export declare function retrieveWorkspaceFiles(workspaceRoot: string, projectRootMap: Record<string, string>): Promise<{
12
- allWorkspaceFiles: import("../file-utils").FileData[];
12
+ allWorkspaceFiles: import("nx/src/devkit-exports").FileData[];
13
13
  fileMap: {
14
14
  projectFileMap: ProjectFiles;
15
- nonProjectFiles: import("../../native").FileData[];
15
+ nonProjectFiles: import("nx/src/native").FileData[];
16
16
  };
17
- rustReferences: import("../../native").NxWorkspaceFilesExternals;
17
+ rustReferences: import("nx/src/native").NxWorkspaceFilesExternals;
18
18
  }>;
19
19
  /**
20
20
  * Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
@@ -0,0 +1,4 @@
1
+ export declare function getGithubSlugOrNull(): string | null;
2
+ export declare function extractUserAndRepoFromGitHubUrl(gitRemotes: string): string | null;
3
+ export declare function commitChanges(commitMessage: string): string | null;
4
+ export declare function getLatestCommitSha(): string | null;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLatestCommitSha = exports.commitChanges = exports.extractUserAndRepoFromGitHubUrl = exports.getGithubSlugOrNull = void 0;
4
+ const child_process_1 = require("child_process");
5
+ function getGithubSlugOrNull() {
6
+ try {
7
+ const gitRemote = (0, child_process_1.execSync)('git remote -v').toString();
8
+ return extractUserAndRepoFromGitHubUrl(gitRemote);
9
+ }
10
+ catch (e) {
11
+ return null;
12
+ }
13
+ }
14
+ exports.getGithubSlugOrNull = getGithubSlugOrNull;
15
+ function extractUserAndRepoFromGitHubUrl(gitRemotes) {
16
+ const regex = /^\s*(\w+)\s+(git@github\.com:|https:\/\/github\.com\/)([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\.git/gm;
17
+ let firstGitHubUrl = null;
18
+ let match;
19
+ while ((match = regex.exec(gitRemotes)) !== null) {
20
+ const remoteName = match[1];
21
+ const url = match[2] + match[3] + '/' + match[4] + '.git';
22
+ if (remoteName === 'origin') {
23
+ return parseGitHubUrl(url);
24
+ }
25
+ if (!firstGitHubUrl) {
26
+ firstGitHubUrl = url;
27
+ }
28
+ }
29
+ return firstGitHubUrl ? parseGitHubUrl(firstGitHubUrl) : null;
30
+ }
31
+ exports.extractUserAndRepoFromGitHubUrl = extractUserAndRepoFromGitHubUrl;
32
+ function parseGitHubUrl(url) {
33
+ const sshPattern = /git@github\.com:([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\.git/;
34
+ const httpsPattern = /https:\/\/github\.com\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\.git/;
35
+ let match = url.match(sshPattern) || url.match(httpsPattern);
36
+ if (match) {
37
+ return `${match[1]}/${match[2]}`;
38
+ }
39
+ return null;
40
+ }
41
+ function commitChanges(commitMessage) {
42
+ try {
43
+ (0, child_process_1.execSync)('git add -A', { encoding: 'utf8', stdio: 'pipe' });
44
+ (0, child_process_1.execSync)('git commit --no-verify -F -', {
45
+ encoding: 'utf8',
46
+ stdio: 'pipe',
47
+ input: commitMessage,
48
+ });
49
+ }
50
+ catch (err) {
51
+ throw new Error(`Error committing changes:\n${err.stderr}`);
52
+ }
53
+ return getLatestCommitSha();
54
+ }
55
+ exports.commitChanges = commitChanges;
56
+ function getLatestCommitSha() {
57
+ try {
58
+ return (0, child_process_1.execSync)('git rev-parse HEAD', {
59
+ encoding: 'utf8',
60
+ stdio: 'pipe',
61
+ }).trim();
62
+ }
63
+ catch {
64
+ return null;
65
+ }
66
+ }
67
+ exports.getLatestCommitSha = getLatestCommitSha;