nx 22.7.0-beta.14 → 22.7.0-beta.16

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/dist/bin/nx.js CHANGED
@@ -10,8 +10,6 @@ if (process.env.FORCE_COLOR === '0') {
10
10
  }
11
11
  const find_workspace_root_1 = require("../src/utils/find-workspace-root");
12
12
  const pc = tslib_1.__importStar(require("picocolors"));
13
- const dotenv_1 = require("../src/utils/dotenv");
14
- const init_local_1 = require("./init-local");
15
13
  const output_1 = require("../src/utils/output");
16
14
  const installation_directory_1 = require("../src/utils/installation-directory");
17
15
  const semver_1 = require("semver");
@@ -20,13 +18,11 @@ const child_process_1 = require("child_process");
20
18
  const module_1 = require("module");
21
19
  const path_1 = require("path");
22
20
  const fs_1 = require("fs");
23
- const assert_supported_platform_1 = require("../src/native/assert-supported-platform");
24
21
  const perf_hooks_1 = require("perf_hooks");
25
- const workspace_context_1 = require("../src/utils/workspace-context");
26
- const client_1 = require("../src/daemon/client/client");
27
- const db_connection_1 = require("../src/utils/db-connection");
28
- const analytics_prompt_1 = require("../src/utils/analytics-prompt");
29
- const analytics_1 = require("../src/analytics");
22
+ // Register the performance observer as early as possible so any
23
+ // `performance.mark` / `measure` anywhere downstream is captured. The module
24
+ // is side-effect only and its heavy deps (analytics, daemon logger) are
25
+ // lazy-loaded inside the observer callback, so the import itself is cheap.
30
26
  require("../src/utils/perf-logging");
31
27
  const isTsExt = (0, path_1.extname)(__filename).endsWith('.ts');
32
28
  const pathToPkgJson = isTsExt ? '../package.json' : '../../package.json';
@@ -35,12 +31,16 @@ async function main() {
35
31
  process.argv[2] !== '--version' &&
36
32
  process.argv[2] !== '--help' &&
37
33
  process.argv[2] !== 'reset') {
38
- (0, assert_supported_platform_1.assertSupportedPlatform)();
34
+ const { assertSupportedPlatform } = await import('../src/native/assert-supported-platform.js');
35
+ assertSupportedPlatform();
39
36
  }
40
37
  const workspace = (0, find_workspace_root_1.findWorkspaceRoot)(process.cwd());
