nx 23.1.1 → 23.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/release/changelog-renderer/index.js +4 -5
  2. package/dist/release/index.d.ts +1 -1
  3. package/dist/src/command-line/add/add.js +5 -0
  4. package/dist/src/command-line/affected/affected.js +1 -0
  5. package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +2 -2
  6. package/dist/src/command-line/import/import.js +1 -2
  7. package/dist/src/command-line/init/init-v2.js +4 -5
  8. package/dist/src/command-line/migrate/migrate.d.ts +4 -0
  9. package/dist/src/command-line/migrate/migrate.js +89 -26
  10. package/dist/src/command-line/release/changelog.js +5 -0
  11. package/dist/src/command-line/release/index.d.ts +1 -1
  12. package/dist/src/command-line/release/utils/git.js +1 -1
  13. package/dist/src/command-line/release/utils/release-graph.d.ts +17 -0
  14. package/dist/src/command-line/release/utils/release-graph.js +71 -19
  15. package/dist/src/command-line/release/utils/remote-release-clients/github.js +6 -0
  16. package/dist/src/command-line/release/version/release-group-processor.d.ts +24 -0
  17. package/dist/src/command-line/release/version/release-group-processor.js +80 -6
  18. package/dist/src/command-line/release/version/version-actions.d.ts +27 -2
  19. package/dist/src/command-line/release/version/version-actions.js +9 -1
  20. package/dist/src/command-line/release/version.js +9 -5
  21. package/dist/src/command-line/reset/reset.js +6 -1
  22. package/dist/src/command-line/run/run-one.js +1 -0
  23. package/dist/src/command-line/run-many/run-many.js +1 -0
  24. package/dist/src/command-line/watch/watch.js +13 -0
  25. package/dist/src/core/graph/main.js +1 -1
  26. package/dist/src/core/graph/styles.js +1 -1
  27. package/dist/src/daemon/client/client.d.ts +52 -1
  28. package/dist/src/daemon/client/client.js +160 -36
  29. package/dist/src/daemon/client/daemon-environment.d.ts +17 -0
  30. package/dist/src/daemon/client/daemon-environment.js +110 -2
  31. package/dist/src/daemon/client/daemon-socket-messenger.js +4 -0
  32. package/dist/src/daemon/message-types/daemon-message.d.ts +33 -0
  33. package/dist/src/daemon/message-types/daemon-message.js +48 -0
  34. package/dist/src/daemon/server/file-watching/file-watcher-sockets.d.ts +5 -0
  35. package/dist/src/daemon/server/file-watching/file-watcher-sockets.js +16 -0
  36. package/dist/src/daemon/server/latest-nx.js +5 -2
  37. package/dist/src/daemon/server/server.js +24 -0
  38. package/dist/src/daemon/server/shutdown-utils.d.ts +5 -0
  39. package/dist/src/daemon/server/shutdown-utils.js +11 -4
  40. package/dist/src/daemon/socket-utils.d.ts +1 -0
  41. package/dist/src/daemon/socket-utils.js +24 -3
  42. package/dist/src/daemon/tmp-dir.d.ts +43 -3
  43. package/dist/src/daemon/tmp-dir.js +437 -15
  44. package/dist/src/devkit-internals.d.ts +94 -4
  45. package/dist/src/devkit-internals.js +194 -5
  46. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +5 -0
  47. package/dist/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +9 -2
  48. package/dist/src/generators/tree.d.ts +4 -2
  49. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.d.ts +12 -0
  50. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.js +250 -0
  51. package/dist/src/migrations/update-23-2-0/set-cache-on-executor-target-defaults.md +50 -0
  52. package/dist/src/native/index.d.ts +10 -0
  53. package/dist/src/native/index.js +71 -28
  54. package/dist/src/native/native-bindings.js +1 -0
  55. package/dist/src/native/native-file-cache-location.d.ts +17 -1
  56. package/dist/src/native/native-file-cache-location.js +86 -12
  57. package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
  58. package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
  59. package/dist/src/nx-cloud/utilities/get-cloud-options.js +5 -2
  60. package/dist/src/nx-cloud/utilities/onboarding.js +5 -2
  61. package/dist/src/plugins/js/lock-file/bun-parser.js +43 -10
  62. package/dist/src/plugins/js/lock-file/pnpm-parser.js +60 -0
  63. package/dist/src/plugins/js/lock-file/project-graph-pruning.js +14 -8
  64. package/dist/src/plugins/js/project-graph/affected/npm-packages.js +51 -20
  65. package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +2 -0
  66. package/dist/src/project-graph/affected/affected-project-graph-models.d.ts +1 -1
  67. package/dist/src/project-graph/affected/affected-project-graph.d.ts +1 -1
  68. package/dist/src/project-graph/affected/affected-project-graph.js +2 -2
  69. package/dist/src/project-graph/affected/locators/project-glob-changes.js +5 -2
  70. package/dist/src/project-graph/error-types.d.ts +12 -1
  71. package/dist/src/project-graph/error-types.js +27 -2
  72. package/dist/src/project-graph/plugins/isolation/isolated-plugin.d.ts +1 -0
  73. package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +18 -1
  74. package/dist/src/project-graph/plugins/isolation/messaging.d.ts +16 -3
  75. package/dist/src/project-graph/plugins/isolation/messaging.js +3 -0
  76. package/dist/src/project-graph/plugins/isolation/plugin-worker.js +58 -8
  77. package/dist/src/project-graph/project-graph.js +20 -0
  78. package/dist/src/project-graph/utils/project-configuration/project-nodes-manager.js +5 -1
  79. package/dist/src/project-graph/utils/project-configuration/target-normalization.js +133 -3
  80. package/dist/src/tasks-runner/task-env.js +5 -2
  81. package/dist/src/tasks-runner/utils.js +2 -6
  82. package/dist/src/utils/assert-workspace-validity.js +7 -2
  83. package/dist/src/utils/fileutils.d.ts +5 -0
  84. package/dist/src/utils/fileutils.js +7 -2
  85. package/dist/src/utils/git-worktrees.d.ts +30 -0
  86. package/dist/src/utils/git-worktrees.js +212 -0
  87. package/dist/src/utils/ignore.d.ts +128 -1
  88. package/dist/src/utils/ignore.js +182 -12
  89. package/dist/src/utils/long-running-target.d.ts +10 -0
  90. package/dist/src/utils/long-running-target.js +19 -0
  91. package/dist/src/utils/min-release-age/behavior/bun.js +7 -11
  92. package/dist/src/utils/min-release-age/behavior/npm.js +5 -2
  93. package/dist/src/utils/min-release-age/packument.js +1 -1
  94. package/dist/src/utils/nx-tmp-dir.d.ts +18 -0
  95. package/dist/src/utils/nx-tmp-dir.js +40 -0
  96. package/dist/src/utils/owned-private-dir.d.ts +132 -0
  97. package/dist/src/utils/owned-private-dir.js +323 -0
  98. package/dist/src/utils/package-manager-config/bunfig.d.ts +14 -0
  99. package/dist/src/utils/package-manager-config/bunfig.js +49 -0
  100. package/dist/src/utils/package-manager-config/npmrc.d.ts +23 -0
  101. package/dist/src/utils/package-manager-config/npmrc.js +124 -0
  102. package/dist/src/utils/package-manager-config/pnpm-config.d.ts +17 -0
  103. package/dist/src/utils/package-manager-config/pnpm-config.js +60 -0
  104. package/dist/src/utils/package-manager.d.ts +21 -2
  105. package/dist/src/utils/package-manager.js +244 -47
  106. package/dist/src/utils/provenance.js +6 -14
  107. package/dist/src/utils/registry-config/bun.d.ts +2 -0
  108. package/dist/src/utils/registry-config/bun.js +257 -0
  109. package/dist/src/utils/registry-config/index.d.ts +13 -0
  110. package/dist/src/utils/registry-config/index.js +102 -0
  111. package/dist/src/utils/registry-config/pnpm.d.ts +2 -0
  112. package/dist/src/utils/registry-config/pnpm.js +1551 -0
  113. package/dist/src/utils/registry-config/utils.d.ts +195 -0
  114. package/dist/src/utils/registry-config/utils.js +496 -0
  115. package/dist/src/utils/registry-config/yarn-berry.d.ts +2 -0
  116. package/dist/src/utils/registry-config/yarn-berry.js +612 -0
  117. package/dist/src/utils/registry-config/yarn-classic.d.ts +2 -0
  118. package/dist/src/utils/registry-config/yarn-classic.js +1001 -0
  119. package/dist/src/utils/safe-spawn.d.ts +24 -0
  120. package/dist/src/utils/safe-spawn.js +104 -0
  121. package/dist/src/utils/shell-quoting.d.ts +15 -0
  122. package/dist/src/utils/shell-quoting.js +35 -0
  123. package/dist/src/utils/wait-for-socket-connection.d.ts +11 -0
  124. package/dist/src/utils/wait-for-socket-connection.js +14 -8
  125. package/migrations.json +6 -0
  126. package/package.json +12 -12
  127. package/dist/src/utils/min-release-age/npmrc.d.ts +0 -15
  128. package/dist/src/utils/min-release-age/npmrc.js +0 -45
