nx 23.2.0-beta.5 → 23.2.0-beta.7

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 (51) hide show
  1. package/dist/src/command-line/init/init-v2.js +2 -0
  2. package/dist/src/command-line/migrate/migrate.js +44 -27
  3. package/dist/src/command-line/migrate/version-skew-guard.d.ts +3 -4
  4. package/dist/src/command-line/migrate/version-skew-guard.js +5 -6
  5. package/dist/src/command-line/reset/reset.js +6 -1
  6. package/dist/src/command-line/run/run-one.js +1 -0
  7. package/dist/src/command-line/run-many/run-many.js +1 -0
  8. package/dist/src/core/graph/main.js +1 -1
  9. package/dist/src/core/graph/styles.js +1 -1
  10. package/dist/src/daemon/client/client.d.ts +45 -1
  11. package/dist/src/daemon/client/client.js +128 -32
  12. package/dist/src/daemon/client/daemon-socket-messenger.js +4 -0
  13. package/dist/src/daemon/message-types/daemon-message.d.ts +32 -0
  14. package/dist/src/daemon/message-types/daemon-message.js +25 -0
  15. package/dist/src/daemon/server/server.js +22 -0
  16. package/dist/src/daemon/server/shutdown-utils.d.ts +5 -0
  17. package/dist/src/daemon/server/shutdown-utils.js +11 -4
  18. package/dist/src/daemon/socket-utils.d.ts +1 -0
  19. package/dist/src/daemon/socket-utils.js +24 -3
  20. package/dist/src/daemon/tmp-dir.d.ts +43 -3
  21. package/dist/src/daemon/tmp-dir.js +437 -15
  22. package/dist/src/devkit-internals.d.ts +2 -1
  23. package/dist/src/devkit-internals.js +14 -5
  24. package/dist/src/generators/tree.d.ts +4 -2
  25. package/dist/src/native/index.d.ts +10 -0
  26. package/dist/src/native/index.js +71 -28
  27. package/dist/src/native/native-bindings.js +1 -0
  28. package/dist/src/native/native-file-cache-location.d.ts +17 -1
  29. package/dist/src/native/native-file-cache-location.js +86 -12
  30. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  31. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  32. package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +1 -0
  33. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +18 -1
  34. package/dist/src/project-graph/plugins/isolation/messaging.d.ts +16 -3
  35. package/dist/src/project-graph/plugins/isolation/messaging.js +3 -0
  36. package/dist/src/project-graph/plugins/isolation/plugin-worker.js +58 -8
  37. package/dist/src/project-graph/project-graph.js +20 -0
  38. package/dist/src/utils/child-process.d.ts +31 -1
  39. package/dist/src/utils/child-process.js +102 -1
  40. package/dist/src/utils/ignore.d.ts +128 -1
  41. package/dist/src/utils/ignore.js +182 -12
  42. package/dist/src/utils/nx-tmp-dir.d.ts +18 -0
  43. package/dist/src/utils/nx-tmp-dir.js +40 -0
  44. package/dist/src/utils/owned-private-dir.d.ts +132 -0
  45. package/dist/src/utils/owned-private-dir.js +323 -0
  46. package/dist/src/utils/plugins/core-plugins.js +4 -0
  47. package/dist/src/utils/shell-quoting.d.ts +15 -0
  48. package/dist/src/utils/shell-quoting.js +35 -0
  49. package/dist/src/utils/wait-for-socket-connection.d.ts +11 -0
  50. package/dist/src/utils/wait-for-socket-connection.js +14 -8
  51. package/package.json +12 -11
