nx 24.0.2 → 24.0.4
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/bin/nx-cloud.js +9 -0
- package/dist/release/changelog-renderer/index.js +12 -5
- package/dist/src/ai/clone-ai-config-repo.d.ts +2 -1
- package/dist/src/ai/clone-ai-config-repo.js +48 -11
- package/dist/src/ai/set-up-ai-agents/set-up-ai-agents.js +37 -8
- package/dist/src/analytics/analytics.js +7 -2
- package/dist/src/command-line/ai/ai-output.js +3 -3
- package/dist/src/command-line/configure-ai-agents/configure-ai-agents.js +2 -2
- package/dist/src/command-line/graph/graph.d.ts +10 -0
- package/dist/src/command-line/graph/graph.js +61 -2
- package/dist/src/command-line/import/import.js +18 -30
- package/dist/src/command-line/import/utils/merge-remote-source.d.ts +1 -0
- package/dist/src/command-line/import/utils/merge-remote-source.js +10 -1
- package/dist/src/command-line/init/implementation/angular/legacy-angular-versions.js +17 -5
- package/dist/src/command-line/init/init-v1.js +2 -2
- package/dist/src/command-line/init/init-v2.js +4 -4
- package/dist/src/command-line/migrate/migrate-analytics.js +2 -2
- package/dist/src/command-line/migrate/migrate.d.ts +3 -0
- package/dist/src/command-line/migrate/migrate.js +40 -22
- package/dist/src/command-line/migrate/workspace-installation.d.ts +15 -0
- package/dist/src/command-line/migrate/workspace-installation.js +73 -0
- package/dist/src/command-line/nx-cloud/complete-run/command-object.js +1 -1
- package/dist/src/command-line/nx-cloud/fix-ci/command-object.js +1 -1
- package/dist/src/command-line/nx-cloud/logout/command-object.js +11 -2
- package/dist/src/command-line/nx-cloud/record/command-object.js +1 -1
- package/dist/src/command-line/nx-cloud/record/record.js +3 -2
- package/dist/src/command-line/nx-cloud/start-ci-run/command-object.js +1 -1
- package/dist/src/command-line/nx-cloud/start-nx-agents/command-object.js +1 -1
- package/dist/src/command-line/nx-commands.js +3 -1
- package/dist/src/command-line/release/changelog/version-plan-filtering.js +4 -1
- package/dist/src/command-line/release/changelog.js +8 -3
- package/dist/src/command-line/release/config/version-plans.js +29 -29
- package/dist/src/command-line/release/utils/git.d.ts +2 -0
- package/dist/src/command-line/release/utils/git.js +49 -26
- package/dist/src/command-line/release/utils/markdown.js +4 -1
- package/dist/src/command-line/release/utils/remote-release-clients/github.js +18 -7
- package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +3 -1
- package/dist/src/command-line/release/version/derive-specifier-from-conventional-commits.js +1 -1
- package/dist/src/command-line/release/version/version-actions.js +2 -1
- package/dist/src/command-line/release/version.js +2 -1
- package/dist/src/command-line/show/show-target/info.d.ts +1 -1
- package/dist/src/command-line/show/show-target/info.js +4 -4
- package/dist/src/core/graph/favicon.ico +0 -0
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/core/graph/styles.js +1 -1
- package/dist/src/daemon/server/latest-nx.js +2 -2
- package/dist/src/daemon/server/project-graph-incremental-recomputation.js +3 -1
- package/dist/src/executors/run-commands/running-tasks.js +7 -0
- package/dist/src/executors/run-commands/schema.json +1 -1
- package/dist/src/hasher/native-task-hasher-impl.js +5 -2
- package/dist/src/native/index.d.ts +11 -1
- package/dist/src/native/index.js +12 -17
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +5 -6
- package/dist/src/nx-cloud/update-manager.d.ts +2 -0
- package/dist/src/nx-cloud/utilities/client.d.ts +1 -0
- package/dist/src/nx-cloud/utilities/client.js +5 -0
- package/dist/src/nx-cloud/utilities/get-cloud-options.d.ts +1 -1
- package/dist/src/nx-cloud/utilities/get-cloud-options.js +5 -2
- package/dist/src/nx-cloud/utilities/is-workspace-claimed.js +1 -1
- package/dist/src/nx-cloud/utilities/url-shorten.d.ts +1 -1
- package/dist/src/nx-cloud/utilities/url-shorten.js +4 -4
- package/dist/src/plugins/js/lock-file/yarn-parser.js +49 -2
- package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +2 -1
- package/dist/src/plugins/js/utils/register.js +3 -2
- package/dist/src/plugins/js/utils/typescript.js +3 -2
- package/dist/src/project-graph/utils/retrieve-workspace-files.js +2 -2
- package/dist/src/tasks-runner/cache.js +24 -8
- package/dist/src/tasks-runner/default-tasks-runner.js +21 -13
- package/dist/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +34 -13
- package/dist/src/tasks-runner/life-cycles/dynamic-run-one-terminal-output-life-cycle.js +26 -5
- package/dist/src/tasks-runner/life-cycles/performance-report.js +2 -2
- package/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +1 -1
- package/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +1 -1
- package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.js +3 -3
- package/dist/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +76 -39
- package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +2 -2
- package/dist/src/tasks-runner/running-tasks/batch-process.js +1 -1
- package/dist/src/tasks-runner/task-orchestrator.d.ts +6 -3
- package/dist/src/tasks-runner/task-orchestrator.js +61 -29
- package/dist/src/utils/git-utils.js +3 -3
- package/dist/src/utils/git-utils.tree-filter.js +102 -24
- package/dist/src/utils/installation-directory.d.ts +8 -0
- package/dist/src/utils/installation-directory.js +13 -0
- package/dist/src/utils/package-manager.d.ts +9 -3
- package/dist/src/utils/package-manager.js +64 -34
- package/dist/src/utils/provenance.d.ts +14 -1
- package/dist/src/utils/provenance.js +44 -13
- package/dist/src/utils/redact-url-credentials.d.ts +1 -0
- package/dist/src/utils/redact-url-credentials.js +7 -0
- package/dist/src/utils/workspace-id.d.ts +4 -3
- package/dist/src/utils/workspace-id.js +4 -3
- package/package.json +12 -12
|
@@ -195,8 +195,6 @@ class TaskOrchestrator {
|
|
|
195
195
|
// exit, and the paths that never spawn one write it inline. The backstop in
|
|
196
196
|
// postRunSteps consults this so a task's output is written exactly once.
|
|
197
197
|
this.tasksWithPersistedOutput = new Set();
|
|
198
|
-
/** Batches whose worker log was handed to the life cycle, so it must survive. */
|
|
199
|
-
this.announcedBatchLogs = new Set();
|
|
200
198
|
}
|
|
201
199
|
async init() {
|
|
202
200
|
this.setupSignalHandlers();
|
|
@@ -286,6 +284,9 @@ class TaskOrchestrator {
|
|
|
286
284
|
for (const task of Object.values(this.taskGraph.tasks)) {
|
|
287
285
|
if (!task.continuous && !this.completedTasks.has(task.id)) {
|
|
288
286
|
this.completedTasks.set(task.id, 'skipped');
|
|
287
|
+
if (this.tuiEnabled) {
|
|
288
|
+
this.options.lifeCycle.setTaskStatus(task.id, 2 /* NativeTaskStatus.Skipped */);
|
|
289
|
+
}
|
|
289
290
|
}
|
|
290
291
|
}
|
|
291
292
|
break;
|
|
@@ -782,8 +783,9 @@ class TaskOrchestrator {
|
|
|
782
783
|
async runBatch(batch, env, groupId) {
|
|
783
784
|
const runBatchStart = perf_hooks_1.performance.mark('TaskOrchestrator-run-batch:start');
|
|
784
785
|
let batchProcess;
|
|
786
|
+
let workerLogAnnounced = false;
|
|
785
787
|
try {
|
|
786
|
-
batchProcess = await this.forkedProcessTaskRunner.forkProcessForBatch(batch, this.projectGraph, this.fullTaskGraph, env,
|
|
788
|
+
batchProcess = await this.forkedProcessTaskRunner.forkProcessForBatch(batch, this.projectGraph, this.fullTaskGraph, env, this.printsBatchOutput());
|
|
787
789
|
// Stream output from batch process to the batch
|
|
788
790
|
batchProcess.onOutput((output) => {
|
|
789
791
|
this.options.lifeCycle.appendBatchOutput?.(batch.id, output);
|
|
@@ -837,7 +839,7 @@ class TaskOrchestrator {
|
|
|
837
839
|
if ((0, output_1.shouldGroupBatchOutput)()) {
|
|
838
840
|
this.renderBatchOutputSafely(batch.id, () => this.printGroupedBatchOutput(batch, taskResults, batchProcess.getCapturedOutputPath()));
|
|
839
841
|
}
|
|
840
|
-
this.announceBatchWorkerLog(batch.id, taskResults, batchProcess.getCapturedOutputPath());
|
|
842
|
+
workerLogAnnounced = this.announceBatchWorkerLog(batch.id, taskResults, batchProcess.getCapturedOutputPath());
|
|
841
843
|
return taskResults;
|
|
842
844
|
}
|
|
843
845
|
catch (e) {
|
|
@@ -855,7 +857,7 @@ class TaskOrchestrator {
|
|
|
855
857
|
};
|
|
856
858
|
});
|
|
857
859
|
await batchProcess?.flushCapturedOutput();
|
|
858
|
-
this.announceBatchWorkerLog(batch.id, taskResults, batchProcess?.getCapturedOutputPath());
|
|
860
|
+
workerLogAnnounced = this.announceBatchWorkerLog(batch.id, taskResults, batchProcess?.getCapturedOutputPath());
|
|
859
861
|
// The worker died without reporting results, so nothing was attributed to
|
|
860
862
|
// a task and no per-task output ran. Everything it wrote went to
|
|
861
863
|
// stdout/stderr, held back under grouping - surface it as one fold. Under
|
|
@@ -882,38 +884,45 @@ class TaskOrchestrator {
|
|
|
882
884
|
// Kept only when something failed and the log was announced; an all-green
|
|
883
885
|
// batch's chatter explains nothing and would sit in `batchOutputs/` until
|
|
884
886
|
// the sweep.
|
|
885
|
-
if (!
|
|
887
|
+
if (!workerLogAnnounced) {
|
|
886
888
|
batchProcess?.discardCapturedOutput();
|
|
887
889
|
}
|
|
888
890
|
const runBatchEnd = perf_hooks_1.performance.mark('TaskOrchestrator-run-batch:end');
|
|
889
891
|
perf_hooks_1.performance.measure('TaskOrchestrator-run-batch', runBatchStart.name, runBatchEnd.name);
|
|
890
892
|
}
|
|
891
893
|
}
|
|
894
|
+
/**
|
|
895
|
+
* Under the TUI, batch worker output reaches only the batch's pane, which
|
|
896
|
+
* closes with the batch (or the TUI, if pinned), so it is captured instead.
|
|
897
|
+
*/
|
|
898
|
+
printsBatchOutput() {
|
|
899
|
+
return (0, output_1.printsTaskOutput)(this.resolvedOutputStyle) && !this.tuiEnabled;
|
|
900
|
+
}
|
|
892
901
|
/**
|
|
893
902
|
* Tells the life cycle where the batch worker's own log is, when something
|
|
894
|
-
* failed and
|
|
903
|
+
* failed and its output was not printed as it streamed.
|
|
895
904
|
*
|
|
896
905
|
* The path is announced rather than the bytes copied into a task: one worker
|
|
897
906
|
* produces one log, it explains the batch rather than any single task, and a
|
|
898
907
|
* task's own output file is read back verbatim on a cache hit.
|
|
899
908
|
*/
|
|
900
909
|
announceBatchWorkerLog(batchId, results, capturedOutputPath) {
|
|
901
|
-
if (!capturedOutputPath ||
|
|
902
|
-
return;
|
|
910
|
+
if (!capturedOutputPath || this.printsBatchOutput()) {
|
|
911
|
+
return false;
|
|
903
912
|
}
|
|
904
913
|
const failed = results.some((r) => batchWorkerLogExplains(r.status));
|
|
905
914
|
if (!failed) {
|
|
906
|
-
return;
|
|
915
|
+
return false;
|
|
907
916
|
}
|
|
908
917
|
// The path is minted when the file is opened, before any byte reaches it,
|
|
909
918
|
// so a capture that failed on its first write leaves one that exists and is
|
|
910
919
|
// empty. Announcing that offers the reader an address holding nothing.
|
|
911
920
|
// Checked after the flush, so the size is what a reader will actually see.
|
|
912
921
|
if (!hasContent(capturedOutputPath)) {
|
|
913
|
-
return;
|
|
922
|
+
return false;
|
|
914
923
|
}
|
|
915
|
-
this.announcedBatchLogs.add(batchId);
|
|
916
924
|
this.options.lifeCycle.batchOutputAvailable?.(batchId, capturedOutputPath);
|
|
925
|
+
return true;
|
|
917
926
|
}
|
|
918
927
|
/**
|
|
919
928
|
* Rendering a batch's output must never change the batch's results. A throw
|
|
@@ -1107,7 +1116,7 @@ class TaskOrchestrator {
|
|
|
1107
1116
|
async handleDiscreteWorkerFailure(doNotSkipCache, task, groupId, e) {
|
|
1108
1117
|
if (this.completedTasks.has(task.id))
|
|
1109
1118
|
return;
|
|
1110
|
-
const terminalOutput = e?.message ??
|
|
1119
|
+
const terminalOutput = e?.message ?? String(e);
|
|
1111
1120
|
// The worker rejected, so whatever the runner was going to leave on disk
|
|
1112
1121
|
// either never landed or can't be trusted. Hand the file back to
|
|
1113
1122
|
// postRunSteps so the failure itself is what the task's output path holds.
|
|
@@ -1164,29 +1173,52 @@ class TaskOrchestrator {
|
|
|
1164
1173
|
let resolveDiscreteExit;
|
|
1165
1174
|
const discreteExitHandled = new Promise((r) => (resolveDiscreteExit = r));
|
|
1166
1175
|
this.discreteTaskExitHandled.set(task.id, discreteExitHandled);
|
|
1167
|
-
this.detectTaskInvocationLoop(task);
|
|
1168
|
-
const childProcess = await this.runTask(task, streamOutput, env, temporaryOutputPath, pipeOutput);
|
|
1169
|
-
this.runningDiscreteTasks.set(task.id, {
|
|
1170
|
-
runningTask: childProcess,
|
|
1171
|
-
stopping: false,
|
|
1172
|
-
});
|
|
1173
|
-
const { code, terminalOutput } = await childProcess.getResults();
|
|
1174
|
-
const isStopping = this.runningDiscreteTasks.get(task.id)?.stopping ?? false;
|
|
1175
|
-
this.runningDiscreteTasks.delete(task.id);
|
|
1176
|
-
const result = {
|
|
1177
|
-
task,
|
|
1178
|
-
code,
|
|
1179
|
-
status: isStopping ? 'stopped' : code === 0 ? 'success' : 'failure',
|
|
1180
|
-
terminalOutput,
|
|
1181
|
-
};
|
|
1182
1176
|
try {
|
|
1177
|
+
let result;
|
|
1178
|
+
try {
|
|
1179
|
+
this.detectTaskInvocationLoop(task);
|
|
1180
|
+
const childProcess = await this.runTask(task, streamOutput, env, temporaryOutputPath, pipeOutput);
|
|
1181
|
+
this.runningDiscreteTasks.set(task.id, {
|
|
1182
|
+
runningTask: childProcess,
|
|
1183
|
+
stopping: false,
|
|
1184
|
+
});
|
|
1185
|
+
// Rejects if run-commands cannot start or a forked child died before
|
|
1186
|
+
// writing its log, so postRunSteps writes the log instead
|
|
1187
|
+
const { code, terminalOutput } = await childProcess
|
|
1188
|
+
.getResults()
|
|
1189
|
+
.catch((e) => {
|
|
1190
|
+
this.tasksWithPersistedOutput.delete(task.id);
|
|
1191
|
+
return { code: 1, terminalOutput: e?.message ?? String(e) };
|
|
1192
|
+
});
|
|
1193
|
+
const isStopping = this.runningDiscreteTasks.get(task.id)?.stopping ?? false;
|
|
1194
|
+
this.runningDiscreteTasks.delete(task.id);
|
|
1195
|
+
result = {
|
|
1196
|
+
task,
|
|
1197
|
+
code,
|
|
1198
|
+
status: isStopping ? 'stopped' : code === 0 ? 'success' : 'failure',
|
|
1199
|
+
terminalOutput,
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
catch (e) {
|
|
1203
|
+
// Record the failure before the exit settles, since cleanup awaits the
|
|
1204
|
+
// exit to let endTasks finish before run() returns
|
|
1205
|
+
await this.handleDiscreteWorkerFailure(doNotSkipCache, task, groupId, e);
|
|
1206
|
+
return {
|
|
1207
|
+
task,
|
|
1208
|
+
code: 1,
|
|
1209
|
+
status: 'failure',
|
|
1210
|
+
terminalOutput: e?.message ?? String(e),
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
// A failed postRunSteps rejects to the caller. dispatchDiscreteWorker
|
|
1214
|
+
// handles it, and handling it here too prints the failure twice
|
|
1183
1215
|
await this.postRunSteps([result], doNotSkipCache, groupId);
|
|
1216
|
+
return result;
|
|
1184
1217
|
}
|
|
1185
1218
|
finally {
|
|
1186
1219
|
this.discreteTaskExitHandled.delete(task.id);
|
|
1187
1220
|
resolveDiscreteExit();
|
|
1188
1221
|
}
|
|
1189
|
-
return result;
|
|
1190
1222
|
}
|
|
1191
1223
|
async runTask(task, streamOutput, env, temporaryOutputPath, pipeOutput) {
|
|
1192
1224
|
const shouldPrefix = streamOutput &&
|
|
@@ -114,7 +114,7 @@ class GitRepository {
|
|
|
114
114
|
]);
|
|
115
115
|
}
|
|
116
116
|
async fetch(remote, ref) {
|
|
117
|
-
return await this.execGit(['fetch', remote, ...(ref ? [ref] : [])]);
|
|
117
|
+
return await this.execGit(['fetch', '--', remote, ...(ref ? [ref] : [])]);
|
|
118
118
|
}
|
|
119
119
|
async checkout(branch, opts) {
|
|
120
120
|
return await this.execGit([
|
|
@@ -128,7 +128,7 @@ class GitRepository {
|
|
|
128
128
|
return await this.execGit(['mv', '--', path, destination]);
|
|
129
129
|
}
|
|
130
130
|
async push(ref, remoteName) {
|
|
131
|
-
return await this.execGit(['push', '-u', '-f', remoteName, ref]);
|
|
131
|
+
return await this.execGit(['push', '-u', '-f', '--', remoteName, ref]);
|
|
132
132
|
}
|
|
133
133
|
async commit(message) {
|
|
134
134
|
return await this.execGit(['commit', '-am', message]);
|
|
@@ -140,7 +140,7 @@ class GitRepository {
|
|
|
140
140
|
return await this.execGit(['remote', 'rm', name]);
|
|
141
141
|
}
|
|
142
142
|
async addGitRemote(name, url) {
|
|
143
|
-
return await this.execGit(['remote', 'add', name, url]);
|
|
143
|
+
return await this.execGit(['remote', 'add', '--no-tags', name, url]);
|
|
144
144
|
}
|
|
145
145
|
async hasFilterRepoInstalled() {
|
|
146
146
|
try {
|
|
@@ -8,36 +8,114 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
* Example:
|
|
9
9
|
* NX_IMPORT_SOURCE=<source> NX_IMPORT_DESTINATION=<destination> git filter-branch --tree-filter 'node git-utils.tree-filter.js' --prune-empty -- --all
|
|
10
10
|
*/
|
|
11
|
-
const {
|
|
12
|
-
const {
|
|
13
|
-
//
|
|
14
|
-
const
|
|
11
|
+
const { execFileSync } = require('child_process');
|
|
12
|
+
const { lstatSync, mkdirSync, mkdtempSync, readdirSync, renameSync, rmdirSync, rmSync, } = require('fs');
|
|
13
|
+
// Paths are raw bytes so names that are not valid UTF-8 move unchanged.
|
|
14
|
+
const SLASH = 0x2f;
|
|
15
|
+
function split(path, separator) {
|
|
16
|
+
const parts = [];
|
|
17
|
+
let start = 0;
|
|
18
|
+
for (let i = 0; i <= path.length; i++) {
|
|
19
|
+
if (i === path.length || path[i] === separator) {
|
|
20
|
+
if (i > start)
|
|
21
|
+
parts.push(path.subarray(start, i));
|
|
22
|
+
start = i + 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return parts;
|
|
26
|
+
}
|
|
27
|
+
function joinPath(parts) {
|
|
28
|
+
const joined = [];
|
|
29
|
+
for (const part of parts) {
|
|
30
|
+
if (joined.length)
|
|
31
|
+
joined.push(Buffer.from('/'));
|
|
32
|
+
joined.push(part);
|
|
33
|
+
}
|
|
34
|
+
return Buffer.concat(joined);
|
|
35
|
+
}
|
|
36
|
+
// Creates the missing directories of `parts` and refuses to pass through
|
|
37
|
+
// anything that is not a real directory.
|
|
38
|
+
function ensureRealDir(parts) {
|
|
39
|
+
for (let i = 1; i <= parts.length; i++) {
|
|
40
|
+
const current = joinPath(parts.slice(0, i));
|
|
41
|
+
let stats;
|
|
42
|
+
try {
|
|
43
|
+
stats = lstatSync(current);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error.code !== 'ENOENT')
|
|
47
|
+
throw error;
|
|
48
|
+
mkdirSync(current);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (!stats.isDirectory()) {
|
|
52
|
+
throw new Error(`${current.toString()} is not a directory`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function removeEmptyDirs(path) {
|
|
57
|
+
if (!lstatSync(path).isDirectory())
|
|
58
|
+
return;
|
|
59
|
+
for (const entry of readdirSync(path, { encoding: 'buffer' })) {
|
|
60
|
+
removeEmptyDirs(joinPath([path, entry]));
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
rmdirSync(path);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error.code !== 'ENOTEMPTY' && error.code !== 'EEXIST')
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
15
70
|
try {
|
|
16
71
|
// NOTE: Using env vars because Windows PowerShell has its own handling of quotes (") messes up quotes in args, even if escaped.
|
|
72
|
+
// NOTE: The paths passed to `git filter-branch` are POSIX.
|
|
17
73
|
const src = process.env.NX_IMPORT_SOURCE;
|
|
18
74
|
const dest = process.env.NX_IMPORT_DESTINATION;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
75
|
+
if (src !== dest) {
|
|
76
|
+
const srcParts = split(Buffer.from(src), SLASH);
|
|
77
|
+
const files = split(execFileSync('git', ['ls-files', '-z', '--', ...(src ? [src] : [])], {
|
|
78
|
+
windowsHide: true,
|
|
79
|
+
maxBuffer: 1024 * 1024 * 1024,
|
|
80
|
+
}), 0);
|
|
81
|
+
// Move everything into a fresh directory first, so the destination is
|
|
82
|
+
// created in a tree that no longer holds any imported entries.
|
|
83
|
+
const staging = Buffer.from(mkdtempSync('.nx-import-'));
|
|
84
|
+
const leftovers = [];
|
|
85
|
+
for (const file of files) {
|
|
86
|
+
const parts = split(file, SLASH);
|
|
87
|
+
const inSource = srcParts.every((part, i) => parts[i]?.equals(part));
|
|
88
|
+
ensureRealDir(parts.slice(0, -1));
|
|
89
|
+
if (inSource && parts.length === srcParts.length) {
|
|
90
|
+
// The source path is itself a file, so it is the only entry and
|
|
91
|
+
// takes the staging directory's place.
|
|
92
|
+
rmdirSync(staging);
|
|
93
|
+
renameSync(file, staging);
|
|
94
|
+
}
|
|
95
|
+
else if (inSource) {
|
|
96
|
+
const target = [staging, ...parts.slice(srcParts.length)];
|
|
97
|
+
ensureRealDir(target.slice(0, -1));
|
|
98
|
+
renameSync(file, joinPath(target));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
rmSync(file);
|
|
102
|
+
}
|
|
103
|
+
if (parts.length > 1)
|
|
104
|
+
leftovers.push(parts[0].toString('hex'));
|
|
105
|
+
}
|
|
106
|
+
for (const leftover of new Set(leftovers)) {
|
|
107
|
+
removeEmptyDirs(Buffer.from(leftover, 'hex'));
|
|
108
|
+
}
|
|
109
|
+
const destParts = split(Buffer.from(dest), SLASH);
|
|
110
|
+
if (destParts.length) {
|
|
111
|
+
ensureRealDir(destParts.slice(0, -1));
|
|
112
|
+
renameSync(staging, joinPath(destParts));
|
|
37
113
|
}
|
|
38
114
|
else {
|
|
39
|
-
|
|
40
|
-
|
|
115
|
+
for (const entry of readdirSync(staging, { encoding: 'buffer' })) {
|
|
116
|
+
renameSync(joinPath([staging, entry]), entry);
|
|
117
|
+
}
|
|
118
|
+
rmdirSync(staging);
|
|
41
119
|
}
|
|
42
120
|
}
|
|
43
121
|
}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export declare function getNxInstallationPath(root?: string): string;
|
|
2
2
|
export declare function getNxRequirePaths(root?: string): string[];
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a package the workspace provides (typescript, a release version
|
|
5
|
+
* actions implementation, ...) from the workspace first, then from this nx
|
|
6
|
+
* installation. A package manager's global or content-addressed store links nx
|
|
7
|
+
* only to its own dependencies, so resolving from nx's location alone cannot
|
|
8
|
+
* see what the workspace installs.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveFromWorkspace(specifier: string, root?: string): string;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNxInstallationPath = getNxInstallationPath;
|
|
4
4
|
exports.getNxRequirePaths = getNxRequirePaths;
|
|
5
|
+
exports.resolveFromWorkspace = resolveFromWorkspace;
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
const workspace_root_1 = require("./workspace-root");
|
|
7
8
|
function getNxInstallationPath(root = workspace_root_1.workspaceRoot) {
|
|
@@ -10,3 +11,15 @@ function getNxInstallationPath(root = workspace_root_1.workspaceRoot) {
|
|
|
10
11
|
function getNxRequirePaths(root = workspace_root_1.workspaceRoot) {
|
|
11
12
|
return [getNxInstallationPath(root), root];
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a package the workspace provides (typescript, a release version
|
|
16
|
+
* actions implementation, ...) from the workspace first, then from this nx
|
|
17
|
+
* installation. A package manager's global or content-addressed store links nx
|
|
18
|
+
* only to its own dependencies, so resolving from nx's location alone cannot
|
|
19
|
+
* see what the workspace installs.
|
|
20
|
+
*/
|
|
21
|
+
function resolveFromWorkspace(specifier, root = workspace_root_1.workspaceRoot) {
|
|
22
|
+
return require.resolve(specifier, {
|
|
23
|
+
paths: [...getNxRequirePaths(root), __dirname],
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -17,15 +17,16 @@ export interface PackageManagerCommands {
|
|
|
17
17
|
* @deprecated Use `publishArgv` instead, which needs no shell off Windows.
|
|
18
18
|
* This will be removed in Nx 25.
|
|
19
19
|
*/
|
|
20
|
-
publish: (packageRoot: string, registry: string, registryConfigKey: string, tag: string) => string;
|
|
21
|
-
publishArgv: (packageRoot: string, registry: string, registryConfigKey: string, tag: string) => {
|
|
20
|
+
publish: (packageRoot: string, registry: string | undefined, registryConfigKey: string, tag: string) => string;
|
|
21
|
+
publishArgv: (packageRoot: string, registry: string | undefined, registryConfigKey: string, tag: string) => {
|
|
22
22
|
command: string;
|
|
23
23
|
args: string[];
|
|
24
24
|
};
|
|
25
25
|
ignoreScriptsFlag?: string;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Detects
|
|
28
|
+
* Detects the package manager from the CLI override or directory lockfiles.
|
|
29
|
+
* Project directories in the current workspace can fall back to its root lockfile.
|
|
29
30
|
*/
|
|
30
31
|
export declare function detectPackageManager(dir?: string): PackageManager;
|
|
31
32
|
/**
|
|
@@ -100,6 +101,11 @@ export declare function modifyYarnRcToFitNewDirectory(contents: string): string;
|
|
|
100
101
|
*/
|
|
101
102
|
export declare function modifyPnpmWorkspaceYamlToFitNewDirectory(contents: string): string;
|
|
102
103
|
export declare function copyPackageManagerConfigurationFiles(root: string, destination: string): void;
|
|
104
|
+
/**
|
|
105
|
+
* A non-JS workspace has no root package.json and keeps its package manager
|
|
106
|
+
* files under the Nx installation directory instead.
|
|
107
|
+
*/
|
|
108
|
+
export declare function getPackageManagerConfigRoot(root?: string): string;
|
|
103
109
|
/**
|
|
104
110
|
* Creates a temporary directory where you can run package manager commands safely.
|
|
105
111
|
*
|
|
@@ -10,6 +10,7 @@ exports.modifyYarnRcYmlToFitNewDirectory = modifyYarnRcYmlToFitNewDirectory;
|
|
|
10
10
|
exports.modifyYarnRcToFitNewDirectory = modifyYarnRcToFitNewDirectory;
|
|
11
11
|
exports.modifyPnpmWorkspaceYamlToFitNewDirectory = modifyPnpmWorkspaceYamlToFitNewDirectory;
|
|
12
12
|
exports.copyPackageManagerConfigurationFiles = copyPackageManagerConfigurationFiles;
|
|
13
|
+
exports.getPackageManagerConfigRoot = getPackageManagerConfigRoot;
|
|
13
14
|
exports.createTempNpmDirectory = createTempNpmDirectory;
|
|
14
15
|
exports.resolvePackageVersionUsingRegistry = resolvePackageVersionUsingRegistry;
|
|
15
16
|
exports.resolvePackageVersionUsingInstallation = resolvePackageVersionUsingInstallation;
|
|
@@ -36,6 +37,7 @@ const fileutils_1 = require("./fileutils");
|
|
|
36
37
|
const installation_directory_1 = require("./installation-directory");
|
|
37
38
|
const logger_1 = require("./logger");
|
|
38
39
|
const package_json_1 = require("./package-json");
|
|
40
|
+
const redact_url_credentials_1 = require("./redact-url-credentials");
|
|
39
41
|
const shell_quoting_1 = require("./shell-quoting");
|
|
40
42
|
const workspace_root_1 = require("./workspace-root");
|
|
41
43
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
@@ -65,20 +67,50 @@ function execPackageManagerSync(pm, args, options) {
|
|
|
65
67
|
return (0, child_process_1.execFileSync)(pm, args, options);
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
|
-
* Detects
|
|
70
|
+
* Detects the package manager from the CLI override or directory lockfiles.
|
|
71
|
+
* Project directories in the current workspace can fall back to its root lockfile.
|
|
69
72
|
*/
|
|
70
|
-
function detectPackageManager(dir =
|
|
73
|
+
function detectPackageManager(dir = workspace_root_1.workspaceRoot) {
|
|
71
74
|
const nxJson = (0, configuration_1.readNxJson)();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
if (nxJson.cli?.packageManager) {
|
|
76
|
+
return nxJson.cli.packageManager;
|
|
77
|
+
}
|
|
78
|
+
const dirsToCheck = isCurrentWorkspaceSubdirectory(dir)
|
|
79
|
+
? [dir, workspace_root_1.workspaceRoot]
|
|
80
|
+
: [dir];
|
|
81
|
+
for (const directory of dirsToCheck) {
|
|
82
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(directory, 'bun.lockb')) ||
|
|
83
|
+
(0, fs_1.existsSync)((0, path_1.join)(directory, 'bun.lock'))) {
|
|
84
|
+
return 'bun';
|
|
85
|
+
}
|
|
86
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(directory, 'yarn.lock'))) {
|
|
87
|
+
return 'yarn';
|
|
88
|
+
}
|
|
89
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(directory, 'pnpm-lock.yaml'))) {
|
|
90
|
+
return 'pnpm';
|
|
91
|
+
}
|
|
92
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(directory, 'package-lock.json'))) {
|
|
93
|
+
return 'npm';
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return detectInvokedPackageManager();
|
|
97
|
+
}
|
|
98
|
+
function isCurrentWorkspaceSubdirectory(dir) {
|
|
99
|
+
let directory = (0, path_1.resolve)(dir);
|
|
100
|
+
const relativePath = (0, path_1.relative)(workspace_root_1.workspaceRoot, directory);
|
|
101
|
+
if (!relativePath ||
|
|
102
|
+
relativePath === '..' ||
|
|
103
|
+
relativePath.startsWith(`..${path_1.sep}`) ||
|
|
104
|
+
(0, path_1.isAbsolute)(relativePath)) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
while ((0, path_1.relative)(workspace_root_1.workspaceRoot, directory) !== '') {
|
|
108
|
+
if (['nx.json', 'nx', 'nx.bat'].some((file) => (0, fileutils_1.fileExists)((0, path_1.join)(directory, file)))) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
directory = (0, path_1.dirname)(directory);
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
82
114
|
}
|
|
83
115
|
/**
|
|
84
116
|
* Detects which package manager was used to invoke the current command
|
|
@@ -164,7 +196,7 @@ function getPackageManagerCommand(packageManager = detectPackageManager(), root
|
|
|
164
196
|
'publish',
|
|
165
197
|
packageRoot,
|
|
166
198
|
'--json',
|
|
167
|
-
`--${registryConfigKey}=${registry}
|
|
199
|
+
...(registry ? [`--${registryConfigKey}=${registry}`] : []),
|
|
168
200
|
`--tag=${tag}`,
|
|
169
201
|
],
|
|
170
202
|
});
|
|
@@ -219,11 +251,15 @@ function getPackageManagerCommand(packageManager = detectPackageManager(), root
|
|
|
219
251
|
'publish',
|
|
220
252
|
packageRoot,
|
|
221
253
|
'--json',
|
|
222
|
-
|
|
223
|
-
?
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
254
|
+
...(registry
|
|
255
|
+
? [
|
|
256
|
+
`--${configForm
|
|
257
|
+
? `config.${registryConfigKey}`
|
|
258
|
+
: scopedForm
|
|
259
|
+
? registryConfigKey
|
|
260
|
+
: 'registry'}=${registry}`,
|
|
261
|
+
]
|
|
262
|
+
: []),
|
|
227
263
|
`--tag=${tag}`,
|
|
228
264
|
'--no-git-checks',
|
|
229
265
|
],
|
|
@@ -261,7 +297,7 @@ function getPackageManagerCommand(packageManager = detectPackageManager(), root
|
|
|
261
297
|
'publish',
|
|
262
298
|
packageRoot,
|
|
263
299
|
'--json',
|
|
264
|
-
`--${registryConfigKey}=${registry}
|
|
300
|
+
...(registry ? [`--${registryConfigKey}=${registry}`] : []),
|
|
265
301
|
`--tag=${tag}`,
|
|
266
302
|
],
|
|
267
303
|
});
|
|
@@ -290,7 +326,7 @@ function getPackageManagerCommand(packageManager = detectPackageManager(), root
|
|
|
290
326
|
'publish',
|
|
291
327
|
`--cwd=${packageRoot}`,
|
|
292
328
|
'--json',
|
|
293
|
-
`--registry=${registry}
|
|
329
|
+
...(registry ? [`--registry=${registry}`] : []),
|
|
294
330
|
`--tag=${tag}`,
|
|
295
331
|
],
|
|
296
332
|
});
|
|
@@ -509,21 +545,19 @@ function copyPackageManagerConfigurationFiles(root, destination) {
|
|
|
509
545
|
* A non-JS workspace has no root package.json and keeps its package manager
|
|
510
546
|
* files under the Nx installation directory instead.
|
|
511
547
|
*/
|
|
512
|
-
function getPackageManagerConfigRoot() {
|
|
513
|
-
if ((0, fs_1.existsSync)((0, path_1.join)(
|
|
514
|
-
return
|
|
548
|
+
function getPackageManagerConfigRoot(root = workspace_root_1.workspaceRoot) {
|
|
549
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(root, 'package.json'))) {
|
|
550
|
+
return root;
|
|
515
551
|
}
|
|
516
|
-
const installationPath = (0, installation_directory_1.getNxInstallationPath)(
|
|
552
|
+
const installationPath = (0, installation_directory_1.getNxInstallationPath)(root);
|
|
517
553
|
// The installation directory can be missing or not a directory, and spawning
|
|
518
554
|
// with such a cwd fails outright (ENOENT/ENOTDIR).
|
|
519
555
|
try {
|
|
520
|
-
return (0, fs_1.statSync)(installationPath).isDirectory()
|
|
521
|
-
? installationPath
|
|
522
|
-
: workspace_root_1.workspaceRoot;
|
|
556
|
+
return (0, fs_1.statSync)(installationPath).isDirectory() ? installationPath : root;
|
|
523
557
|
}
|
|
524
558
|
catch (e) {
|
|
525
559
|
logger_1.logger.verbose(`Failed to stat the Nx installation directory at "${installationPath}".`, e);
|
|
526
|
-
return
|
|
560
|
+
return root;
|
|
527
561
|
}
|
|
528
562
|
}
|
|
529
563
|
/**
|
|
@@ -593,17 +627,13 @@ async function resolvePackageVersionUsingRegistry(packageName, version) {
|
|
|
593
627
|
});
|
|
594
628
|
}
|
|
595
629
|
}
|
|
596
|
-
// Masks the userinfo in a URL: `user`, `user:pass`, or a bare token.
|
|
597
|
-
function redactUrlCredentials(text) {
|
|
598
|
-
return text.replace(/([a-z][a-z0-9+.-]*:\/\/)[^/@\s]+@/gi, '$1***@');
|
|
599
|
-
}
|
|
600
630
|
function redactErrorCause(error) {
|
|
601
631
|
if (error && typeof error === 'object') {
|
|
602
632
|
const e = error;
|
|
603
633
|
// An exec error carries the command and both output streams as fields.
|
|
604
634
|
for (const field of ['message', 'stack', 'stderr', 'stdout', 'cmd']) {
|
|
605
635
|
if (typeof e[field] === 'string') {
|
|
606
|
-
e[field] = redactUrlCredentials(e[field]);
|
|
636
|
+
e[field] = (0, redact_url_credentials_1.redactUrlCredentials)(e[field]);
|
|
607
637
|
}
|
|
608
638
|
}
|
|
609
639
|
}
|
|
@@ -703,7 +733,7 @@ function getWorkspaceRegistryUrlForDisplay(pkg) {
|
|
|
703
733
|
if (protocol !== 'http:' && protocol !== 'https:') {
|
|
704
734
|
return null;
|
|
705
735
|
}
|
|
706
|
-
return redactUrlCredentials(value);
|
|
736
|
+
return (0, redact_url_credentials_1.redactUrlCredentials)(value);
|
|
707
737
|
}
|
|
708
738
|
return null;
|
|
709
739
|
}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Resolves `spec` to the version the workspace's package manager would
|
|
3
|
+
* install under its minimum-release-age policy, verifies that version's
|
|
4
|
+
* provenance, and returns it. Install the returned version, not `spec`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveVersionWithProvenance(packageName: string, spec: string, root?: string): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Verifies that the given npm package has provenance attestations
|
|
9
|
+
* generated by the GitHub Actions workflow at .github/workflows/publish.yml
|
|
10
|
+
* in the nrwl/nx repository, and resolves to the exact version it verified.
|
|
11
|
+
*
|
|
12
|
+
* Will throw if the package does not have valid provenance.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ensurePackageHasProvenance(packageName: string, packageVersion: string): Promise<string>;
|
|
2
15
|
export declare class ProvenanceError extends Error {
|
|
3
16
|
constructor(packageName: string, packageVersion: string, error?: string);
|
|
4
17
|
}
|