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.
- package/dist/src/command-line/init/init-v2.js +2 -0
- package/dist/src/command-line/migrate/migrate.js +44 -27
- package/dist/src/command-line/migrate/version-skew-guard.d.ts +3 -4
- package/dist/src/command-line/migrate/version-skew-guard.js +5 -6
- package/dist/src/command-line/reset/reset.js +6 -1
- package/dist/src/command-line/run/run-one.js +1 -0
- package/dist/src/command-line/run-many/run-many.js +1 -0
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/core/graph/styles.js +1 -1
- package/dist/src/daemon/client/client.d.ts +45 -1
- package/dist/src/daemon/client/client.js +128 -32
- package/dist/src/daemon/client/daemon-socket-messenger.js +4 -0
- package/dist/src/daemon/message-types/daemon-message.d.ts +32 -0
- package/dist/src/daemon/message-types/daemon-message.js +25 -0
- package/dist/src/daemon/server/server.js +22 -0
- package/dist/src/daemon/server/shutdown-utils.d.ts +5 -0
- package/dist/src/daemon/server/shutdown-utils.js +11 -4
- package/dist/src/daemon/socket-utils.d.ts +1 -0
- package/dist/src/daemon/socket-utils.js +24 -3
- package/dist/src/daemon/tmp-dir.d.ts +43 -3
- package/dist/src/daemon/tmp-dir.js +437 -15
- package/dist/src/devkit-internals.d.ts +2 -1
- package/dist/src/devkit-internals.js +14 -5
- package/dist/src/generators/tree.d.ts +4 -2
- package/dist/src/native/index.d.ts +10 -0
- package/dist/src/native/index.js +71 -28
- package/dist/src/native/native-bindings.js +1 -0
- package/dist/src/native/native-file-cache-location.d.ts +17 -1
- package/dist/src/native/native-file-cache-location.js +86 -12
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +1 -0
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +18 -1
- package/dist/src/project-graph/plugins/isolation/messaging.d.ts +16 -3
- package/dist/src/project-graph/plugins/isolation/messaging.js +3 -0
- package/dist/src/project-graph/plugins/isolation/plugin-worker.js +58 -8
- package/dist/src/project-graph/project-graph.js +20 -0
- package/dist/src/utils/child-process.d.ts +31 -1
- package/dist/src/utils/child-process.js +102 -1
- package/dist/src/utils/ignore.d.ts +128 -1
- package/dist/src/utils/ignore.js +182 -12
- package/dist/src/utils/nx-tmp-dir.d.ts +18 -0
- package/dist/src/utils/nx-tmp-dir.js +40 -0
- package/dist/src/utils/owned-private-dir.d.ts +132 -0
- package/dist/src/utils/owned-private-dir.js +323 -0
- package/dist/src/utils/plugins/core-plugins.js +4 -0
- package/dist/src/utils/shell-quoting.d.ts +15 -0
- package/dist/src/utils/shell-quoting.js +35 -0
- package/dist/src/utils/wait-for-socket-connection.d.ts +11 -0
- package/dist/src/utils/wait-for-socket-connection.js +14 -8
- package/package.json +12 -11
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DirectoryRefusedError = void 0;
|
|
4
|
+
exports.describeRefusal = describeRefusal;
|
|
5
|
+
exports.remedyFor = remedyFor;
|
|
6
|
+
exports.isSafeSharedRoot = isSafeSharedRoot;
|
|
7
|
+
exports.isPeerWritable = isPeerWritable;
|
|
8
|
+
exports.ensureSafeSharedRoot = ensureSafeSharedRoot;
|
|
9
|
+
exports.isOwnedRealDirectory = isOwnedRealDirectory;
|
|
10
|
+
exports.getUserSegment = getUserSegment;
|
|
11
|
+
exports.ensureOwnedPrivateDir = ensureOwnedPrivateDir;
|
|
12
|
+
const node_fs_1 = require("node:fs");
|
|
13
|
+
const node_os_1 = require("node:os");
|
|
14
|
+
// A string discriminant, not a boolean `ok`: this repo compiles with
|
|
15
|
+
// `strict: false`, where TypeScript does not narrow a union on a boolean literal.
|
|
16
|
+
const allow = (path) => ({ status: 'ok', path });
|
|
17
|
+
const deny = (refusal) => ({
|
|
18
|
+
status: 'refused',
|
|
19
|
+
refusal,
|
|
20
|
+
});
|
|
21
|
+
const notADirectory = (dir, stats) => stats.isSymbolicLink()
|
|
22
|
+
? { kind: 'not-a-directory', dir, symlink: true }
|
|
23
|
+
: { kind: 'not-a-directory', dir };
|
|
24
|
+
// Four octal digits, so a sticky container reads `1777` and a plain directory
|
|
25
|
+
// `0755` — the notation `chmod` and `ls` use. Prefixing a literal `0` instead
|
|
26
|
+
// renders sticky modes as `01777`, which is not a form anyone writes.
|
|
27
|
+
const asMode = (mode) => (mode & 0o7777).toString(8).padStart(4, '0');
|
|
28
|
+
/** The user-facing sentence for a refusal. The only place wording is decided. */
|
|
29
|
+
function describeRefusal(r) {
|
|
30
|
+
switch (r.kind) {
|
|
31
|
+
case 'not-created':
|
|
32
|
+
return `${r.dir} could not be created${r.code ? ` (${r.code})` : ''}`;
|
|
33
|
+
case 'not-inspectable':
|
|
34
|
+
return `${r.dir} could not be inspected${r.code ? ` (${r.code})` : ''}`;
|
|
35
|
+
case 'not-a-directory':
|
|
36
|
+
return r.symlink
|
|
37
|
+
? `${r.dir} is a symlink, not a real directory — something replaced the path Nx expected to create`
|
|
38
|
+
: `${r.dir} exists and is not a directory`;
|
|
39
|
+
case 'foreign-owner':
|
|
40
|
+
return `${r.dir} is owned by uid ${r.uid}, not by you`;
|
|
41
|
+
case 'foreign-shared-container':
|
|
42
|
+
return `${r.dir} belongs to another user (uid ${r.uid}) rather than to you or to root`;
|
|
43
|
+
case 'not-tightenable':
|
|
44
|
+
return `${r.dir} is reachable by other users (mode ${asMode(r.mode)}) and could not be tightened to 0700`;
|
|
45
|
+
case 'peer-writable-not-sticky':
|
|
46
|
+
return `${r.dir} is writable by other users but not sticky (mode ${asMode(r.mode)}), so a peer could replace directories inside it`;
|
|
47
|
+
default: {
|
|
48
|
+
// This repo sets `strict: false` and leaves `noImplicitReturns` unset, so
|
|
49
|
+
// a new DirRefusal member would otherwise compile here and render as
|
|
50
|
+
// `undefined` inside the aggregate message. Assignability to `never` still
|
|
51
|
+
// holds under these settings, so this is a real compile-time guard.
|
|
52
|
+
const unhandled = r;
|
|
53
|
+
throw new Error(`Unhandled directory refusal: ${unhandled.kind}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Single-quoted for a shell, so a path with a space or quote survives a paste. */
|
|
58
|
+
const shellQuote = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
59
|
+
/** What the user can do about a refusal, or `undefined` when there is nothing. */
|
|
60
|
+
function remedyFor(r) {
|
|
61
|
+
switch (r.kind) {
|
|
62
|
+
case 'not-a-directory':
|
|
63
|
+
return r.symlink
|
|
64
|
+
? `${r.dir} is a symlink where Nx expects a directory. If you did not create it, treat it as hostile: remove the link itself (not what it points at) and run the command again.`
|
|
65
|
+
: undefined;
|
|
66
|
+
case 'foreign-owner':
|
|
67
|
+
return `${r.dir} belongs to another user on this machine, so Nx cannot keep its own directory there. Set NX_SOCKET_DIR to a short directory your user owns, or move it aside — which you can do yourself if you own the directory it sits in, and otherwise needs an administrator.`;
|
|
68
|
+
case 'not-tightenable':
|
|
69
|
+
// Both producers reach here having already established that the directory
|
|
70
|
+
// is ours, so `chmod` is the user's to run. Names no cause: one producer
|
|
71
|
+
// is a mount that discards the mode, the other is any `chmod` failure.
|
|
72
|
+
return `${r.dir} is reachable by other users (mode ${asMode(r.mode)}) and Nx could not restrict it. Run \`chmod 0700 ${shellQuote(r.dir)}\` and try again; if the mode does not stick, set NX_SOCKET_DIR to a short directory on a filesystem that keeps POSIX permissions.`;
|
|
73
|
+
case 'foreign-shared-container':
|
|
74
|
+
// Unreachable today: `isSafeSharedRoot` denies with this kind only when
|
|
75
|
+
// `stats.uid !== 0`, so a root-owned container never reaches here.
|
|
76
|
+
if (r.uid === 0) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
const q = shellQuote(r.dir);
|
|
80
|
+
return `${r.dir} belongs to another user on this machine, so Nx cannot keep a private directory beneath it. Ask an administrator to hand it to root with \`sudo chown root ${q} && sudo chmod 1777 ${q}\`; every user can then keep their own directory under it.`;
|
|
81
|
+
case 'not-created':
|
|
82
|
+
case 'not-inspectable':
|
|
83
|
+
case 'peer-writable-not-sticky':
|
|
84
|
+
return undefined;
|
|
85
|
+
default: {
|
|
86
|
+
// Matches `describeRefusal`'s arm, so a new kind cannot ship with a
|
|
87
|
+
// sentence and no advice — which is how `not-tightenable` went unadvised.
|
|
88
|
+
const unhandled = r;
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** One refusal as an `Error`, so several can travel in an `AggregateError`. */
|
|
94
|
+
class DirectoryRefusedError extends Error {
|
|
95
|
+
constructor(refusal) {
|
|
96
|
+
super(describeRefusal(refusal));
|
|
97
|
+
this.refusal = refusal;
|
|
98
|
+
this.name = 'DirectoryRefusedError';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.DirectoryRefusedError = DirectoryRefusedError;
|
|
102
|
+
/**
|
|
103
|
+
* chmod a path only if it is a real directory, never following a symlink at its
|
|
104
|
+
* final component — `chmodSync` follows them, retargeting the mode change. The
|
|
105
|
+
* directory check is on the descriptor, not the errno: a deny-list fails *open*
|
|
106
|
+
* on codes it does not know. `O_NONBLOCK` stops a planted FIFO blocking `openSync`.
|
|
107
|
+
*/
|
|
108
|
+
function chmodRealDirectory(path, mode) {
|
|
109
|
+
let fd;
|
|
110
|
+
try {
|
|
111
|
+
fd = (0, node_fs_1.openSync)(path, node_fs_1.constants.O_RDONLY | node_fs_1.constants.O_NOFOLLOW | node_fs_1.constants.O_NONBLOCK);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
if (!(0, node_fs_1.fstatSync)(fd).isDirectory()) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
(0, node_fs_1.fchmodSync)(fd, mode);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
(0, node_fs_1.closeSync)(fd);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Sticky. Restricts rename and unlink in a writable directory to the owner of
|
|
132
|
+
* each entry — plus the directory's own owner, which is why the ownership check
|
|
133
|
+
* below is not redundant with this one.
|
|
134
|
+
*/
|
|
135
|
+
const S_ISVTX = 0o1000;
|
|
136
|
+
/**
|
|
137
|
+
* Whether a shared container is safe to keep an owner-only directory under.
|
|
138
|
+
*
|
|
139
|
+
* On POSIX, a container writable by other users must be sticky, and it must be
|
|
140
|
+
* owned by either root or the current user. Windows short-circuits after the
|
|
141
|
+
* directory test — the OS temp root is already scoped to one account, so there
|
|
142
|
+
* is no shared level whose ownership could matter.
|
|
143
|
+
*
|
|
144
|
+
* Sticky directories still let the directory's own owner rename entries, so a
|
|
145
|
+
* container owned by another unprivileged user could replace a previously
|
|
146
|
+
* verified private directory beneath it.
|
|
147
|
+
*/
|
|
148
|
+
function isSafeSharedRoot(dir) {
|
|
149
|
+
try {
|
|
150
|
+
const stats = (0, node_fs_1.lstatSync)(dir);
|
|
151
|
+
if (!stats.isDirectory()) {
|
|
152
|
+
return deny(notADirectory(dir, stats));
|
|
153
|
+
}
|
|
154
|
+
if (process.platform === 'win32') {
|
|
155
|
+
// The OS temp root is already scoped to the current Windows user.
|
|
156
|
+
return allow(dir);
|
|
157
|
+
}
|
|
158
|
+
if (typeof process.getuid === 'function' &&
|
|
159
|
+
stats.uid !== process.getuid() &&
|
|
160
|
+
stats.uid !== 0) {
|
|
161
|
+
return deny({ kind: 'foreign-shared-container', dir, uid: stats.uid });
|
|
162
|
+
}
|
|
163
|
+
return !(stats.mode & 0o022) || !!(stats.mode & S_ISVTX)
|
|
164
|
+
? allow(dir)
|
|
165
|
+
: deny({ kind: 'peer-writable-not-sticky', dir, mode: stats.mode });
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
return deny({ kind: 'not-inspectable', dir, code: e?.code });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Whether other users on this machine can write into `dir`. Gates whether a
|
|
173
|
+
* refusal message may cite other users, so it must not over-report: `false` on
|
|
174
|
+
* Windows, where libuv synthesizes `st_mode` from the READONLY attribute and
|
|
175
|
+
* reports an ordinary per-account directory as `0666`, and `false` on a path
|
|
176
|
+
* that cannot be inspected.
|
|
177
|
+
*
|
|
178
|
+
* `statSync`, not `lstatSync`: the question is about the directory that will be
|
|
179
|
+
* used, not the link pointing at it. Link modes mislead in both directions —
|
|
180
|
+
* Linux creates symlinks `0777`, macOS applies the umask. Nothing here decides
|
|
181
|
+
* whether a path is accepted, so following the link costs nothing the guards
|
|
182
|
+
* do not already re-check.
|
|
183
|
+
*/
|
|
184
|
+
function isPeerWritable(dir) {
|
|
185
|
+
if (process.platform === 'win32') {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
return !!((0, node_fs_1.statSync)(dir).mode & 0o022);
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Create a shared container as sticky + world-writable if it does not exist,
|
|
197
|
+
* and report whether the resulting path is safe for the current user.
|
|
198
|
+
*
|
|
199
|
+
* **A container that already exists is never modified — only judged.** Do not
|
|
200
|
+
* chmod before deciding trust: `CAP_FOWNER` (root's default in Docker and most
|
|
201
|
+
* CI images) can chmod a directory it does not own, so a peer-owned root would
|
|
202
|
+
* be widened to `1777` and then refused, and an operator who deliberately
|
|
203
|
+
* tightened this root would have it re-widened on every `nx` process.
|
|
204
|
+
*/
|
|
205
|
+
function ensureSafeSharedRoot(dir) {
|
|
206
|
+
if (process.platform === 'win32') {
|
|
207
|
+
try {
|
|
208
|
+
(0, node_fs_1.mkdirSync)(dir, { recursive: true });
|
|
209
|
+
return allow(dir);
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
return deny({ kind: 'not-created', dir, code: e?.code });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
(0, node_fs_1.mkdirSync)(dir, { mode: 0o1777 });
|
|
217
|
+
// Ours, created a statement ago. Load-bearing on macOS: XNU strips S_ISVTX
|
|
218
|
+
// at mkdir, so the sticky bit exists solely because of this call.
|
|
219
|
+
chmodRealDirectory(dir, 0o1777);
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
if (e?.code !== 'EEXIST') {
|
|
223
|
+
return deny({ kind: 'not-created', dir, code: e?.code });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// One verdict for both branches: the chmod above can fail and leave a
|
|
227
|
+
// peer-writable non-sticky container, which trusting the creation would brand
|
|
228
|
+
// safe.
|
|
229
|
+
const verdict = isSafeSharedRoot(dir);
|
|
230
|
+
return verdict.status === 'ok'
|
|
231
|
+
? allow(dir)
|
|
232
|
+
: deny(verdict.refusal);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Whether `dir` is an existing real directory owned by us. Unlike
|
|
236
|
+
* `ensureOwnedPrivateDir` it creates nothing and repairs nothing — for callers
|
|
237
|
+
* that only want to know whether a path is safe to act on, such as deleting.
|
|
238
|
+
*/
|
|
239
|
+
function isOwnedRealDirectory(dir) {
|
|
240
|
+
try {
|
|
241
|
+
const stats = (0, node_fs_1.lstatSync)(dir);
|
|
242
|
+
if (!stats.isDirectory()) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
return typeof process.getuid !== 'function' ||
|
|
246
|
+
stats.uid === process.getuid()
|
|
247
|
+
? dir
|
|
248
|
+
: null;
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** The path segment separating one user's Nx runtime state from another's. */
|
|
255
|
+
function getUserSegment() {
|
|
256
|
+
try {
|
|
257
|
+
if (typeof process.getuid === 'function') {
|
|
258
|
+
return String(process.getuid());
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch { }
|
|
262
|
+
try {
|
|
263
|
+
const { username } = (0, node_os_1.userInfo)();
|
|
264
|
+
if (username) {
|
|
265
|
+
return username;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch { }
|
|
269
|
+
return 'unknown';
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Ensure `dir` exists, is a real directory owned by us, and carries no group or
|
|
273
|
+
* other bits at all — read and search alone reach a socket inside it, so 0755 is
|
|
274
|
+
* re-locked rather than accepted. A `refused` status carries which check said
|
|
275
|
+
* no — usually `foreign-owner` for a directory another user planted, but also
|
|
276
|
+
* `not-created`/`not-inspectable` for a filesystem error, `not-a-directory`, or
|
|
277
|
+
* `not-tightenable` when the re-lock did not land.
|
|
278
|
+
*
|
|
279
|
+
* Node builtins only: reached from the native binding loader.
|
|
280
|
+
*/
|
|
281
|
+
function ensureOwnedPrivateDir(dir) {
|
|
282
|
+
try {
|
|
283
|
+
(0, node_fs_1.mkdirSync)(dir, { mode: 0o700 });
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
if (e?.code !== 'EEXIST') {
|
|
287
|
+
return deny({ kind: 'not-created', dir, code: e?.code });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// One verdict for both branches, as in `ensureSafeSharedRoot`: mounts that
|
|
291
|
+
// ignore the mode argument can land a directory Nx asked for at 0700 on 0777,
|
|
292
|
+
// so the creation path is judged like any other.
|
|
293
|
+
try {
|
|
294
|
+
const stats = (0, node_fs_1.lstatSync)(dir);
|
|
295
|
+
// Before the Windows short-circuit: "is a real directory" holds on every
|
|
296
|
+
// platform.
|
|
297
|
+
if (!stats.isDirectory()) {
|
|
298
|
+
return deny(notADirectory(dir, stats));
|
|
299
|
+
}
|
|
300
|
+
if (typeof process.getuid !== 'function') {
|
|
301
|
+
// Windows: the roots there are per-user OS temp dirs, not a shared /tmp.
|
|
302
|
+
return allow(dir);
|
|
303
|
+
}
|
|
304
|
+
if (stats.uid !== process.getuid()) {
|
|
305
|
+
return deny({ kind: 'foreign-owner', dir, uid: stats.uid });
|
|
306
|
+
}
|
|
307
|
+
if (stats.mode & 0o077) {
|
|
308
|
+
if (!chmodRealDirectory(dir, 0o700)) {
|
|
309
|
+
return deny({ kind: 'not-tightenable', dir, mode: stats.mode });
|
|
310
|
+
}
|
|
311
|
+
// Read the mode back rather than trusting the chmod's return: mounts that
|
|
312
|
+
// ignore modes report success and change nothing.
|
|
313
|
+
const after = (0, node_fs_1.lstatSync)(dir);
|
|
314
|
+
if (after.mode & 0o077) {
|
|
315
|
+
return deny({ kind: 'not-tightenable', dir, mode: after.mode });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return allow(dir);
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
return deny({ kind: 'not-inspectable', dir, code: e?.code });
|
|
322
|
+
}
|
|
323
|
+
}
|
|
@@ -8,3 +8,18 @@ export declare function needsShellQuoting(str: string): boolean;
|
|
|
8
8
|
* Check if a string is already wrapped in matching quotes (single or double).
|
|
9
9
|
*/
|
|
10
10
|
export declare function isAlreadyQuoted(str: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Quote a string so it survives being interpolated into a shell command line
|
|
13
|
+
* as a single argument.
|
|
14
|
+
*
|
|
15
|
+
* On Windows the safety boundary is one unbroken double-quoted run: it keeps
|
|
16
|
+
* `^`, `&`, `|`, `<` and `>` literal through cmd.exe's parse and a `.cmd`
|
|
17
|
+
* shim's re-parse of `%*`, but not `%`, which cmd.exe expands inside double
|
|
18
|
+
* quotes too.
|
|
19
|
+
*
|
|
20
|
+
* @throws on Windows when the argument contains a double quote, which ends that
|
|
21
|
+
* run, since cmd.exe recognizes no backslash escape. Carrying one means
|
|
22
|
+
* caret-escaping every metacharacter instead, doubled for a `.cmd` shim, which
|
|
23
|
+
* this path does not implement.
|
|
24
|
+
*/
|
|
25
|
+
export declare function quoteShellArg(arg: string): string;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.needsShellQuoting = needsShellQuoting;
|
|
4
4
|
exports.isAlreadyQuoted = isAlreadyQuoted;
|
|
5
|
+
exports.quoteShellArg = quoteShellArg;
|
|
5
6
|
/**
|
|
6
7
|
* Shell metacharacters that have special meaning and require quoting.
|
|
7
8
|
*
|
|
@@ -39,3 +40,37 @@ function isAlreadyQuoted(str) {
|
|
|
39
40
|
((str[0] === "'" && str[str.length - 1] === "'") ||
|
|
40
41
|
(str[0] === '"' && str[str.length - 1] === '"')));
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Quote a string so it survives being interpolated into a shell command line
|
|
45
|
+
* as a single argument.
|
|
46
|
+
*
|
|
47
|
+
* On Windows the safety boundary is one unbroken double-quoted run: it keeps
|
|
48
|
+
* `^`, `&`, `|`, `<` and `>` literal through cmd.exe's parse and a `.cmd`
|
|
49
|
+
* shim's re-parse of `%*`, but not `%`, which cmd.exe expands inside double
|
|
50
|
+
* quotes too.
|
|
51
|
+
*
|
|
52
|
+
* @throws on Windows when the argument contains a double quote, which ends that
|
|
53
|
+
* run, since cmd.exe recognizes no backslash escape. Carrying one means
|
|
54
|
+
* caret-escaping every metacharacter instead, doubled for a `.cmd` shim, which
|
|
55
|
+
* this path does not implement.
|
|
56
|
+
*/
|
|
57
|
+
function quoteShellArg(arg) {
|
|
58
|
+
const isWindows = process.platform === 'win32';
|
|
59
|
+
if (isWindows && arg.includes('"')) {
|
|
60
|
+
throw new Error(`Cannot safely pass ${arg} to cmd.exe as a single argument: a double quote inside it would end the quoting and leave the rest of the argument to be read as commands. Remove the double quote and run the command again.`);
|
|
61
|
+
}
|
|
62
|
+
if (arg === '') {
|
|
63
|
+
// an unquoted empty string would vanish when joined into a command line
|
|
64
|
+
return isWindows ? '""' : "''";
|
|
65
|
+
}
|
|
66
|
+
// `^` is cmd.exe syntax rather than shell syntax, so it earns quoting only
|
|
67
|
+
// where cmd.exe parses the command line.
|
|
68
|
+
if (!needsShellQuoting(arg) && !(isWindows && arg.includes('^'))) {
|
|
69
|
+
return arg;
|
|
70
|
+
}
|
|
71
|
+
return isWindows
|
|
72
|
+
? // MSVCRT reads the backslashes that precede the closing quote as escapes,
|
|
73
|
+
// so they have to be doubled to survive as themselves.
|
|
74
|
+
`"${arg.replace(/(\\+)$/, '$1$1')}"`
|
|
75
|
+
: `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
76
|
+
}
|
|
@@ -12,4 +12,15 @@ export declare function waitForSocketConnection(socketPath: string | (() => stri
|
|
|
12
12
|
signal?: AbortSignal;
|
|
13
13
|
maxAttempts?: number;
|
|
14
14
|
delayMs?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Called with the errno of each failed connect and the path it was made
|
|
17
|
+
* against. Return `true` to stop polling: a permission refusal does not
|
|
18
|
+
* heal by retrying, and without a way out the caller waits the full budget
|
|
19
|
+
* and then cannot say why.
|
|
20
|
+
*
|
|
21
|
+
* The path is passed rather than left to the caller to recompute — with a
|
|
22
|
+
* resolver it can differ per attempt, and the caller that reports the
|
|
23
|
+
* refusal may no longer be able to resolve one at all.
|
|
24
|
+
*/
|
|
25
|
+
onConnectError?: (error: NodeJS.ErrnoException, socketPath: string) => boolean | void;
|
|
15
26
|
}): Promise<Socket | null>;
|
|
@@ -26,9 +26,15 @@ async function waitForSocketConnection(socketPath, options) {
|
|
|
26
26
|
return null;
|
|
27
27
|
const path = typeof socketPath === 'function' ? socketPath() : socketPath;
|
|
28
28
|
if (path) {
|
|
29
|
-
const
|
|
30
|
-
if (socket) {
|
|
31
|
-
return socket;
|
|
29
|
+
const result = await tryConnect(path);
|
|
30
|
+
if (result.socket) {
|
|
31
|
+
return result.socket;
|
|
32
|
+
}
|
|
33
|
+
// The caller may need the errno this attempt produced — a refused
|
|
34
|
+
// connection is reported very differently from a socket that is not
|
|
35
|
+
// there yet, and polling past it only delays the same answer.
|
|
36
|
+
if (result.error && options?.onConnectError?.(result.error, path)) {
|
|
37
|
+
return null;
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
40
|
attempts++;
|
|
@@ -39,15 +45,15 @@ function tryConnect(socketPath) {
|
|
|
39
45
|
return new Promise((resolve) => {
|
|
40
46
|
try {
|
|
41
47
|
const socket = (0, net_1.connect)(socketPath, () => {
|
|
42
|
-
resolve(socket);
|
|
48
|
+
resolve({ socket });
|
|
43
49
|
});
|
|
44
|
-
socket.once('error', () => {
|
|
50
|
+
socket.once('error', (error) => {
|
|
45
51
|
socket.destroy();
|
|
46
|
-
resolve(
|
|
52
|
+
resolve({ error });
|
|
47
53
|
});
|
|
48
54
|
}
|
|
49
|
-
catch {
|
|
50
|
-
resolve(
|
|
55
|
+
catch (error) {
|
|
56
|
+
resolve({ error: error });
|
|
51
57
|
}
|
|
52
58
|
});
|
|
53
59
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nx",
|
|
3
|
-
"version": "23.2.0-beta.
|
|
3
|
+
"version": "23.2.0-beta.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
|
|
@@ -181,16 +181,16 @@
|
|
|
181
181
|
}
|
|
182
182
|
},
|
|
183
183
|
"optionalDependencies": {
|
|
184
|
-
"@nx/nx-darwin-arm64": "23.2.0-beta.
|
|
185
|
-
"@nx/nx-darwin-x64": "23.2.0-beta.
|
|
186
|
-
"@nx/nx-freebsd-x64": "23.2.0-beta.
|
|
187
|
-
"@nx/nx-linux-arm-gnueabihf": "23.2.0-beta.
|
|
188
|
-
"@nx/nx-linux-arm64-gnu": "23.2.0-beta.
|
|
189
|
-
"@nx/nx-linux-arm64-musl": "23.2.0-beta.
|
|
190
|
-
"@nx/nx-linux-x64-gnu": "23.2.0-beta.
|
|
191
|
-
"@nx/nx-linux-x64-musl": "23.2.0-beta.
|
|
192
|
-
"@nx/nx-win32-arm64-msvc": "23.2.0-beta.
|
|
193
|
-
"@nx/nx-win32-x64-msvc": "23.2.0-beta.
|
|
184
|
+
"@nx/nx-darwin-arm64": "23.2.0-beta.7",
|
|
185
|
+
"@nx/nx-darwin-x64": "23.2.0-beta.7",
|
|
186
|
+
"@nx/nx-freebsd-x64": "23.2.0-beta.7",
|
|
187
|
+
"@nx/nx-linux-arm-gnueabihf": "23.2.0-beta.7",
|
|
188
|
+
"@nx/nx-linux-arm64-gnu": "23.2.0-beta.7",
|
|
189
|
+
"@nx/nx-linux-arm64-musl": "23.2.0-beta.7",
|
|
190
|
+
"@nx/nx-linux-x64-gnu": "23.2.0-beta.7",
|
|
191
|
+
"@nx/nx-linux-x64-musl": "23.2.0-beta.7",
|
|
192
|
+
"@nx/nx-win32-arm64-msvc": "23.2.0-beta.7",
|
|
193
|
+
"@nx/nx-win32-x64-msvc": "23.2.0-beta.7"
|
|
194
194
|
},
|
|
195
195
|
"nx-migrations": {
|
|
196
196
|
"migrations": "./migrations.json",
|
|
@@ -218,6 +218,7 @@
|
|
|
218
218
|
"@nx/next",
|
|
219
219
|
"@nx/node",
|
|
220
220
|
"@nx/nuxt",
|
|
221
|
+
"@nx/oxlint",
|
|
221
222
|
"@nx/playwright",
|
|
222
223
|
"@nx/plugin",
|
|
223
224
|
"@nx/react",
|