@@ -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
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The directory holding bun's global config files (.bunfig.toml and, for bun's
3
+ * npmrc support, .npmrc): $XDG_CONFIG_HOME when set, else the home dir (bun's
4
+ * getHomeConfigPath). Null when neither is set, where bun reads no global
5
+ * config.
6
+ */
7
+ export declare function getBunGlobalConfigBase(env: NodeJS.ProcessEnv): string | null;
8
+ /**
9
+ * Parses a bunfig.toml: null when absent, 'unreadable' when it cannot be read
10
+ * (bun skips it and resolves on, so most callers collapse the two), 'invalid'
11
+ * when bun's own TOML parser would reject it (bun hard-errors there, so no
12
+ * resolution is left for a caller to reproduce).
13
+ */
14
+ export declare function readBunfigRaw(path: string): Record<string, unknown> | 'unreadable' | 'invalid' | null;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBunGlobalConfigBase = getBunGlobalConfigBase;
4
+ exports.readBunfigRaw = readBunfigRaw;
5
+ const fs_1 = require("fs");
6
+ /**
7
+ * The directory holding bun's global config files (.bunfig.toml and, for bun's
8
+ * npmrc support, .npmrc): $XDG_CONFIG_HOME when set, else the home dir (bun's
9
+ * getHomeConfigPath). Null when neither is set, where bun reads no global
10
+ * config.
11
+ */
12
+ function getBunGlobalConfigBase(env) {
13
+ // bun's getenvZ treats a set-but-empty var as present, so an exported empty
14
+ // XDG_CONFIG_HOME still short-circuits HOME (bun: `XDG_CONFIG_HOME orelse HOME`).
15
+ if (env.XDG_CONFIG_HOME !== undefined) {
16
+ return env.XDG_CONFIG_HOME;
17
+ }
18
+ // Mirrors bun's platform-specific HOME accessor (env_var.zig).
19
+ const home = process.platform === 'win32' ? env.USERPROFILE : env.HOME;
20
+ return home ?? null;
21
+ }
22
+ /**
23
+ * Parses a bunfig.toml: null when absent, 'unreadable' when it cannot be read
24
+ * (bun skips it and resolves on, so most callers collapse the two), 'invalid'
25
+ * when bun's own TOML parser would reject it (bun hard-errors there, so no
26
+ * resolution is left for a caller to reproduce).
27
+ */
28
+ function readBunfigRaw(path) {
29
+ // Outside the try because a parser that will not load is a broken
30
+ // installation, not a corrupt bunfig.
31
+ const { parse } = require('smol-toml');
32
+ let raw;
33
+ try {
34
+ raw = (0, fs_1.readFileSync)(path, 'utf-8');
35
+ }
36
+ catch (error) {
37
+ // ENOTDIR (a path through a non-directory) is another shape of absent, the
38
+ // same way the .npmrc reader classifies it.
39
+ return error?.code === 'ENOENT' || error?.code === 'ENOTDIR'
40
+ ? null
41
+ : 'unreadable';
42
+ }
43
+ try {
44
+ return parse(raw);
45
+ }
46
+ catch {
47
+ return 'invalid';
48
+ }
49
+ }
@@ -0,0 +1,23 @@
1
+ export interface NpmrcEntry {
2
+ key: string;
3
+ value: string;
4
+ /** True when the source used ini's `key[]` array-append syntax. */
5
+ array?: boolean;
6
+ }
7
+ /**
8
+ * Parses an .npmrc file into its `key = value` entries the way npm/yarn/pnpm do
9
+ * (via the `ini` package). Returns null when the file is missing, and
10
+ * 'unreadable' when it exists but cannot be read (permissions, a directory):
11
+ * package managers diverge on that state, so each caller decides whether to
12
+ * skip, warn, or abort rather than having it collapsed into "absent" here.
13
+ */
14
+ export declare function readNpmrcEntries(path: string): NpmrcEntry[] | 'unreadable' | null;
15
+ export declare function parseNpmrcContent(raw: string): NpmrcEntry[];
16
+ /**
17
+ * Reads an .npmrc-format file into a map with ini's semantics for repeated
18
+ * keys: scalars last-write-wins, `key[]` values joined. Null and 'unreadable'
19
+ * pass through from {@link readNpmrcEntries}.
20
+ */
21
+ export declare function readNpmrcMap(path: string): Map<string, string> | 'unreadable' | null;
22
+ /** Those entries under ini's semantics for repeated keys. */
23
+ export declare function npmrcEntriesToMap(entries: NpmrcEntry[]): Map<string, string>;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readNpmrcEntries = readNpmrcEntries;
4
+ exports.parseNpmrcContent = parseNpmrcContent;
5
+ exports.readNpmrcMap = readNpmrcMap;
6
+ exports.npmrcEntriesToMap = npmrcEntriesToMap;
7
+ const fs_1 = require("fs");
8
+ /**
9
+ * Parses an .npmrc file into its `key = value` entries the way npm/yarn/pnpm do
10
+ * (via the `ini` package). Returns null when the file is missing, and
11
+ * 'unreadable' when it exists but cannot be read (permissions, a directory):
12
+ * package managers diverge on that state, so each caller decides whether to
13
+ * skip, warn, or abort rather than having it collapsed into "absent" here.
14
+ */
15
+ function readNpmrcEntries(path) {
16
+ let raw;
17
+ try {
18
+ raw = (0, fs_1.readFileSync)(path, 'utf-8');
19
+ }
20
+ catch (e) {
21
+ // ENOTDIR (a path through a non-directory) is another shape of absent, not an
22
+ // unreadable file.
23
+ return e?.code === 'ENOENT' || e?.code === 'ENOTDIR' ? null : 'unreadable';
24
+ }
25
+ return parseNpmrcContent(raw);
26
+ }
27
+ function parseNpmrcContent(raw) {
28
+ const entries = [];
29
+ // ini breaks lines on any run of CR/LF, so splitting on `\r?\n` here would
30
+ // hide everything after a bare CR that npm still reads.
31
+ for (const line of raw.split(/[\r\n]+/)) {
32
+ const trimmed = line.trim();
33
+ if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith(';')) {
34
+ continue;
35
+ }
36
+ // ini matches the header on the raw line, so an indented one stays a literal
37
+ // bare-flag key. Everything after a header nests under it, out of npm's flat
38
+ // lookup, so stop here.
39
+ if (/^\[[^\]]*\]\s*$/.test(line)) {
40
+ break;
41
+ }
42
+ // ini reads a valueless line as the flag `true`; dropping it would lose a bare
43
+ // `always-auth`/`strict-ssl` and flip the credential/TLS decision built on it.
44
+ const eq = trimmed.indexOf('=');
45
+ const rawKey = iniUnsafe(eq === -1 ? trimmed : trimmed.slice(0, eq));
46
+ const value = eq === -1 ? 'true' : iniUnsafe(trimmed.slice(eq + 1));
47
+ // ini enables bracketedArray by default, so a `key[]` suffix appends under the
48
+ // bare key instead of making a literal `key[]` entry.
49
+ if (rawKey.length > 2 && rawKey.endsWith('[]')) {
50
+ entries.push({ key: rawKey.slice(0, -2), value, array: true });
51
+ }
52
+ else {
53
+ entries.push({ key: rawKey, value });
54
+ }
55
+ }
56
+ return entries;
57
+ }
58
+ /**
59
+ * Reads an .npmrc-format file into a map with ini's semantics for repeated
60
+ * keys: scalars last-write-wins, `key[]` values joined. Null and 'unreadable'
61
+ * pass through from {@link readNpmrcEntries}.
62
+ */
63
+ function readNpmrcMap(path) {
64
+ const entries = readNpmrcEntries(path);
65
+ return Array.isArray(entries) ? npmrcEntriesToMap(entries) : entries;
66
+ }
67
+ /** Those entries under ini's semantics for repeated keys. */
68
+ function npmrcEntriesToMap(entries) {
69
+ const map = new Map();
70
+ for (const { key, value, array } of entries) {
71
+ // ini collects repeated `key[]` values into an array under the bare key, and
72
+ // npm rebuilds a config array from the env by splitting on a blank line, so
73
+ // join them that way.
74
+ const existing = map.get(key);
75
+ map.set(key, array && existing !== undefined ? `${existing}\n\n${value}` : value);
76
+ }
77
+ return map;
78
+ }
79
+ function isQuoted(val) {
80
+ return (val.length >= 2 &&
81
+ ((val.startsWith('"') && val.endsWith('"')) ||
82
+ (val.startsWith("'") && val.endsWith("'"))));
83
+ }
84
+ /**
85
+ * Mirrors the `ini` package's `unsafe()`, except that ini JSON-decodes a
86
+ * single-quoted value's contents and we keep them verbatim; that only differs
87
+ * when the contents are valid JSON, never true for a registry, token, or path.
88
+ * See https://github.com/isaacs/ini/blob/a0c72fe9e335a3f949d734fb5ef13371a850bbe3/lib/ini.js#L230
89
+ */
90
+ function iniUnsafe(raw) {
91
+ const val = raw.trim();
92
+ if (isQuoted(val)) {
93
+ if (val.startsWith("'")) {
94
+ return val.slice(1, -1);
95
+ }
96
+ try {
97
+ return JSON.parse(val);
98
+ }
99
+ catch {
100
+ return val;
101
+ }
102
+ }
103
+ let esc = false;
104
+ let unesc = '';
105
+ for (const c of val) {
106
+ if (esc) {
107
+ unesc += '\\;#'.includes(c) ? c : `\\${c}`;
108
+ esc = false;
109
+ }
110
+ else if (c === ';' || c === '#') {
111
+ break;
112
+ }
113
+ else if (c === '\\') {
114
+ esc = true;
115
+ }
116
+ else {
117
+ unesc += c;
118
+ }
119
+ }
120
+ if (esc) {
121
+ unesc += '\\';
122
+ }
123
+ return unesc.trim();
124
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Mirrors pnpm's getConfigDir. Hosts pnpm's global config.yaml and (v11+)
3
+ * auth.ini.
4
+ * See https://github.com/pnpm/pnpm/blob/b7195db5c8469c80908d625c648302b26c2f9977/config/reader/src/dirs.ts#L73-L92
5
+ */
6
+ export declare function getPnpmConfigDir(env: NodeJS.ProcessEnv): string;
7
+ /**
8
+ * Reads a pnpm YAML config file (pnpm-workspace.yaml or the global
9
+ * config.yaml). An absent file returns null so callers can fall through to
10
+ * lower surfaces; everything else returns 'unusable', which every caller turns
11
+ * into a throw. pnpm's own reader tolerates ENOENT alone and rethrows the rest,
12
+ * and it dies the same way on a document it cannot parse or that is not a
13
+ * mapping, so the two failures need no separate states. Requiring an object
14
+ * also keeps the sentinel out of the success domain: a returned string can only
15
+ * ever mean unusable.
16
+ */
17
+ export declare function readPnpmYamlConfig(path: string): Record<string, unknown> | 'unusable' | null;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPnpmConfigDir = getPnpmConfigDir;
4
+ exports.readPnpmYamlConfig = readPnpmYamlConfig;
5
+ const os_1 = require("os");
6
+ const path_1 = require("path");
7
+ const fileutils_1 = require("../fileutils");
8
+ /**
9
+ * Mirrors pnpm's getConfigDir. Hosts pnpm's global config.yaml and (v11+)
10
+ * auth.ini.
11
+ * See https://github.com/pnpm/pnpm/blob/b7195db5c8469c80908d625c648302b26c2f9977/config/reader/src/dirs.ts#L73-L92
12
+ */
13
+ function getPnpmConfigDir(env) {
14
+ if (env.XDG_CONFIG_HOME) {
15
+ return (0, path_1.join)(env.XDG_CONFIG_HOME, 'pnpm');
16
+ }
17
+ if (process.platform === 'darwin') {
18
+ return (0, path_1.join)((0, os_1.homedir)(), 'Library/Preferences/pnpm');
19
+ }
20
+ if (process.platform !== 'win32') {
21
+ return (0, path_1.join)((0, os_1.homedir)(), '.config/pnpm');
22
+ }
23
+ if (env.LOCALAPPDATA) {
24
+ return (0, path_1.join)(env.LOCALAPPDATA, 'pnpm/config');
25
+ }
26
+ return (0, path_1.join)((0, os_1.homedir)(), '.config/pnpm');
27
+ }
28
+ /**
29
+ * Reads a pnpm YAML config file (pnpm-workspace.yaml or the global
30
+ * config.yaml). An absent file returns null so callers can fall through to
31
+ * lower surfaces; everything else returns 'unusable', which every caller turns
32
+ * into a throw. pnpm's own reader tolerates ENOENT alone and rethrows the rest,
33
+ * and it dies the same way on a document it cannot parse or that is not a
34
+ * mapping, so the two failures need no separate states. Requiring an object
35
+ * also keeps the sentinel out of the success domain: a returned string can only
36
+ * ever mean unusable.
37
+ */
38
+ function readPnpmYamlConfig(path) {
39
+ let doc;
40
+ try {
41
+ doc = (0, fileutils_1.readYamlFile)(path);
42
+ }
43
+ catch (e) {
44
+ // Only ENOENT resolves on, so a path through a non-directory or a file that
45
+ // will not open is fatal here. Callers whose pnpm counterpart looks the file
46
+ // up before reading it widen "absent" themselves.
47
+ if (e?.code === 'ENOENT') {
48
+ return null;
49
+ }
50
+ return 'unusable';
51
+ }
52
+ // An empty file declares nothing; pnpm accepts it.
53
+ if (doc === null || doc === undefined) {
54
+ return {};
55
+ }
56
+ if (typeof doc !== 'object' || Array.isArray(doc)) {
57
+ return 'unusable';
58
+ }
59
+ return doc;
60
+ }
@@ -118,14 +118,33 @@ export declare function resolvePackageVersionUsingRegistry(packageName: string,
118
118
  * package.json.
119
119
  */
120
120
  export declare function resolvePackageVersionUsingInstallation(packageName: string, version: string): Promise<string>;
121
- export declare function packageRegistryView(pkg: string, version: string, args: string, options?: {
121
+ /**
122
+ * The registry the fetch for `pkg` went to, with its userinfo masked because a
123
+ * registry URL can carry a bare token. The lookup is spawned the way
124
+ * `packageRegistryView` spawns the fetch this describes (same manager, same
125
+ * environment), so a registry the package manager keeps outside the .npmrc
126
+ * chain and a scope resolved for itself both land on the value that fetch used.
127
+ * Null where the manager yields no usable registry URL; throws where it cannot be run.
128
+ */
129
+ export declare function getWorkspaceRegistryUrlForDisplay(pkg: string): string | null;
130
+ export declare function packageRegistryView(pkg: string, version: string, args: string[], options?: {
122
131
  forceNpm?: boolean;
123
132
  }): Promise<string>;
124
- export declare function packageRegistryPack(cwd: string, pkg: string, version: string, options?: {
133
+ /**
134
+ * Only `npm pack` supports downloading a tarball of a specified remote
135
+ * package. `yarn` packs the active workspace, `pnpm pack` only packs
136
+ * the local project, and `bun` doesn't support pack.
137
+ *
138
+ * @param packDestination Directory passed to npm's `--pack-destination`, where
139
+ * the `.tgz` is written.
140
+ * @see https://github.com/nrwl/nx/pull/9667#discussion_r842553994
141
+ */
142
+ export declare function packageRegistryPack(packDestination: string, pkg: string, version: string, options?: {
125
143
  bypassMinReleaseAge?: boolean;
126
144
  }): Promise<{
127
145
  tarballPath: string;
128
146
  }>;
147
+ export declare function clearPackageManagerVersionCache(): void;
129
148
  /**
130
149
  * Gets the workspaces defined in the package manager configuration.
131
150
  * @returns workspaces defined in the package manager configuration, empty array if none are defined