nx 23.3.0-beta.6 → 23.3.0-beta.8

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 (118) hide show
  1. package/README.md +1 -1
  2. package/dist/nx-cloud-internals.d.ts +1 -1
  3. package/dist/nx-cloud-internals.js +4 -4
  4. package/dist/src/command-line/migrate/agentic/master/run-master-session.d.ts +6 -2
  5. package/dist/src/command-line/migrate/agentic/master/run-master-session.js +88 -14
  6. package/dist/src/command-line/migrate/command-object.d.ts +1 -0
  7. package/dist/src/command-line/migrate/command-object.js +6 -1
  8. package/dist/src/command-line/migrate/migrate-analytics.d.ts +34 -9
  9. package/dist/src/command-line/migrate/migrate-analytics.js +71 -10
  10. package/dist/src/command-line/migrate/migrate-config.d.ts +5 -2
  11. package/dist/src/command-line/migrate/migrate-config.js +19 -11
  12. package/dist/src/command-line/migrate/migrate.d.ts +2 -0
  13. package/dist/src/command-line/migrate/migrate.js +152 -45
  14. package/dist/src/command-line/migrate/resolve-package-version.js +2 -19
  15. package/dist/src/command-line/migrate/run/broker.d.ts +14 -2
  16. package/dist/src/command-line/migrate/run/broker.js +95 -34
  17. package/dist/src/command-line/migrate/run/existing-run-report.d.ts +55 -0
  18. package/dist/src/command-line/migrate/run/existing-run-report.js +225 -0
  19. package/dist/src/command-line/migrate/run/give-up.d.ts +41 -0
  20. package/dist/src/command-line/migrate/run/give-up.js +148 -0
  21. package/dist/src/command-line/migrate/run/index.d.ts +6 -4
  22. package/dist/src/command-line/migrate/run/index.js +15 -2
  23. package/dist/src/command-line/migrate/run/issues.d.ts +14 -0
  24. package/dist/src/command-line/migrate/run/issues.js +59 -0
  25. package/dist/src/command-line/migrate/run/orchestrator.d.ts +40 -1
  26. package/dist/src/command-line/migrate/run/orchestrator.js +509 -160
  27. package/dist/src/command-line/migrate/run/run-id.d.ts +0 -8
  28. package/dist/src/command-line/migrate/run/run-id.js +0 -30
  29. package/dist/src/command-line/migrate/run/run-state.d.ts +11 -9
  30. package/dist/src/command-line/migrate/run/run-state.js +25 -12
  31. package/dist/src/command-line/migrate/run/runbook.js +9 -4
  32. package/dist/src/command-line/migrate/run/state-lock.d.ts +31 -0
  33. package/dist/src/command-line/migrate/run/state-lock.js +126 -0
  34. package/dist/src/command-line/migrate/run/state-machine.d.ts +15 -0
  35. package/dist/src/command-line/migrate/run/state-machine.js +137 -10
  36. package/dist/src/command-line/migrate/run/util.d.ts +1 -0
  37. package/dist/src/command-line/migrate/run/util.js +21 -0
  38. package/dist/src/command-line/migrate/run/worker.js +3 -0
  39. package/dist/src/command-line/migrate/step-actions.d.ts +1 -1
  40. package/dist/src/command-line/migrate/step-actions.js +7 -1
  41. package/dist/src/command-line/migrate/text.d.ts +6 -0
  42. package/dist/src/command-line/migrate/text.js +25 -0
  43. package/dist/src/command-line/release/utils/release-graph.js +1 -1
  44. package/dist/src/command-line/release/utils/remote-release-clients/github.js +2 -5
  45. package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.d.ts +2 -2
  46. package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.js +4 -5
  47. package/dist/src/command-line/release/version/version-actions.d.ts +3 -0
  48. package/dist/src/command-line/reset/reset.js +3 -0
  49. package/dist/src/config/task-graph.d.ts +1 -1
  50. package/dist/src/config/workspace-json-project-json.d.ts +4 -4
  51. package/dist/src/daemon/client/client.d.ts +3 -3
  52. package/dist/src/daemon/client/client.js +4 -4
  53. package/dist/src/daemon/message-types/ultracache-configuration-version.d.ts +8 -0
  54. package/dist/src/daemon/server/handle-hash-tasks.d.ts +2 -2
  55. package/dist/src/daemon/server/handle-hash-tasks.js +3 -3
  56. package/dist/src/daemon/server/handle-select-affected-tasks.js +4 -2
  57. package/dist/src/daemon/server/ultracache-configuration-state.d.ts +7 -0
  58. package/dist/src/daemon/server/{io-snapshots-state.js → ultracache-configuration-state.js} +5 -4
  59. package/dist/src/hasher/create-task-hasher.d.ts +3 -3
  60. package/dist/src/hasher/create-task-hasher.js +6 -6
  61. package/dist/src/hasher/hash-task.d.ts +2 -2
  62. package/dist/src/hasher/hash-task.js +5 -5
  63. package/dist/src/hasher/native-task-hasher-impl.d.ts +7 -7
  64. package/dist/src/hasher/native-task-hasher-impl.js +19 -19
  65. package/dist/src/hasher/task-hasher.d.ts +14 -14
  66. package/dist/src/hasher/task-hasher.js +13 -13
  67. package/dist/src/native/index.d.ts +95 -102
  68. package/dist/src/native/native-bindings.js +4 -5
  69. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  70. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  71. package/dist/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +15 -8
  72. package/dist/src/nx-cloud/update-manager.d.ts +3 -3
  73. package/dist/src/nx-cloud/update-manager.js +19 -13
  74. package/dist/src/nx-cloud/utilities/is-workspace-claimed.js +2 -1
  75. package/dist/src/nx-cloud/utilities/nx-cloud-http-client.d.ts +5 -0
  76. package/dist/src/nx-cloud/utilities/nx-cloud-http-client.js +16 -0
  77. package/dist/src/nx-cloud/utilities/url-shorten.js +17 -10
  78. package/dist/src/plugins/js/index.js +45 -64
  79. package/dist/src/plugins/js/lock-file/lock-file.d.ts +4 -4
  80. package/dist/src/plugins/js/lock-file/lock-file.js +6 -7
  81. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +22 -18
  82. package/dist/src/project-graph/affected/affected-tasks.d.ts +11 -10
  83. package/dist/src/project-graph/affected/affected-tasks.js +16 -20
  84. package/dist/src/tasks-runner/init-tasks-runner.d.ts +5 -5
  85. package/dist/src/tasks-runner/init-tasks-runner.js +8 -15
  86. package/dist/src/tasks-runner/run-command.d.ts +7 -7
  87. package/dist/src/tasks-runner/run-command.js +18 -23
  88. package/dist/src/ultracache/config.d.ts +21 -0
  89. package/dist/src/ultracache/config.js +29 -0
  90. package/dist/src/ultracache/fetch.d.ts +21 -0
  91. package/dist/src/{io-snapshots → ultracache}/fetch.js +9 -9
  92. package/dist/src/ultracache/overrides.d.ts +17 -0
  93. package/dist/src/{io-snapshots → ultracache}/overrides.js +22 -10
  94. package/dist/src/ultracache/report.d.ts +13 -0
  95. package/dist/src/{io-snapshots → ultracache}/report.js +15 -21
  96. package/dist/src/ultracache/store.d.ts +40 -0
  97. package/dist/src/{io-snapshots → ultracache}/store.js +45 -45
  98. package/dist/src/utils/ab-testing.js +11 -12
  99. package/dist/src/utils/db-connection.d.ts +1 -0
  100. package/dist/src/utils/db-connection.js +1 -0
  101. package/dist/src/utils/git-utils.d.ts +7 -0
  102. package/dist/src/utils/git-utils.js +21 -9
  103. package/dist/src/utils/http-client.d.ts +27 -0
  104. package/dist/src/utils/http-client.js +193 -0
  105. package/package.json +12 -38
  106. package/dist/src/daemon/message-types/io-snapshot-version.d.ts +0 -5
  107. package/dist/src/daemon/server/io-snapshots-state.d.ts +0 -7
  108. package/dist/src/io-snapshots/config.d.ts +0 -23
  109. package/dist/src/io-snapshots/config.js +0 -32
  110. package/dist/src/io-snapshots/fetch.d.ts +0 -21
  111. package/dist/src/io-snapshots/outputs.d.ts +0 -12
  112. package/dist/src/io-snapshots/outputs.js +0 -33
  113. package/dist/src/io-snapshots/overrides.d.ts +0 -12
  114. package/dist/src/io-snapshots/report.d.ts +0 -13
  115. package/dist/src/io-snapshots/store.d.ts +0 -37
  116. package/dist/src/nx-cloud/utilities/axios.d.ts +0 -4
  117. package/dist/src/nx-cloud/utilities/axios.js +0 -17
  118. /package/dist/src/daemon/message-types/{io-snapshot-version.js → ultracache-configuration-version.js} +0 -0
