nx 18.3.1 → 18.3.2

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 (31) hide show
  1. package/.eslintrc.json +4 -0
  2. package/bin/nx.js +7 -19
  3. package/package.json +12 -12
  4. package/src/command-line/add/add.js +3 -1
  5. package/src/command-line/add/command-object.d.ts +1 -0
  6. package/src/command-line/add/command-object.js +6 -1
  7. package/src/command-line/init/implementation/react/check-for-uncommitted-changes.js +6 -3
  8. package/src/daemon/cache.js +18 -0
  9. package/src/daemon/client/client.js +3 -4
  10. package/src/daemon/server/handle-hash-tasks.js +2 -2
  11. package/src/daemon/server/project-graph-incremental-recomputation.js +1 -2
  12. package/src/daemon/socket-utils.js +2 -2
  13. package/src/native/index.d.ts +1 -4
  14. package/src/native/index.js +67 -259
  15. package/src/native/native-bindings.js +268 -0
  16. package/src/native/transform-objects.js +1 -0
  17. package/src/project-graph/error-types.d.ts +27 -1
  18. package/src/project-graph/error-types.js +52 -1
  19. package/src/project-graph/plugins/isolation/index.js +8 -4
  20. package/src/project-graph/plugins/isolation/plugin-pool.d.ts +1 -1
  21. package/src/project-graph/plugins/isolation/plugin-pool.js +4 -10
  22. package/src/project-graph/project-graph.d.ts +2 -24
  23. package/src/project-graph/project-graph.js +11 -52
  24. package/src/project-graph/utils/retrieve-workspace-files.d.ts +3 -3
  25. package/src/tasks-runner/init-tasks-runner.js +2 -0
  26. package/src/tasks-runner/task-orchestrator.js +47 -29
  27. package/src/utils/dotenv.d.ts +7 -0
  28. package/src/utils/dotenv.js +22 -0
  29. package/src/utils/params.js +20 -17
  30. package/src/daemon/daemon-project-graph-error.d.ts +0 -8
  31. package/src/daemon/daemon-project-graph-error.js +0 -13
package/.eslintrc.json CHANGED
@@ -25,6 +25,10 @@
25
25
  {
26
26
  "group": ["nx/*"],
27
27
  "message": "Circular import in 'nx' found. Use relative path."
28
+ },
29
+ {
30
+ "group": ["**/native-bindings", "**/native-bindings.js"],
31
+ "message": "Direct imports from native-bindings.js are not allowed. Import from index.js instead."
28
32
  }
29
33
  ]
30
34
  }
package/bin/nx.js CHANGED
@@ -3,8 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const find_workspace_root_1 = require("../src/utils/find-workspace-root");
5
5
  const chalk = require("chalk");
6
- const dotenv_1 = require("dotenv");
7
- const dotenv_expand_1 = require("dotenv-expand");
6
+ const dotenv_1 = require("../src/utils/dotenv");
8
7
  const init_local_1 = require("./init-local");
9
8
  const output_1 = require("../src/utils/output");
10
9
  const installation_directory_1 = require("../src/utils/installation-directory");
@@ -20,15 +19,18 @@ const client_1 = require("../src/daemon/client/client");
20
19
  function main() {
21
20
  if (process.argv[2] !== 'report' &&
22
21
  process.argv[2] !== '--version' &&
23
- process.argv[2] !== '--help') {
22
+ process.argv[2] !== '--help' &&
23
+ process.argv[2] !== 'reset') {
24
24
  (0, assert_supported_platform_1.assertSupportedPlatform)();
25
25
  }
26
26
  require('nx/src/utils/perf-logging');
27
+ const workspace = (0, find_workspace_root_1.findWorkspaceRoot)(process.cwd());
27
28
  perf_hooks_1.performance.mark('loading dotenv files:start');
28
- loadDotEnvFiles();
29
+ if (workspace) {
30
+ (0, dotenv_1.loadRootEnvFiles)(workspace.dir);
31
+ }
29
32
  perf_hooks_1.performance.mark('loading dotenv files:end');
30
33
  perf_hooks_1.performance.measure('loading dotenv files', 'loading dotenv files:start', 'loading dotenv files:end');
31
- const workspace = (0, find_workspace_root_1.findWorkspaceRoot)(process.cwd());
32
34
  // new is a special case because there is no local workspace to load
33
35
  if (process.argv[2] === 'new' ||
34
36
  process.argv[2] === '_migrate' ||
@@ -81,20 +83,6 @@ function main() {
81
83
  }
82
84
  }
83
85
  }
