nx 19.4.0-rc.0 → 19.4.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "19.4.0-rc.0",
3
+ "version": "19.4.0",
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.4.0-rc.0"
73
+ "@nrwl/tao": "19.4.0"
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.4.0-rc.0",
89
- "@nx/nx-darwin-arm64": "19.4.0-rc.0",
90
- "@nx/nx-linux-x64-gnu": "19.4.0-rc.0",
91
- "@nx/nx-linux-x64-musl": "19.4.0-rc.0",
92
- "@nx/nx-win32-x64-msvc": "19.4.0-rc.0",
93
- "@nx/nx-linux-arm64-gnu": "19.4.0-rc.0",
94
- "@nx/nx-linux-arm64-musl": "19.4.0-rc.0",
95
- "@nx/nx-linux-arm-gnueabihf": "19.4.0-rc.0",
96
- "@nx/nx-win32-arm64-msvc": "19.4.0-rc.0",
97
- "@nx/nx-freebsd-x64": "19.4.0-rc.0"
88
+ "@nx/nx-darwin-x64": "19.4.0",
89
+ "@nx/nx-darwin-arm64": "19.4.0",
90
+ "@nx/nx-linux-x64-gnu": "19.4.0",
91
+ "@nx/nx-linux-x64-musl": "19.4.0",
92
+ "@nx/nx-win32-x64-msvc": "19.4.0",
93
+ "@nx/nx-linux-arm64-gnu": "19.4.0",
94
+ "@nx/nx-linux-arm64-musl": "19.4.0",
95
+ "@nx/nx-linux-arm-gnueabihf": "19.4.0",
96
+ "@nx/nx-win32-arm64-msvc": "19.4.0",
97
+ "@nx/nx-freebsd-x64": "19.4.0"
98
98
  },
