nx 18.3.1 → 18.4.0-canary.20240418-e549ea2

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/.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.4.0-canary.20240418-e549ea2",
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.4.0-canary.20240418-e549ea2"
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.4.0-canary.20240418-e549ea2",
85
+ "@nx/nx-darwin-arm64": "18.4.0-canary.20240418-e549ea2",
86
+ "@nx/nx-linux-x64-gnu": "18.4.0-canary.20240418-e549ea2",
87
+ "@nx/nx-linux-x64-musl": "18.4.0-canary.20240418-e549ea2",
88
+ "@nx/nx-win32-x64-msvc": "18.4.0-canary.20240418-e549ea2",
89
+ "@nx/nx-linux-arm64-gnu": "18.4.0-canary.20240418-e549ea2",
90
+ "@nx/nx-linux-arm64-musl": "18.4.0-canary.20240418-e549ea2",
91
+ "@nx/nx-linux-arm-gnueabihf": "18.4.0-canary.20240418-e549ea2",
92
+ "@nx/nx-win32-arm64-msvc": "18.4.0-canary.20240418-e549ea2",
93
+ "@nx/nx-freebsd-x64": "18.4.0-canary.20240418-e549ea2"
94
94
  },
95
95
  "nx-migrations": {
96
96
  "migrations": "./migrations.json",
@@ -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)
@@ -1,268 +1,77 @@
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
+ };
70
+
71
+ const indexModulePath = require.resolve('./native-bindings.js');
72
+ delete require.cache[indexModulePath];
73
+ const indexModule = require('./native-bindings.js');
248
74
 