84
- /**
85
- * This loads dotenv files from:
86
- * - .env
87
- * - .local.env
88
- * - .env.local
89
- */
90
- function loadDotEnvFiles() {
91
- for (const file of ['.local.env', '.env.local', '.env']) {
92
- const myEnv = (0, dotenv_1.config)({
93
- path: file,
94
- });
95
- (0, dotenv_expand_1.expand)(myEnv);
96
- }
97
- }
98
86
  function handleNoWorkspace(globalNxVersion) {
99
87
  output_1.output.log({
100
88
  title: `The current directory isn't part of an Nx workspace.`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "18.3.1",
3
+ "version": "18.3.2",
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": {
@@ -66,7 +66,7 @@
66
66
  "yargs-parser": "21.1.1",
67
67
  "node-machine-id": "1.1.12",
68
68
  "ora": "5.3.0",
69
- "@nrwl/tao": "18.3.1"
69
+ "@nrwl/tao": "18.3.2"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@swc-node/register": "^1.8.0",
@@ -81,16 +81,16 @@
81
81
  }
82
82
  },
83
83
  "optionalDependencies": {
84
- "@nx/nx-darwin-x64": "18.3.1",
85
- "@nx/nx-darwin-arm64": "18.3.1",
86
- "@nx/nx-linux-x64-gnu": "18.3.1",
87
- "@nx/nx-linux-x64-musl": "18.3.1",
88
- "@nx/nx-win32-x64-msvc": "18.3.1",
89
- "@nx/nx-linux-arm64-gnu": "18.3.1",
90
- "@nx/nx-linux-arm64-musl": "18.3.1",
91
- "@nx/nx-linux-arm-gnueabihf": "18.3.1",
92
- "@nx/nx-win32-arm64-msvc": "18.3.1",
93
- "@nx/nx-freebsd-x64": "18.3.1"
84
+ "@nx/nx-darwin-x64": "18.3.2",
85
+ "@nx/nx-darwin-arm64": "18.3.2",
86
+ "@nx/nx-linux-x64-gnu": "18.3.2",
87
+ "@nx/nx-linux-x64-musl": "18.3.2",
88
+ "@nx/nx-win32-x64-msvc": "18.3.2",
89
+ "@nx/nx-linux-arm64-gnu": "18.3.2",
90
+ "@nx/nx-linux-arm64-musl": "18.3.2",
91
+ "@nx/nx-linux-arm-gnueabihf": "18.3.2",
92
+ "@nx/nx-win32-arm64-msvc": "18.3.2",
93
+ "@nx/nx-freebsd-x64": "18.3.2"
94
94
  },
95
95
  "nx-migrations": {
96
96
  "migrations": "./migrations.json",
@@ -101,7 +101,9 @@ async function initializePlugin(pkgName, options) {
101
101
  process.env.NX_ADD_PLUGINS !== 'false' &&
102
102
  coreNxPlugins.includes(pkgName);
103
103
  }
104
- await (0, child_process_2.runNxAsync)(`g ${pkgName}:${initGenerator} --keepExistingVersions${updatePackageScripts ? ' --updatePackageScripts' : ''}`, {
104
+ await (0, child_process_2.runNxAsync)(`g ${pkgName}:${initGenerator} --keepExistingVersions${updatePackageScripts ? ' --updatePackageScripts' : ''}${options.__overrides_unparsed__.length
105
+ ? ' ' + options.__overrides_unparsed__.join(' ')
106
+ : ''}`, {
105
107
  silent: !options.verbose,
106
108
  });
107
109
  }
@@ -3,5 +3,6 @@ export interface AddOptions {
3
3
  packageSpecifier: string;
4
4
  updatePackageScripts?: boolean;
5
5
  verbose?: boolean;
6
+ __overrides_unparsed__: string[];
6
7
  }
7
8
  export declare const yargsAddCommand: CommandModule<Record<string, unknown>, AddOptions>;
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.yargsAddCommand = void 0;
4
+ const shared_options_1 = require("../yargs-utils/shared-options");
4
5
  exports.yargsAddCommand = {
5
6
  command: 'add <packageSpecifier>',
6
7
  describe: 'Install a plugin and initialize it.',
7
8
  builder: (yargs) => yargs
9
+ .parserConfiguration({
10
+ 'strip-dashed': true,
11
+ 'unknown-options-as-args': true,
12
+ })
8
13
  .positional('packageSpecifier', {
9
14
  type: 'string',
10
15
  description: 'The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) to install and initialize. If the version is not specified it will install the same version as the `nx` package for Nx core plugins or the latest version for other packages',
@@ -20,5 +25,5 @@ exports.yargsAddCommand = {
20
25
  .example('$0 add @nx/react', 'Install the latest version of the `@nx/react` package and run its `@nx/react:init` generator')
21
26
  .example('$0 add non-core-nx-plugin', 'Install the latest version of the `non-core-nx-plugin` package and run its `non-core-nx-plugin:init` generator if available')
22
27
  .example('$0 add @nx/react@17.0.0', 'Install version `17.0.0` of the `@nx/react` package and run its `@nx/react:init` generator'),
23
- handler: (args) => Promise.resolve().then(() => require('./add')).then((m) => m.addHandler(args)),
28
+ handler: (args) => Promise.resolve().then(() => require('./add')).then((m) => m.addHandler((0, shared_options_1.withOverrides)(args))),
24
29
  };
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkForUncommittedChanges = void 0;
4
4
  const child_process_1 = require("child_process");
5
5
  function checkForUncommittedChanges() {
6
- const gitResult = (0, child_process_1.execSync)(`git status --porcelain`);
7
- if (gitResult.length > 0) {
6
+ const gitResult = (0, child_process_1.execSync)('git status --porcelain').toString();
7
+ const filteredResults = gitResult
8
+ .split('\n')
9
+ .filter((line) => !line.includes('.nx') && line.trim().length > 0);
10
+ if (filteredResults.length > 0) {
8
11
  console.log('❗️ Careful!');
9
12
  console.log('You have uncommitted changes in your repository.');
10
13
  console.log('');
11
- console.log(gitResult.toString());
14
+ console.log(filteredResults.join('\n').toString());
12
15
  console.log('Please commit your changes before running the migrator!');
13
16
  process.exit(1);
14
17
  }
@@ -30,6 +30,24 @@ async function safelyCleanUpExistingProcess() {
30
30
  if (daemonProcessJson && daemonProcessJson.processId) {
31
31
  try {
32
32
  process.kill(daemonProcessJson.processId);
33
+ // we wait for the process to actually shut down before returning
34
+ await new Promise((resolve, reject) => {
35
+ let count = 0;
36
+ const interval = setInterval(() => {
37
+ try {
38
+ // sending a signal 0 to a process checks if the process is running instead of actually killing it
39
+ process.kill(daemonProcessJson.processId, 0);
40
+ }
41
+ catch (e) {
42
+ clearInterval(interval);
43
+ resolve();
44
+ }
45
+ if ((count += 1) > 200) {
46
+ clearInterval(interval);
47
+ reject(`Daemon process ${daemonProcessJson.processId} didn't exit after 2 seconds.`);
48
+ }
49
+ }, 10);
50
+ });
33
51
  }
34
52
  catch { }
35
53
  }
@@ -18,8 +18,7 @@ const promised_based_queue_1 = require("../../utils/promised-based-queue");
18
18
  const nx_json_1 = require("../../config/nx-json");
19
19
  const daemon_socket_messenger_1 = require("./daemon-socket-messenger");
20
20
  const cache_1 = require("../cache");
21
- const daemon_project_graph_error_1 = require("../daemon-project-graph-error");
22
- const project_graph_1 = require("../../project-graph/project-graph");
21
+ const error_types_1 = require("../../project-graph/error-types");
23
22
  const DAEMON_ENV_SETTINGS = {
24
23
  NX_PROJECT_GLOB_CACHE: 'false',
25
24
  NX_CACHE_PROJECTS_CONFIG: 'false',
@@ -101,8 +100,8 @@ class DaemonClient {
101
100
  };
102
101
  }
103
102
  catch (e) {
104
- if (e.name === daemon_project_graph_error_1.DaemonProjectGraphError.name) {
105
- throw project_graph_1.ProjectGraphError.fromDaemonProjectGraphError(e);
103
+ if (e.name === error_types_1.DaemonProjectGraphError.name) {
104
+ throw error_types_1.ProjectGraphError.fromDaemonProjectGraphError(e);
106
105
  }
107
106
  else {
108
107
  throw e;
@@ -4,7 +4,7 @@ exports.handleHashTasks = void 0;
4
4
  const project_graph_incremental_recomputation_1 = require("./project-graph-incremental-recomputation");
5
5
  const task_hasher_1 = require("../../hasher/task-hasher");
6
6
  const configuration_1 = require("../../config/configuration");
7
- const daemon_project_graph_error_1 = require("../daemon-project-graph-error");
7
+ const error_types_1 = require("../../project-graph/error-types");
8
8
  /**
9
9
  * We use this not to recreated hasher for every hash operation
10
10
  * TaskHasher has a cache inside, so keeping it around results in faster performance
@@ -15,7 +15,7 @@ async function handleHashTasks(payload) {
15
15
  const { error, projectGraph: _graph, allWorkspaceFiles, fileMap, rustReferences, } = await (0, project_graph_incremental_recomputation_1.getCachedSerializedProjectGraphPromise)();
16
16
  let projectGraph = _graph;
17
17
  if (error) {
18
- if (error instanceof daemon_project_graph_error_1.DaemonProjectGraphError) {
18
+ if (error instanceof error_types_1.DaemonProjectGraphError) {
19
19
  projectGraph = error.projectGraph;
20
20
  }
21
21
  else {
@@ -13,7 +13,6 @@ const workspace_context_1 = require("../../utils/workspace-context");
13
13
  const workspace_root_1 = require("../../utils/workspace-root");
14
14
  const file_watcher_sockets_1 = require("./file-watching/file-watcher-sockets");
15
15
  const logger_1 = require("./logger");
16
- const daemon_project_graph_error_1 = require("../daemon-project-graph-error");
17
16
  const plugins_1 = require("./plugins");
18
17
  const error_types_1 = require("../../project-graph/error-types");
19
18
  let cachedSerializedProjectGraphPromise;
@@ -180,7 +179,7 @@ async function processFilesAndCreateAndSerializeProjectGraph(plugins) {
180
179
  }
181
180
  if (errors.length > 0) {
182
181
  return {
183
- error: new daemon_project_graph_error_1.DaemonProjectGraphError(errors, g.projectGraph, graphNodes.sourceMaps),
182
+ error: new error_types_1.DaemonProjectGraphError(errors, g.projectGraph, graphNodes.sourceMaps),
184
183
  projectGraph: null,
185
184
  projectFileMapCache: null,
186
185
  fileMap: null,
@@ -5,7 +5,7 @@ const fs_1 = require("fs");
5
5
  const os_1 = require("os");
6
6
  const path_1 = require("path");
7
7
  const tmp_dir_1 = require("./tmp-dir");
8
- const daemon_project_graph_error_1 = require("./daemon-project-graph-error");
8
+ const error_types_1 = require("../project-graph/error-types");
9
9
  exports.isWindows = (0, os_1.platform)() === 'win32';
10
10
  /**
11
11
  * For IPC with the daemon server we use unix sockets or windows named pipes, depending on the user's operating system.
@@ -33,7 +33,7 @@ function serializeError(error) {
33
33
  if (!error) {
34
34
  return null;
35
35
  }
36
- if (error instanceof daemon_project_graph_error_1.DaemonProjectGraphError) {
36
+ if (error instanceof error_types_1.DaemonProjectGraphError) {
37
37
  error.errors = error.errors.map((e) => JSON.parse(serializeError(e)));
38
38
  }
39
39
  return `{${Object.getOwnPropertyNames(error)
@@ -29,11 +29,8 @@ export function findImports(projectFileMap: Record<string, Array<string>>): Arra
29
29
  * This wont be needed once the project graph is created in Rust
30
30
  */
31
31
  export function transferProjectGraph(projectGraph: ProjectGraph): ExternalObject<ProjectGraph>
32
- export interface ExternalNodeData {
33
- version: string
34
- hash?: string
35
- }
36
32
  export interface ExternalNode {
33
+ packageName?: string
37
34
  version: string
38
35
  hash?: string
39
36
  }
@@ -1,268 +1,76 @@
1
- const { existsSync, readFileSync } = require('fs')
2
- const { join } = require('path')
1
+ const { join, basename } = require('path');
2
+ const { copyFileSync, existsSync, mkdirSync } = require('fs');
3
+ const Module = require('module');
4
+ const { nxVersion } = require('../utils/versions');
5
+ const { cacheDir } = require('../utils/cache-directory');
3
6
 
4
- const { platform, arch } = process
7
+ const nxPackages = new Set([
8
+ '@nx/nx-android-arm64',
9
+ '@nx/nx-android-arm-eabi',
10
+ '@nx/nx-win32-x64-msvc',
11
+ '@nx/nx-win32-ia32-msvc',
12
+ '@nx/nx-win32-arm64-msvc',
13
+ '@nx/nx-darwin-universal',
14
+ '@nx/nx-darwin-x64',
15
+ '@nx/nx-darwin-arm64',
16
+ '@nx/nx-freebsd-x64',
17
+ '@nx/nx-linux-x64-musl',
18
+ '@nx/nx-linux-x64-gnu',
19
+ '@nx/nx-linux-arm64-musl',
20
+ '@nx/nx-linux-arm64-gnu',
21
+ '@nx/nx-linux-arm-gnueabihf',
22
+ ]);
5
23
 
6
- let nativeBinding = null
7
- let localFileExisted = false
8
- let loadError = null
24
+ const localNodeFiles = [
25
+ 'nx.android-arm64.node',
26
+ 'nx.android-arm-eabi.node',
27
+ 'nx.win32-x64-msvc.node',
28
+ 'nx.win32-ia32-msvc.node',
29
+ 'nx.win32-arm64-msvc.node',
30
+ 'nx.darwin-universal.node',
31
+ 'nx.darwin-x64.node',
32
+ 'nx.darwin-arm64.node',
33
+ 'nx.freebsd-x64.node',
34
+ 'nx.linux-x64-musl.node',
35
+ 'nx.linux-x64-gnu.node',
36
+ 'nx.linux-arm64-musl.node',
37
+ 'nx.linux-arm64-gnu.node',
38
+ 'nx.linux-arm-gnueabihf.node',
39
+ ];
9
40
 
10
- function isMusl() {
11
- // For Node 10
12
- if (!process.report || typeof process.report.getReport !== 'function') {
13
- try {
14
- const lddPath = require('child_process').execSync('which ldd').toString().trim();
15
- return readFileSync(lddPath, 'utf8').includes('musl')
16
- } catch (e) {
17
- return true
18
- }
19
- } else {
20
- const { glibcVersionRuntime } = process.report.getReport().header
21
- return !glibcVersionRuntime
22
- }
23
- }
41
+ const originalLoad = Module._load;
24
42
 
25
- switch (platform) {
26
- case 'android':
27
- switch (arch) {
28
- case 'arm64':
29
- localFileExisted = existsSync(join(__dirname, 'nx.android-arm64.node'))
30
- try {
31
- if (localFileExisted) {
32
- nativeBinding = require('./nx.android-arm64.node')
33
- } else {
34
- nativeBinding = require('@nx/nx-android-arm64')
35
- }
36
- } catch (e) {
37
- loadError = e
38
- }
39
- break
40
- case 'arm':
41
- localFileExisted = existsSync(join(__dirname, 'nx.android-arm-eabi.node'))
42
- try {
43
- if (localFileExisted) {
44
- nativeBinding = require('./nx.android-arm-eabi.node')
45
- } else {
46
- nativeBinding = require('@nx/nx-android-arm-eabi')
47
- }
48
- } catch (e) {
49
- loadError = e
50
- }
51
- break
52
- default:
53
- throw new Error(`Unsupported architecture on Android ${arch}`)
54
- }
55
- break
56
- case 'win32':
57
- switch (arch) {
58
- case 'x64':
59
- localFileExisted = existsSync(
60
- join(__dirname, 'nx.win32-x64-msvc.node')
61
- )
62
- try {
63
- if (localFileExisted) {
64
- nativeBinding = require('./nx.win32-x64-msvc.node')
65
- } else {
66
- nativeBinding = require('@nx/nx-win32-x64-msvc')
67
- }
68
- } catch (e) {
69
- loadError = e
70
- }
71
- break
72
- case 'ia32':
73
- localFileExisted = existsSync(
74
- join(__dirname, 'nx.win32-ia32-msvc.node')
75
- )
76
- try {
77
- if (localFileExisted) {
78
- nativeBinding = require('./nx.win32-ia32-msvc.node')
79
- } else {
80
- nativeBinding = require('@nx/nx-win32-ia32-msvc')
81
- }
82
- } catch (e) {
83
- loadError = e
84
- }
85
- break
86
- case 'arm64':
87
- localFileExisted = existsSync(
88
- join(__dirname, 'nx.win32-arm64-msvc.node')
89
- )
90
- try {
91
- if (localFileExisted) {
92
- nativeBinding = require('./nx.win32-arm64-msvc.node')
93
- } else {
94
- nativeBinding = require('@nx/nx-win32-arm64-msvc')
95
- }
96
- } catch (e) {
97
- loadError = e
98
- }
99
- break
100
- default:
101
- throw new Error(`Unsupported architecture on Windows: ${arch}`)
102
- }
103
- break
104
- case 'darwin':
105
- localFileExisted = existsSync(join(__dirname, 'nx.darwin-universal.node'))
106
- try {
107
- if (localFileExisted) {
108
- nativeBinding = require('./nx.darwin-universal.node')
109
- } else {
110
- nativeBinding = require('@nx/nx-darwin-universal')
111
- }
112
- break
113
- } catch {}
114
- switch (arch) {
115
- case 'x64':
116
- localFileExisted = existsSync(join(__dirname, 'nx.darwin-x64.node'))
117
- try {
118
- if (localFileExisted) {
119
- nativeBinding = require('./nx.darwin-x64.node')
120
- } else {
121
- nativeBinding = require('@nx/nx-darwin-x64')
122
- }
123
- } catch (e) {
124
- loadError = e
125
- }
126
- break
127
- case 'arm64':
128
- localFileExisted = existsSync(
129
- join(__dirname, 'nx.darwin-arm64.node')
130
- )
131
- try {
132
- if (localFileExisted) {
133
- nativeBinding = require('./nx.darwin-arm64.node')
134
- } else {
135
- nativeBinding = require('@nx/nx-darwin-arm64')
136
- }
137
- } catch (e) {
138
- loadError = e
139
- }
140
- break
141
- default:
142
- throw new Error(`Unsupported architecture on macOS: ${arch}`)
43
+ // We override the _load function so that when a native file is required,
44
+ // we copy it to a cache directory and require it from there.
45
+ // This prevents the file being loaded from node_modules and causing file locking issues.
46
+ // Will only be called once because the require cache takes over afterwards.
47
+ Module._load = function (request, parent, isMain) {
48
+ const modulePath = request;
49
+ if (
50
+ nxPackages.has(modulePath) ||
51
+ localNodeFiles.some((f) => modulePath.endsWith(f))
52
+ ) {
53
+ const nativeLocation = require.resolve(modulePath);
54
+ const fileName = basename(nativeLocation);
55
+ // we copy the file to the cache directory (.nx/cache by default) and prefix with nxVersion to avoid stale files being loaded
56
+ const tmpFile = join(cacheDir, nxVersion + '-' + fileName);
57
+ if (existsSync(tmpFile)) {
58
+ return originalLoad.apply(this, [tmpFile, parent, isMain]);
143
59
  }
144
- break
145
- case 'freebsd':
146
- if (arch !== 'x64') {
147
- throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
60
+ if (!existsSync(cacheDir)) {
61
+ mkdirSync(cacheDir, { recursive: true });
148
62
  }
149
- localFileExisted = existsSync(join(__dirname, 'nx.freebsd-x64.node'))
150
- try {
151
- if (localFileExisted) {
152
- nativeBinding = require('./nx.freebsd-x64.node')
153
- } else {
154
- nativeBinding = require('@nx/nx-freebsd-x64')
155
- }
156
- } catch (e) {
157
- loadError = e
158
- }
159
- break
160
- case 'linux':
161
- switch (arch) {
162
- case 'x64':
163
- if (isMusl()) {
164
- localFileExisted = existsSync(
165
- join(__dirname, 'nx.linux-x64-musl.node')
166
- )
167
- try {
168
- if (localFileExisted) {
169
- nativeBinding = require('./nx.linux-x64-musl.node')
170
- } else {
171
- nativeBinding = require('@nx/nx-linux-x64-musl')
172
- }
173
- } catch (e) {
174
- loadError = e
175
- }
176
- } else {
177
- localFileExisted = existsSync(
178
- join(__dirname, 'nx.linux-x64-gnu.node')
179
- )
180
- try {
181
- if (localFileExisted) {
182
- nativeBinding = require('./nx.linux-x64-gnu.node')
183
- } else {
184
- nativeBinding = require('@nx/nx-linux-x64-gnu')
185
- }
186
- } catch (e) {
187
- loadError = e
188
- }
189
- }
190
- break
191
- case 'arm64':
192
- if (isMusl()) {
193
- localFileExisted = existsSync(
194
- join(__dirname, 'nx.linux-arm64-musl.node')
195
- )
196
- try {
197
- if (localFileExisted) {
198
- nativeBinding = require('./nx.linux-arm64-musl.node')
199
- } else {
200
- nativeBinding = require('@nx/nx-linux-arm64-musl')
201
- }
202
- } catch (e) {
203
- loadError = e
204
- }
205
- } else {
206
- localFileExisted = existsSync(
207
- join(__dirname, 'nx.linux-arm64-gnu.node')
208
- )
209
- try {
210
- if (localFileExisted) {
211
- nativeBinding = require('./nx.linux-arm64-gnu.node')
212
- } else {
213
- nativeBinding = require('@nx/nx-linux-arm64-gnu')
214
- }
215
- } catch (e) {
216
- loadError = e
217
- }
218
- }
219
- break
220
- case 'arm':
221
- localFileExisted = existsSync(
222
- join(__dirname, 'nx.linux-arm-gnueabihf.node')
223
- )
224
- try {
225
- if (localFileExisted) {
226
- nativeBinding = require('./nx.linux-arm-gnueabihf.node')
227
- } else {
228
- nativeBinding = require('@nx/nx-linux-arm-gnueabihf')
229
- }
230
- } catch (e) {
231
- loadError = e
232
- }
233
- break
234
- default:
235
- throw new Error(`Unsupported architecture on Linux: ${arch}`)
236
- }
237
- break
238
- default:
239
- throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
240
- }
241
-
242
- if (!nativeBinding) {
243
- if (loadError) {
244
- throw loadError
63
+ copyFileSync(nativeLocation, tmpFile);
64
+ return originalLoad.apply(this, [tmpFile, parent, isMain]);
65
+ } else {
66
+ // call the original _load function for everything else
67
+ return originalLoad.apply(this, arguments);
245
68
  }
246
- throw new Error(`Failed to load native binding`)
247
- }
69
+ };
248
70
 
249
- const { expandOutputs, getFilesForOutputs, remove, copy, hashArray, hashFile, ImportResult, findImports, transferProjectGraph, ChildProcess, RustPseudoTerminal, HashPlanner, TaskHasher, EventType, Watcher, WorkspaceContext, WorkspaceErrors, testOnlyTransferFileMap } = nativeBinding
71
+ const indexModulePath = require.resolve('./native-bindings.js');
72
+ delete require.cache[indexModulePath];
73
+ const indexModule = require('./native-bindings.js');
250
74
 
251
- module.exports.expandOutputs = expandOutputs
252
- module.exports.getFilesForOutputs = getFilesForOutputs
253
- module.exports.remove = remove
254
- module.exports.copy = copy
255
- module.exports.hashArray = hashArray
256
- module.exports.hashFile = hashFile
257
- module.exports.ImportResult = ImportResult
258
- module.exports.findImports = findImports
259
- module.exports.transferProjectGraph = transferProjectGraph
260
- module.exports.ChildProcess = ChildProcess
261
- module.exports.RustPseudoTerminal = RustPseudoTerminal
262
- module.exports.HashPlanner = HashPlanner
263
- module.exports.TaskHasher = TaskHasher
264
- module.exports.EventType = EventType
265
- module.exports.Watcher = Watcher
266
- module.exports.WorkspaceContext = WorkspaceContext
267
- module.exports.WorkspaceErrors = WorkspaceErrors
268
- module.exports.testOnlyTransferFileMap = testOnlyTransferFileMap
75
+ module.exports = indexModule;
76
+ Module._load = originalLoad;