nx 18.3.0 → 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.
- package/.eslintrc.json +4 -0
- package/bin/nx.js +7 -19
- package/package.json +12 -12
- package/src/command-line/add/add.js +3 -1
- package/src/command-line/add/command-object.d.ts +1 -0
- package/src/command-line/add/command-object.js +6 -1
- package/src/command-line/init/implementation/react/check-for-uncommitted-changes.js +6 -3
- package/src/core/graph/main.js +1 -1
- package/src/daemon/cache.js +18 -0
- package/src/daemon/client/client.js +3 -4
- package/src/daemon/server/handle-hash-tasks.js +2 -2
- package/src/daemon/server/project-graph-incremental-recomputation.js +1 -2
- package/src/daemon/socket-utils.js +2 -2
- package/src/native/index.d.ts +1 -4
- package/src/native/index.js +67 -259
- package/src/native/native-bindings.js +268 -0
- package/src/native/transform-objects.js +1 -0
- package/src/project-graph/error-types.d.ts +27 -1
- package/src/project-graph/error-types.js +52 -1
- package/src/project-graph/plugins/isolation/index.js +8 -4
- package/src/project-graph/plugins/isolation/plugin-pool.d.ts +1 -1
- package/src/project-graph/plugins/isolation/plugin-pool.js +4 -10
- package/src/project-graph/plugins/utils.js +1 -1
- package/src/project-graph/project-graph.d.ts +2 -24
- package/src/project-graph/project-graph.js +11 -52
- package/src/tasks-runner/init-tasks-runner.js +2 -0
- package/src/tasks-runner/task-orchestrator.js +47 -29
- package/src/utils/dotenv.d.ts +7 -0
- package/src/utils/dotenv.js +22 -0
- package/src/utils/params.js +20 -17
- package/src/daemon/daemon-project-graph-error.d.ts +0 -8
- package/src/daemon/daemon-project-graph-error.js +0 -13
package/src/daemon/cache.js
CHANGED
@@ -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
|
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 ===
|
105
|
-
throw
|
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
|
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
|
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
|
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
|
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
|
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)
|
package/src/native/index.d.ts
CHANGED
@@ -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
|
}
|
package/src/native/index.js
CHANGED
@@ -1,268 +1,76 @@
|
|
1
|
-
const {
|
2
|
-
const {
|
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
|
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
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
145
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
247
|
-
}
|
69
|
+
};
|
248
70
|
|
249
|
-
const
|
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
|
252
|
-
|
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;
|