99
99
  "nx-migrations": {
100
100
  "migrations": "./migrations.json",
@@ -1,2 +1,8 @@
1
1
  export declare function shortenedCloudUrl(installationSource: string, accessToken?: string, usesGithub?: boolean): Promise<string>;
2
2
  export declare function repoUsesGithub(github?: boolean): Promise<boolean>;
3
+ export declare function removeTrailingSlash(apiUrl: string): string;
4
+ export declare function getURLifShortenFailed(usesGithub: boolean, githubSlug: string, apiUrl: string, source: string, accessToken?: string): string;
5
+ export declare function getNxCloudVersion(apiUrl: string): Promise<string | null>;
6
+ export declare function removeVersionModifier(versionString: string): string;
7
+ export declare function versionIsValid(version: string): boolean;
8
+ export declare function compareCleanCloudVersions(version1: string, version2: string): number;
@@ -1,14 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.repoUsesGithub = exports.shortenedCloudUrl = void 0;
3
+ exports.compareCleanCloudVersions = exports.versionIsValid = exports.removeVersionModifier = exports.getNxCloudVersion = exports.getURLifShortenFailed = exports.removeTrailingSlash = exports.repoUsesGithub = exports.shortenedCloudUrl = void 0;
4
4
  const devkit_exports_1 = require("../../devkit-exports");
5
5
  const git_utils_1 = require("../../utils/git-utils");
6
- const semver_1 = require("semver");
7
6
  async function shortenedCloudUrl(installationSource, accessToken, usesGithub) {
8
7
  const githubSlug = (0, git_utils_1.getGithubSlugOrNull)();
9
8
  const apiUrl = removeTrailingSlash(process.env.NX_CLOUD_API || process.env.NRWL_API || `https://cloud.nx.app`);
10
- const version = await getNxCloudVersion(apiUrl);
11
- if (version && (0, semver_1.lt)(removeVersionModifier(version), '2406.11.5')) {
9
+ try {
10
+ const version = await getNxCloudVersion(apiUrl);
11
+ if ((version && compareCleanCloudVersions(version, '2406.11.5') < 0) ||
12
+ !version) {
13
+ return apiUrl;
14
+ }
15
+ }
16
+ catch (e) {
17
+ devkit_exports_1.logger.verbose(`Failed to get Nx Cloud version.
18
+ ${e}`);
12
19
  return apiUrl;
13
20
  }
14
21
  const source = getSource(installationSource);
@@ -44,6 +51,7 @@ exports.repoUsesGithub = repoUsesGithub;
44
51
  function removeTrailingSlash(apiUrl) {
45
52
  return apiUrl[apiUrl.length - 1] === '/' ? apiUrl.slice(0, -1) : apiUrl;
46
53
  }
54
+ exports.removeTrailingSlash = removeTrailingSlash;
47
55
  function getSource(installationSource) {
48
56
  if (installationSource.includes('nx-init')) {
49
57
  return 'nx-init';
@@ -69,6 +77,7 @@ function getURLifShortenFailed(usesGithub, githubSlug, apiUrl, source, accessTok
69
77
  }
70
78
  return `${apiUrl}/setup/connect-workspace/manual?accessToken=${accessToken}&source=${source}`;
71
79
  }
80
+ exports.getURLifShortenFailed = getURLifShortenFailed;
72
81
  async function getInstallationSupportsGitHub(apiUrl) {
73
82
  try {
74
83
  const response = await require('axios').get(`${apiUrl}/nx-cloud/system/features`);
@@ -89,17 +98,55 @@ async function getNxCloudVersion(apiUrl) {
89
98
  try {
90
99
  const response = await require('axios').get(`${apiUrl}/nx-cloud/system/version`);
91
100
  const version = removeVersionModifier(response.data.version);
101
+ const isValid = versionIsValid(version);
92
102
  if (!version) {
93
103
  throw new Error('Failed to extract version from response.');
94
104
  }
105
+ if (!isValid) {
106
+ throw new Error(`Invalid version format: ${version}`);
107
+ }
95
108
  return version;
96
109
  }
97
110
  catch (e) {
98
111
  devkit_exports_1.logger.verbose(`Failed to get version of Nx Cloud.
99
112
  ${e}`);
113
+ return null;
100
114
  }
101
115
  }
116
+ exports.getNxCloudVersion = getNxCloudVersion;
102
117
  function removeVersionModifier(versionString) {
103
- // version may be something like 2406.13.5.hotfix2
118
+ // Cloud version string is in the format of YYMM.DD.BuildNumber-Modifier
104
119
  return versionString.split(/[\.-]/).slice(0, 3).join('.');
105
120
  }
121
+ exports.removeVersionModifier = removeVersionModifier;
122
+ function versionIsValid(version) {
123
+ // Updated Regex pattern to require YYMM.DD.BuildNumber format
124
+ // All parts are required, including the BuildNumber.
125
+ const pattern = /^\d{4}\.\d{2}\.\d+$/;
126
+ return pattern.test(version);
127
+ }
128
+ exports.versionIsValid = versionIsValid;
129
+ function compareCleanCloudVersions(version1, version2) {
130
+ const parseVersion = (version) => {
131
+ // The format we're using is YYMM.DD.BuildNumber
132
+ const parts = version.split('.').map((part) => parseInt(part, 10));
133
+ return {
134
+ yearMonth: parts[0],
135
+ day: parts[1],
136
+ buildNumber: parts[2],
137
+ };
138
+ };
139
+ const v1 = parseVersion(version1);
140
+ const v2 = parseVersion(version2);
141
+ if (v1.yearMonth !== v2.yearMonth) {
142
+ return v1.yearMonth > v2.yearMonth ? 1 : -1;
143
+ }
144
+ if (v1.day !== v2.day) {
145
+ return v1.day > v2.day ? 1 : -1;
146
+ }
147
+ if (v1.buildNumber !== v2.buildNumber) {
148
+ return v1.buildNumber > v2.buildNumber ? 1 : -1;
149
+ }
150
+ return 0;
151
+ }
152
+ exports.compareCleanCloudVersions = compareCleanCloudVersions;
@@ -10,6 +10,7 @@ const configuration_1 = require("../../../config/configuration");
10
10
  const nx_deps_cache_1 = require("../../../project-graph/nx-deps-cache");
11
11
  const path_1 = require("path");
12
12
  const task_hasher_1 = require("../../../hasher/task-hasher");
13
+ const output_1 = require("../../../utils/output");
13
14
  /**
14
15
  * Creates a package.json in the output directory for support to install dependencies within containers.
15
16
  *
@@ -106,6 +107,19 @@ function createPackageJson(projectName, graph, options = {}, fileMap = null) {
106
107
  packageJson.dependencies &&= (0, object_sort_1.sortObjectByKeys)(packageJson.dependencies);
107
108
  packageJson.peerDependencies &&= (0, object_sort_1.sortObjectByKeys)(packageJson.peerDependencies);
108
109
  packageJson.peerDependenciesMeta &&= (0, object_sort_1.sortObjectByKeys)(packageJson.peerDependenciesMeta);
110
+ if (rootPackageJson.packageManager) {
111
+ if (packageJson.packageManager &&
112
+ packageJson.packageManager !== rootPackageJson.packageManager) {
113
+ output_1.output.warn({
114
+ title: 'Package Manager Mismatch',
115
+ bodyLines: [
116
+ `The project ${projectName} has explicitly specified "packageManager" config of "${packageJson.packageManager}" but the workspace is using "${rootPackageJson.packageManager}".`,
117
+ `Please remove the project level "packageManager" config or align it with the workspace root package.json.`,
118
+ ],
119
+ });
120
+ }
121
+ packageJson.packageManager = rootPackageJson.packageManager;
122
+ }
109
123
  return packageJson;
110
124
  }
111
125
  exports.createPackageJson = createPackageJson;
@@ -1,4 +1,3 @@
1
- import type { TsConfigOptions } from 'ts-node';
2
1
  import type { CompilerOptions } from 'typescript';
3
2
  /**
4
3
  * Optionally, if swc-node and tsconfig-paths are available in the current workspace, apply the require
@@ -24,7 +23,7 @@ export declare function registerTsProject(tsConfigPath: string): () => void;
24
23
  */
25
24
  export declare function registerTsProject(path: string, configFilename: string): any;
26
25
  export declare function getSwcTranspiler(compilerOptions: CompilerOptions): (...args: unknown[]) => unknown;
27
- export declare function getTsNodeTranspiler(compilerOptions: CompilerOptions, tsNodeOptions?: TsConfigOptions): (...args: unknown[]) => unknown;
26
+ export declare function getTsNodeTranspiler(compilerOptions: CompilerOptions): (...args: unknown[]) => unknown;
28
27
  export declare function getTranspiler(compilerOptions: CompilerOptions, tsConfigRaw?: unknown): () => (...args: unknown[]) => unknown;
29
28
  /**
30
29
  * Register ts-node or swc-node given a set of compiler options.
@@ -7,7 +7,45 @@ const swcNodeInstalled = packageIsInstalled('@swc-node/register');
7
7
  const tsNodeInstalled = packageIsInstalled('ts-node/register');
8
8
  let ts;
9
9
  let isTsEsmLoaderRegistered = false;
10
+ /**
11
+ * tsx is a utility to run TypeScript files in node which is growing in popularity:
12
+ * https://tsx.is
13
+ *
14
+ * Behind the scenes it is invoking node with relevant --require and --import flags.
15
+ *
16
+ * If the user is invoking Nx via a script which is being invoked via tsx, then we
17
+ * do not need to register any transpiler at all as the environment will have already
18
+ * been configured by tsx. In fact, registering a transpiler such as ts-node or swc
19
+ * in this case causes issues.
20
+ *
21
+ * Because node is being invoked by tsx, the tsx binary does not end up in the final
22
+ * process.argv and so we need to check a few possible things to account for usage
23
+ * via different package managers (e.g. pnpm does not set process._ to tsx, but rather
24
+ * pnpm itself, modern yarn does not set process._ at all etc.).
25
+ */
26
+ const isInvokedByTsx = (() => {
27
+ if (process.env._?.endsWith(`${path_1.sep}tsx`)) {
28
+ return true;
29
+ }
30
+ const requireArgs = [];
31
+ const importArgs = [];
32
+ (process.execArgv ?? []).forEach((arg, i) => {
33
+ if (arg === '-r' || arg === '--require') {
34
+ requireArgs.push(process.execArgv[i + 1]);
35
+ }
36
+ if (arg === '--import') {
37
+ importArgs.push(process.execArgv[i + 1]);
38
+ }
39
+ });
40
+ const isTsxPath = (p) => p.includes(`${path_1.sep}tsx${path_1.sep}`);
41
+ return (requireArgs.some((a) => isTsxPath(a)) ||
42
+ importArgs.some((a) => isTsxPath(a)));
43
+ })();
10
44
  function registerTsProject(path, configFilename) {
45
+ // See explanation alongside isInvokedByTsx declaration
46
+ if (isInvokedByTsx) {
47
+ return () => { };
48
+ }
11
49
  const tsConfigPath = configFilename ? (0, path_1.join)(path, configFilename) : path;
12
50
  const compilerOptions = readCompilerOptions(tsConfigPath);
13
51
  const cleanupFunctions = [
@@ -41,7 +79,13 @@ function getSwcTranspiler(compilerOptions) {
41
79
  return typeof cleanupFn === 'function' ? cleanupFn : () => { };
42
80
  }
43
81
  exports.getSwcTranspiler = getSwcTranspiler;
44
- function getTsNodeTranspiler(compilerOptions, tsNodeOptions) {
82
+ const registered = new Set();
83
+ function getTsNodeTranspiler(compilerOptions) {
84
+ // Just return if transpiler was already registered before.
85
+ const registrationKey = JSON.stringify(compilerOptions);
86
+ if (registered.has(registrationKey)) {
87
+ return () => { };
88
+ }
45
89
  const { register } = require('ts-node');
46
90
  // ts-node doesn't provide a cleanup method
47
91
  const service = register({
@@ -50,13 +94,14 @@ function getTsNodeTranspiler(compilerOptions, tsNodeOptions) {
50
94
  // we already read and provide the compiler options, so prevent ts-node from reading them again
51
95
  skipProject: true,
52
96
  });
97
+ registered.add(registrationKey);
53
98
  const { transpiler, swc } = service.options;
54
99
  // Don't warn if a faster transpiler is enabled
55
100
  if (!transpiler && !swc) {
56
101
  warnTsNodeUsage();
57
102
  }
58
103
  return () => {
59
- service.enabled(false);
104
+ // Do not cleanup ts-node service since other consumers may need it
60
105
  };
61
106
  }
62
107
  exports.getTsNodeTranspiler = getTsNodeTranspiler;
@@ -121,7 +166,7 @@ function getTranspiler(compilerOptions, tsConfigRaw) {
121
166
  // We can fall back on ts-node if it's available
122
167
  if (tsNodeInstalled) {
123
168
  const tsNodeOptions = filterRecognizedTsConfigTsNodeOptions(tsConfigRaw).recognized;
124
- return () => getTsNodeTranspiler(compilerOptions, tsNodeOptions);
169
+ return () => getTsNodeTranspiler(compilerOptions);
125
170
  }
126
171
  }
127
172
  exports.getTranspiler = getTranspiler;