@@ -584,8 +584,6 @@ module.exports.HashPlanner = nativeBinding.HashPlanner
584
584
  module.exports.HttpRemoteCache = nativeBinding.HttpRemoteCache
585
585
  module.exports.IgnoredIndexReader = nativeBinding.IgnoredIndexReader
586
586
  module.exports.ImportResult = nativeBinding.ImportResult
587
- module.exports.IoSnapshots = nativeBinding.IoSnapshots
588
- module.exports.IoSnapshotStore = nativeBinding.IoSnapshotStore
589
587
  module.exports.NxCache = nativeBinding.NxCache
590
588
  module.exports.NxConsolePreferences = nativeBinding.NxConsolePreferences
591
589
  module.exports.NxPluginCapabilities = nativeBinding.NxPluginCapabilities
@@ -596,6 +594,8 @@ module.exports.RustPseudoTerminal = nativeBinding.RustPseudoTerminal
596
594
  module.exports.TaskDetails = nativeBinding.TaskDetails
597
595
  module.exports.TaskHasher = nativeBinding.TaskHasher
598
596
  module.exports.TaskInvocationTracker = nativeBinding.TaskInvocationTracker
597
+ module.exports.UltracacheConfigurations = nativeBinding.UltracacheConfigurations
598
+ module.exports.UltracacheConfigurationStore = nativeBinding.UltracacheConfigurationStore
599
599
  module.exports.WorkspaceContext = nativeBinding.WorkspaceContext
600
600
  module.exports.affectedTasks = nativeBinding.affectedTasks
601
601
  module.exports.BatchStatus = nativeBinding.BatchStatus
@@ -618,11 +618,10 @@ module.exports.getDefaultMaxCacheSize = nativeBinding.getDefaultMaxCacheSize
618
618
  module.exports.getEventDimensions = nativeBinding.getEventDimensions
619
619
  module.exports.getFilesForOutputsBatch = nativeBinding.getFilesForOutputsBatch
620
620
  module.exports.getHardcodedIgnorePatterns = nativeBinding.getHardcodedIgnorePatterns
621
- module.exports.getIoSnapshotDeferredTaskIds = nativeBinding.getIoSnapshotDeferredTaskIds
622
- module.exports.getIoSnapshotReport = nativeBinding.getIoSnapshotReport
623
621
  module.exports.getMainWorktreeRoot = nativeBinding.getMainWorktreeRoot
624
- module.exports.getObservedIoSnapshotOutputs = nativeBinding.getObservedIoSnapshotOutputs
625
622
  module.exports.getTransformableOutputs = nativeBinding.getTransformableOutputs
623
+ module.exports.getUltracacheDeferredTaskIds = nativeBinding.getUltracacheDeferredTaskIds
624
+ module.exports.getUltracacheReport = nativeBinding.getUltracacheReport
626
625
  module.exports.GroupType = nativeBinding.GroupType
