ai-project-manage-cli 8.0.1 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +298 -1055
- package/dist/webide-message-worker.js +4 -131
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -180,10 +180,6 @@ var init_request_config = __esm({
|
|
|
180
180
|
method: "GET",
|
|
181
181
|
path: "/cli/workspaces/baseline"
|
|
182
182
|
}),
|
|
183
|
-
matchRepository: defineEndpoint({
|
|
184
|
-
method: "GET",
|
|
185
|
-
path: "/cli/repositories/match"
|
|
186
|
-
}),
|
|
187
183
|
createWebIdeDraftPullRequest: defineEndpoint({
|
|
188
184
|
method: "POST",
|
|
189
185
|
path: "/cli/webide/draft-pull-requests"
|
|
@@ -208,22 +204,6 @@ var init_request_config = __esm({
|
|
|
208
204
|
method: "DELETE",
|
|
209
205
|
path: "/cli/project-documents"
|
|
210
206
|
}),
|
|
211
|
-
createTaskDeployment: defineEndpoint({
|
|
212
|
-
method: "POST",
|
|
213
|
-
path: "/cli/task-deployments"
|
|
214
|
-
}),
|
|
215
|
-
updateTaskDeploymentStatus: defineEndpoint({
|
|
216
|
-
method: "PUT",
|
|
217
|
-
path: "/cli/task-deployments/status"
|
|
218
|
-
}),
|
|
219
|
-
syncTaskDeploymentLog: defineEndpoint({
|
|
220
|
-
method: "PUT",
|
|
221
|
-
path: "/cli/task-deployments/log"
|
|
222
|
-
}),
|
|
223
|
-
completeTaskDeployment: defineEndpoint({
|
|
224
|
-
method: "PUT",
|
|
225
|
-
path: "/cli/task-deployments/complete"
|
|
226
|
-
}),
|
|
227
207
|
getDeployArtifactStorage: defineEndpoint(
|
|
228
208
|
{
|
|
229
209
|
method: "GET",
|
|
@@ -233,10 +213,6 @@ var init_request_config = __esm({
|
|
|
233
213
|
getApmLogStorage: defineEndpoint({
|
|
234
214
|
method: "GET",
|
|
235
215
|
path: "/cli/apm-log-storage"
|
|
236
|
-
}),
|
|
237
|
-
attachTaskDeploymentArtifact: defineEndpoint({
|
|
238
|
-
method: "PUT",
|
|
239
|
-
path: "/cli/task-deployments/artifact"
|
|
240
216
|
})
|
|
241
217
|
}
|
|
242
218
|
};
|
|
@@ -267,13 +243,13 @@ var init_client = __esm({
|
|
|
267
243
|
});
|
|
268
244
|
|
|
269
245
|
// src/commands/deploy/internal/minio.ts
|
|
270
|
-
import { statSync as
|
|
246
|
+
import { statSync as statSync3 } from "node:fs";
|
|
271
247
|
import { readdir, readFile } from "node:fs/promises";
|
|
272
248
|
import path from "node:path";
|
|
273
249
|
import * as Minio from "minio";
|
|
274
250
|
async function isDirectoryPath(dir) {
|
|
275
251
|
try {
|
|
276
|
-
const st =
|
|
252
|
+
const st = statSync3(dir);
|
|
277
253
|
return st.isDirectory();
|
|
278
254
|
} catch {
|
|
279
255
|
return false;
|
|
@@ -303,7 +279,7 @@ async function collectFiles(root) {
|
|
|
303
279
|
if (e.isDirectory()) {
|
|
304
280
|
await walk(abs, rel);
|
|
305
281
|
} else if (e.isFile()) {
|
|
306
|
-
const st =
|
|
282
|
+
const st = statSync3(abs);
|
|
307
283
|
out.push({
|
|
308
284
|
absPath: abs,
|
|
309
285
|
relativePath: rel.replace(/\\/g, "/"),
|
|
@@ -370,14 +346,14 @@ var init_minio = __esm({
|
|
|
370
346
|
async deleteObjectsByPrefix(bucket, prefix) {
|
|
371
347
|
const objectsStream = this.inner.listObjectsV2(bucket, prefix, true);
|
|
372
348
|
const keys = [];
|
|
373
|
-
await new Promise((
|
|
349
|
+
await new Promise((resolve7, reject) => {
|
|
374
350
|
objectsStream.on("data", (obj) => {
|
|
375
351
|
if (obj.name) {
|
|
376
352
|
keys.push(obj.name);
|
|
377
353
|
}
|
|
378
354
|
});
|
|
379
355
|
objectsStream.on("error", reject);
|
|
380
|
-
objectsStream.on("end",
|
|
356
|
+
objectsStream.on("end", resolve7);
|
|
381
357
|
});
|
|
382
358
|
const chunkSize = 500;
|
|
383
359
|
for (let i = 0; i < keys.length; i += chunkSize) {
|
|
@@ -1409,16 +1385,16 @@ function hashLocalFileContent(content) {
|
|
|
1409
1385
|
return createHash("sha256").update(content, "utf8").digest("hex");
|
|
1410
1386
|
}
|
|
1411
1387
|
function readLocalManifest(apmRoot, projectId) {
|
|
1412
|
-
const
|
|
1388
|
+
const manifestPath = join4(
|
|
1413
1389
|
projectDocumentsDir(apmRoot, projectId),
|
|
1414
1390
|
MANIFEST_FILE
|
|
1415
1391
|
);
|
|
1416
|
-
if (!existsSync3(
|
|
1392
|
+
if (!existsSync3(manifestPath)) {
|
|
1417
1393
|
return null;
|
|
1418
1394
|
}
|
|
1419
1395
|
try {
|
|
1420
1396
|
return JSON.parse(
|
|
1421
|
-
readFileSync3(
|
|
1397
|
+
readFileSync3(manifestPath, "utf8")
|
|
1422
1398
|
);
|
|
1423
1399
|
} catch {
|
|
1424
1400
|
return null;
|
|
@@ -1650,7 +1626,7 @@ async function runSyncProjectDocuments(options) {
|
|
|
1650
1626
|
// src/commands/connect.ts
|
|
1651
1627
|
init_client();
|
|
1652
1628
|
import WebSocket from "ws";
|
|
1653
|
-
import { setTimeout as
|
|
1629
|
+
import { setTimeout as delay2 } from "node:timers/promises";
|
|
1654
1630
|
init_config();
|
|
1655
1631
|
|
|
1656
1632
|
// src/ws/protocol.ts
|
|
@@ -1752,7 +1728,6 @@ function validateDeployPush(o) {
|
|
|
1752
1728
|
deploymentRunId: o.deploymentRunId.trim(),
|
|
1753
1729
|
workdir: o.workdir.trim(),
|
|
1754
1730
|
environment,
|
|
1755
|
-
...typeof o.repositoryId === "string" && o.repositoryId.trim() ? { repositoryId: o.repositoryId.trim() } : {},
|
|
1756
1731
|
...o.packOnly === true ? { packOnly: true } : {}
|
|
1757
1732
|
}
|
|
1758
1733
|
};
|
|
@@ -1828,316 +1803,12 @@ function validateAgentWsMessage(value, kind) {
|
|
|
1828
1803
|
return validateWebIdeMessagePush(o);
|
|
1829
1804
|
}
|
|
1830
1805
|
|
|
1831
|
-
// src/commands/connect/deploy-run.ts
|
|
1832
|
-
init_client();
|
|
1833
|
-
|
|
1834
|
-
// src/git-remote.ts
|
|
1835
|
-
import { execFile } from "child_process";
|
|
1836
|
-
import { promisify } from "util";
|
|
1837
|
-
var execFileAsync = promisify(execFile);
|
|
1838
|
-
function toHttpsGitRemoteUrl(raw) {
|
|
1839
|
-
let s = raw.trim();
|
|
1840
|
-
if (!s) return null;
|
|
1841
|
-
const sshScp = /^git@([^:]+):(.+)$/.exec(s);
|
|
1842
|
-
if (sshScp) {
|
|
1843
|
-
s = `https://${sshScp[1]}/${sshScp[2]}`;
|
|
1844
|
-
} else {
|
|
1845
|
-
const sshUri = /^ssh:\/\/(?:git@)?([^/]+)\/(.+)$/i.exec(s);
|
|
1846
|
-
if (sshUri) {
|
|
1847
|
-
s = `https://${sshUri[1]}/${sshUri[2]}`;
|
|
1848
|
-
} else if (/^http:\/\//i.test(s)) {
|
|
1849
|
-
s = `https://${s.slice("http://".length)}`;
|
|
1850
|
-
} else if (!/^https:\/\//i.test(s)) {
|
|
1851
|
-
const scpLike = /^([^/:]+):(.+)$/.exec(s);
|
|
1852
|
-
if (scpLike && !scpLike[1].includes(".")) {
|
|
1853
|
-
return null;
|
|
1854
|
-
}
|
|
1855
|
-
if (scpLike) {
|
|
1856
|
-
s = `https://${scpLike[1]}/${scpLike[2]}`;
|
|
1857
|
-
} else if (s.includes("/")) {
|
|
1858
|
-
s = `https://${s}`;
|
|
1859
|
-
} else {
|
|
1860
|
-
return null;
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
s = s.replace(/\/+$/, "");
|
|
1865
|
-
if (!/^https:\/\//i.test(s)) return null;
|
|
1866
|
-
return s;
|
|
1867
|
-
}
|
|
1868
|
-
async function tryReadGitOriginUrl(cwd) {
|
|
1869
|
-
try {
|
|
1870
|
-
const { stdout } = await execFileAsync(
|
|
1871
|
-
"git",
|
|
1872
|
-
["config", "--get", "remote.origin.url"],
|
|
1873
|
-
{ cwd, encoding: "utf8", maxBuffer: 1024 * 1024 }
|
|
1874
|
-
);
|
|
1875
|
-
const url = stdout.trim();
|
|
1876
|
-
return url || null;
|
|
1877
|
-
} catch {
|
|
1878
|
-
return null;
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
async function tryReadHttpsGitOriginUrl(cwd) {
|
|
1882
|
-
const raw = await tryReadGitOriginUrl(cwd);
|
|
1883
|
-
if (!raw) return null;
|
|
1884
|
-
return toHttpsGitRemoteUrl(raw);
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
// src/git-utils.ts
|
|
1888
|
-
import { execFile as execFile2 } from "child_process";
|
|
1889
|
-
import { promisify as promisify2 } from "util";
|
|
1890
|
-
var execFileAsync2 = promisify2(execFile2);
|
|
1891
|
-
function gitExecEnv() {
|
|
1892
|
-
const existing = process.env.GIT_SSH_COMMAND?.trim();
|
|
1893
|
-
const acceptNew = "-o StrictHostKeyChecking=accept-new";
|
|
1894
|
-
let gitSshCommand;
|
|
1895
|
-
if (!existing) {
|
|
1896
|
-
gitSshCommand = `ssh ${acceptNew}`;
|
|
1897
|
-
} else if (/\bStrictHostKeyChecking=/.test(existing)) {
|
|
1898
|
-
gitSshCommand = existing;
|
|
1899
|
-
} else {
|
|
1900
|
-
gitSshCommand = `${existing} ${acceptNew}`;
|
|
1901
|
-
}
|
|
1902
|
-
return { ...process.env, GIT_SSH_COMMAND: gitSshCommand };
|
|
1903
|
-
}
|
|
1904
|
-
async function execGit(cwd, args, quiet = false) {
|
|
1905
|
-
try {
|
|
1906
|
-
const { stdout, stderr } = await execFileAsync2("git", args, {
|
|
1907
|
-
cwd,
|
|
1908
|
-
env: gitExecEnv(),
|
|
1909
|
-
encoding: "utf8",
|
|
1910
|
-
maxBuffer: 10 * 1024 * 1024
|
|
1911
|
-
});
|
|
1912
|
-
if (!quiet && stderr.trim()) {
|
|
1913
|
-
process.stderr.write(stderr);
|
|
1914
|
-
}
|
|
1915
|
-
return stdout;
|
|
1916
|
-
} catch (err) {
|
|
1917
|
-
const e = err;
|
|
1918
|
-
const detail = (e.stderr ?? e.message ?? String(err)).trim();
|
|
1919
|
-
throw new Error(
|
|
1920
|
-
`[apm] git ${args.join(" ")} \u5931\u8D25${detail ? `: ${detail}` : ""}`
|
|
1921
|
-
);
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
async function isGitRepo(cwd) {
|
|
1925
|
-
try {
|
|
1926
|
-
await execGit(cwd, ["rev-parse", "--git-dir"], true);
|
|
1927
|
-
return true;
|
|
1928
|
-
} catch {
|
|
1929
|
-
return false;
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
async function ensureGitRepo(cwd) {
|
|
1933
|
-
await execGit(cwd, ["rev-parse", "--git-dir"], true);
|
|
1934
|
-
}
|
|
1935
|
-
async function getCurrentBranch(cwd) {
|
|
1936
|
-
return (await execGit(cwd, ["rev-parse", "--abbrev-ref", "HEAD"], true)).trim();
|
|
1937
|
-
}
|
|
1938
|
-
async function isWorkingTreeDirty(cwd) {
|
|
1939
|
-
const out = await execGit(cwd, ["status", "--porcelain"], true);
|
|
1940
|
-
return out.trim().length > 0;
|
|
1941
|
-
}
|
|
1942
|
-
async function remoteBranchExists(cwd, branch) {
|
|
1943
|
-
const out = await execGit(
|
|
1944
|
-
cwd,
|
|
1945
|
-
["ls-remote", "--heads", "origin", branch],
|
|
1946
|
-
true
|
|
1947
|
-
);
|
|
1948
|
-
return out.trim().length > 0;
|
|
1949
|
-
}
|
|
1950
|
-
async function resolveGitRepoRoot(cwd) {
|
|
1951
|
-
return (await execGit(cwd, ["rev-parse", "--show-toplevel"], true)).trim();
|
|
1952
|
-
}
|
|
1953
|
-
async function ensureRemoteBaselineBranch(cwd, baselineBranch) {
|
|
1954
|
-
await execGit(cwd, ["fetch", "origin", baselineBranch], true);
|
|
1955
|
-
if (await remoteBranchExists(cwd, baselineBranch)) {
|
|
1956
|
-
return;
|
|
1957
|
-
}
|
|
1958
|
-
throw new Error(
|
|
1959
|
-
`[apm] \u8FDC\u7A0B\u4E0D\u5B58\u5728\u57FA\u7EBF\u5206\u652F origin/${baselineBranch}\uFF0C\u8BF7\u786E\u8BA4\u4ED3\u5E93\u9ED8\u8BA4\u5206\u652F\u5DF2\u63A8\u9001\u5230 origin`
|
|
1960
|
-
);
|
|
1961
|
-
}
|
|
1962
|
-
async function resolveDefaultRemoteBranch(cwd) {
|
|
1963
|
-
try {
|
|
1964
|
-
const ref = (await execGit(cwd, ["symbolic-ref", "refs/remotes/origin/HEAD"], true)).trim();
|
|
1965
|
-
const match = ref.match(/^refs\/remotes\/origin\/(.+)$/);
|
|
1966
|
-
if (match?.[1]) {
|
|
1967
|
-
return match[1];
|
|
1968
|
-
}
|
|
1969
|
-
} catch {
|
|
1970
|
-
}
|
|
1971
|
-
for (const candidate of ["main", "master"]) {
|
|
1972
|
-
if (await remoteBranchExists(cwd, candidate)) {
|
|
1973
|
-
return candidate;
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
throw new Error(
|
|
1977
|
-
"[apm] \u65E0\u6CD5\u786E\u5B9A\u8FDC\u7A0B\u9ED8\u8BA4\u5206\u652F\uFF08origin/HEAD\u3001main\u3001master \u5747\u4E0D\u53EF\u7528\uFF09"
|
|
1978
|
-
);
|
|
1979
|
-
}
|
|
1980
|
-
|
|
1981
|
-
// src/workspace-repos.ts
|
|
1982
|
-
import {
|
|
1983
|
-
existsSync as existsSync4,
|
|
1984
|
-
mkdirSync as mkdirSync3,
|
|
1985
|
-
readFileSync as readFileSync4,
|
|
1986
|
-
readdirSync as readdirSync3,
|
|
1987
|
-
statSync as statSync3,
|
|
1988
|
-
writeFileSync as writeFileSync3
|
|
1989
|
-
} from "fs";
|
|
1990
|
-
import { basename, dirname as dirname4, join as join5, relative as relative2, resolve as resolve3 } from "path";
|
|
1991
|
-
var WORKSPACE_REPOS_MANIFEST = "workspace-repos.json";
|
|
1992
|
-
var WORKSPACE_REPOS_VERSION = 1;
|
|
1993
|
-
function manifestPath(workdir) {
|
|
1994
|
-
return join5(workspaceApmDir(workdir), WORKSPACE_REPOS_MANIFEST);
|
|
1995
|
-
}
|
|
1996
|
-
function absoluteRepoPath(workdir, entry) {
|
|
1997
|
-
if (entry.path === "." || entry.path === "") {
|
|
1998
|
-
return workdir;
|
|
1999
|
-
}
|
|
2000
|
-
return resolve3(workdir, entry.path);
|
|
2001
|
-
}
|
|
2002
|
-
function normalizeRepoEntry(raw) {
|
|
2003
|
-
if (!raw || typeof raw !== "object") return null;
|
|
2004
|
-
const o = raw;
|
|
2005
|
-
if (typeof o.path !== "string" || !o.path.trim()) return null;
|
|
2006
|
-
const entry = {
|
|
2007
|
-
path: o.path.trim().replace(/\\/g, "/")
|
|
2008
|
-
};
|
|
2009
|
-
if (typeof o.remoteUrl === "string" && o.remoteUrl.trim()) {
|
|
2010
|
-
entry.remoteUrl = o.remoteUrl.trim();
|
|
2011
|
-
} else if (o.remoteUrl === null) {
|
|
2012
|
-
entry.remoteUrl = null;
|
|
2013
|
-
}
|
|
2014
|
-
return entry;
|
|
2015
|
-
}
|
|
2016
|
-
function readManifest(workdir) {
|
|
2017
|
-
const path19 = toFsPath(manifestPath(workdir));
|
|
2018
|
-
if (!existsSync4(path19)) {
|
|
2019
|
-
return null;
|
|
2020
|
-
}
|
|
2021
|
-
try {
|
|
2022
|
-
const raw = JSON.parse(
|
|
2023
|
-
readFileSync4(path19, "utf8")
|
|
2024
|
-
);
|
|
2025
|
-
if (raw?.version !== WORKSPACE_REPOS_VERSION) {
|
|
2026
|
-
return null;
|
|
2027
|
-
}
|
|
2028
|
-
if (raw.kind !== "single" && raw.kind !== "multi") {
|
|
2029
|
-
return null;
|
|
2030
|
-
}
|
|
2031
|
-
if (!Array.isArray(raw.repos) || raw.repos.length === 0) {
|
|
2032
|
-
return null;
|
|
2033
|
-
}
|
|
2034
|
-
if (typeof raw.workdir !== "string" || !raw.workdir.trim()) {
|
|
2035
|
-
return null;
|
|
2036
|
-
}
|
|
2037
|
-
const repos = raw.repos.map((item) => normalizeRepoEntry(item)).filter((item) => item != null);
|
|
2038
|
-
if (repos.length === 0) {
|
|
2039
|
-
return null;
|
|
2040
|
-
}
|
|
2041
|
-
return {
|
|
2042
|
-
version: WORKSPACE_REPOS_VERSION,
|
|
2043
|
-
kind: raw.kind,
|
|
2044
|
-
workdir: raw.workdir,
|
|
2045
|
-
repos,
|
|
2046
|
-
scannedAt: typeof raw.scannedAt === "string" && raw.scannedAt.trim() ? raw.scannedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
2047
|
-
};
|
|
2048
|
-
} catch {
|
|
2049
|
-
return null;
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
function writeManifest(workdir, manifest) {
|
|
2053
|
-
const apmDir = toFsPath(workspaceApmDir(workdir));
|
|
2054
|
-
mkdirSync3(apmDir, { recursive: true });
|
|
2055
|
-
const path19 = toFsPath(manifestPath(workdir));
|
|
2056
|
-
writeFileSync3(path19, `${JSON.stringify(manifest, null, 2)}
|
|
2057
|
-
`, "utf8");
|
|
2058
|
-
}
|
|
2059
|
-
function isPathInsideOrEqual(parentAbs, childAbs) {
|
|
2060
|
-
const parent = normalizeWorkdirPath(parentAbs);
|
|
2061
|
-
const child = normalizeWorkdirPath(childAbs);
|
|
2062
|
-
if (child === parent) return true;
|
|
2063
|
-
const prefix = parent.endsWith("/") ? parent : `${parent}/`;
|
|
2064
|
-
return child.startsWith(prefix);
|
|
2065
|
-
}
|
|
2066
|
-
function findWorkspaceReposManifestNearPath(startDirInput) {
|
|
2067
|
-
let current = resolve3(startDirInput);
|
|
2068
|
-
for (; ; ) {
|
|
2069
|
-
const candidates = /* @__PURE__ */ new Set([normalizeWorkdirPath(current)]);
|
|
2070
|
-
try {
|
|
2071
|
-
if (existsSync4(toFsPath(current))) {
|
|
2072
|
-
candidates.add(resolveWorkdirPath(current));
|
|
2073
|
-
}
|
|
2074
|
-
} catch {
|
|
2075
|
-
}
|
|
2076
|
-
for (const candidate of candidates) {
|
|
2077
|
-
const cached = readManifest(candidate);
|
|
2078
|
-
if (!cached) continue;
|
|
2079
|
-
const cachedWorkdir = resolveWorkdirPath(cached.workdir);
|
|
2080
|
-
const candidateNorm = resolveWorkdirPath(candidate);
|
|
2081
|
-
if (cachedWorkdir === candidateNorm) {
|
|
2082
|
-
return { ...cached, workdir: cachedWorkdir };
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
const parent = dirname4(current);
|
|
2086
|
-
if (parent === current) {
|
|
2087
|
-
return null;
|
|
2088
|
-
}
|
|
2089
|
-
current = parent;
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
function matchWorkspaceRepoEntryForPath(manifest, pathInput) {
|
|
2093
|
-
const target = resolveWorkdirPath(pathInput);
|
|
2094
|
-
const workdir = resolveWorkdirPath(manifest.workdir);
|
|
2095
|
-
let best = null;
|
|
2096
|
-
let bestLen = -1;
|
|
2097
|
-
for (const entry of manifest.repos) {
|
|
2098
|
-
const abs = resolveWorkdirPath(absoluteRepoPath(workdir, entry));
|
|
2099
|
-
if (!isPathInsideOrEqual(abs, target)) {
|
|
2100
|
-
continue;
|
|
2101
|
-
}
|
|
2102
|
-
if (abs.length > bestLen) {
|
|
2103
|
-
best = entry;
|
|
2104
|
-
bestLen = abs.length;
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
return best;
|
|
2108
|
-
}
|
|
2109
|
-
async function enrichWorkspaceReposRemoteUrls(manifest) {
|
|
2110
|
-
let changed = false;
|
|
2111
|
-
const repos = [];
|
|
2112
|
-
for (const entry of manifest.repos) {
|
|
2113
|
-
const abs = absoluteRepoPath(manifest.workdir, entry);
|
|
2114
|
-
const remoteUrl = await tryReadHttpsGitOriginUrl(abs);
|
|
2115
|
-
const next = {
|
|
2116
|
-
path: entry.path,
|
|
2117
|
-
remoteUrl: remoteUrl || null
|
|
2118
|
-
};
|
|
2119
|
-
if ((entry.remoteUrl ?? null) !== next.remoteUrl) {
|
|
2120
|
-
changed = true;
|
|
2121
|
-
}
|
|
2122
|
-
repos.push(next);
|
|
2123
|
-
}
|
|
2124
|
-
const nextManifest = {
|
|
2125
|
-
...manifest,
|
|
2126
|
-
repos,
|
|
2127
|
-
scannedAt: changed ? (/* @__PURE__ */ new Date()).toISOString() : manifest.scannedAt
|
|
2128
|
-
};
|
|
2129
|
-
if (changed) {
|
|
2130
|
-
writeManifest(manifest.workdir, nextManifest);
|
|
2131
|
-
}
|
|
2132
|
-
return nextManifest;
|
|
2133
|
-
}
|
|
2134
|
-
|
|
2135
1806
|
// src/commands/deploy/deploy-execute.ts
|
|
2136
1807
|
import path11 from "node:path";
|
|
2137
1808
|
|
|
2138
1809
|
// src/commands/deploy/internal/apm-config.ts
|
|
2139
|
-
import { existsSync as
|
|
2140
|
-
import { resolve as
|
|
1810
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5 } from "node:fs";
|
|
1811
|
+
import { resolve as resolve4 } from "node:path";
|
|
2141
1812
|
|
|
2142
1813
|
// src/commands/deploy/internal/config/config-validation.ts
|
|
2143
1814
|
function req(v, field, section) {
|
|
@@ -2229,9 +1900,9 @@ function resolveFrontendDeployFromApmConfig(cfg) {
|
|
|
2229
1900
|
}
|
|
2230
1901
|
|
|
2231
1902
|
// src/commands/deploy/internal/config/maven-repo.ts
|
|
2232
|
-
import { existsSync as
|
|
1903
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
|
|
2233
1904
|
import { homedir as homedir2 } from "node:os";
|
|
2234
|
-
import { join as
|
|
1905
|
+
import { join as join5, resolve as resolve3 } from "node:path";
|
|
2235
1906
|
var MAVEN_REPO_ENV_KEYS = [
|
|
2236
1907
|
"MAVEN_LOCAL_REPO",
|
|
2237
1908
|
"M2_REPO",
|
|
@@ -2264,7 +1935,7 @@ function expandUserPath(pathStr, env = process.env) {
|
|
|
2264
1935
|
if (/^[a-zA-Z]:[/\\]/.test(expanded)) {
|
|
2265
1936
|
return expanded;
|
|
2266
1937
|
}
|
|
2267
|
-
return
|
|
1938
|
+
return resolve3(expanded);
|
|
2268
1939
|
}
|
|
2269
1940
|
function readMavenLocalRepoFromMavenOpts(mavenOpts, env = process.env) {
|
|
2270
1941
|
const match = mavenOpts.match(/-Dmaven\.repo\.local=(?:"([^"]+)"|(\S+))/);
|
|
@@ -2288,12 +1959,12 @@ function readMavenLocalRepoFromEnv(env = process.env) {
|
|
|
2288
1959
|
return null;
|
|
2289
1960
|
}
|
|
2290
1961
|
function readMavenLocalRepoFromSettings() {
|
|
2291
|
-
const settingsPath =
|
|
2292
|
-
if (!
|
|
1962
|
+
const settingsPath = join5(homedir2(), ".m2", "settings.xml");
|
|
1963
|
+
if (!existsSync4(settingsPath)) {
|
|
2293
1964
|
return null;
|
|
2294
1965
|
}
|
|
2295
1966
|
try {
|
|
2296
|
-
const xml =
|
|
1967
|
+
const xml = readFileSync4(settingsPath, "utf8");
|
|
2297
1968
|
const match = xml.match(
|
|
2298
1969
|
/<localRepository>\s*([^<]+?)\s*<\/localRepository>/
|
|
2299
1970
|
);
|
|
@@ -2324,7 +1995,7 @@ function resolveMavenLocalRepoWithSource() {
|
|
|
2324
1995
|
};
|
|
2325
1996
|
}
|
|
2326
1997
|
return {
|
|
2327
|
-
path:
|
|
1998
|
+
path: join5(homedir2(), ".m2", "repository"),
|
|
2328
1999
|
source: "default",
|
|
2329
2000
|
sourceDetail: "~/.m2/repository"
|
|
2330
2001
|
};
|
|
@@ -2420,16 +2091,16 @@ function resolveWisdomBackendDeployFromApmConfig(cfg) {
|
|
|
2420
2091
|
|
|
2421
2092
|
// src/commands/deploy/internal/apm-config.ts
|
|
2422
2093
|
function loadApmConfig(options) {
|
|
2423
|
-
const p =
|
|
2094
|
+
const p = resolve4(
|
|
2424
2095
|
process.cwd(),
|
|
2425
|
-
options?.configPath ??
|
|
2096
|
+
options?.configPath ?? resolve4(workspaceApmDir(), "apm.config.json")
|
|
2426
2097
|
);
|
|
2427
|
-
if (!
|
|
2098
|
+
if (!existsSync5(p)) {
|
|
2428
2099
|
console.error(`\u672A\u627E\u5230\u914D\u7F6E\u6587\u4EF6\uFF1A${p}`);
|
|
2429
2100
|
process.exit(1);
|
|
2430
2101
|
}
|
|
2431
2102
|
try {
|
|
2432
|
-
const raw =
|
|
2103
|
+
const raw = readFileSync5(p, "utf8");
|
|
2433
2104
|
return JSON.parse(raw);
|
|
2434
2105
|
} catch (e) {
|
|
2435
2106
|
console.error(`\u65E0\u6CD5\u89E3\u6790 apm.config.json\uFF1A${p}`, e);
|
|
@@ -2474,8 +2145,8 @@ var DeployExecutionError = class extends Error {
|
|
|
2474
2145
|
|
|
2475
2146
|
// src/commands/deploy/deploy-debug-log.ts
|
|
2476
2147
|
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
2477
|
-
import { existsSync as
|
|
2478
|
-
import { dirname as
|
|
2148
|
+
import { existsSync as existsSync9 } from "node:fs";
|
|
2149
|
+
import { dirname as dirname5, join as join9 } from "node:path";
|
|
2479
2150
|
|
|
2480
2151
|
// src/commands/deploy/internal/deploy-artifact-minio.ts
|
|
2481
2152
|
init_client();
|
|
@@ -2568,22 +2239,6 @@ async function uploadDeployArtifactZip(options) {
|
|
|
2568
2239
|
console.warn(`[apm] MinIO \u90E8\u7F72\u4EA7\u7269\u5F52\u6863\u5931\u8D25: ${detail}`);
|
|
2569
2240
|
return null;
|
|
2570
2241
|
}
|
|
2571
|
-
if (deploymentRunId) {
|
|
2572
|
-
try {
|
|
2573
|
-
await api.cli.attachTaskDeploymentArtifact({
|
|
2574
|
-
id: deploymentRunId,
|
|
2575
|
-
artifactObjectKey: objectKey,
|
|
2576
|
-
artifactFileName: fileName
|
|
2577
|
-
});
|
|
2578
|
-
console.error(
|
|
2579
|
-
`[apm] \u5DF2\u7ED1\u5B9A\u90E8\u7F72\u4EA7\u7269\u5230\u8BB0\u5F55 id=${deploymentRunId} file=${fileName}`
|
|
2580
|
-
);
|
|
2581
|
-
} catch (error) {
|
|
2582
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
2583
|
-
console.warn(`[apm] \u7ED1\u5B9A\u90E8\u7F72\u4EA7\u7269\u5230\u8BB0\u5F55\u5931\u8D25: ${detail}`);
|
|
2584
|
-
return null;
|
|
2585
|
-
}
|
|
2586
|
-
}
|
|
2587
2242
|
return {
|
|
2588
2243
|
objectKey,
|
|
2589
2244
|
fileName,
|
|
@@ -2593,27 +2248,27 @@ async function uploadDeployArtifactZip(options) {
|
|
|
2593
2248
|
|
|
2594
2249
|
// src/commands/deploy/internal/deploy-shell-env.ts
|
|
2595
2250
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
2596
|
-
import { existsSync as
|
|
2597
|
-
import { dirname as
|
|
2251
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
2252
|
+
import { dirname as dirname4, join as join8 } from "node:path";
|
|
2598
2253
|
|
|
2599
2254
|
// src/commands/daemon.ts
|
|
2600
2255
|
init_config();
|
|
2601
2256
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
2602
2257
|
import { setTimeout as delay } from "node:timers/promises";
|
|
2603
|
-
import { existsSync as
|
|
2604
|
-
import { join as
|
|
2258
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
2259
|
+
import { join as join7 } from "path";
|
|
2605
2260
|
|
|
2606
2261
|
// src/commands/connect-lock.ts
|
|
2607
2262
|
init_config();
|
|
2608
2263
|
import {
|
|
2609
|
-
existsSync as
|
|
2610
|
-
mkdirSync as
|
|
2611
|
-
readFileSync as
|
|
2264
|
+
existsSync as existsSync6,
|
|
2265
|
+
mkdirSync as mkdirSync3,
|
|
2266
|
+
readFileSync as readFileSync6,
|
|
2612
2267
|
unlinkSync,
|
|
2613
|
-
writeFileSync as
|
|
2268
|
+
writeFileSync as writeFileSync3
|
|
2614
2269
|
} from "fs";
|
|
2615
|
-
import { join as
|
|
2616
|
-
var CONNECT_LOCK_PATH =
|
|
2270
|
+
import { join as join6 } from "path";
|
|
2271
|
+
var CONNECT_LOCK_PATH = join6(APM_CONFIG_DIR, "connect.lock");
|
|
2617
2272
|
function isProcessAlive(pid) {
|
|
2618
2273
|
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
2619
2274
|
try {
|
|
@@ -2640,9 +2295,9 @@ function waitForPm2LockHandoff(timeoutMs = 5e3) {
|
|
|
2640
2295
|
}
|
|
2641
2296
|
}
|
|
2642
2297
|
function readConnectLock() {
|
|
2643
|
-
if (!
|
|
2298
|
+
if (!existsSync6(CONNECT_LOCK_PATH)) return null;
|
|
2644
2299
|
try {
|
|
2645
|
-
const raw =
|
|
2300
|
+
const raw = readFileSync6(CONNECT_LOCK_PATH, "utf8");
|
|
2646
2301
|
const parsed = JSON.parse(raw);
|
|
2647
2302
|
if (typeof parsed.pid !== "number" || parsed.mode !== "foreground" && parsed.mode !== "pm2" || typeof parsed.startedAt !== "string") {
|
|
2648
2303
|
return null;
|
|
@@ -2677,13 +2332,13 @@ function acquireConnectLock(mode) {
|
|
|
2677
2332
|
process.exit(1);
|
|
2678
2333
|
}
|
|
2679
2334
|
}
|
|
2680
|
-
|
|
2335
|
+
mkdirSync3(APM_CONFIG_DIR, { recursive: true });
|
|
2681
2336
|
const lock = {
|
|
2682
2337
|
pid: process.pid,
|
|
2683
2338
|
mode,
|
|
2684
2339
|
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2685
2340
|
};
|
|
2686
|
-
|
|
2341
|
+
writeFileSync3(
|
|
2687
2342
|
CONNECT_LOCK_PATH,
|
|
2688
2343
|
JSON.stringify(lock, null, 2) + "\n",
|
|
2689
2344
|
"utf8"
|
|
@@ -2699,7 +2354,7 @@ function releaseConnectLock() {
|
|
|
2699
2354
|
}
|
|
2700
2355
|
function forceReleaseConnectLock() {
|
|
2701
2356
|
try {
|
|
2702
|
-
if (
|
|
2357
|
+
if (existsSync6(CONNECT_LOCK_PATH)) {
|
|
2703
2358
|
unlinkSync(CONNECT_LOCK_PATH);
|
|
2704
2359
|
}
|
|
2705
2360
|
} catch {
|
|
@@ -2708,16 +2363,16 @@ function forceReleaseConnectLock() {
|
|
|
2708
2363
|
|
|
2709
2364
|
// src/commands/daemon.ts
|
|
2710
2365
|
var PM2_APP_NAME = "apm-connect";
|
|
2711
|
-
var PM2_ECOSYSTEM_PATH =
|
|
2366
|
+
var PM2_ECOSYSTEM_PATH = join7(
|
|
2712
2367
|
APM_CONFIG_DIR,
|
|
2713
2368
|
"connect.ecosystem.config.cjs"
|
|
2714
2369
|
);
|
|
2715
|
-
var PM2_CONNECT_ENTRY_PATH =
|
|
2716
|
-
var PM2_CONNECT_LAUNCH_PATH =
|
|
2370
|
+
var PM2_CONNECT_ENTRY_PATH = join7(APM_CONFIG_DIR, "connect.entry.cjs");
|
|
2371
|
+
var PM2_CONNECT_LAUNCH_PATH = join7(
|
|
2717
2372
|
APM_CONFIG_DIR,
|
|
2718
2373
|
"connect.launch.json"
|
|
2719
2374
|
);
|
|
2720
|
-
var LEGACY_PM2_ECOSYSTEM_PATH =
|
|
2375
|
+
var LEGACY_PM2_ECOSYSTEM_PATH = join7(
|
|
2721
2376
|
APM_CONFIG_DIR,
|
|
2722
2377
|
"connect.ecosystem.cjs"
|
|
2723
2378
|
);
|
|
@@ -2849,8 +2504,8 @@ function resolvePm2FromNpmRoot() {
|
|
|
2849
2504
|
const root = rootResult.stdout?.toString().trim();
|
|
2850
2505
|
if (!root) return null;
|
|
2851
2506
|
for (const rel of ["pm2/bin/pm2", "pm2/bin/pm2.js"]) {
|
|
2852
|
-
const candidate =
|
|
2853
|
-
if (
|
|
2507
|
+
const candidate = join7(root, ...rel.split("/"));
|
|
2508
|
+
if (existsSync7(candidate)) {
|
|
2854
2509
|
return candidate;
|
|
2855
2510
|
}
|
|
2856
2511
|
}
|
|
@@ -2887,7 +2542,7 @@ function spawnPm2At(binPath, args, options = {}) {
|
|
|
2887
2542
|
return spawnPm2Target(buildPm2SpawnTarget(binPath), args, options);
|
|
2888
2543
|
}
|
|
2889
2544
|
function verifyPm2Bin(pm2Bin) {
|
|
2890
|
-
if (!pm2Bin.trim() || !
|
|
2545
|
+
if (!pm2Bin.trim() || !existsSync7(pm2Bin)) {
|
|
2891
2546
|
return false;
|
|
2892
2547
|
}
|
|
2893
2548
|
const result = spawnPm2At(pm2Bin, ["--version"], {
|
|
@@ -2900,10 +2555,10 @@ function collectPm2Candidates() {
|
|
|
2900
2555
|
const globalBin = resolveNpmGlobalBin();
|
|
2901
2556
|
if (globalBin) {
|
|
2902
2557
|
if (useNpmShell2) {
|
|
2903
|
-
candidates.push(
|
|
2904
|
-
candidates.push(
|
|
2558
|
+
candidates.push(join7(globalBin, "pm2.cmd"));
|
|
2559
|
+
candidates.push(join7(globalBin, "pm2"));
|
|
2905
2560
|
} else {
|
|
2906
|
-
candidates.push(
|
|
2561
|
+
candidates.push(join7(globalBin, "pm2"));
|
|
2907
2562
|
}
|
|
2908
2563
|
}
|
|
2909
2564
|
const fromRoot = resolvePm2FromNpmRoot();
|
|
@@ -3026,7 +2681,7 @@ function ensureGlobalPm2(options) {
|
|
|
3026
2681
|
}
|
|
3027
2682
|
function resolveApmEntryPath(entryArg = process.argv[1]) {
|
|
3028
2683
|
const fromArgv = entryArg?.trim();
|
|
3029
|
-
if (fromArgv &&
|
|
2684
|
+
if (fromArgv && existsSync7(fromArgv)) {
|
|
3030
2685
|
return fromArgv;
|
|
3031
2686
|
}
|
|
3032
2687
|
const npmResult = spawnSync2(useNpmShell2 ? "npm.cmd" : "npm", ["root", "-g"], {
|
|
@@ -3037,8 +2692,8 @@ function resolveApmEntryPath(entryArg = process.argv[1]) {
|
|
|
3037
2692
|
if (npmResult.status === 0) {
|
|
3038
2693
|
const globalRoot = npmResult.stdout?.toString().trim();
|
|
3039
2694
|
if (globalRoot) {
|
|
3040
|
-
const candidate =
|
|
3041
|
-
if (
|
|
2695
|
+
const candidate = join7(globalRoot, CLI_PACKAGE_NAME, "dist", "index.js");
|
|
2696
|
+
if (existsSync7(candidate)) {
|
|
3042
2697
|
return candidate;
|
|
3043
2698
|
}
|
|
3044
2699
|
}
|
|
@@ -3196,8 +2851,8 @@ async function resolveBaseUrl(server) {
|
|
|
3196
2851
|
return cfg?.baseUrl;
|
|
3197
2852
|
}
|
|
3198
2853
|
function writeConnectLaunchFiles(options) {
|
|
3199
|
-
|
|
3200
|
-
|
|
2854
|
+
mkdirSync4(APM_CONFIG_DIR, { recursive: true });
|
|
2855
|
+
writeFileSync4(PM2_CONNECT_ENTRY_PATH, CONNECT_ENTRY_SCRIPT, "utf8");
|
|
3201
2856
|
const env = {
|
|
3202
2857
|
...collectPm2LaunchEnv()
|
|
3203
2858
|
};
|
|
@@ -3212,7 +2867,7 @@ function writeConnectLaunchFiles(options) {
|
|
|
3212
2867
|
cwd: options.cwd,
|
|
3213
2868
|
env
|
|
3214
2869
|
};
|
|
3215
|
-
|
|
2870
|
+
writeFileSync4(
|
|
3216
2871
|
PM2_CONNECT_LAUNCH_PATH,
|
|
3217
2872
|
JSON.stringify(launch, null, 2) + "\n",
|
|
3218
2873
|
"utf8"
|
|
@@ -3224,12 +2879,12 @@ function writeEcosystemFile(options) {
|
|
|
3224
2879
|
entryScript: PM2_CONNECT_ENTRY_PATH,
|
|
3225
2880
|
baseUrl: options.baseUrl
|
|
3226
2881
|
});
|
|
3227
|
-
|
|
2882
|
+
writeFileSync4(
|
|
3228
2883
|
PM2_ECOSYSTEM_PATH,
|
|
3229
2884
|
formatConnectPm2EcosystemFile(ecosystem),
|
|
3230
2885
|
"utf8"
|
|
3231
2886
|
);
|
|
3232
|
-
if (
|
|
2887
|
+
if (existsSync7(LEGACY_PM2_ECOSYSTEM_PATH)) {
|
|
3233
2888
|
try {
|
|
3234
2889
|
unlinkSync2(LEGACY_PM2_ECOSYSTEM_PATH);
|
|
3235
2890
|
} catch {
|
|
@@ -3388,14 +3043,14 @@ function writeEnvPath(env, value) {
|
|
|
3388
3043
|
env.PATH = value;
|
|
3389
3044
|
}
|
|
3390
3045
|
function resolveNodeInstallDir() {
|
|
3391
|
-
return
|
|
3046
|
+
return dirname4(process.execPath);
|
|
3392
3047
|
}
|
|
3393
3048
|
function resolveNpmCmdPath() {
|
|
3394
3049
|
if (process.platform !== "win32") {
|
|
3395
3050
|
return null;
|
|
3396
3051
|
}
|
|
3397
|
-
const candidate =
|
|
3398
|
-
return
|
|
3052
|
+
const candidate = join8(resolveNodeInstallDir(), "npm.cmd");
|
|
3053
|
+
return existsSync8(candidate) ? candidate : null;
|
|
3399
3054
|
}
|
|
3400
3055
|
function formatNpmRunShellCommand(scriptName) {
|
|
3401
3056
|
const trimmed = scriptName.trim();
|
|
@@ -3567,7 +3222,7 @@ function logExecuteDeployContext(input) {
|
|
|
3567
3222
|
const deploymentRunId = process.env[APM_DEPLOYMENT_RUN_ID_ENV]?.trim() || null;
|
|
3568
3223
|
const shellEnv = buildDeployShellEnv();
|
|
3569
3224
|
const npmGlobalBin = resolveNpmGlobalBin2();
|
|
3570
|
-
const packageJsonPath =
|
|
3225
|
+
const packageJsonPath = join9(input.cwd, "package.json");
|
|
3571
3226
|
logLine("========== executeDeploy \u4E0A\u4E0B\u6587 ==========");
|
|
3572
3227
|
logLine(`trigger=${trigger} deployEnv=${input.env}`);
|
|
3573
3228
|
logLine(`cwd(input)=${input.cwdInput}`);
|
|
@@ -3577,12 +3232,12 @@ function logExecuteDeployContext(input) {
|
|
|
3577
3232
|
`cwdMatchProcess=${input.cwd === input.processCwd ? "yes" : "no"} (connect \u901A\u5E38\u4E3A no)`
|
|
3578
3233
|
);
|
|
3579
3234
|
logLine(
|
|
3580
|
-
`apm.config=${input.apmConfigPath} exists=${
|
|
3235
|
+
`apm.config=${input.apmConfigPath} exists=${existsSync9(
|
|
3581
3236
|
input.apmConfigPath
|
|
3582
3237
|
)}`
|
|
3583
3238
|
);
|
|
3584
3239
|
logLine(
|
|
3585
|
-
`package.json=${packageJsonPath} exists=${
|
|
3240
|
+
`package.json=${packageJsonPath} exists=${existsSync9(packageJsonPath)}`
|
|
3586
3241
|
);
|
|
3587
3242
|
logLine(
|
|
3588
3243
|
`flags captureOutput=${input.captureOutput} packOnly=${Boolean(
|
|
@@ -3596,7 +3251,7 @@ function logExecuteDeployContext(input) {
|
|
|
3596
3251
|
);
|
|
3597
3252
|
logLine(`process argv=${process.argv.join(" ")}`);
|
|
3598
3253
|
logLine(`npmGlobalBin=${npmGlobalBin ?? "(resolve failed)"}`);
|
|
3599
|
-
logLine(`nodeDir=${
|
|
3254
|
+
logLine(`nodeDir=${dirname5(process.execPath)}`);
|
|
3600
3255
|
logLine("--- process.env\uFF08\u8282\u9009\uFF09---");
|
|
3601
3256
|
for (const [key, value] of Object.entries(
|
|
3602
3257
|
collectInterestingEnv(process.env)
|
|
@@ -3638,62 +3293,22 @@ function logWisdomFrontendDeployContext(input) {
|
|
|
3638
3293
|
logLine(
|
|
3639
3294
|
`buildKey=build:${input.env} buildCmd=${input.buildCmd ?? "(missing)"}`
|
|
3640
3295
|
);
|
|
3641
|
-
logLine(`distDir=${input.distDir} exists=${
|
|
3296
|
+
logLine(`distDir=${input.distDir} exists=${existsSync9(input.distDir)}`);
|
|
3642
3297
|
logLine(
|
|
3643
3298
|
`packOnly=${input.packOnly} archiveDeployArtifact=${input.archiveDeployArtifact}`
|
|
3644
3299
|
);
|
|
3645
3300
|
}
|
|
3646
3301
|
|
|
3647
3302
|
// src/commands/deploy/internal/wisdom-deploy.ts
|
|
3648
|
-
import { existsSync as
|
|
3303
|
+
import { existsSync as existsSync13, readFileSync as readFileSync9, statSync as statSync7 } from "node:fs";
|
|
3649
3304
|
import path10 from "node:path";
|
|
3650
3305
|
|
|
3651
3306
|
// src/commands/deploy/deploy-shell-run.ts
|
|
3652
3307
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
3653
3308
|
|
|
3654
3309
|
// src/commands/deploy/deploy-log-utils.ts
|
|
3655
|
-
import { setTimeout as delay2 } from "node:timers/promises";
|
|
3656
3310
|
var DEPLOY_SPAWN_MAX_BUFFER_BYTES = 50 * 1024 * 1024;
|
|
3657
3311
|
var DEPLOY_LOG_SYNC_MAX_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
3658
|
-
var DEPLOY_LOG_SYNC_MAX_ATTEMPTS = 3;
|
|
3659
|
-
async function retryDeployLogSync(fn, attempts = DEPLOY_LOG_SYNC_MAX_ATTEMPTS) {
|
|
3660
|
-
let lastError;
|
|
3661
|
-
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
3662
|
-
try {
|
|
3663
|
-
return await fn();
|
|
3664
|
-
} catch (error) {
|
|
3665
|
-
lastError = error;
|
|
3666
|
-
if (attempt < attempts) {
|
|
3667
|
-
await delay2(1e3 * attempt);
|
|
3668
|
-
}
|
|
3669
|
-
}
|
|
3670
|
-
}
|
|
3671
|
-
throw lastError;
|
|
3672
|
-
}
|
|
3673
|
-
var retryDeployStatusComplete = retryDeployLogSync;
|
|
3674
|
-
function splitUtf8StringByMaxBytes(value, maxBytes) {
|
|
3675
|
-
if (maxBytes <= 0) {
|
|
3676
|
-
throw new Error("maxBytes must be positive");
|
|
3677
|
-
}
|
|
3678
|
-
const bytes = Buffer.from(value, "utf8");
|
|
3679
|
-
if (bytes.length <= maxBytes) {
|
|
3680
|
-
return [value];
|
|
3681
|
-
}
|
|
3682
|
-
const chunks = [];
|
|
3683
|
-
let offset = 0;
|
|
3684
|
-
while (offset < bytes.length) {
|
|
3685
|
-
let end = Math.min(offset + maxBytes, bytes.length);
|
|
3686
|
-
while (end > offset && (bytes[end] & 192) === 128) {
|
|
3687
|
-
end -= 1;
|
|
3688
|
-
}
|
|
3689
|
-
if (end <= offset) {
|
|
3690
|
-
end = Math.min(offset + maxBytes, bytes.length);
|
|
3691
|
-
}
|
|
3692
|
-
chunks.push(bytes.subarray(offset, end).toString("utf8"));
|
|
3693
|
-
offset = end;
|
|
3694
|
-
}
|
|
3695
|
-
return chunks;
|
|
3696
|
-
}
|
|
3697
3312
|
|
|
3698
3313
|
// src/commands/deploy/deploy-shell-run.ts
|
|
3699
3314
|
function runDeployShellCommand(command, cwd, captureOutput) {
|
|
@@ -3743,22 +3358,22 @@ import path9 from "node:path";
|
|
|
3743
3358
|
|
|
3744
3359
|
// src/commands/deploy/internal/wisdom-backend/jar-incremental.ts
|
|
3745
3360
|
import {
|
|
3746
|
-
mkdirSync as
|
|
3747
|
-
readdirSync as
|
|
3748
|
-
readFileSync as
|
|
3749
|
-
statSync as
|
|
3750
|
-
writeFileSync as
|
|
3361
|
+
mkdirSync as mkdirSync6,
|
|
3362
|
+
readdirSync as readdirSync3,
|
|
3363
|
+
readFileSync as readFileSync8,
|
|
3364
|
+
statSync as statSync5,
|
|
3365
|
+
writeFileSync as writeFileSync6
|
|
3751
3366
|
} from "node:fs";
|
|
3752
3367
|
import path6 from "node:path";
|
|
3753
3368
|
import JSZip2 from "jszip";
|
|
3754
3369
|
|
|
3755
3370
|
// src/commands/deploy/internal/wisdom-backend/manifest.ts
|
|
3756
3371
|
import {
|
|
3757
|
-
existsSync as
|
|
3758
|
-
mkdirSync as
|
|
3759
|
-
readFileSync as
|
|
3760
|
-
statSync as
|
|
3761
|
-
writeFileSync as
|
|
3372
|
+
existsSync as existsSync10,
|
|
3373
|
+
mkdirSync as mkdirSync5,
|
|
3374
|
+
readFileSync as readFileSync7,
|
|
3375
|
+
statSync as statSync4,
|
|
3376
|
+
writeFileSync as writeFileSync5
|
|
3762
3377
|
} from "node:fs";
|
|
3763
3378
|
import path2 from "node:path";
|
|
3764
3379
|
function deployCacheDir() {
|
|
@@ -3771,20 +3386,20 @@ function relativeKey(projectRoot, filePath) {
|
|
|
3771
3386
|
return path2.relative(projectRoot, filePath).split(path2.sep).join("/");
|
|
3772
3387
|
}
|
|
3773
3388
|
function fileSignature(filePath) {
|
|
3774
|
-
const stat2 =
|
|
3389
|
+
const stat2 = statSync4(filePath);
|
|
3775
3390
|
return { size: stat2.size, mtime: stat2.mtimeMs / 1e3 };
|
|
3776
3391
|
}
|
|
3777
3392
|
function loadManifest() {
|
|
3778
|
-
const
|
|
3779
|
-
if (!
|
|
3393
|
+
const manifestPath = manifestFilePath();
|
|
3394
|
+
if (!existsSync10(manifestPath)) {
|
|
3780
3395
|
return {};
|
|
3781
3396
|
}
|
|
3782
|
-
return JSON.parse(
|
|
3397
|
+
return JSON.parse(readFileSync7(manifestPath, "utf8"));
|
|
3783
3398
|
}
|
|
3784
3399
|
function saveManifest(manifest) {
|
|
3785
3400
|
const dir = deployCacheDir();
|
|
3786
|
-
|
|
3787
|
-
|
|
3401
|
+
mkdirSync5(dir, { recursive: true });
|
|
3402
|
+
writeFileSync5(manifestFilePath(), JSON.stringify(manifest, null, 2), "utf8");
|
|
3788
3403
|
}
|
|
3789
3404
|
function updateManifestEntries(manifest, entries, projectRoot) {
|
|
3790
3405
|
for (const entry of entries) {
|
|
@@ -3915,7 +3530,7 @@ function buildSftpConnectOptions(settings) {
|
|
|
3915
3530
|
};
|
|
3916
3531
|
}
|
|
3917
3532
|
async function sleep(ms) {
|
|
3918
|
-
await new Promise((
|
|
3533
|
+
await new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
3919
3534
|
}
|
|
3920
3535
|
async function uploadZipWithRetry(settings, localZip, remoteZipPath) {
|
|
3921
3536
|
let lastError;
|
|
@@ -3959,7 +3574,7 @@ async function ensureRemoteDir(sftp, dir) {
|
|
|
3959
3574
|
}
|
|
3960
3575
|
}
|
|
3961
3576
|
function execCommand(client, command) {
|
|
3962
|
-
return new Promise((
|
|
3577
|
+
return new Promise((resolve7, reject) => {
|
|
3963
3578
|
client.exec(command, (err, stream) => {
|
|
3964
3579
|
if (err) return reject(err);
|
|
3965
3580
|
let stdout = "";
|
|
@@ -3969,7 +3584,7 @@ function execCommand(client, command) {
|
|
|
3969
3584
|
reject(new Error(`\u8FDC\u7A0B\u547D\u4EE4\u5931\u8D25 (${code}): ${stderr || stdout}`));
|
|
3970
3585
|
return;
|
|
3971
3586
|
}
|
|
3972
|
-
|
|
3587
|
+
resolve7(stdout);
|
|
3973
3588
|
}).on("data", (data) => {
|
|
3974
3589
|
stdout += data.toString();
|
|
3975
3590
|
});
|
|
@@ -4152,7 +3767,7 @@ function shouldUploadLibFile(localPath, remoteAttr, manifest, projectRoot) {
|
|
|
4152
3767
|
if (!remoteAttr) {
|
|
4153
3768
|
return [false, "\u8FDC\u7A0B\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7"];
|
|
4154
3769
|
}
|
|
4155
|
-
const localSize =
|
|
3770
|
+
const localSize = statSync5(localPath).size;
|
|
4156
3771
|
const remoteSize = remoteAttr.size;
|
|
4157
3772
|
if (localSize !== remoteSize) {
|
|
4158
3773
|
return [true, `\u5927\u5C0F\u53D8\u5316 ${remoteSize} -> ${localSize}`];
|
|
@@ -4175,7 +3790,7 @@ function shouldUploadLibFile(localPath, remoteAttr, manifest, projectRoot) {
|
|
|
4175
3790
|
}
|
|
4176
3791
|
function listLibFilesToUpload(localLibDir, remoteStats, projectRoot, manifest = null) {
|
|
4177
3792
|
const entries = [];
|
|
4178
|
-
const jarFiles =
|
|
3793
|
+
const jarFiles = readdirSync3(localLibDir).filter((name) => name.endsWith(".jar")).sort();
|
|
4179
3794
|
for (const jarName of jarFiles) {
|
|
4180
3795
|
const jarPath = path6.join(localLibDir, jarName);
|
|
4181
3796
|
const remoteAttr = remoteStats.get(jarName);
|
|
@@ -4193,12 +3808,12 @@ function listLibFilesToUpload(localLibDir, remoteStats, projectRoot, manifest =
|
|
|
4193
3808
|
}
|
|
4194
3809
|
async function createUpdatePackage(entries, packageName) {
|
|
4195
3810
|
const dir = deployCacheDirectory();
|
|
4196
|
-
|
|
3811
|
+
mkdirSync6(dir, { recursive: true });
|
|
4197
3812
|
const zipPath = path6.join(dir, packageName);
|
|
4198
3813
|
log(`\u521B\u5EFA\u66F4\u65B0\u5305: ${path6.basename(zipPath)}\uFF08${entries.length} \u4E2A\u6587\u4EF6\uFF09`);
|
|
4199
3814
|
const zip = new JSZip2();
|
|
4200
3815
|
for (const entry of entries) {
|
|
4201
|
-
const content =
|
|
3816
|
+
const content = readFileSync8(entry.path);
|
|
4202
3817
|
zip.file(entry.arcname, content);
|
|
4203
3818
|
log(` \u6253\u5305: ${entry.arcname} (${entry.reason})`);
|
|
4204
3819
|
}
|
|
@@ -4207,11 +3822,11 @@ async function createUpdatePackage(entries, packageName) {
|
|
|
4207
3822
|
compression: "DEFLATE",
|
|
4208
3823
|
compressionOptions: { level: 6 }
|
|
4209
3824
|
});
|
|
4210
|
-
|
|
3825
|
+
writeFileSync6(zipPath, buffer);
|
|
4211
3826
|
return zipPath;
|
|
4212
3827
|
}
|
|
4213
3828
|
function listAllLibFilesForArchive(libDir) {
|
|
4214
|
-
return
|
|
3829
|
+
return readdirSync3(libDir).filter((name) => name.endsWith(".jar")).sort().map((jarName) => ({
|
|
4215
3830
|
path: path6.join(libDir, jarName),
|
|
4216
3831
|
arcname: jarName,
|
|
4217
3832
|
reason: "\u4EC5\u6253\u5305\u5F52\u6863"
|
|
@@ -4219,7 +3834,7 @@ function listAllLibFilesForArchive(libDir) {
|
|
|
4219
3834
|
}
|
|
4220
3835
|
|
|
4221
3836
|
// src/commands/deploy/internal/wisdom-backend/maven-build.ts
|
|
4222
|
-
import { existsSync as
|
|
3837
|
+
import { existsSync as existsSync12, readdirSync as readdirSync4, statSync as statSync6 } from "node:fs";
|
|
4223
3838
|
import path7 from "node:path";
|
|
4224
3839
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
4225
3840
|
function getMvnExecutable() {
|
|
@@ -4268,14 +3883,14 @@ function runMavenBuild(projectRoot, mavenLocalRepo, repoSource) {
|
|
|
4268
3883
|
}
|
|
4269
3884
|
function locateLibDir(projectRoot) {
|
|
4270
3885
|
const targetDir = getTargetDir(projectRoot);
|
|
4271
|
-
if (!
|
|
3886
|
+
if (!existsSync12(targetDir)) {
|
|
4272
3887
|
fail(`\u6784\u5EFA\u4EA7\u7269\u76EE\u5F55\u4E0D\u5B58\u5728: ${targetDir}`);
|
|
4273
3888
|
}
|
|
4274
3889
|
const libDir = path7.join(targetDir, "lib");
|
|
4275
|
-
if (!
|
|
3890
|
+
if (!existsSync12(libDir) || !statSync6(libDir).isDirectory()) {
|
|
4276
3891
|
fail(`lib \u76EE\u5F55\u4E0D\u5B58\u5728: ${libDir}`);
|
|
4277
3892
|
}
|
|
4278
|
-
const libJars =
|
|
3893
|
+
const libJars = readdirSync4(libDir).filter((name) => name.endsWith(".jar"));
|
|
4279
3894
|
if (libJars.length === 0) {
|
|
4280
3895
|
fail(`lib \u76EE\u5F55\u4E0B\u6CA1\u6709\u4F9D\u8D56 JAR: ${libDir}`);
|
|
4281
3896
|
}
|
|
@@ -4284,10 +3899,10 @@ function locateLibDir(projectRoot) {
|
|
|
4284
3899
|
}
|
|
4285
3900
|
function locateMainJar(projectRoot) {
|
|
4286
3901
|
const targetDir = getTargetDir(projectRoot);
|
|
4287
|
-
if (!
|
|
3902
|
+
if (!existsSync12(targetDir)) {
|
|
4288
3903
|
fail(`\u6784\u5EFA\u4EA7\u7269\u76EE\u5F55\u4E0D\u5B58\u5728: ${targetDir}`);
|
|
4289
3904
|
}
|
|
4290
|
-
const jarFiles =
|
|
3905
|
+
const jarFiles = readdirSync4(targetDir).filter((name) => name.endsWith(".jar") && !name.endsWith(".jar.original")).map((name) => path7.join(targetDir, name)).sort((a, b) => statSync6(b).mtimeMs - statSync6(a).mtimeMs);
|
|
4291
3906
|
if (jarFiles.length === 0) {
|
|
4292
3907
|
fail(`target \u76EE\u5F55\u4E0B\u6CA1\u6709\u4E3B JAR: ${targetDir}`);
|
|
4293
3908
|
}
|
|
@@ -4444,8 +4059,8 @@ function springbootOutputIndicatesSuccess(action, combined) {
|
|
|
4444
4059
|
async function connectSsh(config) {
|
|
4445
4060
|
const client = new Client2();
|
|
4446
4061
|
log(`\u8FDE\u63A5\u670D\u52A1\u5668 ${config.username}@${config.host}:${config.port}`);
|
|
4447
|
-
await new Promise((
|
|
4448
|
-
client.on("ready", () =>
|
|
4062
|
+
await new Promise((resolve7, reject) => {
|
|
4063
|
+
client.on("ready", () => resolve7()).on("error", (err) => reject(err)).connect({
|
|
4449
4064
|
host: config.host,
|
|
4450
4065
|
port: config.port,
|
|
4451
4066
|
username: config.username,
|
|
@@ -4513,7 +4128,7 @@ async function runRemoteCommand(client, command, options) {
|
|
|
4513
4128
|
const check = options?.check ?? true;
|
|
4514
4129
|
const stream = options?.stream ?? false;
|
|
4515
4130
|
const label = options?.label ?? "\u8FDC\u7A0B\u547D\u4EE4";
|
|
4516
|
-
return new Promise((
|
|
4131
|
+
return new Promise((resolve7, reject) => {
|
|
4517
4132
|
client.exec(command, (err, execStream) => {
|
|
4518
4133
|
if (err) {
|
|
4519
4134
|
reject(err);
|
|
@@ -4543,7 +4158,7 @@ ${errText}`.trim();
|
|
|
4543
4158
|
\u8F93\u51FA: ${combined}` : "")
|
|
4544
4159
|
);
|
|
4545
4160
|
}
|
|
4546
|
-
|
|
4161
|
+
resolve7({ exitCode: code, out: out.trim(), err: errText.trim() });
|
|
4547
4162
|
});
|
|
4548
4163
|
});
|
|
4549
4164
|
});
|
|
@@ -4773,15 +4388,15 @@ function isWisdomDeployConfigured(cfg) {
|
|
|
4773
4388
|
return Boolean(w?.host?.trim() && w?.remotePath?.trim());
|
|
4774
4389
|
}
|
|
4775
4390
|
function detectWisdomProjectType(cwd) {
|
|
4776
|
-
return
|
|
4391
|
+
return existsSync13(path10.join(cwd, "package.json")) ? "frontend" : "backend";
|
|
4777
4392
|
}
|
|
4778
4393
|
function readPackageScripts(cwd) {
|
|
4779
4394
|
const pkgPath = path10.join(cwd, "package.json");
|
|
4780
|
-
if (!
|
|
4395
|
+
if (!existsSync13(pkgPath)) {
|
|
4781
4396
|
return {};
|
|
4782
4397
|
}
|
|
4783
4398
|
try {
|
|
4784
|
-
const raw =
|
|
4399
|
+
const raw = readFileSync9(pkgPath, "utf8");
|
|
4785
4400
|
const parsed = JSON.parse(raw);
|
|
4786
4401
|
return parsed.scripts ?? {};
|
|
4787
4402
|
} catch {
|
|
@@ -4804,7 +4419,7 @@ function resolveFrontendDistDir(cwd) {
|
|
|
4804
4419
|
for (const rel of candidates) {
|
|
4805
4420
|
const full = path10.join(cwd, rel);
|
|
4806
4421
|
try {
|
|
4807
|
-
if (
|
|
4422
|
+
if (existsSync13(full) && statSync7(full).isDirectory()) {
|
|
4808
4423
|
return full;
|
|
4809
4424
|
}
|
|
4810
4425
|
} catch {
|
|
@@ -4898,58 +4513,141 @@ async function executeWisdomDeploy(options) {
|
|
|
4898
4513
|
// src/commands/deploy/internal/deploy-baseline-sync.ts
|
|
4899
4514
|
init_client();
|
|
4900
4515
|
|
|
4901
|
-
// src/
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
const
|
|
4914
|
-
const
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
}
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4516
|
+
// src/git-utils.ts
|
|
4517
|
+
import { execFile as execFile2 } from "child_process";
|
|
4518
|
+
import { promisify as promisify2 } from "util";
|
|
4519
|
+
|
|
4520
|
+
// src/git-remote.ts
|
|
4521
|
+
import { execFile } from "child_process";
|
|
4522
|
+
import { promisify } from "util";
|
|
4523
|
+
var execFileAsync = promisify(execFile);
|
|
4524
|
+
|
|
4525
|
+
// src/git-utils.ts
|
|
4526
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
4527
|
+
function gitExecEnv() {
|
|
4528
|
+
const existing = process.env.GIT_SSH_COMMAND?.trim();
|
|
4529
|
+
const acceptNew = "-o StrictHostKeyChecking=accept-new";
|
|
4530
|
+
let gitSshCommand;
|
|
4531
|
+
if (!existing) {
|
|
4532
|
+
gitSshCommand = `ssh ${acceptNew}`;
|
|
4533
|
+
} else if (/\bStrictHostKeyChecking=/.test(existing)) {
|
|
4534
|
+
gitSshCommand = existing;
|
|
4535
|
+
} else {
|
|
4536
|
+
gitSshCommand = `${existing} ${acceptNew}`;
|
|
4537
|
+
}
|
|
4538
|
+
return { ...process.env, GIT_SSH_COMMAND: gitSshCommand };
|
|
4539
|
+
}
|
|
4540
|
+
async function execGit(cwd, args, quiet = false) {
|
|
4541
|
+
try {
|
|
4542
|
+
const { stdout, stderr } = await execFileAsync2("git", args, {
|
|
4543
|
+
cwd,
|
|
4544
|
+
env: gitExecEnv(),
|
|
4545
|
+
encoding: "utf8",
|
|
4546
|
+
maxBuffer: 10 * 1024 * 1024
|
|
4547
|
+
});
|
|
4548
|
+
if (!quiet && stderr.trim()) {
|
|
4549
|
+
process.stderr.write(stderr);
|
|
4550
|
+
}
|
|
4551
|
+
return stdout;
|
|
4552
|
+
} catch (err) {
|
|
4553
|
+
const e = err;
|
|
4554
|
+
const detail = (e.stderr ?? e.message ?? String(err)).trim();
|
|
4555
|
+
throw new Error(
|
|
4556
|
+
`[apm] git ${args.join(" ")} \u5931\u8D25${detail ? `: ${detail}` : ""}`
|
|
4557
|
+
);
|
|
4558
|
+
}
|
|
4559
|
+
}
|
|
4560
|
+
async function isGitRepo(cwd) {
|
|
4561
|
+
try {
|
|
4562
|
+
await execGit(cwd, ["rev-parse", "--git-dir"], true);
|
|
4563
|
+
return true;
|
|
4564
|
+
} catch {
|
|
4565
|
+
return false;
|
|
4566
|
+
}
|
|
4567
|
+
}
|
|
4568
|
+
async function ensureGitRepo(cwd) {
|
|
4569
|
+
await execGit(cwd, ["rev-parse", "--git-dir"], true);
|
|
4570
|
+
}
|
|
4571
|
+
async function getCurrentBranch(cwd) {
|
|
4572
|
+
return (await execGit(cwd, ["rev-parse", "--abbrev-ref", "HEAD"], true)).trim();
|
|
4573
|
+
}
|
|
4574
|
+
async function isWorkingTreeDirty(cwd) {
|
|
4575
|
+
const out = await execGit(cwd, ["status", "--porcelain"], true);
|
|
4576
|
+
return out.trim().length > 0;
|
|
4577
|
+
}
|
|
4578
|
+
async function remoteBranchExists(cwd, branch) {
|
|
4579
|
+
const out = await execGit(
|
|
4580
|
+
cwd,
|
|
4581
|
+
["ls-remote", "--heads", "origin", branch],
|
|
4582
|
+
true
|
|
4583
|
+
);
|
|
4584
|
+
return out.trim().length > 0;
|
|
4585
|
+
}
|
|
4586
|
+
async function resolveGitRepoRoot(cwd) {
|
|
4587
|
+
return (await execGit(cwd, ["rev-parse", "--show-toplevel"], true)).trim();
|
|
4588
|
+
}
|
|
4589
|
+
async function ensureRemoteBaselineBranch(cwd, baselineBranch) {
|
|
4590
|
+
await execGit(cwd, ["fetch", "origin", baselineBranch], true);
|
|
4591
|
+
if (await remoteBranchExists(cwd, baselineBranch)) {
|
|
4592
|
+
return;
|
|
4593
|
+
}
|
|
4594
|
+
throw new Error(
|
|
4595
|
+
`[apm] \u8FDC\u7A0B\u4E0D\u5B58\u5728\u57FA\u7EBF\u5206\u652F origin/${baselineBranch}\uFF0C\u8BF7\u786E\u8BA4\u4ED3\u5E93\u9ED8\u8BA4\u5206\u652F\u5DF2\u63A8\u9001\u5230 origin`
|
|
4596
|
+
);
|
|
4597
|
+
}
|
|
4598
|
+
async function resolveDefaultRemoteBranch(cwd) {
|
|
4599
|
+
try {
|
|
4600
|
+
const ref = (await execGit(cwd, ["symbolic-ref", "refs/remotes/origin/HEAD"], true)).trim();
|
|
4601
|
+
const match = ref.match(/^refs\/remotes\/origin\/(.+)$/);
|
|
4602
|
+
if (match?.[1]) {
|
|
4603
|
+
return match[1];
|
|
4604
|
+
}
|
|
4605
|
+
} catch {
|
|
4606
|
+
}
|
|
4607
|
+
for (const candidate of ["main", "master"]) {
|
|
4608
|
+
if (await remoteBranchExists(cwd, candidate)) {
|
|
4609
|
+
return candidate;
|
|
4610
|
+
}
|
|
4611
|
+
}
|
|
4612
|
+
throw new Error(
|
|
4613
|
+
"[apm] \u65E0\u6CD5\u786E\u5B9A\u8FDC\u7A0B\u9ED8\u8BA4\u5206\u652F\uFF08origin/HEAD\u3001main\u3001master \u5747\u4E0D\u53EF\u7528\uFF09"
|
|
4614
|
+
);
|
|
4615
|
+
}
|
|
4616
|
+
|
|
4617
|
+
// src/baseline-resolve.ts
|
|
4618
|
+
function formatBaselineDiagnostic(workdirPath, baselineWorkdirPath, diagnostic) {
|
|
4619
|
+
return diagnostic?.message ?? `\u672A\u5728\u5E73\u53F0\u627E\u5230\u4E0E\u5F53\u524D\u76EE\u5F55\u5339\u914D\u7684\u5DE5\u4F5C\u76EE\u5F55\u767B\u8BB0\uFF1A${workdirPath}\uFF08\u89C4\u8303\u5316\uFF1A${baselineWorkdirPath}\uFF09
|
|
4620
|
+
\u8BF7\u5148\u5728\u5E73\u53F0\u767B\u8BB0\u8BE5\u8DEF\u5F84\u5BF9\u5E94\u7684\u5DE5\u4F5C\u76EE\u5F55\u3002`;
|
|
4621
|
+
}
|
|
4622
|
+
async function resolveWorkspaceBaseline(api, workdirPath) {
|
|
4623
|
+
const baseline = await api.cli.workspaceBaseline({ workdirPath });
|
|
4624
|
+
if (!baseline.workspaceId) {
|
|
4625
|
+
throw new Error(
|
|
4626
|
+
`[apm] ${formatBaselineDiagnostic(
|
|
4627
|
+
workdirPath,
|
|
4628
|
+
baseline.workdirPath,
|
|
4629
|
+
baseline.diagnostic
|
|
4630
|
+
)}`
|
|
4631
|
+
);
|
|
4632
|
+
}
|
|
4633
|
+
let defaultBranch = baseline.defaultBranch?.trim() || "";
|
|
4634
|
+
if (!defaultBranch) {
|
|
4635
|
+
try {
|
|
4636
|
+
const gitRoot = await resolveGitRepoRoot(workdirPath);
|
|
4637
|
+
defaultBranch = (await resolveDefaultRemoteBranch(gitRoot)).trim();
|
|
4638
|
+
} catch {
|
|
4639
|
+
defaultBranch = "";
|
|
4640
|
+
}
|
|
4641
|
+
}
|
|
4642
|
+
if (!defaultBranch) {
|
|
4643
|
+
throw new Error(
|
|
4644
|
+
"[apm] \u5DE5\u4F5C\u76EE\u5F55\u5DF2\u5339\u914D\uFF0C\u4F46\u65E0\u6CD5\u89E3\u6790\u57FA\u7EBF\u5206\u652F\u3002\u8BF7\u5728\u9879\u76EE\u4E2D\u914D\u7F6E\u57FA\u7840\u5206\u652F\uFF0C\u6216\u786E\u8BA4 origin \u5B58\u5728\u9ED8\u8BA4\u5206\u652F\u3002"
|
|
4645
|
+
);
|
|
4646
|
+
}
|
|
4647
|
+
return { defaultBranch, workdirPath: baseline.workdirPath };
|
|
4648
|
+
}
|
|
4649
|
+
|
|
4650
|
+
// src/commands/deploy/internal/deploy-baseline-sync.ts
|
|
4953
4651
|
init_config();
|
|
4954
4652
|
var LOG_PREFIX2 = "[apm] \u90E8\u7F72\u524D\u57FA\u7EBF\u540C\u6B65:";
|
|
4955
4653
|
function formatGitError(error) {
|
|
@@ -5149,348 +4847,54 @@ function printDeployExecutionError(error) {
|
|
|
5149
4847
|
console.error(error.message);
|
|
5150
4848
|
}
|
|
5151
4849
|
|
|
5152
|
-
// src/commands/
|
|
5153
|
-
function
|
|
5154
|
-
|
|
5155
|
-
const appendLog = (line) => {
|
|
5156
|
-
if (!line) return;
|
|
5157
|
-
chunks.push(line);
|
|
5158
|
-
logSyncer.updateLog(chunks.join("\n"));
|
|
5159
|
-
};
|
|
5160
|
-
const originalLog = console.log;
|
|
5161
|
-
const originalError = console.error;
|
|
5162
|
-
console.log = (...args) => {
|
|
5163
|
-
appendLog(args.map(String).join(" "));
|
|
5164
|
-
originalLog.apply(console, args);
|
|
5165
|
-
};
|
|
5166
|
-
console.error = (...args) => {
|
|
5167
|
-
appendLog(args.map(String).join(" "));
|
|
5168
|
-
originalError.apply(console, args);
|
|
5169
|
-
};
|
|
5170
|
-
return {
|
|
5171
|
-
appendLog,
|
|
5172
|
-
restore: () => {
|
|
5173
|
-
console.log = originalLog;
|
|
5174
|
-
console.error = originalError;
|
|
5175
|
-
},
|
|
5176
|
-
getLog: () => chunks.join("\n")
|
|
5177
|
-
};
|
|
5178
|
-
}
|
|
5179
|
-
|
|
5180
|
-
// src/commands/deploy/platform/deploy-log-syncer.ts
|
|
5181
|
-
var DEPLOY_LOG_SYNC_INTERVAL_MS = 1e4;
|
|
5182
|
-
function logDeploySyncFailure(error) {
|
|
5183
|
-
console.error(
|
|
5184
|
-
"[apm] deploy log sync failed:",
|
|
5185
|
-
error instanceof Error ? error.message : String(error)
|
|
5186
|
-
);
|
|
5187
|
-
}
|
|
5188
|
-
function createDeployLogSyncer(api, deploymentRunId) {
|
|
5189
|
-
let lastSyncedLog = "";
|
|
5190
|
-
let latestLog = "";
|
|
5191
|
-
let lastRunAt = 0;
|
|
5192
|
-
let timer;
|
|
5193
|
-
let syncChain = Promise.resolve();
|
|
5194
|
-
const syncDelta = async (delta, append) => {
|
|
5195
|
-
const chunks = splitUtf8StringByMaxBytes(
|
|
5196
|
-
delta,
|
|
5197
|
-
DEPLOY_LOG_SYNC_MAX_CHUNK_BYTES
|
|
5198
|
-
);
|
|
5199
|
-
for (let index = 0; index < chunks.length; index += 1) {
|
|
5200
|
-
const chunk = chunks[index];
|
|
5201
|
-
await retryDeployLogSync(
|
|
5202
|
-
() => api.cli.syncTaskDeploymentLog({
|
|
5203
|
-
id: deploymentRunId,
|
|
5204
|
-
log: chunk,
|
|
5205
|
-
append: append || index > 0
|
|
5206
|
-
})
|
|
5207
|
-
);
|
|
5208
|
-
}
|
|
5209
|
-
};
|
|
5210
|
-
const syncIfChanged = async () => {
|
|
5211
|
-
if (!latestLog || latestLog === lastSyncedLog) {
|
|
5212
|
-
return;
|
|
5213
|
-
}
|
|
5214
|
-
const delta = latestLog.startsWith(lastSyncedLog) && lastSyncedLog.length > 0 ? latestLog.slice(lastSyncedLog.length) : latestLog;
|
|
5215
|
-
if (!delta) {
|
|
5216
|
-
return;
|
|
5217
|
-
}
|
|
5218
|
-
await syncDelta(delta, lastSyncedLog.length > 0);
|
|
5219
|
-
lastSyncedLog = latestLog;
|
|
5220
|
-
};
|
|
5221
|
-
const enqueueSync = () => {
|
|
5222
|
-
syncChain = syncChain.then(async () => {
|
|
5223
|
-
try {
|
|
5224
|
-
await syncIfChanged();
|
|
5225
|
-
lastRunAt = Date.now();
|
|
5226
|
-
} catch (error) {
|
|
5227
|
-
logDeploySyncFailure(error);
|
|
5228
|
-
}
|
|
5229
|
-
});
|
|
5230
|
-
};
|
|
5231
|
-
const schedule = () => {
|
|
5232
|
-
const now = Date.now();
|
|
5233
|
-
const elapsed = now - lastRunAt;
|
|
5234
|
-
if (elapsed >= DEPLOY_LOG_SYNC_INTERVAL_MS) {
|
|
5235
|
-
if (timer) {
|
|
5236
|
-
clearTimeout(timer);
|
|
5237
|
-
timer = void 0;
|
|
5238
|
-
}
|
|
5239
|
-
enqueueSync();
|
|
5240
|
-
return;
|
|
5241
|
-
}
|
|
5242
|
-
if (timer) {
|
|
5243
|
-
return;
|
|
5244
|
-
}
|
|
5245
|
-
timer = setTimeout(() => {
|
|
5246
|
-
timer = void 0;
|
|
5247
|
-
enqueueSync();
|
|
5248
|
-
}, DEPLOY_LOG_SYNC_INTERVAL_MS - elapsed);
|
|
5249
|
-
};
|
|
5250
|
-
const stopTimer = () => {
|
|
5251
|
-
if (timer) {
|
|
5252
|
-
clearTimeout(timer);
|
|
5253
|
-
timer = void 0;
|
|
5254
|
-
}
|
|
5255
|
-
};
|
|
5256
|
-
return {
|
|
5257
|
-
updateLog(log2) {
|
|
5258
|
-
latestLog = log2;
|
|
5259
|
-
schedule();
|
|
5260
|
-
},
|
|
5261
|
-
async flush() {
|
|
5262
|
-
stopTimer();
|
|
5263
|
-
await syncChain;
|
|
5264
|
-
await syncIfChanged();
|
|
5265
|
-
},
|
|
5266
|
-
async flushSafe() {
|
|
5267
|
-
stopTimer();
|
|
5268
|
-
try {
|
|
5269
|
-
await syncChain;
|
|
5270
|
-
await syncIfChanged();
|
|
5271
|
-
return true;
|
|
5272
|
-
} catch (error) {
|
|
5273
|
-
logDeploySyncFailure(error);
|
|
5274
|
-
return false;
|
|
5275
|
-
}
|
|
5276
|
-
},
|
|
5277
|
-
dispose() {
|
|
5278
|
-
stopTimer();
|
|
5279
|
-
}
|
|
5280
|
-
};
|
|
5281
|
-
}
|
|
5282
|
-
async function finalizeTaskDeployment(api, deploymentRunId, logSyncer, input) {
|
|
5283
|
-
await logSyncer.flushSafe();
|
|
5284
|
-
const payload = {
|
|
5285
|
-
id: deploymentRunId,
|
|
5286
|
-
status: input.status
|
|
5287
|
-
};
|
|
5288
|
-
if (input.error) {
|
|
5289
|
-
payload.error = input.error;
|
|
5290
|
-
}
|
|
5291
|
-
await retryDeployStatusComplete(
|
|
5292
|
-
() => api.cli.completeTaskDeployment(payload)
|
|
5293
|
-
);
|
|
5294
|
-
}
|
|
5295
|
-
async function ensureDeploymentStatusSynced(api, deploymentRunId, logSyncer, outcome) {
|
|
5296
|
-
await finalizeTaskDeployment(api, deploymentRunId, logSyncer, outcome);
|
|
5297
|
-
}
|
|
5298
|
-
|
|
5299
|
-
// src/commands/deploy/platform/deploy-run-coordinator.ts
|
|
5300
|
-
function logDeployStatusSyncFailure(error) {
|
|
5301
|
-
console.error(
|
|
5302
|
-
"[apm] deploy status sync failed:",
|
|
5303
|
-
error instanceof Error ? error.message : String(error)
|
|
5304
|
-
);
|
|
4850
|
+
// src/commands/connect/deploy-run.ts
|
|
4851
|
+
function resolveDeployCommand(environment, packOnly) {
|
|
4852
|
+
return packOnly ? `apm deploy ${environment} --pack-only` : `apm deploy ${environment}`;
|
|
5305
4853
|
}
|
|
5306
|
-
async function
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
const
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
logSyncer.updateLog(capture.getLog());
|
|
5321
|
-
await ensureDeploymentStatusSynced(
|
|
5322
|
-
api,
|
|
5323
|
-
deploymentRunId,
|
|
5324
|
-
logSyncer,
|
|
5325
|
-
outcome
|
|
5326
|
-
);
|
|
5327
|
-
statusSynced = true;
|
|
4854
|
+
async function handleInboundDeploy(_cfg, msg, signal) {
|
|
4855
|
+
if (signal.aborted) return;
|
|
4856
|
+
const cwd = requireRemoteWorkdir(msg.workdir);
|
|
4857
|
+
const displayCommand = resolveDeployCommand(msg.environment, msg.packOnly);
|
|
4858
|
+
console.log(`[apm] deploy start env=${msg.environment} cwd=${cwd}`);
|
|
4859
|
+
console.log(`[apm] deploy command: ${displayCommand}`);
|
|
4860
|
+
if (signal.aborted) return;
|
|
4861
|
+
const deployOptions = {
|
|
4862
|
+
env: msg.environment,
|
|
4863
|
+
cwd,
|
|
4864
|
+
packOnly: msg.packOnly,
|
|
4865
|
+
captureOutput: true,
|
|
4866
|
+
archiveDeployArtifact: true,
|
|
4867
|
+
deployTrigger: "connect"
|
|
5328
4868
|
};
|
|
5329
4869
|
try {
|
|
5330
|
-
|
|
4870
|
+
await executeDeploy(deployOptions);
|
|
4871
|
+
console.log(`[apm] deploy success env=${msg.environment}`);
|
|
5331
4872
|
} catch (error) {
|
|
5332
|
-
deployError = error instanceof DeployExecutionError ? error : new DeployExecutionError(
|
|
4873
|
+
const deployError = error instanceof DeployExecutionError ? error : new DeployExecutionError(
|
|
5333
4874
|
error instanceof Error ? error.message : String(error),
|
|
5334
4875
|
1
|
|
5335
4876
|
);
|
|
5336
|
-
|
|
5337
|
-
capture.appendLog(deployError.output);
|
|
5338
|
-
} else {
|
|
5339
|
-
capture.appendLog(deployError.message);
|
|
5340
|
-
}
|
|
5341
|
-
outcome = { status: "FAILED", error: deployError.message };
|
|
5342
|
-
} finally {
|
|
5343
|
-
if (deploymentStarted && !statusSynced) {
|
|
5344
|
-
if (!outcome) {
|
|
5345
|
-
outcome = { status: "FAILED", error: "\u90E8\u7F72\u672A\u5B8C\u6210" };
|
|
5346
|
-
}
|
|
5347
|
-
try {
|
|
5348
|
-
await ensureStatusSynced();
|
|
5349
|
-
} catch (error) {
|
|
5350
|
-
logDeployStatusSyncFailure(error);
|
|
5351
|
-
}
|
|
5352
|
-
}
|
|
5353
|
-
capture.restore();
|
|
5354
|
-
if (previousDeploymentRunId === void 0) {
|
|
5355
|
-
delete process.env[APM_DEPLOYMENT_RUN_ID_ENV];
|
|
5356
|
-
} else {
|
|
5357
|
-
process.env[APM_DEPLOYMENT_RUN_ID_ENV] = previousDeploymentRunId;
|
|
5358
|
-
}
|
|
5359
|
-
logSyncer.dispose();
|
|
5360
|
-
}
|
|
5361
|
-
return { outcome, error: deployError };
|
|
5362
|
-
}
|
|
5363
|
-
|
|
5364
|
-
// src/commands/connect/deploy-run.ts
|
|
5365
|
-
function resolveDeployCommand(environment, packOnly) {
|
|
5366
|
-
return packOnly ? `apm deploy ${environment} --pack-only` : `apm deploy ${environment}`;
|
|
5367
|
-
}
|
|
5368
|
-
async function resolveDeployCwdForRepository(workspaceRoot, repositoryId, api) {
|
|
5369
|
-
const start = resolveWorkdirPath(workspaceRoot);
|
|
5370
|
-
let manifest = findWorkspaceReposManifestNearPath(start);
|
|
5371
|
-
if (!manifest) {
|
|
5372
|
-
return null;
|
|
5373
|
-
}
|
|
5374
|
-
try {
|
|
5375
|
-
manifest = await enrichWorkspaceReposRemoteUrls(manifest);
|
|
5376
|
-
} catch {
|
|
5377
|
-
return null;
|
|
5378
|
-
}
|
|
5379
|
-
for (const entry of manifest.repos) {
|
|
5380
|
-
const abs = absoluteRepoPath(manifest.workdir, entry);
|
|
5381
|
-
const remoteUrl = toHttpsGitRemoteUrl(entry.remoteUrl ?? "");
|
|
5382
|
-
if (!remoteUrl) {
|
|
5383
|
-
continue;
|
|
5384
|
-
}
|
|
5385
|
-
let baseBranch = "";
|
|
5386
|
-
try {
|
|
5387
|
-
const gitRoot = await resolveGitRepoRoot(abs);
|
|
5388
|
-
baseBranch = (await resolveDefaultRemoteBranch(gitRoot)).trim();
|
|
5389
|
-
} catch {
|
|
5390
|
-
continue;
|
|
5391
|
-
}
|
|
5392
|
-
if (!baseBranch) {
|
|
5393
|
-
continue;
|
|
5394
|
-
}
|
|
5395
|
-
try {
|
|
5396
|
-
const matched = await api.cli.matchRepository({
|
|
5397
|
-
url: remoteUrl,
|
|
5398
|
-
baseBranch
|
|
5399
|
-
});
|
|
5400
|
-
if (matched.repositoryId?.trim() === repositoryId) {
|
|
5401
|
-
return abs;
|
|
5402
|
-
}
|
|
5403
|
-
} catch {
|
|
5404
|
-
continue;
|
|
5405
|
-
}
|
|
5406
|
-
}
|
|
5407
|
-
return null;
|
|
5408
|
-
}
|
|
5409
|
-
async function handleInboundDeploy(cfg, msg, signal) {
|
|
5410
|
-
if (signal.aborted) return;
|
|
5411
|
-
const api = createApmApiClient(cfg);
|
|
5412
|
-
const deploymentRunId = msg.deploymentRunId;
|
|
5413
|
-
const repositoryId = msg.repositoryId?.trim() || "";
|
|
5414
|
-
await api.cli.updateTaskDeploymentStatus({
|
|
5415
|
-
id: deploymentRunId,
|
|
5416
|
-
status: "DEPLOYING"
|
|
5417
|
-
});
|
|
5418
|
-
const { error: deployError } = await runTrackedDeploy({
|
|
5419
|
-
api,
|
|
5420
|
-
deploymentRunId,
|
|
5421
|
-
run: async (appendLog) => {
|
|
5422
|
-
const workspaceRoot = requireRemoteWorkdir(msg.workdir);
|
|
5423
|
-
let cwd = workspaceRoot;
|
|
5424
|
-
if (repositoryId) {
|
|
5425
|
-
const resolved = await resolveDeployCwdForRepository(
|
|
5426
|
-
workspaceRoot,
|
|
5427
|
-
repositoryId,
|
|
5428
|
-
api
|
|
5429
|
-
);
|
|
5430
|
-
if (resolved) {
|
|
5431
|
-
cwd = resolved;
|
|
5432
|
-
appendLog(
|
|
5433
|
-
`[apm] \u591A\u4ED3\u90E8\u7F72\uFF1A\u6309 repositoryId=${repositoryId} \u89E3\u6790 cwd=${cwd}
|
|
5434
|
-
`
|
|
5435
|
-
);
|
|
5436
|
-
} else {
|
|
5437
|
-
appendLog(
|
|
5438
|
-
`[apm] \u672A\u5728 workspace-repos \u547D\u4E2D repositoryId=${repositoryId}\uFF0C\u4F7F\u7528\u5DE5\u4F5C\u7A7A\u95F4\u76EE\u5F55 cwd=${cwd}
|
|
5439
|
-
`
|
|
5440
|
-
);
|
|
5441
|
-
}
|
|
5442
|
-
}
|
|
5443
|
-
const displayCommand = resolveDeployCommand(
|
|
5444
|
-
msg.environment,
|
|
5445
|
-
msg.packOnly
|
|
5446
|
-
);
|
|
5447
|
-
console.log(
|
|
5448
|
-
`[apm] deploy start id=${deploymentRunId} env=${msg.environment} cwd=${cwd}` + (repositoryId ? ` repositoryId=${repositoryId}` : "")
|
|
5449
|
-
);
|
|
5450
|
-
console.log(`[apm] deploy command: ${displayCommand}`);
|
|
5451
|
-
if (signal.aborted) {
|
|
5452
|
-
return { status: "FAILED", error: "\u90E8\u7F72\u5DF2\u53D6\u6D88" };
|
|
5453
|
-
}
|
|
5454
|
-
const deployOptions = {
|
|
5455
|
-
env: msg.environment,
|
|
5456
|
-
cwd,
|
|
5457
|
-
packOnly: msg.packOnly,
|
|
5458
|
-
captureOutput: true,
|
|
5459
|
-
archiveDeployArtifact: true,
|
|
5460
|
-
deployTrigger: "connect"
|
|
5461
|
-
};
|
|
5462
|
-
const output = await executeDeploy(deployOptions);
|
|
5463
|
-
if (output.trim()) {
|
|
5464
|
-
appendLog(output);
|
|
5465
|
-
}
|
|
5466
|
-
console.log(`[apm] deploy success id=${deploymentRunId}`);
|
|
5467
|
-
return { status: "SUCCESS" };
|
|
5468
|
-
}
|
|
5469
|
-
});
|
|
5470
|
-
if (deployError) {
|
|
5471
|
-
console.error(
|
|
5472
|
-
`[apm] deploy failed id=${deploymentRunId}: ${deployError.message}`
|
|
5473
|
-
);
|
|
4877
|
+
printDeployExecutionError(deployError);
|
|
5474
4878
|
}
|
|
5475
4879
|
}
|
|
5476
4880
|
|
|
5477
4881
|
// src/commands/clean-webide-cache.ts
|
|
5478
|
-
import { existsSync as
|
|
5479
|
-
import { resolve as
|
|
4882
|
+
import { existsSync as existsSync15, rmSync as rmSync2 } from "node:fs";
|
|
4883
|
+
import { resolve as resolve6 } from "node:path";
|
|
5480
4884
|
import { getDefaultSdkStateRoot } from "@cursor/sdk";
|
|
5481
4885
|
|
|
5482
4886
|
// src/commands/connect/webide-agent-registry.ts
|
|
5483
|
-
import { existsSync as
|
|
5484
|
-
import { dirname as
|
|
4887
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync7, readFileSync as readFileSync10, writeFileSync as writeFileSync7 } from "node:fs";
|
|
4888
|
+
import { dirname as dirname6, resolve as resolve5 } from "node:path";
|
|
5485
4889
|
function registryPath(workdir, taskId) {
|
|
5486
|
-
return
|
|
4890
|
+
return resolve5(workdir, ".apm", "webide", taskId, "cursor-agent.json");
|
|
5487
4891
|
}
|
|
5488
4892
|
function readRegistry(path19) {
|
|
5489
|
-
if (!
|
|
4893
|
+
if (!existsSync14(path19)) {
|
|
5490
4894
|
return {};
|
|
5491
4895
|
}
|
|
5492
4896
|
try {
|
|
5493
|
-
const parsed = JSON.parse(
|
|
4897
|
+
const parsed = JSON.parse(readFileSync10(path19, "utf8"));
|
|
5494
4898
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
5495
4899
|
const raw = parsed;
|
|
5496
4900
|
const state = {};
|
|
@@ -5528,7 +4932,7 @@ async function purgeCursorAgentStoreForAgent(workdir, agentId) {
|
|
|
5528
4932
|
const trimmedWorkdir = workdir.trim();
|
|
5529
4933
|
if (!trimmedAgentId || !trimmedWorkdir) return false;
|
|
5530
4934
|
const stateRoot = getDefaultSdkStateRoot(trimmedWorkdir);
|
|
5531
|
-
if (!
|
|
4935
|
+
if (!existsSync15(stateRoot)) return false;
|
|
5532
4936
|
const { SqliteLocalAgentStore } = await import(
|
|
5533
4937
|
/* @vite-ignore */
|
|
5534
4938
|
"@cursor/sdk/sqlite"
|
|
@@ -5592,8 +4996,8 @@ async function cleanWebIdeWorkspaceCache(taskId, workdir) {
|
|
|
5592
4996
|
`[apm] \u65E0 WebIDE agentId\uFF0C\u8DF3\u8FC7 agent store \u6E05\u7406 taskId=${trimmedTaskId}`
|
|
5593
4997
|
);
|
|
5594
4998
|
}
|
|
5595
|
-
const dir =
|
|
5596
|
-
if (
|
|
4999
|
+
const dir = resolve6(trimmedWorkdir, ".apm", "webide", trimmedTaskId);
|
|
5000
|
+
if (existsSync15(dir)) {
|
|
5597
5001
|
rmSync2(dir, { recursive: true, force: true });
|
|
5598
5002
|
console.log(`[apm] \u5DF2\u6E05\u7406 WebIDE \u7F13\u5B58 ${dir}`);
|
|
5599
5003
|
} else {
|
|
@@ -5653,7 +5057,7 @@ function createRunSlotPool(maxConcurrent = DEFAULT_MAX_CONCURRENT, options = {})
|
|
|
5653
5057
|
);
|
|
5654
5058
|
}
|
|
5655
5059
|
const queuedAt = Date.now();
|
|
5656
|
-
return new Promise((
|
|
5060
|
+
return new Promise((resolve7) => {
|
|
5657
5061
|
waiters.push(() => {
|
|
5658
5062
|
active += 1;
|
|
5659
5063
|
const waitedMs = Date.now() - queuedAt;
|
|
@@ -5664,7 +5068,7 @@ function createRunSlotPool(maxConcurrent = DEFAULT_MAX_CONCURRENT, options = {})
|
|
|
5664
5068
|
)}s\uFF0C\u5F53\u524D\u5360\u7528 ${active}/${maxConcurrent}`
|
|
5665
5069
|
);
|
|
5666
5070
|
}
|
|
5667
|
-
|
|
5071
|
+
resolve7();
|
|
5668
5072
|
});
|
|
5669
5073
|
});
|
|
5670
5074
|
};
|
|
@@ -5686,9 +5090,9 @@ init_webide_terminal_registry();
|
|
|
5686
5090
|
import { Worker } from "node:worker_threads";
|
|
5687
5091
|
import { totalmem } from "node:os";
|
|
5688
5092
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
5689
|
-
import { dirname as
|
|
5690
|
-
var workerFile =
|
|
5691
|
-
|
|
5093
|
+
import { dirname as dirname7, join as join10 } from "node:path";
|
|
5094
|
+
var workerFile = join10(
|
|
5095
|
+
dirname7(fileURLToPath3(import.meta.url)),
|
|
5692
5096
|
"webide-message-worker.js"
|
|
5693
5097
|
);
|
|
5694
5098
|
var SYSTEM_RESERVE_MB = 3072;
|
|
@@ -5722,8 +5126,8 @@ function spawnWebIdeMessageWorker(cfg, msg) {
|
|
|
5722
5126
|
const registry = getWebIdeTerminalRegistry(cfg);
|
|
5723
5127
|
let settled = false;
|
|
5724
5128
|
let resolveDone;
|
|
5725
|
-
const done = new Promise((
|
|
5726
|
-
resolveDone =
|
|
5129
|
+
const done = new Promise((resolve7) => {
|
|
5130
|
+
resolveDone = resolve7;
|
|
5727
5131
|
});
|
|
5728
5132
|
const failIfStillQueued = async (reason) => {
|
|
5729
5133
|
if (settled) return;
|
|
@@ -5846,11 +5250,11 @@ var RECONNECT_MAX_MS = 6e4;
|
|
|
5846
5250
|
var SHUTDOWN_DRAIN_MS = 3e3;
|
|
5847
5251
|
function interruptibleSleep(ms, signal) {
|
|
5848
5252
|
if (signal.aborted) return Promise.resolve();
|
|
5849
|
-
return new Promise((
|
|
5850
|
-
const timer = setTimeout(
|
|
5253
|
+
return new Promise((resolve7) => {
|
|
5254
|
+
const timer = setTimeout(resolve7, ms);
|
|
5851
5255
|
const onAbort = () => {
|
|
5852
5256
|
clearTimeout(timer);
|
|
5853
|
-
|
|
5257
|
+
resolve7();
|
|
5854
5258
|
};
|
|
5855
5259
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
5856
5260
|
});
|
|
@@ -6010,7 +5414,7 @@ function attachWsHandlers(ws, ctx, onOpen) {
|
|
|
6010
5414
|
});
|
|
6011
5415
|
}
|
|
6012
5416
|
function connectOnce(url, ctx, connectionAbort, onConnected) {
|
|
6013
|
-
return new Promise((
|
|
5417
|
+
return new Promise((resolve7, reject) => {
|
|
6014
5418
|
const ws = new WebSocket(url);
|
|
6015
5419
|
let stopHeartbeat;
|
|
6016
5420
|
let settled = false;
|
|
@@ -6039,7 +5443,7 @@ function connectOnce(url, ctx, connectionAbort, onConnected) {
|
|
|
6039
5443
|
finish(() => reject(new Error("shutdown")));
|
|
6040
5444
|
return;
|
|
6041
5445
|
}
|
|
6042
|
-
finish(
|
|
5446
|
+
finish(resolve7);
|
|
6043
5447
|
});
|
|
6044
5448
|
ws.on("error", (err) => {
|
|
6045
5449
|
console.error("[apm] WebSocket \u9519\u8BEF:", err.message);
|
|
@@ -6121,7 +5525,7 @@ async function runConnect(options) {
|
|
|
6121
5525
|
shutdownAbort.abort();
|
|
6122
5526
|
logAbortSignalStats(shutdownAbort.signal, "connect:shutdown-after-abort");
|
|
6123
5527
|
try {
|
|
6124
|
-
await Promise.race([Promise.all(activeTasks),
|
|
5528
|
+
await Promise.race([Promise.all(activeTasks), delay2(drainMs)]);
|
|
6125
5529
|
} catch {
|
|
6126
5530
|
}
|
|
6127
5531
|
releaseConnectLock();
|
|
@@ -6184,150 +5588,6 @@ async function runConnect(options) {
|
|
|
6184
5588
|
}
|
|
6185
5589
|
}
|
|
6186
5590
|
|
|
6187
|
-
// src/commands/deploy/deploy-tracking.ts
|
|
6188
|
-
init_client();
|
|
6189
|
-
init_config();
|
|
6190
|
-
function normalizeDeployEnvironment(env) {
|
|
6191
|
-
const normalized = env.trim().toLowerCase();
|
|
6192
|
-
if (normalized === "test") return "TEST";
|
|
6193
|
-
if (normalized === "online") return "ONLINE";
|
|
6194
|
-
return null;
|
|
6195
|
-
}
|
|
6196
|
-
async function resolveRepositoryIdForWebIdeDeploy(cwd, api) {
|
|
6197
|
-
const start = resolveWorkdirPath(cwd);
|
|
6198
|
-
let manifest = findWorkspaceReposManifestNearPath(start);
|
|
6199
|
-
if (!manifest) {
|
|
6200
|
-
throw new DeployExecutionError(
|
|
6201
|
-
"\u672A\u627E\u5230 .apm/workspace-repos.json\uFF0C\u65E0\u6CD5\u5339\u914D\u5E73\u53F0\u4ED3\u5E93",
|
|
6202
|
-
1
|
|
6203
|
-
);
|
|
6204
|
-
}
|
|
6205
|
-
try {
|
|
6206
|
-
manifest = await enrichWorkspaceReposRemoteUrls(manifest);
|
|
6207
|
-
} catch (err) {
|
|
6208
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
6209
|
-
throw new DeployExecutionError(
|
|
6210
|
-
`\u5237\u65B0 workspace-repos remoteUrl \u5931\u8D25: ${detail}`,
|
|
6211
|
-
1
|
|
6212
|
-
);
|
|
6213
|
-
}
|
|
6214
|
-
const entry = matchWorkspaceRepoEntryForPath(manifest, start);
|
|
6215
|
-
if (!entry) {
|
|
6216
|
-
throw new DeployExecutionError(
|
|
6217
|
-
`\u5F53\u524D\u76EE\u5F55\u672A\u547D\u4E2D workspace-repos \u4E2D\u7684\u4ED3\u5E93: ${start}`,
|
|
6218
|
-
1
|
|
6219
|
-
);
|
|
6220
|
-
}
|
|
6221
|
-
const abs = absoluteRepoPath(manifest.workdir, entry);
|
|
6222
|
-
const remoteUrl = toHttpsGitRemoteUrl(entry.remoteUrl ?? "") || await tryReadHttpsGitOriginUrl(abs);
|
|
6223
|
-
if (!remoteUrl) {
|
|
6224
|
-
throw new DeployExecutionError(
|
|
6225
|
-
`\u4ED3 ${entry.path} \u65E0\u53EF\u7528\u7684 https remote\uFF0C\u65E0\u6CD5\u5339\u914D\u5E73\u53F0\u4ED3\u5E93`,
|
|
6226
|
-
1
|
|
6227
|
-
);
|
|
6228
|
-
}
|
|
6229
|
-
let baseBranch = "";
|
|
6230
|
-
try {
|
|
6231
|
-
const gitRoot = await resolveGitRepoRoot(abs);
|
|
6232
|
-
baseBranch = (await resolveDefaultRemoteBranch(gitRoot)).trim();
|
|
6233
|
-
} catch (err) {
|
|
6234
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
6235
|
-
throw new DeployExecutionError(`\u89E3\u6790\u5F53\u524D\u4ED3\u57FA\u7EBF\u5206\u652F\u5931\u8D25: ${detail}`, 1);
|
|
6236
|
-
}
|
|
6237
|
-
if (!baseBranch) {
|
|
6238
|
-
throw new DeployExecutionError(
|
|
6239
|
-
"\u65E0\u6CD5\u786E\u5B9A\u5F53\u524D\u4ED3\u57FA\u7EBF\u5206\u652F\uFF0C\u65E0\u6CD5\u5339\u914D\u5E73\u53F0\u4ED3\u5E93",
|
|
6240
|
-
1
|
|
6241
|
-
);
|
|
6242
|
-
}
|
|
6243
|
-
let matched;
|
|
6244
|
-
try {
|
|
6245
|
-
matched = await api.cli.matchRepository({
|
|
6246
|
-
url: remoteUrl,
|
|
6247
|
-
baseBranch
|
|
6248
|
-
});
|
|
6249
|
-
} catch (err) {
|
|
6250
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
6251
|
-
throw new DeployExecutionError(
|
|
6252
|
-
`\u6309 https remote + \u57FA\u7EBF\u5206\u652F\u5339\u914D\u5E73\u53F0\u4ED3\u5E93\u5931\u8D25: ${detail}`,
|
|
6253
|
-
1
|
|
6254
|
-
);
|
|
6255
|
-
}
|
|
6256
|
-
const repositoryId = matched.repositoryId?.trim() || "";
|
|
6257
|
-
if (!repositoryId) {
|
|
6258
|
-
throw new DeployExecutionError(
|
|
6259
|
-
`\u672A\u5339\u914D\u5230\u5E73\u53F0\u4ED3\u5E93 path=${entry.path} url=${remoteUrl} baseBranch=${baseBranch}`,
|
|
6260
|
-
1
|
|
6261
|
-
);
|
|
6262
|
-
}
|
|
6263
|
-
console.log(
|
|
6264
|
-
`[apm] \u90E8\u7F72\u8BB0\u5F55\u4ED3\u5E93 path=${entry.path} https+baseBranch=${baseBranch} \u2192 repositoryId=${repositoryId}`
|
|
6265
|
-
);
|
|
6266
|
-
return repositoryId;
|
|
6267
|
-
}
|
|
6268
|
-
async function runDeployWithBackendTracking(options) {
|
|
6269
|
-
const { tracking, ...deployOptions } = options;
|
|
6270
|
-
const cfg = await tryReadApmConfig();
|
|
6271
|
-
if (!cfg || !resolveApiKey(cfg)) {
|
|
6272
|
-
throw new DeployExecutionError("\u672A\u767B\u5F55\uFF0C\u65E0\u6CD5\u521B\u5EFA\u90E8\u7F72\u8BB0\u5F55", 1);
|
|
6273
|
-
}
|
|
6274
|
-
const environment = normalizeDeployEnvironment(deployOptions.env);
|
|
6275
|
-
if (!environment) {
|
|
6276
|
-
throw new DeployExecutionError(
|
|
6277
|
-
`\u672A\u77E5\u90E8\u7F72\u73AF\u5883 ${deployOptions.env}\uFF0C\u4EC5\u652F\u6301 test/online`,
|
|
6278
|
-
1
|
|
6279
|
-
);
|
|
6280
|
-
}
|
|
6281
|
-
const api = createApmApiClient(cfg);
|
|
6282
|
-
const repositoryId = await resolveRepositoryIdForWebIdeDeploy(
|
|
6283
|
-
deployOptions.cwd,
|
|
6284
|
-
api
|
|
6285
|
-
);
|
|
6286
|
-
let deploymentRunId;
|
|
6287
|
-
try {
|
|
6288
|
-
const run = await api.cli.createTaskDeployment({
|
|
6289
|
-
taskId: tracking.taskId,
|
|
6290
|
-
environment,
|
|
6291
|
-
workdirPath: resolveWorkdirPath(deployOptions.cwd),
|
|
6292
|
-
...repositoryId ? { repositoryId } : {}
|
|
6293
|
-
});
|
|
6294
|
-
deploymentRunId = run.id;
|
|
6295
|
-
console.log(
|
|
6296
|
-
`[apm] \u5DF2\u521B\u5EFA\u90E8\u7F72\u8BB0\u5F55 id=${deploymentRunId} env=${environment}`
|
|
6297
|
-
);
|
|
6298
|
-
} catch (error) {
|
|
6299
|
-
if (error instanceof DeployExecutionError) {
|
|
6300
|
-
throw error;
|
|
6301
|
-
}
|
|
6302
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
6303
|
-
throw new DeployExecutionError(`\u521B\u5EFA\u90E8\u7F72\u8BB0\u5F55\u5931\u8D25: ${detail}`, 1);
|
|
6304
|
-
}
|
|
6305
|
-
await api.cli.updateTaskDeploymentStatus({
|
|
6306
|
-
id: deploymentRunId,
|
|
6307
|
-
status: "DEPLOYING"
|
|
6308
|
-
});
|
|
6309
|
-
const { error: deployError } = await runTrackedDeploy({
|
|
6310
|
-
api,
|
|
6311
|
-
deploymentRunId,
|
|
6312
|
-
run: async (appendLog) => {
|
|
6313
|
-
const output = await executeDeploy({
|
|
6314
|
-
...deployOptions,
|
|
6315
|
-
captureOutput: true,
|
|
6316
|
-
archiveDeployArtifact: true
|
|
6317
|
-
});
|
|
6318
|
-
if (output.trim()) {
|
|
6319
|
-
appendLog(output);
|
|
6320
|
-
}
|
|
6321
|
-
console.log(`[apm] deploy success id=${deploymentRunId}`);
|
|
6322
|
-
return { status: "SUCCESS" };
|
|
6323
|
-
}
|
|
6324
|
-
});
|
|
6325
|
-
if (deployError) {
|
|
6326
|
-
printDeployExecutionError(deployError);
|
|
6327
|
-
process.exit(deployError.exitCode);
|
|
6328
|
-
}
|
|
6329
|
-
}
|
|
6330
|
-
|
|
6331
5591
|
// src/commands/deploy/deploy.ts
|
|
6332
5592
|
function registerDeployMainCommand(program) {
|
|
6333
5593
|
program.command("deploy").description(
|
|
@@ -6335,34 +5595,17 @@ function registerDeployMainCommand(program) {
|
|
|
6335
5595
|
).argument("<env>", "\u90E8\u7F72\u73AF\u5883\u540D\uFF08\u5982 test\u3001online\uFF1BVue \u5BF9\u5E94 build:<env>\uFF09").option(
|
|
6336
5596
|
"--config <path>",
|
|
6337
5597
|
"apm.config.json \u8DEF\u5F84\uFF08\u9ED8\u8BA4 .apm/apm.config.json\uFF09"
|
|
6338
|
-
).option(
|
|
6339
|
-
"--task <taskId>",
|
|
6340
|
-
"WebIDE \u4EFB\u52A1 ID\uFF1B\u4F20\u5165\u65F6\u5728\u5E73\u53F0\u521B\u5EFA\u90E8\u7F72\u8BB0\u5F55\u5E76\u540C\u6B65\u65E5\u5FD7"
|
|
6341
5598
|
).option(
|
|
6342
5599
|
"--pack-only",
|
|
6343
5600
|
"\u4EC5\u6784\u5EFA/\u6253\u5305\u5E76\u4E0A\u4F20 MinIO \u5F52\u6863\uFF0C\u4E0D\u4E0A\u4F20\u8FDC\u7A0B SFTP/SSH\uFF08\u65E0\u9700 wisdomDeploy\uFF09"
|
|
6344
5601
|
).action(
|
|
6345
5602
|
async (env, opts) => {
|
|
6346
|
-
const cwd = process.cwd();
|
|
6347
|
-
const taskId = opts.task?.trim();
|
|
6348
|
-
const packOnly = Boolean(opts.packOnly);
|
|
6349
5603
|
try {
|
|
6350
|
-
if (taskId) {
|
|
6351
|
-
await runDeployWithBackendTracking({
|
|
6352
|
-
env,
|
|
6353
|
-
cwd,
|
|
6354
|
-
configPath: opts.config,
|
|
6355
|
-
tracking: { taskId },
|
|
6356
|
-
packOnly,
|
|
6357
|
-
deployTrigger: "cli"
|
|
6358
|
-
});
|
|
6359
|
-
return;
|
|
6360
|
-
}
|
|
6361
5604
|
await executeDeploy({
|
|
6362
5605
|
env,
|
|
6363
|
-
cwd,
|
|
5606
|
+
cwd: process.cwd(),
|
|
6364
5607
|
configPath: opts.config,
|
|
6365
|
-
packOnly,
|
|
5608
|
+
packOnly: Boolean(opts.packOnly),
|
|
6366
5609
|
deployTrigger: "cli"
|
|
6367
5610
|
});
|
|
6368
5611
|
} catch (error) {
|
|
@@ -6386,7 +5629,7 @@ import path15 from "node:path";
|
|
|
6386
5629
|
import Docker from "dockerode";
|
|
6387
5630
|
|
|
6388
5631
|
// src/commands/deploy/internal/backend-deploy/dockerode-client/connection-options.ts
|
|
6389
|
-
import { existsSync as
|
|
5632
|
+
import { existsSync as existsSync16, readFileSync as readFileSync11 } from "node:fs";
|
|
6390
5633
|
import path12 from "node:path";
|
|
6391
5634
|
function asOptionalTlsBuffer(value) {
|
|
6392
5635
|
if (typeof value !== "string") {
|
|
@@ -6398,8 +5641,8 @@ function asOptionalTlsBuffer(value) {
|
|
|
6398
5641
|
if (normalized === "") {
|
|
6399
5642
|
return void 0;
|
|
6400
5643
|
}
|
|
6401
|
-
if (
|
|
6402
|
-
return
|
|
5644
|
+
if (existsSync16(normalized)) {
|
|
5645
|
+
return readFileSync11(normalized);
|
|
6403
5646
|
}
|
|
6404
5647
|
const looksLikePath = /[\\/]/.test(normalized) || normalized.endsWith(".pem");
|
|
6405
5648
|
if (looksLikePath) {
|
|
@@ -6524,17 +5767,17 @@ var DockerodeClient = class {
|
|
|
6524
5767
|
await this.client.getImage(image).remove({ force: true });
|
|
6525
5768
|
}
|
|
6526
5769
|
async pullImage(image, auth) {
|
|
6527
|
-
const stream = await new Promise((
|
|
5770
|
+
const stream = await new Promise((resolve7, reject) => {
|
|
6528
5771
|
const pullOptions = auth ? { authconfig: auth } : void 0;
|
|
6529
5772
|
this.client.pull(image, pullOptions, (err, output) => {
|
|
6530
5773
|
if (err || !output) {
|
|
6531
5774
|
reject(err ?? new Error("docker pull \u8FD4\u56DE\u7A7A\u8F93\u51FA"));
|
|
6532
5775
|
return;
|
|
6533
5776
|
}
|
|
6534
|
-
|
|
5777
|
+
resolve7(output);
|
|
6535
5778
|
});
|
|
6536
5779
|
});
|
|
6537
|
-
await new Promise((
|
|
5780
|
+
await new Promise((resolve7, reject) => {
|
|
6538
5781
|
this.client.modem.followProgress(
|
|
6539
5782
|
stream,
|
|
6540
5783
|
(err) => {
|
|
@@ -6542,7 +5785,7 @@ var DockerodeClient = class {
|
|
|
6542
5785
|
reject(err);
|
|
6543
5786
|
return;
|
|
6544
5787
|
}
|
|
6545
|
-
|
|
5788
|
+
resolve7();
|
|
6546
5789
|
},
|
|
6547
5790
|
() => void 0
|
|
6548
5791
|
);
|
|
@@ -6609,7 +5852,7 @@ var DockerodeClient = class {
|
|
|
6609
5852
|
var createDockerodeClient = (config) => new DockerodeClient(config);
|
|
6610
5853
|
|
|
6611
5854
|
// src/commands/deploy/internal/backend-deploy/dockerode-client/env.ts
|
|
6612
|
-
import { existsSync as
|
|
5855
|
+
import { existsSync as existsSync17, readFileSync as readFileSync12, statSync as statSync8 } from "node:fs";
|
|
6613
5856
|
import path13 from "node:path";
|
|
6614
5857
|
function stripSurroundingQuotes(value) {
|
|
6615
5858
|
const t = value.trim();
|
|
@@ -6626,10 +5869,10 @@ function loadEnvFromFile(envFilePath) {
|
|
|
6626
5869
|
return {};
|
|
6627
5870
|
}
|
|
6628
5871
|
const targetPath = path13.resolve(envFilePath);
|
|
6629
|
-
if (!
|
|
5872
|
+
if (!existsSync17(targetPath) || !statSync8(targetPath).isFile()) {
|
|
6630
5873
|
return {};
|
|
6631
5874
|
}
|
|
6632
|
-
const raw =
|
|
5875
|
+
const raw = readFileSync12(targetPath, "utf-8");
|
|
6633
5876
|
const result = {};
|
|
6634
5877
|
for (const line of raw.split(/\r?\n/)) {
|
|
6635
5878
|
const normalized = line.trim();
|
|
@@ -6800,12 +6043,12 @@ function dockerPushImage(params, cwd) {
|
|
|
6800
6043
|
}
|
|
6801
6044
|
|
|
6802
6045
|
// src/commands/deploy/internal/backend-deploy/resolve-dockerfile.ts
|
|
6803
|
-
import { existsSync as
|
|
6046
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
6804
6047
|
import path14 from "node:path";
|
|
6805
6048
|
function resolveDockerBuildPaths(cwd) {
|
|
6806
6049
|
const dockerfilePath = path14.join(cwd, "Dockerfile");
|
|
6807
6050
|
Logger.info(`\u67E5\u627EDockerfile\u6587\u4EF6\uFF0C\u8DEF\u5F84: ${dockerfilePath}`);
|
|
6808
|
-
if (!
|
|
6051
|
+
if (!existsSync18(dockerfilePath)) {
|
|
6809
6052
|
throw new Error(`Dockerfile \u4E0D\u5B58\u5728\uFF1A${dockerfilePath}`);
|
|
6810
6053
|
}
|
|
6811
6054
|
Logger.info("\u2713 Dockerfile \u5B58\u5728");
|