249
- const { expandOutputs, getFilesForOutputs, remove, copy, hashArray, hashFile, ImportResult, findImports, transferProjectGraph, ChildProcess, RustPseudoTerminal, HashPlanner, TaskHasher, EventType, Watcher, WorkspaceContext, WorkspaceErrors, testOnlyTransferFileMap } = nativeBinding
250
75
 
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
76
+ module.exports = indexModule;
77
+ Module._load = originalLoad;
@@ -0,0 +1,290 @@
1
+ const { existsSync, readFileSync } = require('fs');
2
+ const { join } = require('path');
3
+
4
+ const { platform, arch } = process;
5
+
6
+ let nativeBinding = null;
7
+ let localFileExisted = false;
8
+ let loadError = null;
9
+
10
+ function isMusl() {
11
+ // For Node 10
12
+ if (!process.report || typeof process.report.getReport !== 'function') {
13
+ try {
14
+ const lddPath = require('child_process')
15
+ .execSync('which ldd')
16
+ .toString()
17
+ .trim();
18
+ return readFileSync(lddPath, 'utf8').includes('musl');
19
+ } catch (e) {
20
+ return true;
21
+ }
22
+ } else {
23
+ const { glibcVersionRuntime } = process.report.getReport().header;
24
+ return !glibcVersionRuntime;
25
+ }
26
+ }
27
+
28
+ switch (platform) {
29
+ case 'android':
30
+ switch (arch) {
31
+ case 'arm64':
32
+ localFileExisted = existsSync(join(__dirname, 'nx.android-arm64.node'));
33
+ try {
34
+ if (localFileExisted) {
35
+ nativeBinding = require('./nx.android-arm64.node');
36
+ } else {
37
+ nativeBinding = require('@nx/nx-android-arm64');
38
+ }
39
+ } catch (e) {
40
+ loadError = e;
41
+ }
42
+ break;
43
+ case 'arm':
44
+ localFileExisted = existsSync(
45
+ join(__dirname, 'nx.android-arm-eabi.node')
46
+ );
47
+ try {
48
+ if (localFileExisted) {
49
+ nativeBinding = require('./nx.android-arm-eabi.node');
50
+ } else {
51
+ nativeBinding = require('@nx/nx-android-arm-eabi');
52
+ }
53
+ } catch (e) {
54
+ loadError = e;
55
+ }
56
+ break;
57
+ default:
58
+ throw new Error(`Unsupported architecture on Android ${arch}`);
59
+ }
60
+ break;
61
+ case 'win32':
62
+ switch (arch) {
63
+ case 'x64':
64
+ localFileExisted = existsSync(
65
+ join(__dirname, 'nx.win32-x64-msvc.node')
66
+ );
67
+ try {
68
+ if (localFileExisted) {
69
+ nativeBinding = require('./nx.win32-x64-msvc.node');
70
+ } else {
71
+ nativeBinding = require('@nx/nx-win32-x64-msvc');
72
+ }
73
+ } catch (e) {
74
+ loadError = e;
75
+ }
76
+ break;
77
+ case 'ia32':
78
+ localFileExisted = existsSync(
79
+ join(__dirname, 'nx.win32-ia32-msvc.node')
80
+ );
81
+ try {
82
+ if (localFileExisted) {
83
+ nativeBinding = require('./nx.win32-ia32-msvc.node');
84
+ } else {
85
+ nativeBinding = require('@nx/nx-win32-ia32-msvc');
86
+ }
87
+ } catch (e) {
88
+ loadError = e;
89
+ }
90
+ break;
91
+ case 'arm64':
92
+ localFileExisted = existsSync(
93
+ join(__dirname, 'nx.win32-arm64-msvc.node')
94
+ );
95
+ try {
96
+ if (localFileExisted) {
97
+ nativeBinding = require('./nx.win32-arm64-msvc.node');
98
+ } else {
99
+ nativeBinding = require('@nx/nx-win32-arm64-msvc');
100
+ }
101
+ } catch (e) {
102
+ loadError = e;
103
+ }
104
+ break;
105
+ default:
106
+ throw new Error(`Unsupported architecture on Windows: ${arch}`);
107
+ }
108
+ break;
109
+ case 'darwin':
110
+ localFileExisted = existsSync(join(__dirname, 'nx.darwin-universal.node'));
111
+ try {
112
+ if (localFileExisted) {
113
+ nativeBinding = require('./nx.darwin-universal.node');
114
+ } else {
115
+ nativeBinding = require('@nx/nx-darwin-universal');
116
+ }
117
+ break;
118
+ } catch {}
119
+ switch (arch) {
120
+ case 'x64':
121
+ localFileExisted = existsSync(join(__dirname, 'nx.darwin-x64.node'));
122
+ try {
123
+ if (localFileExisted) {
124
+ nativeBinding = require('./nx.darwin-x64.node');
125
+ } else {
126
+ nativeBinding = require('@nx/nx-darwin-x64');
127
+ }
128
+ } catch (e) {
129
+ loadError = e;
130
+ }
131
+ break;
132
+ case 'arm64':
133
+ localFileExisted = existsSync(join(__dirname, 'nx.darwin-arm64.node'));
134
+ try {
135
+ if (localFileExisted) {
136
+ nativeBinding = require('./nx.darwin-arm64.node');
137
+ } else {
138
+ nativeBinding = require('@nx/nx-darwin-arm64');
139
+ }
140
+ } catch (e) {
141
+ loadError = e;
142
+ }
143
+ break;
144
+ default:
145
+ throw new Error(`Unsupported architecture on macOS: ${arch}`);
146
+ }
147
+ break;
148
+ case 'freebsd':
149
+ if (arch !== 'x64') {
150
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
151
+ }
152
+ localFileExisted = existsSync(join(__dirname, 'nx.freebsd-x64.node'));
153
+ try {
154
+ if (localFileExisted) {
155
+ nativeBinding = require('./nx.freebsd-x64.node');
156
+ } else {
157
+ nativeBinding = require('@nx/nx-freebsd-x64');
158
+ }
159
+ } catch (e) {
160
+ loadError = e;
161
+ }
162
+ break;
163
+ case 'linux':
164
+ switch (arch) {
165
+ case 'x64':
166
+ if (isMusl()) {
167
+ localFileExisted = existsSync(
168
+ join(__dirname, 'nx.linux-x64-musl.node')
169
+ );
170
+ try {
171
+ if (localFileExisted) {
172
+ nativeBinding = require('./nx.linux-x64-musl.node');
173
+ } else {
174
+ nativeBinding = require('@nx/nx-linux-x64-musl');
175
+ }
176
+ } catch (e) {
177
+ loadError = e;
178
+ }
179
+ } else {
180
+ localFileExisted = existsSync(
181
+ join(__dirname, 'nx.linux-x64-gnu.node')
182
+ );
183
+ try {
184
+ if (localFileExisted) {
185
+ nativeBinding = require('./nx.linux-x64-gnu.node');
186
+ } else {
187
+ nativeBinding = require('@nx/nx-linux-x64-gnu');
188
+ }
189
+ } catch (e) {
190
+ loadError = e;
191
+ }
192
+ }
193
+ break;
194
+ case 'arm64':
195
+ if (isMusl()) {
196
+ localFileExisted = existsSync(
197
+ join(__dirname, 'nx.linux-arm64-musl.node')
198
+ );
199
+ try {
200
+ if (localFileExisted) {
201
+ nativeBinding = require('./nx.linux-arm64-musl.node');
202
+ } else {
203
+ nativeBinding = require('@nx/nx-linux-arm64-musl');
204
+ }
205
+ } catch (e) {
206
+ loadError = e;
207
+ }
208
+ } else {
209
+ localFileExisted = existsSync(
210
+ join(__dirname, 'nx.linux-arm64-gnu.node')
211
+ );
212
+ try {
213
+ if (localFileExisted) {
214
+ nativeBinding = require('./nx.linux-arm64-gnu.node');
215
+ } else {
216
+ nativeBinding = require('@nx/nx-linux-arm64-gnu');
217
+ }
218
+ } catch (e) {
219
+ loadError = e;
220
+ }
221
+ }
222
+ break;
223
+ case 'arm':
224
+ localFileExisted = existsSync(
225
+ join(__dirname, 'nx.linux-arm-gnueabihf.node')
226
+ );
227
+ try {
228
+ if (localFileExisted) {
229
+ nativeBinding = require('./nx.linux-arm-gnueabihf.node');
230
+ } else {
231
+ nativeBinding = require('@nx/nx-linux-arm-gnueabihf');
232
+ }
233
+ } catch (e) {
234
+ loadError = e;
235
+ }
236
+ break;
237
+ default:
238
+ throw new Error(`Unsupported architecture on Linux: ${arch}`);
239
+ }
240
+ break;
241
+ default:
242
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
243
+ }
244
+
245
+ if (!nativeBinding) {
246
+ if (loadError) {
247
+ throw loadError;
248
+ }
249
+ throw new Error(`Failed to load native binding`);
250
+ }
251
+
252
+ const {
253
+ expandOutputs,
254
+ getFilesForOutputs,
255
+ remove,
256
+ copy,
257
+ hashArray,
258
+ hashFile,
259
+ ImportResult,
260
+ findImports,
261
+ transferProjectGraph,
262
+ ChildProcess,
263
+ RustPseudoTerminal,
264
+ HashPlanner,
265
+ TaskHasher,
266
+ EventType,
267
+ Watcher,
268
+ WorkspaceContext,
269
+ WorkspaceErrors,
270
+ testOnlyTransferFileMap,
271
+ } = nativeBinding;
272
+
273
+ module.exports.expandOutputs = expandOutputs;
274
+ module.exports.getFilesForOutputs = getFilesForOutputs;
275
+ module.exports.remove = remove;
276
+ module.exports.copy = copy;
277
+ module.exports.hashArray = hashArray;
278
+ module.exports.hashFile = hashFile;
279
+ module.exports.ImportResult = ImportResult;
280
+ module.exports.findImports = findImports;
281
+ module.exports.transferProjectGraph = transferProjectGraph;
282
+ module.exports.ChildProcess = ChildProcess;
283
+ module.exports.RustPseudoTerminal = RustPseudoTerminal;
284
+ module.exports.HashPlanner = HashPlanner;
285
+ module.exports.TaskHasher = TaskHasher;
286
+ module.exports.EventType = EventType;
287
+ module.exports.Watcher = Watcher;
288
+ module.exports.WorkspaceContext = WorkspaceContext;
289
+ module.exports.WorkspaceErrors = WorkspaceErrors;
290
+ module.exports.testOnlyTransferFileMap = testOnlyTransferFileMap;
@@ -1,6 +1,26 @@
1
1
  import { CreateNodesResultWithContext } from './plugins/internal-api';
