dsh-ris-ide 1.8.5 → 1.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/run-with-log.sh +28 -10
- package/lib/client.js +402 -111
- package/lib/index.js +224 -64
- package/lib/proxy-lifecycle.js +502 -0
- package/lib/proxy.js +50 -0
- package/lib/risd/server.js +144 -38
- package/lib/risd/ui.js +114 -23
- package/package.json +2 -2
- package/test/client-viewer.test.mjs +229 -31
- package/test/clipboard.test.mjs +41 -2
- package/test/host-tail.test.mjs +137 -1
- package/test/proxy-lifecycle.test.mjs +251 -0
- package/test/proxy.test.mjs +48 -0
- package/test/risd-api.test.mjs +4 -1
- package/test/risd-engine.test.mjs +45 -3
- package/test/risd-follow-start.test.mjs +3 -2
- package/test/risd-handoff.test.mjs +4 -2
- package/test/risd-helpers.mjs +23 -2
- package/test/risd-teardown.test.mjs +4 -2
- package/test/risd-ui.test.mjs +21 -2
package/lib/index.js
CHANGED
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
waitForJdwpListening, toJsonSafe,
|
|
67
67
|
} from './debug/engine.js'
|
|
68
68
|
import { allowList, autoRules, engineSide, gitProxyPlan, injectionFor, isSocksCapableProgram, mergeConfigs, parseHostSpec, parsePortSpec, programKey, proxyConfigPath, proxyHomeDir, proxyPid, proxyStatus, readProxyConfig, ruleEffectiveness, runWindowsGitConfig, startProxy, stopProxy, stopProxySync, writeProxyConfig } from './proxy.js'
|
|
69
|
+
import { proxyServiceSnapshot, releaseProxyLifecycle, startProxyService, stopProxyService } from './proxy-lifecycle.js'
|
|
69
70
|
import {
|
|
70
71
|
buildProfile,
|
|
71
72
|
redirectorCommand,
|
|
@@ -670,6 +671,9 @@ function armLocalProxyCleanup() {
|
|
|
670
671
|
// same three layers; a second hook would just run the same sync cleanups twice.
|
|
671
672
|
if (lifecycle !== null) return
|
|
672
673
|
localProxyCleanup = () => {
|
|
674
|
+
// 待启动 must not outlive the process doing the waiting (a wait means "this
|
|
675
|
+
// process will start the engine"; nobody is left to do it after this exit).
|
|
676
|
+
try { releaseProxyLifecycle() } catch { /* best effort while exiting */ }
|
|
673
677
|
try { stopProxySync() } catch { /* best effort while exiting */ }
|
|
674
678
|
try { stopRedirectorSync() } catch { /* best effort while exiting */ }
|
|
675
679
|
try { clearGitProxySync() } catch { /* best effort while exiting */ }
|
|
@@ -3294,14 +3298,20 @@ export async function readPidFile(logPath) {
|
|
|
3294
3298
|
const pid = Number(parts[0])
|
|
3295
3299
|
const wrapperPid = Number(parts[1])
|
|
3296
3300
|
const startedAt = Number(parts[2])
|
|
3297
|
-
|
|
3301
|
+
// The 4th field is optional and every wrapper writes it, empty when the program
|
|
3302
|
+
// did not ask for a grace. Number('') is 0, which clampBytes would turn into the
|
|
3303
|
+
// 1 KiB floor — a one-second TERM→KILL window that kills the wrapper before it
|
|
3304
|
+
// can write its exit banner. Treat "empty" as "not recorded" so the caller's
|
|
3305
|
+
// fallback (per-program config or the route default) wins.
|
|
3306
|
+
const recordedGrace = parts[3] !== undefined && /^\d+$/.test(parts[3]) ? Number(parts[3]) : Number.NaN
|
|
3307
|
+
const graceMs = recordedGrace > 0 ? recordedGrace : undefined
|
|
3298
3308
|
if (!Number.isSafeInteger(pid) || pid <= 1) return undefined
|
|
3299
3309
|
if (!Number.isSafeInteger(wrapperPid) || wrapperPid <= 1) return undefined
|
|
3300
3310
|
return {
|
|
3301
3311
|
pid,
|
|
3302
3312
|
wrapperPid,
|
|
3303
3313
|
startedAt: Number.isFinite(startedAt) ? startedAt : undefined,
|
|
3304
|
-
graceMs
|
|
3314
|
+
graceMs,
|
|
3305
3315
|
}
|
|
3306
3316
|
}
|
|
3307
3317
|
|
|
@@ -4026,13 +4036,27 @@ function describe(error) {
|
|
|
4026
4036
|
* @param options - `{ restrictToCwd }` (see {@link apply}).
|
|
4027
4037
|
*/
|
|
4028
4038
|
/**
|
|
4029
|
-
*
|
|
4039
|
+
* Open one program in a browser: the URL it printed, or — for a yds front-end —
|
|
4040
|
+
* that front-end's WORKBENCH in yds' own debugging browser.
|
|
4030
4041
|
*
|
|
4031
|
-
*
|
|
4032
|
-
*
|
|
4033
|
-
*
|
|
4034
|
-
*
|
|
4035
|
-
*
|
|
4042
|
+
* Two different pages, because the two cases need different browsers:
|
|
4043
|
+
*
|
|
4044
|
+
* - A plain program (npm app, spring service) prints the page it serves; opening it
|
|
4045
|
+
* in the browser you are already using is enough.
|
|
4046
|
+
* - A yds front-end does NOT live on its dev server. Its page is the workbench, and
|
|
4047
|
+
* what makes it local is that the module's extend bundle is rewritten to the dev
|
|
4048
|
+
* server — by yds' extension, which a `window.open` tab cannot get. So the button
|
|
4049
|
+
* asks dsh-ris-yds to open the workbench in its debugging browser (CDP on :9222,
|
|
4050
|
+
* extension preloaded); that browser brings its own rdbga, so the page's requests
|
|
4051
|
+
* come back to this machine (m0xxx — the previous behaviour opened the raw dev
|
|
4052
|
+
* URL, which for a yds front-end is a page without platform chrome, session, or
|
|
4053
|
+
* the module's data).
|
|
4054
|
+
*
|
|
4055
|
+
* The dev URL is still handed to yds, but only as evidence of WHERE that front-end's
|
|
4056
|
+
* dev server actually listens — the declared `localDevUrl` port goes stale, and the
|
|
4057
|
+
* extension has to follow the live one. A missing yds plugin, or a plugin that
|
|
4058
|
+
* answers nothing, falls back to the plain dev-server page: the button never fails
|
|
4059
|
+
* just because yds is absent.
|
|
4036
4060
|
*/
|
|
4037
4061
|
async function serveOpenTarget(ctx, req, res, options) {
|
|
4038
4062
|
try {
|
|
@@ -4047,28 +4071,29 @@ async function serveOpenTarget(ctx, req, res, options) {
|
|
|
4047
4071
|
let program = await findProgramById(cwd, logsDir, wanted)
|
|
4048
4072
|
if (program === null) throw new TailError('not-found', `没有找到程序「${wanted.id || wanted.name}」,刷新程序列表后再试`, 404)
|
|
4049
4073
|
const devUrl = await logUrl(program.logPath)
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
code: 'no-url',
|
|
4054
|
-
message: '这个程序还没打印出访问地址:先启动它,日志里出现 Local: http://localhost:<端口> 后再点',
|
|
4055
|
-
})
|
|
4056
|
-
return
|
|
4057
|
-
}
|
|
4058
|
-
// The 🌐 button opens the dev-server page the program printed. That page is
|
|
4059
|
-
// enough on its own; dsh-ris-yds is asked ONLY for a program that IS a yds
|
|
4060
|
-
// frontend, and it is told WHICH frontend: `yds.webConfig` declares one entry
|
|
4061
|
-
// per front-end project with its own port, and injecting another entry's rules
|
|
4062
|
-
// opens a page that talks to the wrong dev server (m00555). A plain npm app, a
|
|
4063
|
-
// spring program, or an unlisted frontend opens directly — no proxy, no
|
|
4064
|
-
// private browser (m00462), and a yds refusal is not an error.
|
|
4074
|
+
// `yds.webConfig` declares one entry per front-end project; the plugin is told
|
|
4075
|
+
// WHICH one, because injecting another entry's rules opens a page that points at
|
|
4076
|
+
// the wrong dev server (m00555).
|
|
4065
4077
|
const frontend = program.kind === 'frontend' ? await ydsFrontendOf(req, cwd, program) : null
|
|
4066
4078
|
if (frontend !== null) {
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4079
|
+
// The workbench page is remote, so it does not need this dev server to have
|
|
4080
|
+
// announced itself — but driving a browser at a program that never started is
|
|
4081
|
+
// still a mistake worth reporting.
|
|
4082
|
+
if (devUrl === undefined && program.running?.alive !== true) {
|
|
4083
|
+
writeJson(res, 200, { ok: false, code: 'no-url', message: OPEN_NO_URL_MESSAGE })
|
|
4084
|
+
return
|
|
4085
|
+
}
|
|
4086
|
+
const opened = await askYdsToOpenFrontend(req, cwd, frontend, devUrl)
|
|
4087
|
+
if (opened !== null) {
|
|
4088
|
+
writeJson(res, 200, opened.ok === true ? { ...opened, source: 'yds' } : opened)
|
|
4070
4089
|
return
|
|
4071
4090
|
}
|
|
4091
|
+
// The plugin answered the probe but not this call (a reload in between). Fall
|
|
4092
|
+
// through to the plain dev-server page instead of failing the button.
|
|
4093
|
+
}
|
|
4094
|
+
if (devUrl === undefined) {
|
|
4095
|
+
writeJson(res, 200, { ok: false, code: 'no-url', message: OPEN_NO_URL_MESSAGE })
|
|
4096
|
+
return
|
|
4072
4097
|
}
|
|
4073
4098
|
writeJson(res, 200, { ok: true, url: devUrl, source: 'dev-server' })
|
|
4074
4099
|
} catch (error) {
|
|
@@ -4140,25 +4165,46 @@ async function askYdsProbe(req, cwd) {
|
|
|
4140
4165
|
}
|
|
4141
4166
|
|
|
4142
4167
|
/**
|
|
4143
|
-
* Ask dsh-ris-yds to
|
|
4168
|
+
* Ask dsh-ris-yds to open ONE front-end's workbench in its own debugging browser.
|
|
4169
|
+
*
|
|
4170
|
+
* The dev URL travels along as a port hint only: the workbench page is the thing
|
|
4171
|
+
* opened, but yds needs to know which dev server this front-end really started (the
|
|
4172
|
+
* declared port can be stale), because its extension rewrites the module bundle to
|
|
4173
|
+
* it. A browser launch takes seconds, so the timeout is generous — longer than yds'
|
|
4174
|
+
* own 15s port wait.
|
|
4144
4175
|
* @param {object} frontend - `{code, name, relDir}` of the yds front-end program.
|
|
4176
|
+
* @param {string|undefined} devUrl - the dev URL its log printed, if any.
|
|
4145
4177
|
* @returns {Promise<object|null>} the yds answer, or null when the plugin is absent.
|
|
4146
4178
|
*/
|
|
4147
|
-
async function
|
|
4179
|
+
async function askYdsToOpenFrontend(req, cwd, frontend, devUrl) {
|
|
4148
4180
|
const host = typeof req.headers.host === 'string' ? req.headers.host : ''
|
|
4149
4181
|
if (host === '') return null
|
|
4150
4182
|
const controller = new AbortController()
|
|
4151
|
-
const timer = setTimeout(() => controller.abort(),
|
|
4183
|
+
const timer = setTimeout(() => controller.abort(), 25000)
|
|
4152
4184
|
try {
|
|
4153
4185
|
const response = await fetch(`http://${host}/dsh-ris-yds/open`, {
|
|
4154
4186
|
method: 'POST',
|
|
4155
4187
|
headers: { 'content-type': 'application/json' },
|
|
4156
|
-
body: JSON.stringify({
|
|
4188
|
+
body: JSON.stringify({
|
|
4189
|
+
workspace: cwd,
|
|
4190
|
+
mode: 'debug',
|
|
4191
|
+
frontend,
|
|
4192
|
+
...(typeof devUrl === 'string' && devUrl !== '' ? { devUrl } : {}),
|
|
4193
|
+
}),
|
|
4157
4194
|
signal: controller.signal,
|
|
4158
4195
|
})
|
|
4159
4196
|
if (response.status === 404) return null
|
|
4160
4197
|
const parsed = await response.json().catch(() => null)
|
|
4161
|
-
|
|
4198
|
+
if (parsed === null || typeof parsed !== 'object') return null
|
|
4199
|
+
if (parsed.ok === true) return parsed
|
|
4200
|
+
// A refusal is an answer, not a transient: pass it on so the button can say WHY
|
|
4201
|
+
// (no browser installed, project not a yds one, …) instead of silently opening a
|
|
4202
|
+
// page the user did not ask for.
|
|
4203
|
+
return {
|
|
4204
|
+
ok: false,
|
|
4205
|
+
code: typeof parsed.code === 'string' ? parsed.code : 'yds-refused',
|
|
4206
|
+
message: typeof parsed.reason === 'string' && parsed.reason !== '' ? parsed.reason : 'dsh-ris-yds 没能打开调试浏览器',
|
|
4207
|
+
}
|
|
4162
4208
|
} catch {
|
|
4163
4209
|
return null
|
|
4164
4210
|
} finally {
|
|
@@ -5000,23 +5046,73 @@ async function clipboardStageMapping(root) {
|
|
|
5000
5046
|
const entries = await readdir(base, { withFileTypes: true }).catch(() => [])
|
|
5001
5047
|
for (const entry of entries) {
|
|
5002
5048
|
if (!entry.isDirectory()) continue
|
|
5003
|
-
const
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5049
|
+
const table = await clipboardStageTable(join(base, entry.name))
|
|
5050
|
+
for (const [staged, original] of table) mapping.set(staged, original)
|
|
5051
|
+
}
|
|
5052
|
+
return mapping
|
|
5053
|
+
}
|
|
5054
|
+
|
|
5055
|
+
/**
|
|
5056
|
+
* One batch's `staged → original` table, read from its manifest.
|
|
5057
|
+
* @param {string} batchDir - absolute `<…>/stage/<batch>`.
|
|
5058
|
+
* @returns {Promise<Map<string,string>>} resolved staged path → original path.
|
|
5059
|
+
*/
|
|
5060
|
+
async function clipboardStageTable(batchDir) {
|
|
5061
|
+
const table = new Map()
|
|
5062
|
+
const manifest = await readFile(join(batchDir, CLIPBOARD_STAGE_MANIFEST), 'utf8').catch(() => undefined)
|
|
5063
|
+
if (manifest === undefined) return table
|
|
5064
|
+
let parsed
|
|
5065
|
+
try {
|
|
5066
|
+
parsed = JSON.parse(manifest)
|
|
5067
|
+
} catch {
|
|
5068
|
+
return table
|
|
5069
|
+
}
|
|
5070
|
+
if (parsed === null || typeof parsed !== 'object') return table
|
|
5071
|
+
const staged = Array.isArray(parsed.staged) ? parsed.staged : []
|
|
5072
|
+
const originals = Array.isArray(parsed.originals) ? parsed.originals : []
|
|
5073
|
+
for (let index = 0; index < staged.length; index += 1) {
|
|
5074
|
+
if (typeof staged[index] === 'string' && typeof originals[index] === 'string') {
|
|
5075
|
+
table.set(resolve(staged[index]), originals[index])
|
|
5018
5076
|
}
|
|
5019
5077
|
}
|
|
5078
|
+
return table
|
|
5079
|
+
}
|
|
5080
|
+
|
|
5081
|
+
/**
|
|
5082
|
+
* staged path → original path, resolved from the PATH ITSELF.
|
|
5083
|
+
*
|
|
5084
|
+
* A staged copy lives at `<workspace>/.dsh-ris-ide/stage/<batch>/<i>/<name>`, so
|
|
5085
|
+
* the manifest that owns it is findable without knowing which workspace it came
|
|
5086
|
+
* from. Reading only the CURRENT workspace's manifests broke the
|
|
5087
|
+
* cross-workspace case: after switching to B, A's staged paths came back
|
|
5088
|
+
* verbatim, the page compared them with its own clipboard, decided they were
|
|
5089
|
+
* NEWER external files and turned a Copy into an import (and dropped the copy).
|
|
5090
|
+
* @param {string[]} paths - paths read back from the OS clipboard.
|
|
5091
|
+
* @returns {Promise<Map<string,string>>} staged → original for the ones we published.
|
|
5092
|
+
*/
|
|
5093
|
+
async function clipboardStageMappingFor(paths) {
|
|
5094
|
+
const mapping = new Map()
|
|
5095
|
+
const manifests = new Map()
|
|
5096
|
+
const marker = `${sep}${CLIPBOARD_STAGE_DIR.split('/').join(sep)}${sep}`
|
|
5097
|
+
for (const raw of paths) {
|
|
5098
|
+
if (typeof raw !== 'string' || raw === '') continue
|
|
5099
|
+
const resolved = resolve(raw)
|
|
5100
|
+
const at = resolved.indexOf(marker)
|
|
5101
|
+
if (at < 0) continue
|
|
5102
|
+
const rest = resolved.slice(at + marker.length)
|
|
5103
|
+
const cut = rest.indexOf(sep)
|
|
5104
|
+
if (cut <= 0) continue
|
|
5105
|
+
// `at + marker.length` sits right after the separator: prepending it keeps
|
|
5106
|
+
// the drive/UNC prefix intact on Windows.
|
|
5107
|
+
const batchDir = resolved.slice(0, at + marker.length) + rest.slice(0, cut)
|
|
5108
|
+
let table = manifests.get(batchDir)
|
|
5109
|
+
if (table === undefined) {
|
|
5110
|
+
table = await clipboardStageTable(batchDir)
|
|
5111
|
+
manifests.set(batchDir, table)
|
|
5112
|
+
}
|
|
5113
|
+
const original = table.get(resolved)
|
|
5114
|
+
if (original !== undefined) mapping.set(resolved, original)
|
|
5115
|
+
}
|
|
5020
5116
|
return mapping
|
|
5021
5117
|
}
|
|
5022
5118
|
|
|
@@ -5275,15 +5371,28 @@ async function serveClipboardRead(ctx, req, res) {
|
|
|
5275
5371
|
// second copy of files the tree already has).
|
|
5276
5372
|
let files = state.files
|
|
5277
5373
|
let warnings = []
|
|
5374
|
+
// Translate by the staged path ITSELF (see clipboardStageMappingFor): the
|
|
5375
|
+
// clipboard outlives a workspace switch, the current root does not.
|
|
5376
|
+
const mapping = await clipboardStageMappingFor(files)
|
|
5377
|
+
if (mapping.size > 0) files = files.map((path) => mapping.get(resolve(path)) ?? path)
|
|
5378
|
+
// A CUT publish leaves the REAL paths on the clipboard. Once they have been
|
|
5379
|
+
// pasted (or deleted) those paths are gone, and handing them back would offer
|
|
5380
|
+
// the page a ghost selection that fails item by item. Drop them and say so.
|
|
5381
|
+
const missing = []
|
|
5382
|
+
const present = []
|
|
5383
|
+
for (const path of files) {
|
|
5384
|
+
const info = await lstat(path).catch(() => undefined)
|
|
5385
|
+
if (info === undefined) missing.push(path)
|
|
5386
|
+
else present.push(path)
|
|
5387
|
+
}
|
|
5388
|
+
files = present
|
|
5278
5389
|
if (root !== undefined) {
|
|
5279
|
-
const mapping = await clipboardStageMapping(root)
|
|
5280
|
-
if (mapping.size > 0) files = files.map((path) => mapping.get(resolve(path)) ?? path)
|
|
5281
5390
|
// A staged original that vanished between Ctrl+C and Ctrl+V is the exact
|
|
5282
5391
|
// symptom this route exists to explain: say so once, with the staged path
|
|
5283
5392
|
// that still holds the bytes, and leave a line in stage/integrity.log.
|
|
5284
5393
|
warnings = (await verifyClipboardStageOriginals(root)).map((finding) => finding.message)
|
|
5285
5394
|
}
|
|
5286
|
-
writeJson(res, 200, { ok: true, files, text: state.text, method: state.method, warnings })
|
|
5395
|
+
writeJson(res, 200, { ok: true, files, text: state.text, method: state.method, warnings, missing })
|
|
5287
5396
|
} catch (error) {
|
|
5288
5397
|
writeTailError(res, error)
|
|
5289
5398
|
}
|
|
@@ -7158,9 +7267,14 @@ async function proxyView(cwd, gitHost) {
|
|
|
7158
7267
|
// dialog shows a takeover banner with a one-click stop instead of pretending this
|
|
7159
7268
|
// session started it. The flag is dropped as soon as that engine is gone.
|
|
7160
7269
|
const inherited = inheritedEngine !== null && inheritedEngine.pid === status.pid ? inheritedEngine : null
|
|
7270
|
+
// running / pending(待启动) / stopped, plus how long a wait has been going and the
|
|
7271
|
+
// upstream error that caused it. Any process may read it (the daemon may own the
|
|
7272
|
+
// wait), so it comes from the shared state file when this host is not watching.
|
|
7273
|
+
const service = proxyServiceSnapshot()
|
|
7161
7274
|
return {
|
|
7162
7275
|
ok: true,
|
|
7163
7276
|
side: engineSide(),
|
|
7277
|
+
service,
|
|
7164
7278
|
// The dialog sends this back with its save, so a table edited in another window
|
|
7165
7279
|
// is refused instead of silently overwritten.
|
|
7166
7280
|
revision: configRevision(status.config),
|
|
@@ -7902,19 +8016,28 @@ async function serveProxyAction(ctx, req, res, options) {
|
|
|
7902
8016
|
// answers): this engine is ours, so install the exit hook that auto mode would
|
|
7903
8017
|
// otherwise rely on the daemon to provide (review C2-P1-3).
|
|
7904
8018
|
armLocalProxyCleanup()
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
|
|
8019
|
+
// The service probes SOCKS before spawning anything: an upstream that is down
|
|
8020
|
+
// parks the request in 待启动 and a watcher brings the engine up later (the
|
|
8021
|
+
// engine would otherwise bind its loopback ports and fail every tunnel).
|
|
8022
|
+
const outcome = await startProxyService({ cwd, gitHost, interactive, syncGit: (plan) => syncGitProxy(plan) })
|
|
8023
|
+
if (outcome.phase === 'running') inheritedEngine = null
|
|
8024
|
+
result = Object.assign({}, outcome.engine, {
|
|
8025
|
+
redirector: outcome.redirector,
|
|
8026
|
+
git: outcome.git,
|
|
8027
|
+
phase: outcome.phase,
|
|
8028
|
+
waiting: outcome.waiting === true,
|
|
8029
|
+
reason: outcome.reason ?? '',
|
|
8030
|
+
})
|
|
7910
8031
|
} else if (action === 'stop') {
|
|
7911
|
-
const
|
|
7912
|
-
const redirector = await stopRedirector()
|
|
7913
|
-
const stopped = await stopProxy(cwd)
|
|
8032
|
+
const outcome = await stopProxyService({ cwd, gitHost, syncGit: (plan) => syncGitProxy(plan) })
|
|
7914
8033
|
disarmLocalProxyCleanup()
|
|
7915
8034
|
// The banner must not come back once the adopted engine is really gone.
|
|
7916
8035
|
if (proxyPid() === null) inheritedEngine = null
|
|
7917
|
-
result = Object.assign({},
|
|
8036
|
+
result = Object.assign({}, outcome.engine, {
|
|
8037
|
+
redirector: outcome.redirector,
|
|
8038
|
+
git: outcome.git,
|
|
8039
|
+
phase: outcome.phase,
|
|
8040
|
+
})
|
|
7918
8041
|
} else if (action === 'git-on' || action === 'git-off') {
|
|
7919
8042
|
const plan = gitProxyPlan(readProxyConfig(cwd), { host: gitHost, enabled: action === 'git-on' })
|
|
7920
8043
|
result = action === 'git-on'
|
|
@@ -11199,12 +11322,48 @@ async function logUrl(logPath) {
|
|
|
11199
11322
|
if (tail === undefined || typeof tail.content !== 'string') return undefined
|
|
11200
11323
|
// eslint-disable-next-line no-control-regex
|
|
11201
11324
|
const text = tail.content.replace(/\u001b\[[0-9;]*m/g, '')
|
|
11202
|
-
const
|
|
11203
|
-
const
|
|
11204
|
-
|
|
11205
|
-
|
|
11206
|
-
|
|
11207
|
-
|
|
11325
|
+
const urls = []
|
|
11326
|
+
const lines = text.split(/\r?\n/)
|
|
11327
|
+
for (const line of lines) {
|
|
11328
|
+
const match = line.match(LOG_URL_PATTERN)
|
|
11329
|
+
if (match === null) continue
|
|
11330
|
+
const candidate = dialableUrl(match[0])
|
|
11331
|
+
if (candidate === undefined) continue
|
|
11332
|
+
// The LAST match in a log is often a quoted URL from a failed request (an asset
|
|
11333
|
+
// the app could not load), never the address the server announced. Only a line
|
|
11334
|
+
// that names the server owns an address; anything else is a hint at best.
|
|
11335
|
+
urls.push({ url: candidate, announced: LOG_URL_ANNOUNCEMENT.test(line), quoted: LOG_URL_TROUBLE.test(line) })
|
|
11336
|
+
}
|
|
11337
|
+
const announced = urls.filter((entry) => entry.announced)
|
|
11338
|
+
if (announced.length > 0) return announced[announced.length - 1].url
|
|
11339
|
+
const quiet = urls.filter((entry) => entry.quoted !== true)
|
|
11340
|
+
return quiet.length > 0 ? quiet[quiet.length - 1].url : undefined
|
|
11341
|
+
}
|
|
11342
|
+
|
|
11343
|
+
/** A loopback address with a port: the only shape a dev server announces (m03945). */
|
|
11344
|
+
const LOG_URL_PATTERN = /https?:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1?\]|\[::\]|<[^>\s]{1,40}>):\d+[^\s)"',。;]*/gi
|
|
11345
|
+
|
|
11346
|
+
/** Lines that introduce a listening dev server (`Local:`, `服务地址`, vite's `ready in`…). */
|
|
11347
|
+
const LOG_URL_ANNOUNCEMENT = /(?:Local|Network|Listening|running at|服务地址|Dev Server|Server started|ready in|available at)/i
|
|
11348
|
+
|
|
11349
|
+
/** Lines that quote a URL because something failed (a fetch, a missing asset). */
|
|
11350
|
+
const LOG_URL_TROUBLE = /\b(?:error|warn(?:ing)?|failed|not found|status|未获取到|失败|异常)\b/i
|
|
11351
|
+
|
|
11352
|
+
/** The 🌐 answer when a program's log never announced a page (pressed too early). */
|
|
11353
|
+
const OPEN_NO_URL_MESSAGE = '这个程序还没打印出访问地址:先启动它,日志里出现 Local: http://localhost:<端口> 后再点'
|
|
11354
|
+
|
|
11355
|
+
/**
|
|
11356
|
+
* The dialable form of one loopback URL, or undefined when it is not an address.
|
|
11357
|
+
*
|
|
11358
|
+
* A wildcard/placeholder host is a listening address, not a dialable one, so it is
|
|
11359
|
+
* rewritten to 127.0.0.1. A URL that still carries a template (`.../}/module/...`)
|
|
11360
|
+
* is not an address at all — opening it lands on a 404.
|
|
11361
|
+
* @param {string} raw - one URL matched from a log line.
|
|
11362
|
+
* @returns {string|undefined} the URL to open, or undefined to skip it.
|
|
11363
|
+
*/
|
|
11364
|
+
function dialableUrl(raw) {
|
|
11365
|
+
const url = raw.replace(/^(https?):\/\/(?:0\.0\.0\.0|\[::\]|<[^>]+>|\[::1\]):/i, '$1://127.0.0.1:')
|
|
11366
|
+
return /[{}]/.test(url) ? undefined : url
|
|
11208
11367
|
}
|
|
11209
11368
|
|
|
11210
11369
|
/** Status of one log path (a program's fixed log, or an ad-hoc instance log). */
|
|
@@ -11737,6 +11896,7 @@ export const __test = {
|
|
|
11737
11896
|
stageClipboardCopy,
|
|
11738
11897
|
pruneClipboardStage,
|
|
11739
11898
|
clipboardStageMapping,
|
|
11899
|
+
clipboardStageMappingFor,
|
|
11740
11900
|
verifyClipboardStageOriginals,
|
|
11741
11901
|
CLIPBOARD_STAGE_INTEGRITY_LOG,
|
|
11742
11902
|
serveClipboardFiles,
|