@@ -401,6 +401,7 @@ async function runInit(options, baseMeta) {
401
401
  function getPluginReason(plugin) {
402
402
  const reasonMap = {
403
403
  '@nx/eslint': 'eslint detected in dependencies',
404
+ '@nx/oxlint': 'oxlint detected in dependencies',
404
405
  '@nx/storybook': 'storybook detected in dependencies',
405
406
  '@nx/vite': 'vite detected in dependencies',
406
407
  '@nx/vitest': 'vitest detected in dependencies',
@@ -448,6 +449,7 @@ function parsePluginsFlag(value) {
448
449
  const npmPackageToPluginMap = {
449
450
  // Generic JS tools
450
451
  eslint: '@nx/eslint',
452
+ oxlint: '@nx/oxlint',
451
453
  storybook: '@nx/storybook',
452
454
  // Bundlers
453
455
  vite: '@nx/vite',
@@ -28,6 +28,7 @@ const util_1 = require("util");
28
28
  const fileutils_1 = require("../../utils/fileutils");
29
29
  const tar_1 = require("../../utils/tar");
30
30
  const write_formatted_json_file_1 = require("../../utils/write-formatted-json-file");
31
+ const shell_quoting_1 = require("../../utils/shell-quoting");
31
32
  const logger_1 = require("../../utils/logger");
32
33
  const git_utils_1 = require("../../utils/git-utils");
33
34
  const command_line_utils_1 = require("../../utils/command-line-utils");
@@ -1989,13 +1990,10 @@ async function executeMigrations(root, migrations, isVerbose, shouldCreateCommit
1989
1990
  retainedAtSuccess: (0, migrate_output_1.retainedMigrations)(outcomes).map((p) => `${p.package}: ${p.name}`),
1990
1991
  };
1991
1992
  }
1992
- // Forwards this invocation's raw argv to the workspace-local nx, used from
1993
- // each run path's temp-installation check (`!__dirname.startsWith(workspaceRoot)`)
1994
- // right after its gated `runInstall` pre-install. `runNxSync` resolves nx
1995
- // through the workspace's package manager at spawn time, so the child runs
1996
- // the bytes that pre-install put in place.
1993
+ // nx is located at spawn time, after the gated pre-install, so the child runs
1994
+ // the bytes that install put in place.
1997
1995
  function handOffToLocalNx(args) {
1998
- const exitCode = runOrReturnExitCode(() => (0, child_process_2.runNxSync)(`migrate ${args.join(' ')}`, {
1996
+ const exitCode = runOrReturnExitCode(() => (0, child_process_2.runNxArgvSync)(['migrate', ...args], {
1999
1997
  stdio: ['inherit', 'inherit', 'inherit'],
2000
1998
  env: {
2001
1999
  ...process.env,
@@ -2283,10 +2281,14 @@ function stringifyCaught(e) {
2283
2281
  // A resolver-based lookup (including `resolvePackageJsonWithoutCachePollution`,
2284
2282
  // which does defeat Node's package self-reference) is the wrong tool here:
2285
2283
  // resolvers fall back to NODE_PATH after the explicit paths, and NODE_PATH
2286
- // names the temp installation when this runs there, while the hand-off spawn
2287
- // locates nx through the package manager's bin lookup, which ignores
2288
- // NODE_PATH. The PnP branch below stays bespoke either way: a resolver cannot
2289
- // see into the zip cache without the PnP runtime.
2284
+ // names the temp installation when this runs there. The scan below reads its
2285
+ // candidate directories itself, so neither NODE_PATH nor self-reference can
2286
+ // reach it; `getNxBin` (utils/child-process.ts), which locates the nx the
2287
+ // hand-off spawns, avoids resolvers for the same reason, over a narrower set
2288
+ // of directories: it skips `.nx/installation`, declines a root without a
2289
+ // package.json, and stops at the nearest install rather than reading past an
2290
+ // unusable one. The PnP branch below stays bespoke either way: a resolver
2291
+ // cannot see into the zip cache without the PnP runtime.
2290
2292
  function readLocalNxVersion(root) {
2291
2293
  // A PnP manifest is consulted only when yarn drives the hand-off:
2292
2294
  // `getRunNxBaseCommand` builds the hand-off command through this same
@@ -2387,12 +2389,13 @@ function readLocalNxVersion(root) {
2387
2389
  // The workspace's own install locations first (.nx/installation, root), then
2388
2390
  // ancestor directories: package-manager executable lookup ascends (npx and
2389
2391
  // bun always, pnpm and yarn inside an outer workspace) and hoisted layouts
2390
- // install nx above the workspace root. An unrelated ancestor install the
2391
- // hand-off's spawn would not run can be read here; the guards then judge that
2392
- // version rather than failing open. A hand-off issued anyway may not fail
2393
- // visibly: yarn reports "command not found", but pnpm exec falls back to an
2394
- // nx on PATH, so the version read here is the readable answer, not
2395
- // necessarily the executed one.
2392
+ // install nx above the workspace root. `getNxBin` ascends too, so an ancestor
2393
+ // read here is usually the one the hand-off spawns. They diverge for a
2394
+ // `.nx/installation` workspace, which `getNxBin` declines, and where the only
2395
+ // nx found sits past the package manager's own lookup boundary and the spawn
2396
+ // has fallen back to that manager: yarn then reports "command not found"
2397
+ // while pnpm exec lands on an nx on PATH. The version read here is therefore
2398
+ // the readable answer, not necessarily the executed one.
2396
2399
  function scanNodeModulesForNxVersion(root) {
2397
2400
  const searchPaths = [...(0, installation_directory_1.getNxRequirePaths)(root)];
2398
2401
  for (let dir = (0, path_1.dirname)(root);; dir = (0, path_1.dirname)(dir)) {
@@ -2469,9 +2472,11 @@ async function runMigration() {
2469
2472
  // that parsed the flags, so it needs no capability check. Two lookups
2470
2473
  // can still diverge from the running install, both properties of the
2471
2474
  // spawn machinery rather than of this fallback: a `.nx/installation`
2472
- // beside a root package.json, and a spawn that misses the workspace
2473
- // install and falls back to an nx on PATH (pnpm exec).
2474
- const runLocalMigrate = () => runOrReturnExitCode(() => (0, child_process_2.runNxSync)(`_migrate ${process.argv.slice(3).join(' ')}`, {
2475
+ // beside a root package.json, and, once the spawn falls back to the
2476
+ // package manager, a lookup that misses the workspace install and lands
2477
+ // on an nx on PATH (pnpm exec).
2478
+ const forwardedArgv = process.argv.slice(3);
2479
+ const runLocalMigrate = () => runOrReturnExitCode(() => (0, child_process_2.runNxArgvSync)(['_migrate', ...forwardedArgv], {
2475
2480
  stdio: ['inherit', 'inherit', 'inherit'],
2476
2481
  }));
2477
2482
  if (process.env.NX_USE_LOCAL !== 'true' &&
@@ -2505,14 +2510,26 @@ async function runMigration() {
2505
2510
  process.env.npm_config_registry.match(/^https:\/\/registry\.(npmjs\.org|yarnpkg\.com)/)) {
2506
2511
  delete process.env.npm_config_registry;
2507
2512
  }
2508
- // Intentionally not runNxSync: `p` is an nx CLI freshly installed into a
2509
- // temp dir by nxCliPath() (latest, or NX_MIGRATE_CLI_VERSION), so
2510
- // migrations run with an up-to-date migrate implementation instead of
2511
- // the workspace's current nx.
2512
- return runOrReturnExitCode(() => (0, child_process_1.execSync)(`${p} _migrate ${process.argv.slice(3).join(' ')}`, {
2513
- stdio: ['inherit', 'inherit', 'inherit'],
2514
- windowsHide: true,
2515
- }));
2513
+ // Intentionally not the workspace's nx: `p` is an nx CLI freshly
2514
+ // installed into a temp dir by nxCliPath() (latest, or
2515
+ // NX_MIGRATE_CLI_VERSION), so migrations run with an up-to-date migrate
2516
+ // implementation. `p` is <tmpDir>/node_modules/.bin/nx, a shell shim;
2517
+ // spawning the entry point that install's own manifest names instead
2518
+ // keeps the forwarded argv out of a shell. That install declares nx
2519
+ // itself, so it is read without ascending: an nx above the temp dir is
2520
+ // one nothing asked for, and the shim below is the answer instead.
2521
+ const tempNxEntry = (0, child_process_2.readInstalledNxBin)((0, path_1.dirname)((0, path_1.dirname)((0, path_1.dirname)(p))));
2522
+ return runOrReturnExitCode(() => tempNxEntry
2523
+ ? (0, child_process_2.runNxArgvSync)(['_migrate', ...forwardedArgv], {
2524
+ stdio: ['inherit', 'inherit', 'inherit'],
2525
+ nxBin: tempNxEntry,
2526
+ })
2527
+ : (0, child_process_1.execSync)(`${(0, shell_quoting_1.quoteShellArg)(p)} _migrate ${forwardedArgv
2528
+ .map(shell_quoting_1.quoteShellArg)
2529
+ .join(' ')}`, {
2530
+ stdio: ['inherit', 'inherit', 'inherit'],
2531
+ windowsHide: true,
2532
+ }));
2516
2533
  }
2517
2534
  return runLocalMigrate();
2518
2535
  });
@@ -48,10 +48,9 @@ export declare function resolveNewMigrateFlagsRunTarget(options: {
48
48
  * because the invoking nx's version is not forwarded across hop A; the
49
49
  * refusal names the workspace update that resolves it.
50
50
  *
51
- * `readLocalNxVersion` returns undefined when no readable nx install exists
52
- * at or above the workspace root; that case does not block. The hand-off
53
- * spawns the `nx migrate` wrapper, and without an nx installation to
54
- * delegate to it exits visibly rather than running anything.
51
+ * `readLocalNxVersion` returning undefined does not block: the hand-off then
52
+ * resolves nx as it always does, which may fail visibly or land on another nx
53
+ * the package manager locates.
55
54
  */
56
55
  export declare function assertWorkspaceNxSupportsNewMigrateFlags(options: {
57
56
  argv: string[];
@@ -18,8 +18,8 @@ const version_utils_1 = require("./version-utils");
18
18
  // this floor and route to a temp CLI that drops the new flags and runs the
19
19
  // plan phase instead.
20
20
  exports.NEW_MIGRATE_FLAGS_FLOOR = '23.2.0';
21
- // yargs accepts both spellings and the raw argv is forwarded verbatim across
22
- // both migrate hops, so detection must catch each one.
21
+ // yargs accepts both spellings and the raw argv is forwarded across both
22
+ // migrate hops, so detection must catch each one.
23
23
  exports.NEW_MIGRATE_FLAGS = ['--run-migration', '--runMigration'];
24
24
  /**
25
25
  * Matches an exact token or `<flag>=<value>`. The `=` matters: a bare
@@ -132,10 +132,9 @@ async function resolveNewMigrateFlagsRunTarget(options) {
132
132
  * because the invoking nx's version is not forwarded across hop A; the
133
133
  * refusal names the workspace update that resolves it.
134
134
  *
135
- * `readLocalNxVersion` returns undefined when no readable nx install exists
136
- * at or above the workspace root; that case does not block. The hand-off
137
- * spawns the `nx migrate` wrapper, and without an nx installation to
138
- * delegate to it exits visibly rather than running anything.
135
+ * `readLocalNxVersion` returning undefined does not block: the hand-off then
136
+ * resolves nx as it always does, which may fail visibly or land on another nx
137
+ * the package manager locates.
139
138
  */
140
139
  function assertWorkspaceNxSupportsNewMigrateFlags(options) {
141
140
  const flag = findNewMigrateFlag(options.argv);
@@ -137,7 +137,12 @@ function cleanupCacheEntries() {
137
137
  }
138
138
  function cleanupNativeFileCache() {
139
139
  return incrementalBackoff(INCREMENTAL_BACKOFF_FIRST_DELAY, INCREMENTAL_BACKOFF_MAX_DURATION, () => {
140
- (0, node_fs_1.rmSync)((0, native_file_cache_location_1.getNativeFileCacheLocation)(), { recursive: true, force: true });
140
+ // Null when the native cache root is not a real directory we own, which
141
+ // would mean deleting through a path another user planted.
142
+ const cacheDir = (0, native_file_cache_location_1.getNativeFileCacheLocationToDelete)();
143
+ if (cacheDir) {
144
+ (0, node_fs_1.rmSync)(cacheDir, { recursive: true, force: true });
145
+ }
141
146
  });
142
147
  }
143
148
  function cleanupWorkspaceData() {
@@ -51,6 +51,7 @@ async function runOne(cwd, args, extraTargetDependencies = {}, extraOptions = {
51
51
  }
52
52
  else {
53
53
  const status = await (0, run_command_1.runCommand)(projects, projectGraph, { nxJson }, nxArgs, overrides, projectName, extraTargetDependencies, extraOptions);
54
+ await output_1.output.drain();
54
55
  process.exit(status);
55
56
  }
56
57
  }
@@ -41,6 +41,7 @@ async function runMany(args, extraTargetDependencies = {}, extraOptions = {
41
41
  }
42
42
  else {
43
43
  const status = await (0, run_command_1.runCommand)(projects, projectGraph, { nxJson }, nxArgs, overrides, null, extraTargetDependencies, extraOptions);
44
+ await output_1.output.drain();
44
45
  process.exit(status);
45
46
  }
46
47
  }