41
- if (workspace) {
38
+ // --version doesn't need any env / daemon / analytics state — skip dotenv
39
+ // loading (and the heavy modules it would pull in).
40
+ if (workspace && process.argv[2] !== '--version') {
41
+ const { loadRootEnvFiles } = await import('../src/utils/dotenv.js');
42
42
  perf_hooks_1.performance.mark('loading dotenv files:start');
43
- (0, dotenv_1.loadRootEnvFiles)(workspace.dir);
43
+ loadRootEnvFiles(workspace.dir);
44
44
  perf_hooks_1.performance.mark('loading dotenv files:end');
45
45
  perf_hooks_1.performance.measure('loading dotenv files', 'loading dotenv files:start', 'loading dotenv files:end');
46
46
  }
@@ -51,7 +51,7 @@ async function main() {
51
51
  process.argv[2] === 'configure-ai-agents' ||
52
52
  (process.argv[2] === 'graph' && !workspace)) {
53
53
  process.env.NX_DAEMON = 'false';
54
- require('nx/src/command-line/nx-commands').commandsObject.argv;
54
+ (await import('nx/src/command-line/nx-commands')).commandsObject.argv;
55
55
  }
56
56
  else {
57
57
  // polyfill rxjs observable to avoid issues with multiple version of Observable installed in node_modules
@@ -79,20 +79,25 @@ async function main() {
79
79
  }
80
80
  // this file is already in the local workspace
81
81
  if (isNxCloudCommand(process.argv[2])) {
82
- if (!client_1.daemonClient.enabled() && workspace !== null) {
83
- (0, workspace_context_1.setupWorkspaceContext)(workspace.dir);
82
+ const { daemonClient } = await import('../src/daemon/client/client.js');
83
+ if (!daemonClient.enabled() && workspace !== null) {
84
+ const { setupWorkspaceContext } = await import('../src/utils/workspace-context.js');
85
+ setupWorkspaceContext(workspace.dir);
84
86
  }
85
87
  await initAnalytics();
86
88
  // nx-cloud commands can run without local Nx installation
87
89
  process.env.NX_DAEMON = 'false';
88
- require('nx/src/command-line/nx-commands').commandsObject.argv;
90
+ (await import('nx/src/command-line/nx-commands')).commandsObject.argv;
89
91
  }
90
92
  else if (isLocalInstall) {
91
- if (!client_1.daemonClient.enabled() && workspace !== null) {
92
- (0, workspace_context_1.setupWorkspaceContext)(workspace.dir);
93
+ const { daemonClient } = await import('../src/daemon/client/client.js');
94
+ if (!daemonClient.enabled() && workspace !== null) {
95
+ const { setupWorkspaceContext } = await import('../src/utils/workspace-context.js');
96
+ setupWorkspaceContext(workspace.dir);
93
97
  }
94
98
  await initAnalytics();
95
- await (0, init_local_1.initLocal)(workspace);
99
+ const { initLocal } = await import('./init-local.js');
100
+ await initLocal(workspace);
96
101
  }
97
102
  else if (localNx) {
98
103
  // Nx is being run from globally installed CLI - hand off to the local
@@ -101,10 +106,10 @@ async function main() {
101
106
  warnIfUsingOutdatedGlobalInstall(GLOBAL_NX_VERSION, LOCAL_NX_VERSION);
102
107
  if (localNx.includes('.nx')) {
103
108
  const nxWrapperPath = localNx.replace(/\.nx.*/, '.nx/') + 'nxw.js';
104
- require(nxWrapperPath);
109
+ await import(nxWrapperPath);
105
110
  }
106
111
  else {
107
- require(localNx);
112
+ await import(localNx);
108
113
  }
109
114
  }
110
115
  }
@@ -177,12 +182,16 @@ function isNxCloudCommand(command) {
177
182
  ];
178
183
  return nxCloudCommands.includes(command);
179
184
  }
185
+ let analyticsStarted = false;
180
186
  async function initAnalytics() {
187
+ const { ensureAnalyticsPreferenceSet } = await import('../src/utils/analytics-prompt.js');
188
+ const { startAnalytics } = await import('../src/analytics/index.js');
181
189
  try {
182
- await (0, analytics_prompt_1.ensureAnalyticsPreferenceSet)();
190
+ await ensureAnalyticsPreferenceSet();
183
191
  }
184
192
  catch { }
185
- await (0, analytics_1.startAnalytics)();
193
+ await startAnalytics();
194
+ analyticsStarted = true;
186
195
  }
187
196
  function handleMissingLocalInstallation(detectedWorkspaceRoot) {
188
197
  output_1.output.error({
@@ -279,11 +288,13 @@ const getLatestVersionOfNx = ((fn) => {
279
288
  let cache = null;
280
289
  return () => cache || (cache = fn());
281
290
  })(_getLatestVersionOfNx);
282
- process.on('exit', () => {
283
- (0, db_connection_1.removeDbConnections)();
284
- });
285
- main().catch((error) => {
291
+ main().catch(async (error) => {
286
292
  console.error(error);
287
- (0, analytics_1.flushAnalytics)();
293
+ if (analyticsStarted) {
294
+ // analyticsStarted implies '../src/analytics' is already in the module
295
+ // cache, so this resolves from cache without any disk work.
296
+ const { flushAnalytics } = await import('../src/analytics/index.js');
297
+ flushAnalytics();
298
+ }
288
299
  process.exit(1);
289
300
  });