2
- import { ConfigurationResult } from './utils/project-configuration-utils';
2
+ import { ConfigurationResult, ConfigurationSourceMaps } from './utils/project-configuration-utils';
3
3
  import { ProjectConfiguration } from '../config/workspace-json-project-json';
4
+ import { ProcessDependenciesError, ProcessProjectGraphError } from './build-project-graph';
5
+ import { ProjectGraph } from '../config/project-graph';
6
+ export declare class ProjectGraphError extends Error {
7
+ #private;
8
+ constructor(errors: Array<CreateNodesError | MergeNodesError | ProjectsWithNoNameError | ProjectsWithConflictingNamesError | ProcessDependenciesError | ProcessProjectGraphError>, partialProjectGraph: ProjectGraph, partialSourceMaps: ConfigurationSourceMaps);
9
+ /**
10
+ * The daemon cannot throw errors which contain methods as they are not serializable.
11
+ *
12
+ * This method creates a new {@link ProjectGraphError} from a {@link DaemonProjectGraphError} with the methods based on the same serialized data.
13
+ */
14
+ static fromDaemonProjectGraphError(e: DaemonProjectGraphError): ProjectGraphError;
15
+ /**
16
+ * This gets the partial project graph despite the errors which occured.
17
+ * This partial project graph may be missing nodes, properties of nodes, or dependencies.
18
+ * This is useful mostly for visualization/debugging. It should not be used for running tasks.
19
+ */
20
+ getPartialProjectGraph(): ProjectGraph;
21
+ getPartialSourcemaps(): ConfigurationSourceMaps;
22
+ getErrors(): (CreateNodesError | MergeNodesError | ProjectsWithNoNameError | ProjectsWithConflictingNamesError | ProcessDependenciesError | ProcessProjectGraphError)[];
23
+ }
4
24
  export declare class ProjectsWithConflictingNamesError extends Error {
5
25
  projects: Record<string, ProjectConfiguration>;
6
26
  constructor(conflicts: Map<string, string[]>, projects: Record<string, ProjectConfiguration>);
@@ -43,3 +63,9 @@ export declare class MergeNodesError extends Error {
43
63
  export declare function isCreateNodesError(e: unknown): e is CreateNodesError;
44
64
  export declare function isAggregateCreateNodesError(e: unknown): e is AggregateCreateNodesError;
45
65
  export declare function isMergeNodesError(e: unknown): e is MergeNodesError;
66
+ export declare class DaemonProjectGraphError extends Error {
67
+ errors: any[];
68
+ readonly projectGraph: ProjectGraph;
69
+ readonly sourceMaps: ConfigurationSourceMaps;
70
+ constructor(errors: any[], projectGraph: ProjectGraph, sourceMaps: ConfigurationSourceMaps);
71
+ }
@@ -1,6 +1,47 @@
1
1
  "use strict";
2
+ var _ProjectGraphError_errors, _ProjectGraphError_partialProjectGraph, _ProjectGraphError_partialSourceMaps;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isMergeNodesError = exports.isAggregateCreateNodesError = exports.isCreateNodesError = exports.MergeNodesError = exports.AggregateCreateNodesError = exports.CreateNodesError = exports.ProjectConfigurationsError = exports.isProjectsWithNoNameError = exports.ProjectsWithNoNameError = exports.isProjectsWithConflictingNamesError = exports.ProjectsWithConflictingNamesError = void 0;
4
+ exports.DaemonProjectGraphError = exports.isMergeNodesError = exports.isAggregateCreateNodesError = exports.isCreateNodesError = exports.MergeNodesError = exports.AggregateCreateNodesError = exports.CreateNodesError = exports.ProjectConfigurationsError = exports.isProjectsWithNoNameError = exports.ProjectsWithNoNameError = exports.isProjectsWithConflictingNamesError = exports.ProjectsWithConflictingNamesError = exports.ProjectGraphError = void 0;
5
+ const tslib_1 = require("tslib");
6
+ class ProjectGraphError extends Error {
7
+ constructor(errors, partialProjectGraph, partialSourceMaps) {
8
+ super(`Failed to process project graph.`);
9
+ _ProjectGraphError_errors.set(this, void 0);
10
+ _ProjectGraphError_partialProjectGraph.set(this, void 0);
11
+ _ProjectGraphError_partialSourceMaps.set(this, void 0);
12
+ this.name = this.constructor.name;
13
+ tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_errors, errors, "f");
14
+ tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_partialProjectGraph, partialProjectGraph, "f");
15
+ tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_partialSourceMaps, partialSourceMaps, "f");
16
+ this.stack = `${this.message}\n ${errors
17
+ .map((error) => error.stack.split('\n').join('\n '))
18
+ .join('\n')}`;
19
+ }
20
+ /**
21
+ * The daemon cannot throw errors which contain methods as they are not serializable.
22
+ *
23
+ * This method creates a new {@link ProjectGraphError} from a {@link DaemonProjectGraphError} with the methods based on the same serialized data.
24
+ */
25
+ static fromDaemonProjectGraphError(e) {
26
+ return new ProjectGraphError(e.errors, e.projectGraph, e.sourceMaps);
27
+ }
28
+ /**
29
+ * This gets the partial project graph despite the errors which occured.
30
+ * This partial project graph may be missing nodes, properties of nodes, or dependencies.
31
+ * This is useful mostly for visualization/debugging. It should not be used for running tasks.
32
+ */
33
+ getPartialProjectGraph() {
34
+ return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_partialProjectGraph, "f");
35
+ }
36
+ getPartialSourcemaps() {
37
+ return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_partialSourceMaps, "f");
38
+ }
39
+ getErrors() {
40
+ return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_errors, "f");
41
+ }
42
+ }
43
+ exports.ProjectGraphError = ProjectGraphError;
44
+ _ProjectGraphError_errors = new WeakMap(), _ProjectGraphError_partialProjectGraph = new WeakMap(), _ProjectGraphError_partialSourceMaps = new WeakMap();
4
45
  class ProjectsWithConflictingNamesError extends Error {
5
46
  constructor(conflicts, projects) {
6
47
  super([
@@ -94,3 +135,13 @@ function isMergeNodesError(e) {
94
135
  (typeof e === 'object' && 'name' in e && e?.name === MergeNodesError.name));
95
136
  }
96
137
  exports.isMergeNodesError = isMergeNodesError;
138
+ class DaemonProjectGraphError extends Error {
139
+ constructor(errors, projectGraph, sourceMaps) {
140
+ super(`The Daemon Process threw an error while calculating the project graph. Convert this error to a ProjectGraphError to get more information.`);
141
+ this.errors = errors;
142
+ this.projectGraph = projectGraph;
143
+ this.sourceMaps = sourceMaps;
144
+ this.name = this.constructor.name;
145
+ }
146
+ }
147
+ exports.DaemonProjectGraphError = DaemonProjectGraphError;
@@ -3,14 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadNxPluginInIsolation = void 0;
4
4
  const workspace_root_1 = require("../../../utils/workspace-root");
5
5
  const plugin_pool_1 = require("./plugin-pool");
6
+ /**
7
+ * Used to ensure 1 plugin : 1 worker
8
+ */
6
9
  const remotePluginCache = new Map();
7
10
  function loadNxPluginInIsolation(plugin, root = workspace_root_1.workspaceRoot) {
8
11
  const cacheKey = JSON.stringify(plugin);
9
12
  if (remotePluginCache.has(cacheKey)) {
10
- return remotePluginCache.get(cacheKey);
13
+ return [remotePluginCache.get(cacheKey), () => { }];
11
14
  }
12
- const [loadingPlugin, cleanup] = (0, plugin_pool_1.loadRemoteNxPlugin)(plugin, root);
13
- remotePluginCache.set(cacheKey, [loadingPlugin, cleanup]);
14
- return [loadingPlugin, cleanup];
15
+ const loadingPlugin = (0, plugin_pool_1.loadRemoteNxPlugin)(plugin, root);
16
+ remotePluginCache.set(cacheKey, loadingPlugin);
17
+ // We clean up plugin workers when Nx process completes.
18
+ return [loadingPlugin, () => { }];
15
19
  }
16
20
  exports.loadNxPluginInIsolation = loadNxPluginInIsolation;
@@ -1,3 +1,3 @@
1
1
  import { PluginConfiguration } from '../../../config/nx-json';
2
2
  import { LoadedNxPlugin } from '../internal-api';
3
- export declare function loadRemoteNxPlugin(plugin: PluginConfiguration, root: string): [Promise<LoadedNxPlugin>, () => void];
3
+ export declare function loadRemoteNxPlugin(plugin: PluginConfiguration, root: string): Promise<LoadedNxPlugin>;
@@ -41,16 +41,10 @@ function loadRemoteNxPlugin(plugin, root) {
41
41
  shutdownPluginWorker(worker, pendingPromises);
42
42
  };
43
43
  cleanupFunctions.add(cleanupFunction);
44
- return [
45
- new Promise((res, rej) => {
46
- worker.on('message', createWorkerHandler(worker, pendingPromises, res, rej));
47
- worker.on('exit', exitHandler);
48
- }),
49
- () => {
50
- cleanupFunction();
51
- cleanupFunctions.delete(cleanupFunction);
52
- },
53
- ];
44
+ return new Promise((res, rej) => {
45
+ worker.on('message', createWorkerHandler(worker, pendingPromises, res, rej));
46
+ worker.on('exit', exitHandler);
47
+ });
54
48
  }
55
49
  exports.loadRemoteNxPlugin = loadRemoteNxPlugin;
56
50
  async function shutdownPluginWorker(worker, pendingPromises) {
@@ -1,9 +1,5 @@
1
- import { ProcessDependenciesError, ProcessProjectGraphError } from './build-project-graph';
2
1
  import { ProjectGraph } from '../config/project-graph';
3
2
  import { ProjectConfiguration, ProjectsConfigurations } from '../config/workspace-json-project-json';
4
- import { ConfigurationSourceMaps } from './utils/project-configuration-utils';
5
- import { CreateNodesError, MergeNodesError, ProjectsWithNoNameError, ProjectsWithConflictingNamesError } from './error-types';
6
- import { DaemonProjectGraphError } from '../daemon/daemon-project-graph-error';
7
3
  /**
8
4
  * Synchronously reads the latest cached copy of the workspace's ProjectGraph.
9
5
  * @throws {Error} if there is no cached ProjectGraph to read from
@@ -16,26 +12,8 @@ export declare function readCachedProjectConfiguration(projectName: string): Pro
16
12
  export declare function readProjectsConfigurationFromProjectGraph(projectGraph: ProjectGraph): ProjectsConfigurations;
17
13
  export declare function buildProjectGraphAndSourceMapsWithoutDaemon(): Promise<{
18
14
  projectGraph: ProjectGraph;
19
- sourceMaps: ConfigurationSourceMaps;
15
+ sourceMaps: import("./utils/project-configuration-utils").ConfigurationSourceMaps;
20
16
  }>;
21
- export declare class ProjectGraphError extends Error {
22
- #private;
23
- constructor(errors: Array<CreateNodesError | MergeNodesError | ProjectsWithNoNameError | ProjectsWithConflictingNamesError | ProcessDependenciesError | ProcessProjectGraphError>, partialProjectGraph: ProjectGraph, partialSourceMaps: ConfigurationSourceMaps);
24
- /**
25
- * The daemon cannot throw errors which contain methods as they are not serializable.
26
- *
27
- * This method creates a new {@link ProjectGraphError} from a {@link DaemonProjectGraphError} with the methods based on the same serialized data.
28
- */
29
- static fromDaemonProjectGraphError(e: DaemonProjectGraphError): ProjectGraphError;
30
- /**
31
- * This gets the partial project graph despite the errors which occured.
32
- * This partial project graph may be missing nodes, properties of nodes, or dependencies.
33
- * This is useful mostly for visualization/debugging. It should not be used for running tasks.
34
- */
35
- getPartialProjectGraph(): ProjectGraph;
36
- getPartialSourcemaps(): ConfigurationSourceMaps;
37
- getErrors(): (ProjectsWithConflictingNamesError | ProjectsWithNoNameError | MergeNodesError | CreateNodesError | ProcessDependenciesError | ProcessProjectGraphError)[];
38
- }
39
17
  /**
40
18
  * Computes and returns a ProjectGraph.
41
19
  *
@@ -66,5 +44,5 @@ export declare function createProjectGraphAndSourceMapsAsync(opts?: {
66
44
  resetDaemonClient?: boolean;
67
45
  }): Promise<{
68
46
  projectGraph: ProjectGraph;
69
- sourceMaps: ConfigurationSourceMaps;
47
+ sourceMaps: import("./utils/project-configuration-utils").ConfigurationSourceMaps;
70
48
  }>;
@@ -1,21 +1,19 @@
1
1
  "use strict";
2
- var _ProjectGraphError_errors, _ProjectGraphError_partialProjectGraph, _ProjectGraphError_partialSourceMaps;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createProjectGraphAndSourceMapsAsync = exports.createProjectGraphAsync = exports.ProjectGraphError = exports.buildProjectGraphAndSourceMapsWithoutDaemon = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectConfiguration = exports.readCachedProjectGraph = void 0;
5
- const tslib_1 = require("tslib");
6
- const nx_deps_cache_1 = require("./nx-deps-cache");
7
- const build_project_graph_1 = require("./build-project-graph");
8
- const output_1 = require("../utils/output");
9
- const tmp_dir_1 = require("../daemon/tmp-dir");
10
- const strip_indents_1 = require("../utils/strip-indents");
3
+ exports.createProjectGraphAndSourceMapsAsync = exports.createProjectGraphAsync = exports.buildProjectGraphAndSourceMapsWithoutDaemon = exports.readProjectsConfigurationFromProjectGraph = exports.readCachedProjectConfiguration = exports.readCachedProjectGraph = void 0;
4
+ const perf_hooks_1 = require("perf_hooks");
5
+ const nx_json_1 = require("../config/nx-json");
11
6
  const client_1 = require("../daemon/client/client");
7
+ const tmp_dir_1 = require("../daemon/tmp-dir");
12
8
  const fileutils_1 = require("../utils/fileutils");
9
+ const output_1 = require("../utils/output");
10
+ const strip_indents_1 = require("../utils/strip-indents");
13
11
  const workspace_root_1 = require("../utils/workspace-root");
14
- const perf_hooks_1 = require("perf_hooks");
15
- const retrieve_workspace_files_1 = require("./utils/retrieve-workspace-files");
16
- const nx_json_1 = require("../config/nx-json");
12
+ const build_project_graph_1 = require("./build-project-graph");
13
+ const nx_deps_cache_1 = require("./nx-deps-cache");
17
14
  const error_types_1 = require("./error-types");
18
15
  const internal_api_1 = require("./plugins/internal-api");
16
+ const retrieve_workspace_files_1 = require("./utils/retrieve-workspace-files");
19
17
  /**
20
18
  * Synchronously reads the latest cached copy of the workspace's ProjectGraph.
21
19
  * @throws {Error} if there is no cached ProjectGraph to read from
@@ -122,7 +120,7 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
122
120
  ...(createDependenciesError?.errors ?? []),
123
121
  ];
124
122
  if (errors.length > 0) {
125
- throw new ProjectGraphError(errors, projectGraph, sourceMaps);
123
+ throw new error_types_1.ProjectGraphError(errors, projectGraph, sourceMaps);
126
124
  }
127
125
  else {
128
126
  if (cacheEnabled) {
@@ -132,49 +130,10 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
132
130
  }
133
131
  }
134
132
  exports.buildProjectGraphAndSourceMapsWithoutDaemon = buildProjectGraphAndSourceMapsWithoutDaemon;
135
- class ProjectGraphError extends Error {
136
- constructor(errors, partialProjectGraph, partialSourceMaps) {
137
- super(`Failed to process project graph.`);
138
- _ProjectGraphError_errors.set(this, void 0);
139
- _ProjectGraphError_partialProjectGraph.set(this, void 0);
140
- _ProjectGraphError_partialSourceMaps.set(this, void 0);
141
- this.name = this.constructor.name;
142
- tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_errors, errors, "f");
143
- tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_partialProjectGraph, partialProjectGraph, "f");
144
- tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_partialSourceMaps, partialSourceMaps, "f");
145
- this.stack = `${this.message}\n ${errors
146
- .map((error) => error.stack.split('\n').join('\n '))
147
- .join('\n')}`;
148
- }
149
- /**
150
- * The daemon cannot throw errors which contain methods as they are not serializable.
151
- *
152
- * This method creates a new {@link ProjectGraphError} from a {@link DaemonProjectGraphError} with the methods based on the same serialized data.
153
- */
154
- static fromDaemonProjectGraphError(e) {
155
- return new ProjectGraphError(e.errors, e.projectGraph, e.sourceMaps);
156
- }
157
- /**
158
- * This gets the partial project graph despite the errors which occured.
159
- * This partial project graph may be missing nodes, properties of nodes, or dependencies.
160
- * This is useful mostly for visualization/debugging. It should not be used for running tasks.
161
- */
162
- getPartialProjectGraph() {
163
- return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_partialProjectGraph, "f");
164
- }
165
- getPartialSourcemaps() {
166
- return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_partialSourceMaps, "f");
167
- }
168
- getErrors() {
169
- return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_errors, "f");
170
- }
171
- }
172
- exports.ProjectGraphError = ProjectGraphError;
173
- _ProjectGraphError_errors = new WeakMap(), _ProjectGraphError_partialProjectGraph = new WeakMap(), _ProjectGraphError_partialSourceMaps = new WeakMap();
174
133
  function handleProjectGraphError(opts, e) {
175
134
  if (opts.exitOnError) {
176
135
  const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true';
177
- if (e instanceof ProjectGraphError) {
136
+ if (e instanceof error_types_1.ProjectGraphError) {
178
137
  let title = e.message;
179
138
  if (isVerbose) {
180
139
  title += ' See errors below.';
@@ -8,8 +8,10 @@ const run_command_1 = require("./run-command");
8
8
  const invoke_runner_terminal_output_life_cycle_1 = require("./life-cycles/invoke-runner-terminal-output-life-cycle");
9
9
  const perf_hooks_1 = require("perf_hooks");
10
10
  const utils_1 = require("./utils");
11
+ const dotenv_1 = require("../utils/dotenv");
11
12
  async function initTasksRunner(nxArgs) {
12
13
  perf_hooks_1.performance.mark('init-local');
14
+ (0, dotenv_1.loadRootEnvFiles)();
13
15
  (0, workspace_configuration_check_1.workspaceConfigurationCheck)();
14
16
  const nxJson = (0, configuration_1.readNxJson)();
15
17
  if (nxArgs.verbose) {
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This loads dotenv files from:
3
+ * - .env
4
+ * - .local.env
5
+ * - .env.local
6
+ */
7
+ export declare function loadRootEnvFiles(root?: string): void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadRootEnvFiles = void 0;
4
+ const dotenv_1 = require("dotenv");
5
+ const dotenv_expand_1 = require("dotenv-expand");
6
+ const workspace_root_1 = require("./workspace-root");
7
+ const path_1 = require("path");
8
+ /**
9
+ * This loads dotenv files from:
10
+ * - .env
11
+ * - .local.env
12
+ * - .env.local
13
+ */
14
+ function loadRootEnvFiles(root = workspace_root_1.workspaceRoot) {
15
+ for (const file of ['.local.env', '.env.local', '.env']) {
16
+ const myEnv = (0, dotenv_1.config)({
17
+ path: (0, path_1.join)(root, file),
18
+ });
19
+ (0, dotenv_expand_1.expand)(myEnv);
20
+ }
21
+ }
22
+ exports.loadRootEnvFiles = loadRootEnvFiles;
@@ -1,8 +0,0 @@
1
- import { ProjectGraph } from '../config/project-graph';
2
- import { ConfigurationSourceMaps } from '../project-graph/utils/project-configuration-utils';
3
- export declare class DaemonProjectGraphError extends Error {
4
- errors: any[];
5
- readonly projectGraph: ProjectGraph;
6
- readonly sourceMaps: ConfigurationSourceMaps;
7
- constructor(errors: any[], projectGraph: ProjectGraph, sourceMaps: ConfigurationSourceMaps);
8
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DaemonProjectGraphError = void 0;
4
- class DaemonProjectGraphError extends Error {
5
- constructor(errors, projectGraph, sourceMaps) {
6
- super(`The Daemon Process threw an error while calculating the project graph. Convert this error to a ProjectGraphError to get more information.`);
7
- this.errors = errors;
8
- this.projectGraph = projectGraph;
9
- this.sourceMaps = sourceMaps;
10
- this.name = this.constructor.name;
11
- }
12
- }
13
- exports.DaemonProjectGraphError = DaemonProjectGraphError;