627
626
  module.exports.hashArray = nativeBinding.hashArray
628
627
  module.exports.hashFile = nativeBinding.hashFile
Binary file
@@ -11,6 +11,7 @@ const url_shorten_1 = require("../../utilities/url-shorten");
11
11
  const get_cloud_options_1 = require("../../utilities/get-cloud-options");
12
12
  const path_1 = require("path");
13
13
  const git_utils_1 = require("../../../utils/git-utils");
14
+ const http_client_1 = require("../../../utils/http-client");
14
15
  function printCloudConnectionDisabledMessage() {
15
16
  output_1.output.error({
16
17
  title: `Connections to Nx Cloud are disabled for this workspace`,
@@ -46,10 +47,13 @@ function getNxInitDate() {
46
47
  }
47
48
  async function createNxCloudWorkspaceV1(workspaceName, installationSource, nxInitDate) {
48
49
  const apiUrl = (0, get_cloud_options_1.getCloudUrl)();
49
- const response = await require('axios').post(`${apiUrl}/nx-cloud/create-org-and-workspace`, {
50
- workspaceName,
51
- installationSource,
52
- nxInitDate,
50
+ const response = await (0, http_client_1.httpRequest)(`${apiUrl}/nx-cloud/create-org-and-workspace`, {
51
+ method: 'POST',
52
+ data: {
53
+ workspaceName,
54
+ installationSource,
55
+ nxInitDate,
56
+ },
53
57
  });
54
58
  if (response.data.message) {
55
59
  throw new Error(response.data.message);
@@ -58,10 +62,13 @@ async function createNxCloudWorkspaceV1(workspaceName, installationSource, nxIni
58
62
  }
59
63
  async function createNxCloudWorkspaceV2(workspaceName, installationSource, nxInitDate) {
60
64
  const apiUrl = (0, get_cloud_options_1.getCloudUrl)();
61
- const response = await require('axios').post(`${apiUrl}/nx-cloud/v2/create-org-and-workspace`, {
62
- workspaceName,
63
- installationSource,
64
- nxInitDate,
65
+ const response = await (0, http_client_1.httpRequest)(`${apiUrl}/nx-cloud/v2/create-org-and-workspace`, {
66
+ method: 'POST',
67
+ data: {
68
+ workspaceName,
69
+ installationSource,
70
+ nxInitDate,
71
+ },
65
72
  });
66
73
  if (response.data.message) {
67
74
  throw new Error(response.data.message);
@@ -1,5 +1,5 @@
1
1
  import type { CloudTaskRunnerOptions } from './nx-cloud-tasks-runner-shell';
2
- import type { ReadIoSnapshotsOptions, ReadIoSnapshotsResult } from '../io-snapshots/fetch';
2
+ import type { ReadUltracacheConfigurationsOptions, ReadUltracacheConfigurationsResult } from '../ultracache/fetch';
3
3
  import { TasksRunner } from '../tasks-runner/tasks-runner';
4
4
  import { RemoteCacheV2 } from '../tasks-runner/default-tasks-runner';
5
5
  export declare class NxCloudEnterpriseOutdatedError extends Error {
@@ -13,8 +13,8 @@ export interface NxCloudClient {
13
13
  commands: Record<string, () => Promise<void>>;
14
14
  nxCloudTasksRunner: TasksRunner<CloudTaskRunnerOptions>;
15
15
  getRemoteCache: () => RemoteCacheV2;
16
- /** Clients that expose I/O snapshots; see `fetchIoSnapshots`. */
17
- readIoSnapshots?: (options: ReadIoSnapshotsOptions) => Promise<ReadIoSnapshotsResult | null>;
16
+ /** Clients that expose Ultracache configurations; see `fetchUltracacheConfigurations`. */
17
+ readUltracacheConfigurations?: (options: ReadUltracacheConfigurationsOptions) => Promise<ReadUltracacheConfigurationsResult | null>;
18
18
  }
19
19
  export declare function verifyOrUpdateNxCloudClient(options?: {
20
20
  url?: string;
@@ -6,9 +6,11 @@ exports.getBundleInstallDefaultLocation = getBundleInstallDefaultLocation;
6
6
  const tslib_1 = require("tslib");
7
7
  const fs_1 = require("fs");
8
8
  const zlib_1 = require("zlib");
9
+ const stream_1 = require("stream");
9
10
  const path_1 = require("path");
10
11
  const os_1 = require("os");
11
- const axios_1 = require("./utilities/axios");
12
+ const nx_cloud_http_client_1 = require("./utilities/nx-cloud-http-client");
13
+ const http_client_1 = require("../utils/http-client");
12
14
  const debug_logger_1 = require("./debug-logger");
13
15
  const tar = tslib_1.__importStar(require("tar-stream"));
14
16
  const cache_directory_1 = require("../utils/cache-directory");
@@ -32,14 +34,14 @@ async function verifyOrUpdateNxCloudClient(options) {
32
34
  const currentBundle = getLatestInstalledRunnerBundle();
33
35
  const apiUrl = process.env.NX_CLOUD_API || options?.url || 'https://cloud.nx.app';
34
36
  if (shouldVerifyInstalledRunnerBundle(currentBundle)) {
35
- const axios = (0, axios_1.createApiAxiosInstance)(options);
37
+ const httpClient = (0, nx_cloud_http_client_1.createApiHttpClient)(options);
36
38
  let verifyBundleResponse;
37
39
  try {
38
- verifyBundleResponse = await verifyCurrentBundle(axios, currentBundle);
40
+ verifyBundleResponse = await verifyCurrentBundle(httpClient, currentBundle);
39
41
  }
40
42
  catch (e) {
41
43
  // Enterprise image compatibility, to be removed
42
- if (e.message === 'Request failed with status code 404' && apiUrl) {
44
+ if (e instanceof http_client_1.HttpError && e.status === 404 && apiUrl) {
43
45
  throw new NxCloudEnterpriseOutdatedError(apiUrl);
44
46
  }
45
47
  (0, debug_logger_1.debugLog)('Could not verify bundle. Resetting validation timer and using previously installed or default runner. Error: ', e);
@@ -72,7 +74,7 @@ async function verifyOrUpdateNxCloudClient(options) {
72
74
  if (version === 'NX_ENTERPRISE_OUTDATED_IMAGE') {
73
75
  throw new NxCloudEnterpriseOutdatedError(apiUrl);
74
76
  }
75
- const fullPath = await downloadAndExtractClientBundle(axios, runnerBundleInstallDirectory, version, url);
77
+ const fullPath = await downloadAndExtractClientBundle(httpClient, runnerBundleInstallDirectory, version, url);
76
78
  (0, debug_logger_1.debugLog)('Done: ', fullPath);
77
79
  const nxCloudClient = require(fullPath);
78
80
  if (nxCloudClient.commands === undefined) {
@@ -157,8 +159,8 @@ function shouldVerifyInstalledRunnerBundle(currentBundle) {
157
159
  }
158
160
  return true;
159
161
  }
160
- async function verifyCurrentBundle(axios, currentBundle) {
161
- return axios.get('/nx-cloud/client/verify', {
162
+ async function verifyCurrentBundle(httpClient, currentBundle) {
163
+ return httpClient.get('/nx-cloud/client/verify', {
162
164
  params: currentBundle
163
165
  ? {
164
166
  version: currentBundle.version,
@@ -209,10 +211,10 @@ function hashDirectory(dir) {
209
211
  const combinedHashes = hashes.sort().join('');
210
212
  return (0, crypto_1.createHash)('sha256').update(combinedHashes).digest('hex');
211
213
  }
212
- async function downloadAndExtractClientBundle(axios, runnerBundleInstallDirectory, version, url) {
214
+ async function downloadAndExtractClientBundle(httpClient, runnerBundleInstallDirectory, version, url) {
213
215
  let resp;
214
216
  try {
215
- resp = await axios.get(url, {
217
+ resp = await httpClient.get(url, {
216
218
  responseType: 'stream',
217
219
  });
218
220
  }
@@ -238,6 +240,8 @@ async function downloadAndExtractClientBundle(axios, runnerBundleInstallDirector
238
240
  else if (headers.type === 'file') {
239
241
  const outputFilePath = (0, path_1.join)(bundleExtractLocation, headers.name);
240
242
  const writeStream = (0, fs_1.createWriteStream)(outputFilePath);
243
+ // Surface disk errors through the pipeline instead of crashing
244
+ writeStream.on('error', (e) => extract.destroy(e));
241
245
  stream.pipe(writeStream);
242
246
  // Continue the tar stream after the write stream closes
243
247
  writeStream.on('close', () => {
@@ -246,15 +250,17 @@ async function downloadAndExtractClientBundle(axios, runnerBundleInstallDirector
246
250
  stream.resume();
247
251
  }
248
252
  });
249
- extract.on('error', (e) => {
250
- rej(e);
251
- });
252
253
  extract.on('finish', function () {
253
254
  removeOldClientBundles(version);
254
255
  writeBundleVerificationLock();
255
256
  res(bundleExtractLocation);
256
257
  });
257
- resp.data.pipe((0, zlib_1.createGunzip)()).pipe(extract);
258
+ // pipeline propagates download/gunzip errors that .pipe() would leave
259
+ // uncaught
260
+ (0, stream_1.pipeline)(resp.data, (0, zlib_1.createGunzip)(), extract, (e) => {
261
+ if (e)
262
+ rej(e);
263
+ });
258
264
  });
259
265
  }
260
266
  function removeOldClientBundles(currentInstallVersion) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isWorkspaceClaimed = isWorkspaceClaimed;
4
4
  const get_cloud_options_1 = require("./get-cloud-options");
5
+ const http_client_1 = require("../../utils/http-client");
5
6
  async function isWorkspaceClaimed(accessToken) {
6
7
  if (!accessToken)
7
8
  return false;
@@ -10,7 +11,7 @@ async function isWorkspaceClaimed(accessToken) {
10
11
  const requestData = (0, get_cloud_options_1.isNxCloudId)(accessToken)
11
12
  ? { nxCloudId: accessToken }
12
13
  : { nxCloudAccessToken: accessToken };
13
- const response = await require('axios').post(`${apiUrl}/nx-cloud/is-workspace-claimed`, requestData);
14
+ const response = await (0, http_client_1.httpRequest)(`${apiUrl}/nx-cloud/is-workspace-claimed`, { method: 'POST', data: requestData });
14
15
  if (response.data.message) {
15
16
  return false;
16
17
  }
@@ -0,0 +1,5 @@
1
+ import { type HttpClient } from '../../utils/http-client';
2
+ export declare function createApiHttpClient(options?: {
3
+ url?: string;
4
+ customProxyConfigPath?: string;
5
+ }): HttpClient;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createApiHttpClient = createApiHttpClient;
4
+ const http_client_1 = require("../../utils/http-client");
5
+ const environment_1 = require("./environment");
6
+ function createApiHttpClient(options) {
7
+ if (options?.customProxyConfigPath) {
8
+ const { logger } = require('../../utils/logger');
9
+ // The client bundle still reads this file for its own requests
10
+ logger.warn('customProxyConfigPath is not used for downloading the Nx Cloud client. Set HTTP_PROXY/HTTPS_PROXY/NO_PROXY (and NODE_EXTRA_CA_CERTS for custom certificates) instead.');
11
+ }
12
+ return (0, http_client_1.createHttpClient)({
13
+ baseURL: process.env.NX_CLOUD_API || options?.url || 'https://cloud.nx.app',
14
+ timeout: environment_1.NX_CLOUD_NO_TIMEOUTS ? environment_1.UNLIMITED_TIMEOUT : 10000,
15
+ });
16
+ }
@@ -5,10 +5,11 @@ exports.getURLifShortenFailed = getURLifShortenFailed;
5
5
  const logger_1 = require("../../utils/logger");
6
6
  const get_cloud_options_1 = require("./get-cloud-options");
7
7
  const git_utils_1 = require("../../utils/git-utils");
8
+ const http_client_1 = require("../../utils/http-client");
8
9
  async function createNxCloudOnboardingURL(onboardingSource, accessToken, meta, forceManual = false, forceGithub = false, directory,
9
10
  // Aborting tears down the in-flight request; without it a caller that stops
10
11
  // waiting (see prefetchRemoteCacheOnboardingUrl) leaves the socket holding
11
- // the event loop open, since axios has no default timeout.
12
+ // the event loop open, since these requests have no timeout.
12
13
  signal) {
13
14
  const remoteInfo = (0, git_utils_1.getVcsRemoteInfo)(directory);
14
15
  const apiUrl = (0, get_cloud_options_1.getCloudUrl)();
@@ -26,14 +27,18 @@ signal) {
26
27
  }
27
28
  const source = getSource(onboardingSource);
28
29
  try {
29
- const response = await require('axios').post(`${apiUrl}/nx-cloud/onboarding`, {
30
- type: usesGithub ? 'GITHUB' : 'MANUAL',
31
- source,
32
- accessToken: usesGithub ? null : accessToken,
33
- selectedRepositoryName: remoteInfo?.slug ?? null,
34
- repositoryDomain: remoteInfo?.domain ?? null,
35
- meta,
36
- }, { signal });
30
+ const response = await (0, http_client_1.httpRequest)(`${apiUrl}/nx-cloud/onboarding`, {
31
+ method: 'POST',
32
+ data: {
33
+ type: usesGithub ? 'GITHUB' : 'MANUAL',
34
+ source,
35
+ accessToken: usesGithub ? null : accessToken,
36
+ selectedRepositoryName: remoteInfo?.slug ?? null,
37
+ repositoryDomain: remoteInfo?.domain ?? null,
38
+ meta,
39
+ },
40
+ signal,
41
+ });
37
42
  if (!response?.data || response.data.message) {
38
43
  throw new Error(response?.data?.message ?? 'Failed to shorten Nx Cloud URL');
39
44
  }
@@ -69,7 +74,9 @@ function getURLifShortenFailed(usesGithub, githubSlug, apiUrl, source, accessTok
69
74
  }
70
75
  async function getInstallationSupportsGitHub(apiUrl, signal) {
71
76
  try {
72
- const response = await require('axios').get(`${apiUrl}/nx-cloud/system/features`, { signal });
77
+ const response = await (0, http_client_1.httpRequest)(`${apiUrl}/nx-cloud/system/features`, {
78
+ signal,
79
+ });
73
80
  if (!response?.data || response.data.message) {
74
81
  throw new Error(response?.data?.message ?? 'Failed to shorten Nx Cloud URL');
75
82
  }
@@ -18,12 +18,16 @@ const lock_file_1 = require("./lock-file/lock-file");
18
18
  const build_dependencies_1 = require("./project-graph/build-dependencies/build-dependencies");
19
19
  const config_1 = require("./utils/config");
20
20
  exports.name = 'nx/js/dependencies-and-lockfile';
21
- // Separate in-memory caches
22
- let cachedExternalNodes;
21
+ // An install can rewrite the lockfile between createNodes and
22
+ // createDependencies, so both parse the one createNodes read.
23
+ let cachedLockFile;
23
24
  let cachedKeyMap;
24
25
  exports.createNodes = [
25
26
  (0, globs_1.combineGlobPatterns)(lock_file_1.LOCKFILES),
26
27
  (files, _, context) => {
28
+ // A long-lived process must not reuse a lockfile this computation skipped.
29
+ cachedLockFile = undefined;
30
+ cachedKeyMap = undefined;
27
31
  return (0, plugins_1.createNodesFromFiles)(internalCreateNodes, files, _, context);
28
32
  },
29
33
  ];
@@ -42,41 +46,45 @@ function internalCreateNodes(lockFile, _, context) {
42
46
  ? (0, fs_1.readFileSync)(lockFilePath, 'utf-8')
43
47
  : (0, bun_parser_1.readBunLockFile)(lockFilePath);
44
48
  const lockFileHash = getLockFileHash(lockFileContents);
45
- if (!lockFileNeedsReprocessing(lockFileHash, externalNodesHashFile)) {
46
- const { nodes, keyMap } = readCachedExternalNodes();
47
- cachedExternalNodes = nodes;
48
- cachedKeyMap = keyMap;
49
+ cachedLockFile = { packageManager, lockFile, lockFileContents, lockFileHash };
50
+ const cached = readCache(externalNodesCache, lockFileHash);
51
+ if (cached) {
52
+ cachedKeyMap = deserializeKeyMap(cached.keyMap, cached.nodes);
49
53
  return {
50
- externalNodes: nodes,
54
+ externalNodes: cached.nodes,
51
55
  };
52
56
  }
53
- const { nodes: externalNodes, keyMap } = (0, lock_file_1.getLockFileNodes)(packageManager, lockFileContents, lockFileHash, context);
54
- cachedExternalNodes = externalNodes;
57
+ const { nodes: externalNodes, keyMap } = (0, lock_file_1.getLockFileNodes)(packageManager, lockFile, lockFileContents, lockFileHash, context);
55
58
  cachedKeyMap = keyMap;
56
- writeExternalNodesCache(lockFileHash, externalNodes, keyMap);
59
+ writeCache(externalNodesCache, lockFileHash, {
60
+ nodes: externalNodes,
61
+ keyMap: serializeKeyMap(keyMap),
62
+ });
57
63
  return {
58
64
  externalNodes,
59
65
  };
60
66
  }
61
67
  const createDependencies = (_, ctx) => {
62
68
  const pluginConfig = (0, config_1.jsPluginConfig)(ctx.nxJsonConfiguration);
63
- const packageManager = (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot);
64
69
  let lockfileDependencies = [];
65
70
  // lockfile may not exist yet
66
71
  if (pluginConfig.analyzeLockfile &&
67
- (0, lock_file_1.lockFileExists)(packageManager) &&
68
- cachedExternalNodes) {
69
- const lockFilePath = (0, path_1.join)(workspace_root_1.workspaceRoot, (0, lock_file_1.getLockFileName)(packageManager));
70
- const lockFileContents = packageManager !== 'bun'
71
- ? (0, fs_1.readFileSync)(lockFilePath, 'utf-8')
72
- : (0, bun_parser_1.readBunLockFile)(lockFilePath);
73
- const lockFileHash = getLockFileHash(lockFileContents);
74
- if (!lockFileNeedsReprocessing(lockFileHash, dependenciesHashFile)) {
75
- lockfileDependencies = readCachedDependencies();
72
+ cachedLockFile &&
73
+ (0, lock_file_1.lockFileExists)(cachedLockFile.packageManager)) {
74
+ const { packageManager, lockFile, lockFileContents, lockFileHash } = cachedLockFile;
75
+ // Cached dependencies name their external nodes, and those names also
76
+ // depend on node_modules hoisting.
77
+ const dependenciesHash = (0, file_hasher_1.hashArray)([
78
+ lockFileHash,
79
+ ...Object.keys(ctx.externalNodes),
80
+ ]);
81
+ const cachedDependencies = readCache(dependenciesCache, dependenciesHash);
82
+ if (cachedDependencies) {
83
+ lockfileDependencies = cachedDependencies;
76
84
  }
77
85
  else {
78
- lockfileDependencies = (0, lock_file_1.getLockFileDependencies)(packageManager, lockFileContents, lockFileHash, ctx, cachedKeyMap);
79
- writeDependenciesCache(lockFileHash, lockfileDependencies);
86
+ lockfileDependencies = (0, lock_file_1.getLockFileDependencies)(packageManager, lockFile, lockFileContents, lockFileHash, ctx, cachedKeyMap);
87
+ writeCache(dependenciesCache, dependenciesHash, lockfileDependencies);
80
88
  }
81
89
  }
82
90
  perf_hooks_1.performance.mark('build typescript dependencies - start');
@@ -107,7 +115,7 @@ function serializeKeyMap(keyMap) {
107
115
  }
108
116
  return serialized;
109
117
  }
110
- // Deserialize keyMap from JSON format using ctx.externalNodes
118
+ // Deserialize keyMap from JSON format
111
119
  function deserializeKeyMap(serialized, externalNodes) {
112
120
  const keyMap = new Map();
113
121
  for (const [key, value] of Object.entries(serialized)) {
@@ -131,47 +139,24 @@ function deserializeKeyMap(serialized, externalNodes) {
131
139
  }
132
140
  return keyMap;
133
141
  }
134
- function lockFileNeedsReprocessing(lockHash, hashFilePath) {
142
+ function readCache(path, key) {
135
143
  try {
136
- return (0, fs_1.readFileSync)(hashFilePath).toString() !== lockHash;
144
+ const cache = JSON.parse((0, fs_1.readFileSync)(path, 'utf-8'));
145
+ return cache.key === key ? cache.data : undefined;
137
146
  }
138
147
  catch {
139
- return true;
140
- }
141
- }
142
- // External nodes cache functions
143
- function writeExternalNodesCache(hash, nodes, keyMap) {
144
- const serializedKeyMap = serializeKeyMap(keyMap);
145
- const cacheData = { nodes, keyMap: serializedKeyMap };
146
- const content = safeStringify(cacheData);
147
- if (content === undefined) {
148
- logger_1.logger.warn(`Failed to serialize external nodes cache. Skipping cache write.`);
149
- tryRemoveFile(externalNodesCache);
150
- tryRemoveFile(externalNodesHashFile);
151
- return;
152
- }
153
- (0, plugin_cache_utils_1.safeWriteFileCache)(externalNodesCache, content);
154
- if ((0, fs_1.existsSync)(externalNodesCache)) {
155
- (0, plugin_cache_utils_1.safeWriteFileCache)(externalNodesHashFile, hash);
148
+ // Another process can be mid-write, so an unreadable cache is a miss.
149
+ return undefined;
156
150
  }
157
151
  }
158
- function readCachedExternalNodes() {
159
- const { nodes, keyMap } = JSON.parse((0, fs_1.readFileSync)(externalNodesCache, 'utf-8'));
160
- return { nodes, keyMap: deserializeKeyMap(keyMap, nodes) };
161
- }
162
- // Dependencies cache functions
163
- function writeDependenciesCache(hash, dependencies) {
164
- const content = safeStringify(dependencies);
152
+ function writeCache(path, key, data) {
153
+ const content = safeStringify({ key, data });
165
154
  if (content === undefined) {
166
- logger_1.logger.warn(`Failed to serialize dependencies cache. Skipping cache write.`);
167
- tryRemoveFile(dependenciesCache);
168
- tryRemoveFile(dependenciesHashFile);
155
+ logger_1.logger.warn(`Failed to serialize ${path}. Skipping cache write.`);
156
+ tryRemoveFile(path);
169
157
  return;
170
158
  }
171
- (0, plugin_cache_utils_1.safeWriteFileCache)(dependenciesCache, content);
172
- if ((0, fs_1.existsSync)(dependenciesCache)) {
173
- (0, plugin_cache_utils_1.safeWriteFileCache)(dependenciesHashFile, hash);
174
- }
159
+ (0, plugin_cache_utils_1.safeWriteFileCache)(path, content);
175
160
  }
176
161
  function safeStringify(data) {
177
162
  try {
@@ -191,11 +176,7 @@ function tryRemoveFile(path) {
191
176
  // Best effort
192
177
  }
193
178
  }
194
- function readCachedDependencies() {
195
- return JSON.parse((0, fs_1.readFileSync)(dependenciesCache).toString());
196
- }
197
- // Cache file paths
198
- const externalNodesHashFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'lockfile-nodes.hash');
199
- const dependenciesHashFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'lockfile-dependencies.hash');
200
- const externalNodesCache = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'parsed-lock-file.nodes.json');
201
- const dependenciesCache = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'parsed-lock-file.dependencies.json');
179
+ // Each cache file holds its key, so key and data come from one write.
180
+ // Older Nx versions read other names with a hash file; keep these distinct.
181
+ const externalNodesCache = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'lockfile-nodes.json');
182
+ const dependenciesCache = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'lockfile-dependencies.json');
@@ -10,9 +10,9 @@ import { PackageManager } from '../../../utils/package-manager';
10
10
  export declare const LOCKFILES: string[];
11
11
  export declare const AUTO_AFFECTED_LOCK_FILES: readonly ["yarn.lock", "package-lock.json", "pnpm-lock.yaml", "pnpm-lock.yml", "bun.lockb", "bun.lock"];
12
12
  /**
13
- * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
13
+ * Parses the lockfile into external nodes, plus the keyMap that getLockFileDependencies reads.
14
14
  */
15
- export declare function getLockFileNodes(packageManager: PackageManager, contents: string, lockFileHash: string, context: CreateNodesContext): {
15
+ export declare function getLockFileNodes(packageManager: PackageManager, lockFile: string, contents: string, lockFileHash: string, context: CreateNodesContext): {
16
16
  nodes: Record<string, ProjectGraphExternalNode>;
17
17
  keyMap: Map<string, any>;
18
18
  };
@@ -21,9 +21,9 @@ export declare function getLockFileNodesForName(lockFile: string, contents: stri
21
21
  keyMap: Map<string, any>;
22
22
  };
23
23
  /**
24
- * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
24
+ * Parses the lockfile into dependencies between external nodes.
25
25
  */
26
- export declare function getLockFileDependencies(packageManager: PackageManager, contents: string, lockFileHash: string, context: CreateDependenciesContext, keyMap: Map<string, any>): RawProjectGraphDependency[];
26
+ export declare function getLockFileDependencies(packageManager: PackageManager, lockFile: string, contents: string, lockFileHash: string, context: CreateDependenciesContext, keyMap: Map<string, any>): RawProjectGraphDependency[];
27
27
  export declare function lockFileExists(packageManager: PackageManager): boolean;
28
28
  /**
29
29
  * Returns lock file name based on the detected package manager in the root
@@ -54,14 +54,14 @@ const PNPM_LOCK_PATH = (0, node_path_1.join)(workspace_root_1.workspaceRoot, PNP
54
54
  const BUN_LOCK_PATH = (0, node_path_1.join)(workspace_root_1.workspaceRoot, bun_parser_1.BUN_LOCK_FILE);
55
55
  const BUN_TEXT_LOCK_PATH = (0, node_path_1.join)(workspace_root_1.workspaceRoot, bun_parser_1.BUN_TEXT_LOCK_FILE);
56
56
  /**
57
- * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
57
+ * Parses the lockfile into external nodes, plus the keyMap that getLockFileDependencies reads.
58
58
  */
59
- function getLockFileNodes(packageManager, contents, lockFileHash, context) {
59
+ function getLockFileNodes(packageManager, lockFile, contents, lockFileHash, context) {
60
60
  try {
61
61
  const packageJson = packageManager === 'yarn' || packageManager === 'bun'
62
62
  ? (0, fileutils_1.readJsonFile)((0, node_path_1.join)(context.workspaceRoot, 'package.json'))
63
63
  : undefined;
64
- return getLockFileNodesForName(getLockFileName(packageManager), contents, lockFileHash, packageJson);
64
+ return getLockFileNodesForName(lockFile, contents, lockFileHash, packageJson);
65
65
  }
66
66
  catch (e) {
67
67
  if (!isPostInstallProcess()) {
@@ -94,9 +94,9 @@ function getLockFileNodesForName(lockFile, contents, lockFileHash, packageJson)
94
94
  throw new Error(`Unknown lock file: ${lockFile}`);
95
95
  }
96
96
  /**
97
- * Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
97
+ * Parses the lockfile into dependencies between external nodes.
98
98
  */
99
- function getLockFileDependencies(packageManager, contents, lockFileHash, context, keyMap) {
99
+ function getLockFileDependencies(packageManager, lockFile, contents, lockFileHash, context, keyMap) {
100
100
  try {
101
101
  if (packageManager === 'yarn') {
102
102
  return (0, yarn_parser_1.getYarnLockfileDependencies)(contents, lockFileHash, context, keyMap);
@@ -108,8 +108,7 @@ function getLockFileDependencies(packageManager, contents, lockFileHash, context
108
108
  return (0, npm_parser_1.getNpmLockfileDependencies)(contents, lockFileHash, context, keyMap);
109
109
  }
110
110
  if (packageManager === 'bun') {
111
- const lockFilePath = getLockFilePath(packageManager);
112
- if (lockFilePath.endsWith(bun_parser_1.BUN_TEXT_LOCK_FILE)) {
111
+ if (lockFile === bun_parser_1.BUN_TEXT_LOCK_FILE) {
113
112
  // Bun parser doesn't use keyMap
114
113
  return (0, bun_parser_1.getBunTextLockfileDependencies)(contents, lockFileHash, context);
115
114
  }
@@ -416,17 +416,16 @@ class TargetProjectLocator {
416
416
  const packageJsonPath = (0, resolve_relative_to_dir_1.resolveRelativeToDir)((0, node_path_1.join)(packageName, 'package.json'), relativeToDir);
417
417
  if (packageJsonPath) {
418
418
  if (this.packageJsonResolutionCache.has(packageJsonPath)) {
419
- return this.packageJsonResolutionCache.get(packageJsonPath);
419
+ const cached = this.packageJsonResolutionCache.get(packageJsonPath);
420
+ if (cached) {
421
+ return cached;
422
+ }
420
423
  }
421
424
  const parsedPackageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
422
425
  if (parsedPackageJson.name && parsedPackageJson.version) {
423
426
  this.packageJsonResolutionCache.set(packageJsonPath, parsedPackageJson);
424
427
  return parsedPackageJson;
425
428
  }
426
- else {
427
- this.packageJsonResolutionCache.set(packageJsonPath, null);
428
- return null;
429
- }
430
429
  }
431
430
  try {
432
431
  // Resolve the main entry point of the package
@@ -435,22 +434,27 @@ class TargetProjectLocator {
435
434
  while (dir !== (0, node_path_1.dirname)(dir)) {
436
435
  const packageJsonPath = (0, node_path_1.join)(dir, 'package.json');
437
436
  if (this.packageJsonResolutionCache.has(packageJsonPath)) {
438
- return this.packageJsonResolutionCache.get(packageJsonPath);
439
- }
440
- try {
441
- const parsedPackageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
442
- // Ensure the package.json contains the "name" and "version" fields
443
- if (parsedPackageJson.name && parsedPackageJson.version) {
444
- this.packageJsonResolutionCache.set(packageJsonPath, parsedPackageJson);
445
- return parsedPackageJson;
437
+ const cached = this.packageJsonResolutionCache.get(packageJsonPath);
438
+ if (cached) {
439
+ return cached;
446
440
  }
447
- else {
441
+ // Cached incomplete manifests are traversal points, not terminal misses.
442
+ }
443
+ else {
444
+ try {
445
+ const parsedPackageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
446
+ // Ensure the package.json contains the "name" and "version" fields
447
+ if (parsedPackageJson.name && parsedPackageJson.version) {
448
+ this.packageJsonResolutionCache.set(packageJsonPath, parsedPackageJson);
449
+ return parsedPackageJson;
450
+ }
451
+ // A module-format stub without name/version: remember it and keep
452
+ // traversing towards the real manifest.
448
453
  this.packageJsonResolutionCache.set(packageJsonPath, null);
449
- return null;
450
454
  }
451
- }
452
- catch {
453
- // Package.json is invalid, keep traversing
455
+ catch {
456
+ // Package.json is invalid, keep traversing
457
+ }
454
458
  }
455
459
  dir = (0, node_path_1.dirname)(dir);
456
460
  }
@@ -1,9 +1,9 @@
1
1
  import { NxJsonConfiguration, TargetDependencies } from '../../config/nx-json';
2
2
  import { ProjectGraph } from '../../config/project-graph';
3
3
  import { TaskGraph } from '../../config/task-graph';
4
- import { type IoSnapshots } from '../../native';
5
- import { type IoSnapshotOutcome } from '../../io-snapshots/store';
6
- import type { IoSnapshotVersion } from '../../daemon/message-types/io-snapshot-version';
4
+ import { type UltracacheConfigurations } from '../../native';
5
+ import { type UltracacheConfigurationOutcome } from '../../ultracache/store';
6
+ import type { UltracacheConfigurationVersion } from '../../daemon/message-types/ultracache-configuration-version';
7
7
  import { FileChange } from '../file-utils';
8
8
  import type { NxArgs } from '../../utils/command-line-utils';
9
9
  import { TaskPlanningContext } from '../../hasher/task-planning-context';
@@ -42,8 +42,8 @@ export interface ComputeAffectedTasksOptions {
42
42
  /** `--exclude` project patterns. Their tasks leave the selection but still carry a change and run as dependencies. */
43
43
  exclude?: string[];
44
44
  packageJson?: any;
45
- /** This command's I/O snapshot set. Selection plans with it, as the run hashes with it. */
46
- ioSnapshotOutcome?: IoSnapshotOutcome | null;
45
+ /** This command's Ultracache configurations. Selection plans with them, as the run hashes with them. */
46
+ ultracacheConfigurationOutcome?: UltracacheConfigurationOutcome | null;
47
47
  selectivelyHashTsConfig?: boolean;
48
48
  }
49
49
  export type FileChangeArgs = Pick<NxArgs, 'base' | 'head' | 'files'>;
@@ -61,7 +61,7 @@ export interface AffectedTasksRequest {
61
61
  extraTargetDependencies: TargetDependencies;
62
62
  excludeTaskDependencies: boolean;
63
63
  exclude: string[];
64
- ioSnapshots?: IoSnapshotVersion;
64
+ ultracacheConfigurationsVersion?: UltracacheConfigurationVersion;
65
65
  /** The runner's `selectivelyHashTsConfig`, which decides what the tsconfig hash reads. */
66
66
  selectivelyHashTsConfig?: boolean;
67
67
  }
@@ -76,13 +76,14 @@ export interface AffectedTasksRequest {
76
76
  export declare function computeAffectedTasks(opts: ComputeAffectedTasksOptions): Promise<AffectedTasksResult>;
77
77
  /**
78
78
  * Plans the targets' full task graph and matches the changed paths against
79
- * every plan. No project-level prefilter: under an I/O snapshot a task can read
80
- * files no affected project owns. Shared by the client and the daemon.
79
+ * every plan. No project-level prefilter: under Ultracache configurations a
80
+ * task can read files no affected project owns. Shared by the client and the
81
+ * daemon.
81
82
  */
82
- export declare function selectAffectedTasks(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration, planningContext: TaskPlanningContext, request: AffectedTasksRequest, { touchedFiles, packageJson, ioSnapshots, }?: {
83
+ export declare function selectAffectedTasks(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration, planningContext: TaskPlanningContext, request: AffectedTasksRequest, { touchedFiles, packageJson, ultracacheConfigurations, }?: {
83
84
  touchedFiles?: FileChange[];
84
85
  packageJson?: any;
85
- ioSnapshots?: IoSnapshots;
86
+ ultracacheConfigurations?: UltracacheConfigurations;
86
87
  }): Promise<{
87
88
  affectedTaskIds: Set<string>;
88
89
  taskGraph: TaskGraph;