@oniroproject/core 0.17.0 → 0.18.0
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/README.md +11 -0
- package/dist/index.cjs +484 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +196 -2
- package/dist/index.d.ts +196 -2
- package/dist/index.js +468 -66
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -52,6 +52,10 @@ __export(index_exports, {
|
|
|
52
52
|
DEFAULT_SMOKE_PID_TIMEOUT_MS: () => DEFAULT_SMOKE_PID_TIMEOUT_MS,
|
|
53
53
|
DEFAULT_TRACE_BUFFER_KB: () => DEFAULT_TRACE_BUFFER_KB,
|
|
54
54
|
DEFAULT_TRACE_CATEGORIES: () => DEFAULT_TRACE_CATEGORIES,
|
|
55
|
+
DOCS_REPO: () => DOCS_REPO,
|
|
56
|
+
DOCS_SPARSE_PATH: () => DOCS_SPARSE_PATH,
|
|
57
|
+
DOCS_SPARSE_PATTERNS: () => DOCS_SPARSE_PATTERNS,
|
|
58
|
+
DocsIndex: () => DocsIndex,
|
|
55
59
|
EMULATOR_KERNEL_APPEND: () => EMULATOR_KERNEL_APPEND,
|
|
56
60
|
FAULTLOG_DIR: () => FAULTLOG_DIR,
|
|
57
61
|
FAULTLOG_TEMP_DIR: () => FAULTLOG_TEMP_DIR,
|
|
@@ -174,6 +178,12 @@ __export(index_exports, {
|
|
|
174
178
|
diffHapAssets: () => diffHapAssets,
|
|
175
179
|
diffLayouts: () => diffLayouts,
|
|
176
180
|
discoverHaps: () => discoverHaps,
|
|
181
|
+
docQueryTerms: () => docQueryTerms,
|
|
182
|
+
docTokens: () => docTokens,
|
|
183
|
+
docWords: () => docWords,
|
|
184
|
+
docsDirFor: () => docsDirFor,
|
|
185
|
+
docsRefFor: () => docsRefFor,
|
|
186
|
+
docsTree: () => docsTree,
|
|
177
187
|
downloadAndInstallSdk: () => downloadAndInstallSdk,
|
|
178
188
|
downloadFile: () => downloadFile,
|
|
179
189
|
dumpLayout: () => dumpLayout,
|
|
@@ -234,6 +244,7 @@ __export(index_exports, {
|
|
|
234
244
|
getDefaultInstanceStatus: () => getDefaultInstanceStatus,
|
|
235
245
|
getDeviceInfo: () => getDeviceInfo,
|
|
236
246
|
getDisplaySize: () => getDisplaySize,
|
|
247
|
+
getDocsRootDir: () => getDocsRootDir,
|
|
237
248
|
getEmulatorDir: () => getEmulatorDir,
|
|
238
249
|
getEmulatorStatus: () => getEmulatorStatus,
|
|
239
250
|
getFreeSpaceBytes: () => getFreeSpaceBytes,
|
|
@@ -297,6 +308,7 @@ __export(index_exports, {
|
|
|
297
308
|
listDevices: () => listDevices,
|
|
298
309
|
listFaultLogs: () => listFaultLogs,
|
|
299
310
|
listLayoutWindows: () => listLayoutWindows,
|
|
311
|
+
listMarkdown: () => listMarkdown,
|
|
300
312
|
listModules: () => listModules,
|
|
301
313
|
listPoolInstanceNumbers: () => listPoolInstanceNumbers,
|
|
302
314
|
listPoolInstanceStatuses: () => listPoolInstanceStatuses,
|
|
@@ -337,6 +349,7 @@ __export(index_exports, {
|
|
|
337
349
|
parseCrashRecordHeads: () => parseCrashRecordHeads,
|
|
338
350
|
parseDeviceList: () => parseDeviceList,
|
|
339
351
|
parseDeviceTime: () => parseDeviceTime,
|
|
352
|
+
parseDoc: () => parseDoc,
|
|
340
353
|
parseDocBlock: () => parseDocBlock,
|
|
341
354
|
parseFaultLogList: () => parseFaultLogList,
|
|
342
355
|
parseFaultLogName: () => parseFaultLogName,
|
|
@@ -393,6 +406,7 @@ __export(index_exports, {
|
|
|
393
406
|
readPoolState: () => readPoolState,
|
|
394
407
|
readProvisionProfile: () => readProvisionProfile,
|
|
395
408
|
readSdkPkg: () => readSdkPkg,
|
|
409
|
+
readSdkRelease: () => readSdkRelease,
|
|
396
410
|
readTestModuleName: () => readTestModuleName,
|
|
397
411
|
readZipEntry: () => readZipEntry,
|
|
398
412
|
reboot: () => reboot,
|
|
@@ -455,6 +469,7 @@ __export(index_exports, {
|
|
|
455
469
|
summarizeDivergenceLayout: () => summarizeDivergenceLayout,
|
|
456
470
|
summarizeLayout: () => summarizeLayout,
|
|
457
471
|
summarizeTrace: () => summarizeTrace,
|
|
472
|
+
syncDocs: () => syncDocs,
|
|
458
473
|
takeScreenshot: () => takeScreenshot,
|
|
459
474
|
testHapPath: () => testHapPath,
|
|
460
475
|
toLongPath: () => toLongPath,
|
|
@@ -478,6 +493,7 @@ __export(index_exports, {
|
|
|
478
493
|
windowSubtree: () => windowSubtree,
|
|
479
494
|
withHapZip: () => withHapZip,
|
|
480
495
|
withoutWindow: () => withoutWindow,
|
|
496
|
+
wordIn: () => wordIn,
|
|
481
497
|
writeJson5File: () => writeJson5File,
|
|
482
498
|
writeJsonFile: () => writeJsonFile,
|
|
483
499
|
writePoolState: () => writePoolState
|
|
@@ -1089,14 +1105,14 @@ var pipelineAsync = (0, import_node_util.promisify)(import_node_stream.pipeline)
|
|
|
1089
1105
|
async function downloadFile(opts) {
|
|
1090
1106
|
const { url, dest, progress, abortSignal } = opts;
|
|
1091
1107
|
const proto = url.startsWith("https") ? https : http;
|
|
1092
|
-
return new Promise((
|
|
1108
|
+
return new Promise((resolve22, reject) => {
|
|
1093
1109
|
const s = Math.max(0, Math.min(100, opts.start ?? 0));
|
|
1094
1110
|
const r = Math.max(0, Math.min(100 - s, opts.range ?? 100));
|
|
1095
1111
|
let settled = false;
|
|
1096
1112
|
const done = (err) => {
|
|
1097
1113
|
if (settled) return;
|
|
1098
1114
|
settled = true;
|
|
1099
|
-
err ? reject(err) :
|
|
1115
|
+
err ? reject(err) : resolve22();
|
|
1100
1116
|
};
|
|
1101
1117
|
if (abortSignal?.aborted) {
|
|
1102
1118
|
done(new CancelledError("Download cancelled before start."));
|
|
@@ -1277,10 +1293,10 @@ async function extractTarball(tarPath, dest, strip = 0, filter) {
|
|
|
1277
1293
|
var SIGNED_HAP_CHUNK_SIZE = 128 * 1024;
|
|
1278
1294
|
async function withHapZip(zipPath, use) {
|
|
1279
1295
|
const zip = new import_node_stream_zip.default({ file: zipPath, chunkSize: SIGNED_HAP_CHUNK_SIZE, storeEntries: true });
|
|
1280
|
-
const close = () => new Promise((
|
|
1296
|
+
const close = () => new Promise((resolve22) => zip.close(() => resolve22()));
|
|
1281
1297
|
try {
|
|
1282
|
-
await new Promise((
|
|
1283
|
-
zip.once("ready", () =>
|
|
1298
|
+
await new Promise((resolve22, reject) => {
|
|
1299
|
+
zip.once("ready", () => resolve22());
|
|
1284
1300
|
zip.once("error", (err) => reject(err));
|
|
1285
1301
|
});
|
|
1286
1302
|
return await use({ entries: () => zip.entries(), entryData: (name) => zip.entryDataSync(name) });
|
|
@@ -2770,7 +2786,7 @@ function runProcess(opts) {
|
|
|
2770
2786
|
const { command, args, cwd, env, onOutput } = opts;
|
|
2771
2787
|
const timeoutMs = opts.timeoutMs ?? 6e4;
|
|
2772
2788
|
const { abortSignal } = opts;
|
|
2773
|
-
return new Promise((
|
|
2789
|
+
return new Promise((resolve22, reject) => {
|
|
2774
2790
|
if (abortSignal?.aborted) {
|
|
2775
2791
|
reject(new CancelledError(`Command aborted before start: ${command}`));
|
|
2776
2792
|
return;
|
|
@@ -2843,7 +2859,7 @@ ${stderr.trim()}` : "")
|
|
|
2843
2859
|
);
|
|
2844
2860
|
return;
|
|
2845
2861
|
}
|
|
2846
|
-
|
|
2862
|
+
resolve22({ code: code ?? -1, stdout, stderr });
|
|
2847
2863
|
});
|
|
2848
2864
|
});
|
|
2849
2865
|
}
|
|
@@ -3494,11 +3510,11 @@ async function getDefaultInstanceStatus(config, opts) {
|
|
|
3494
3510
|
};
|
|
3495
3511
|
}
|
|
3496
3512
|
function isTcpPortFree(port, host = "127.0.0.1") {
|
|
3497
|
-
return new Promise((
|
|
3513
|
+
return new Promise((resolve22) => {
|
|
3498
3514
|
const srv = net.createServer();
|
|
3499
|
-
srv.once("error", () =>
|
|
3515
|
+
srv.once("error", () => resolve22(false));
|
|
3500
3516
|
srv.listen({ port, host, exclusive: true }, () => {
|
|
3501
|
-
srv.close(() =>
|
|
3517
|
+
srv.close(() => resolve22(true));
|
|
3502
3518
|
});
|
|
3503
3519
|
});
|
|
3504
3520
|
}
|
|
@@ -3659,9 +3675,9 @@ async function startPoolInstance(opts) {
|
|
|
3659
3675
|
} finally {
|
|
3660
3676
|
fs22.closeSync(logFd);
|
|
3661
3677
|
}
|
|
3662
|
-
const earlyExit = new Promise((
|
|
3663
|
-
child.once("exit", (code) =>
|
|
3664
|
-
child.once("error", () =>
|
|
3678
|
+
const earlyExit = new Promise((resolve22) => {
|
|
3679
|
+
child.once("exit", (code) => resolve22(code));
|
|
3680
|
+
child.once("error", () => resolve22(-1));
|
|
3665
3681
|
});
|
|
3666
3682
|
if (!child.pid) {
|
|
3667
3683
|
await earlyExit;
|
|
@@ -3871,11 +3887,11 @@ async function startEmulator(opts) {
|
|
|
3871
3887
|
fs23.writeFileSync(DEFAULT_EMULATOR_PID_FILE, String(child.pid));
|
|
3872
3888
|
child.unref();
|
|
3873
3889
|
logger.info(`Emulator launched (PID ${child.pid}). Logs: ${logPath}`);
|
|
3874
|
-
const earlyExit = new Promise((
|
|
3875
|
-
child.once("exit", (code) =>
|
|
3876
|
-
child.once("error", () =>
|
|
3890
|
+
const earlyExit = new Promise((resolve22) => {
|
|
3891
|
+
child.once("exit", (code) => resolve22(code));
|
|
3892
|
+
child.once("error", () => resolve22(-1));
|
|
3877
3893
|
});
|
|
3878
|
-
const liveness = new Promise((
|
|
3894
|
+
const liveness = new Promise((resolve22) => setTimeout(() => resolve22("alive"), 2e3));
|
|
3879
3895
|
const outcome = await Promise.race([earlyExit, liveness]);
|
|
3880
3896
|
if (outcome !== "alive") {
|
|
3881
3897
|
const tail = readTail(logPath, 4e3);
|
|
@@ -4204,7 +4220,7 @@ async function getDisplaySize(config, opts = {}) {
|
|
|
4204
4220
|
|
|
4205
4221
|
// src/hdc/wait.ts
|
|
4206
4222
|
function delay(ms, signal) {
|
|
4207
|
-
return new Promise((
|
|
4223
|
+
return new Promise((resolve22, reject) => {
|
|
4208
4224
|
if (signal?.aborted) {
|
|
4209
4225
|
reject(new CancelledError("Wait cancelled."));
|
|
4210
4226
|
return;
|
|
@@ -4219,7 +4235,7 @@ function delay(ms, signal) {
|
|
|
4219
4235
|
};
|
|
4220
4236
|
const timer = setTimeout(() => {
|
|
4221
4237
|
cleanup();
|
|
4222
|
-
|
|
4238
|
+
resolve22();
|
|
4223
4239
|
}, ms);
|
|
4224
4240
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
4225
4241
|
});
|
|
@@ -4394,8 +4410,8 @@ async function resolveInstallHap(opts, logger) {
|
|
|
4394
4410
|
return hap;
|
|
4395
4411
|
};
|
|
4396
4412
|
const configured = opts.hapPath ?? opts.config.get("hapPath", "");
|
|
4397
|
-
const
|
|
4398
|
-
const hapPath = path26.isAbsolute(
|
|
4413
|
+
const relative8 = configured || defaultPaths.hapPath;
|
|
4414
|
+
const hapPath = path26.isAbsolute(relative8) ? relative8 : path26.join(opts.projectDir, relative8);
|
|
4399
4415
|
if (configured) {
|
|
4400
4416
|
const hap = existingHapOrUnsigned(hapPath);
|
|
4401
4417
|
if (!hap) throw new OniroError(`HAP file not found at: ${hapPath}. Build the app first.`);
|
|
@@ -4512,7 +4528,7 @@ function listRunningProcesses(config, options = {}) {
|
|
|
4512
4528
|
const logger = options.logger ?? noopLogger;
|
|
4513
4529
|
const timeoutMs = options.timeoutMs ?? 1e3;
|
|
4514
4530
|
const hdc = getHdcPath(config);
|
|
4515
|
-
return new Promise((
|
|
4531
|
+
return new Promise((resolve22, reject) => {
|
|
4516
4532
|
let proc;
|
|
4517
4533
|
try {
|
|
4518
4534
|
proc = spawnCompat(hdc, [...hdcTargetArgs(options.deviceSerial), "track-jpid"]);
|
|
@@ -4532,7 +4548,7 @@ function listRunningProcesses(config, options = {}) {
|
|
|
4532
4548
|
if (options.targetProcessName && name === options.targetProcessName && !resolved) {
|
|
4533
4549
|
resolved = true;
|
|
4534
4550
|
killProcessTree(proc);
|
|
4535
|
-
|
|
4551
|
+
resolve22(pid);
|
|
4536
4552
|
return;
|
|
4537
4553
|
}
|
|
4538
4554
|
}
|
|
@@ -4553,7 +4569,7 @@ function listRunningProcesses(config, options = {}) {
|
|
|
4553
4569
|
if (options.targetProcessName) {
|
|
4554
4570
|
reject(new OniroError(`Could not find process for bundle: ${options.targetProcessName}`));
|
|
4555
4571
|
} else {
|
|
4556
|
-
|
|
4572
|
+
resolve22(processes);
|
|
4557
4573
|
}
|
|
4558
4574
|
}, timeoutMs);
|
|
4559
4575
|
proc.on("close", () => {
|
|
@@ -4563,7 +4579,7 @@ function listRunningProcesses(config, options = {}) {
|
|
|
4563
4579
|
if (options.targetProcessName) {
|
|
4564
4580
|
reject(new OniroError(`Could not find process for bundle: ${options.targetProcessName}`));
|
|
4565
4581
|
} else {
|
|
4566
|
-
|
|
4582
|
+
resolve22(processes);
|
|
4567
4583
|
}
|
|
4568
4584
|
});
|
|
4569
4585
|
});
|
|
@@ -5187,9 +5203,9 @@ var Parser = class {
|
|
|
5187
5203
|
return tok2.t === "name" && tok2.v === v;
|
|
5188
5204
|
}
|
|
5189
5205
|
parseTop() {
|
|
5190
|
-
const
|
|
5206
|
+
const path62 = this.parsePath();
|
|
5191
5207
|
if (this.peek().t !== "eof") this.fail("unexpected trailing input");
|
|
5192
|
-
return
|
|
5208
|
+
return path62;
|
|
5193
5209
|
}
|
|
5194
5210
|
parsePath() {
|
|
5195
5211
|
const startTok = this.peek();
|
|
@@ -5204,10 +5220,10 @@ var Parser = class {
|
|
|
5204
5220
|
}
|
|
5205
5221
|
const steps = [];
|
|
5206
5222
|
for (; ; ) {
|
|
5207
|
-
const
|
|
5208
|
-
if (
|
|
5223
|
+
const sep7 = this.peek();
|
|
5224
|
+
if (sep7.t !== "/" && sep7.t !== "//") break;
|
|
5209
5225
|
this.next();
|
|
5210
|
-
steps.push(this.parseStep(
|
|
5226
|
+
steps.push(this.parseStep(sep7.t === "//"));
|
|
5211
5227
|
}
|
|
5212
5228
|
if (start === "root" && steps.length === 0) this.fail("expected a step");
|
|
5213
5229
|
return { source: this.src, start, steps };
|
|
@@ -6057,7 +6073,7 @@ async function listWindows(opts) {
|
|
|
6057
6073
|
// src/hdc/uiActions.ts
|
|
6058
6074
|
var FOCUS_SETTLE_MS = 400;
|
|
6059
6075
|
var KEYBOARD_SETTLE_MS = 400;
|
|
6060
|
-
var sleep = (ms) => new Promise((
|
|
6076
|
+
var sleep = (ms) => new Promise((resolve22) => setTimeout(resolve22, ms));
|
|
6061
6077
|
function selectableTree(layout, windowId) {
|
|
6062
6078
|
const kb = layout.keyboard;
|
|
6063
6079
|
return kb?.shown && kb.bundle && windowId === void 0 ? withoutWindow(layout.tree, kb.bundle) : layout.tree;
|
|
@@ -6223,7 +6239,7 @@ var fs29 = __toESM(require("fs"), 1);
|
|
|
6223
6239
|
function setHilogLevel(opts) {
|
|
6224
6240
|
const logger = opts.logger ?? noopLogger;
|
|
6225
6241
|
const hdc = getHdcPath(opts.config);
|
|
6226
|
-
return new Promise((
|
|
6242
|
+
return new Promise((resolve22, reject) => {
|
|
6227
6243
|
let child;
|
|
6228
6244
|
try {
|
|
6229
6245
|
child = spawnCompat(hdc, [...hdcTargetArgs(opts.deviceSerial), "shell", "hilog", "-b", opts.level]);
|
|
@@ -6243,7 +6259,7 @@ function setHilogLevel(opts) {
|
|
|
6243
6259
|
});
|
|
6244
6260
|
child.once("close", (code) => {
|
|
6245
6261
|
if (code === 0) {
|
|
6246
|
-
|
|
6262
|
+
resolve22();
|
|
6247
6263
|
} else {
|
|
6248
6264
|
const msg = stderr.trim() || `hdc shell hilog -b ${opts.level} exited with code ${code}`;
|
|
6249
6265
|
logger.error(`[hilog] ${msg}`);
|
|
@@ -6345,7 +6361,7 @@ async function recentEntryFilter(opts) {
|
|
|
6345
6361
|
};
|
|
6346
6362
|
}
|
|
6347
6363
|
function waitForLog(opts) {
|
|
6348
|
-
return new Promise((
|
|
6364
|
+
return new Promise((resolve22, reject) => {
|
|
6349
6365
|
const deadline = Date.now() + opts.timeoutMs;
|
|
6350
6366
|
let settled = false;
|
|
6351
6367
|
let child = null;
|
|
@@ -6366,7 +6382,7 @@ function waitForLog(opts) {
|
|
|
6366
6382
|
if (settled) return;
|
|
6367
6383
|
settled = true;
|
|
6368
6384
|
cleanup();
|
|
6369
|
-
|
|
6385
|
+
resolve22(entry);
|
|
6370
6386
|
};
|
|
6371
6387
|
const fail = (err) => {
|
|
6372
6388
|
if (settled) return;
|
|
@@ -6421,7 +6437,7 @@ function waitForLog(opts) {
|
|
|
6421
6437
|
});
|
|
6422
6438
|
}
|
|
6423
6439
|
function watchLog(opts) {
|
|
6424
|
-
return new Promise((
|
|
6440
|
+
return new Promise((resolve22, reject) => {
|
|
6425
6441
|
const matches = [];
|
|
6426
6442
|
let settled = false;
|
|
6427
6443
|
let child = null;
|
|
@@ -6440,7 +6456,7 @@ function watchLog(opts) {
|
|
|
6440
6456
|
if (settled) return;
|
|
6441
6457
|
settled = true;
|
|
6442
6458
|
cleanup();
|
|
6443
|
-
|
|
6459
|
+
resolve22(opts.dedup === false ? matches : dedupEntries(matches));
|
|
6444
6460
|
};
|
|
6445
6461
|
const onAbort = () => {
|
|
6446
6462
|
if (settled) return;
|
|
@@ -6489,7 +6505,7 @@ async function captureLog(opts) {
|
|
|
6489
6505
|
let lines = 0;
|
|
6490
6506
|
let reconnects = 0;
|
|
6491
6507
|
try {
|
|
6492
|
-
await new Promise((
|
|
6508
|
+
await new Promise((resolve22, reject) => {
|
|
6493
6509
|
const deadline = opts.durationMs !== void 0 ? Date.now() + opts.durationMs : Infinity;
|
|
6494
6510
|
let settled = false;
|
|
6495
6511
|
let child = null;
|
|
@@ -6519,7 +6535,7 @@ async function captureLog(opts) {
|
|
|
6519
6535
|
if (settled) return;
|
|
6520
6536
|
settled = true;
|
|
6521
6537
|
cleanup();
|
|
6522
|
-
|
|
6538
|
+
resolve22();
|
|
6523
6539
|
}
|
|
6524
6540
|
const fail = (err) => {
|
|
6525
6541
|
if (settled) return;
|
|
@@ -6966,7 +6982,7 @@ function analyzeBlank(img) {
|
|
|
6966
6982
|
var DEFAULT_SMOKE_DELAY_MS = 2e3;
|
|
6967
6983
|
var DEFAULT_SMOKE_PID_TIMEOUT_MS = 1e4;
|
|
6968
6984
|
var PID_POLL_MS = 500;
|
|
6969
|
-
var sleep2 = (ms) => new Promise((
|
|
6985
|
+
var sleep2 = (ms) => new Promise((resolve22) => setTimeout(resolve22, ms));
|
|
6970
6986
|
async function pidOf(opts) {
|
|
6971
6987
|
const proc = await findRunningProcess({ config: opts.config, bundle: opts.bundle, deviceSerial: opts.deviceSerial });
|
|
6972
6988
|
return proc ? Number(proc.pid) : null;
|
|
@@ -7119,7 +7135,7 @@ function runHvigorw(opts) {
|
|
|
7119
7135
|
}
|
|
7120
7136
|
}
|
|
7121
7137
|
const env = { ...process.env, ...sdkEnv };
|
|
7122
|
-
return new Promise((
|
|
7138
|
+
return new Promise((resolve22, reject) => {
|
|
7123
7139
|
if (opts.abortSignal?.aborted) {
|
|
7124
7140
|
reject(new CancelledError("hvigorw build cancelled."));
|
|
7125
7141
|
return;
|
|
@@ -7163,7 +7179,7 @@ function runHvigorw(opts) {
|
|
|
7163
7179
|
settled = true;
|
|
7164
7180
|
cleanup();
|
|
7165
7181
|
const exitCode = code ?? 1;
|
|
7166
|
-
if (exitCode === 0)
|
|
7182
|
+
if (exitCode === 0) resolve22({ exitCode });
|
|
7167
7183
|
else reject(new OniroError(`hvigorw exited with code ${exitCode}`));
|
|
7168
7184
|
});
|
|
7169
7185
|
});
|
|
@@ -7547,17 +7563,17 @@ function sdkTooOldDiagnostic(diagnostics, sdkHome, projectApi) {
|
|
|
7547
7563
|
} catch {
|
|
7548
7564
|
return null;
|
|
7549
7565
|
}
|
|
7550
|
-
const
|
|
7566
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
7551
7567
|
const declares = (api2, s) => {
|
|
7552
7568
|
const file = moduleDeclarationFile(path33.join(sdkHome, String(api2)), s.module);
|
|
7553
|
-
if (!
|
|
7569
|
+
if (!cache2.has(file)) {
|
|
7554
7570
|
try {
|
|
7555
|
-
|
|
7571
|
+
cache2.set(file, fs35.readFileSync(file, "utf8"));
|
|
7556
7572
|
} catch {
|
|
7557
|
-
|
|
7573
|
+
cache2.set(file, null);
|
|
7558
7574
|
}
|
|
7559
7575
|
}
|
|
7560
|
-
const text =
|
|
7576
|
+
const text = cache2.get(file);
|
|
7561
7577
|
return !!text && new RegExp(`\\b${s.symbol.replace(/\$/g, "\\$")}\\b`).test(text);
|
|
7562
7578
|
};
|
|
7563
7579
|
const api = apis.find((a) => missing.every((s) => declares(a, s)));
|
|
@@ -8659,8 +8675,8 @@ async function startCallbackServer(opts) {
|
|
|
8659
8675
|
}
|
|
8660
8676
|
let resolveCallback;
|
|
8661
8677
|
let rejectCallback;
|
|
8662
|
-
const callback = new Promise((
|
|
8663
|
-
resolveCallback =
|
|
8678
|
+
const callback = new Promise((resolve22, reject) => {
|
|
8679
|
+
resolveCallback = resolve22;
|
|
8664
8680
|
rejectCallback = reject;
|
|
8665
8681
|
});
|
|
8666
8682
|
callback.catch(() => {
|
|
@@ -8712,12 +8728,12 @@ async function startCallbackServer(opts) {
|
|
|
8712
8728
|
}
|
|
8713
8729
|
});
|
|
8714
8730
|
server.keepAliveTimeout = 1;
|
|
8715
|
-
await new Promise((
|
|
8731
|
+
await new Promise((resolve22, reject) => {
|
|
8716
8732
|
server.once("error", (err) => {
|
|
8717
8733
|
const why = err.code === "EADDRINUSE" ? `port ${requested} is already in use on 127.0.0.1; pick another with --port` : err.code === "EACCES" ? `this user may not listen on port ${requested}; pick one above 1023` : err.message;
|
|
8718
8734
|
reject(new OniroError(`Failed to start the local login callback server: ${why}.`, err));
|
|
8719
8735
|
});
|
|
8720
|
-
server.listen(requested, "127.0.0.1",
|
|
8736
|
+
server.listen(requested, "127.0.0.1", resolve22);
|
|
8721
8737
|
});
|
|
8722
8738
|
const port = server.address().port;
|
|
8723
8739
|
return {
|
|
@@ -8739,12 +8755,12 @@ async function startCallbackServer(opts) {
|
|
|
8739
8755
|
return { accepted: true };
|
|
8740
8756
|
},
|
|
8741
8757
|
stop() {
|
|
8742
|
-
return new Promise((
|
|
8758
|
+
return new Promise((resolve22) => {
|
|
8743
8759
|
server.closeAllConnections?.();
|
|
8744
|
-
const timer = setTimeout(
|
|
8760
|
+
const timer = setTimeout(resolve22, 100);
|
|
8745
8761
|
server.close(() => {
|
|
8746
8762
|
clearTimeout(timer);
|
|
8747
|
-
|
|
8763
|
+
resolve22();
|
|
8748
8764
|
});
|
|
8749
8765
|
});
|
|
8750
8766
|
}
|
|
@@ -8776,11 +8792,11 @@ function openBrowser(url) {
|
|
|
8776
8792
|
windowsHide: true
|
|
8777
8793
|
});
|
|
8778
8794
|
child.unref();
|
|
8779
|
-
return new Promise((
|
|
8795
|
+
return new Promise((resolve22, reject) => {
|
|
8780
8796
|
child.on("error", (err) => reject(new OniroError(`Failed to open a browser (${command}).`, err)));
|
|
8781
8797
|
child.on(
|
|
8782
8798
|
"exit",
|
|
8783
|
-
(code) => code === 0 ?
|
|
8799
|
+
(code) => code === 0 ? resolve22() : reject(new OniroError(`Browser launcher '${command}' exited with code ${code}.`))
|
|
8784
8800
|
);
|
|
8785
8801
|
});
|
|
8786
8802
|
}
|
|
@@ -13189,13 +13205,13 @@ function cycleFrom(start, g) {
|
|
|
13189
13205
|
const node = queue.shift();
|
|
13190
13206
|
for (const n of g.out.get(key2(node)) ?? []) {
|
|
13191
13207
|
if (same(n, start)) {
|
|
13192
|
-
const
|
|
13208
|
+
const path62 = [];
|
|
13193
13209
|
let cursor = node;
|
|
13194
13210
|
while (cursor && !same(cursor, start)) {
|
|
13195
|
-
|
|
13211
|
+
path62.push(cursor);
|
|
13196
13212
|
cursor = parent.get(key2(cursor));
|
|
13197
13213
|
}
|
|
13198
|
-
return cursor ? [start, ...
|
|
13214
|
+
return cursor ? [start, ...path62.reverse()] : null;
|
|
13199
13215
|
}
|
|
13200
13216
|
const k = key2(n);
|
|
13201
13217
|
if (!seen.has(k) && g.out.has(k)) {
|
|
@@ -13727,7 +13743,7 @@ async function latestCrash(opts) {
|
|
|
13727
13743
|
return verdict;
|
|
13728
13744
|
}
|
|
13729
13745
|
if (Date.now() >= deadline) return null;
|
|
13730
|
-
await new Promise((
|
|
13746
|
+
await new Promise((resolve22) => setTimeout(resolve22, Math.min(opts.pollMs ?? 1e3, Math.max(0, deadline - Date.now()))));
|
|
13731
13747
|
}
|
|
13732
13748
|
}
|
|
13733
13749
|
|
|
@@ -14282,12 +14298,12 @@ var UI_RECORD_CSV = "/data/local/tmp/record.csv";
|
|
|
14282
14298
|
var RECORD_CONSOLE = "/data/local/tmp/oniro_record_console.txt";
|
|
14283
14299
|
var MMI_SERVER_DOMAIN = "0xD002801";
|
|
14284
14300
|
function sleep3(ms, signal) {
|
|
14285
|
-
return new Promise((
|
|
14286
|
-
if (signal?.aborted) return
|
|
14301
|
+
return new Promise((resolve22) => {
|
|
14302
|
+
if (signal?.aborted) return resolve22();
|
|
14287
14303
|
const done = () => {
|
|
14288
14304
|
clearTimeout(t);
|
|
14289
14305
|
signal?.removeEventListener("abort", done);
|
|
14290
|
-
|
|
14306
|
+
resolve22();
|
|
14291
14307
|
};
|
|
14292
14308
|
const t = setTimeout(done, ms);
|
|
14293
14309
|
signal?.addEventListener("abort", done, { once: true });
|
|
@@ -15151,11 +15167,11 @@ function parseActiveRefreshRate(hidumper) {
|
|
|
15151
15167
|
const m = /activeMode:[^\n]*?refreshRate=(\d+(?:\.\d+)?)/.exec(hidumper);
|
|
15152
15168
|
return m ? Number(m[1]) : null;
|
|
15153
15169
|
}
|
|
15154
|
-
var sleep5 = (ms, signal) => new Promise((
|
|
15170
|
+
var sleep5 = (ms, signal) => new Promise((resolve22, reject) => {
|
|
15155
15171
|
if (signal?.aborted) return reject(new CancelledError("Capture cancelled."));
|
|
15156
15172
|
const t = setTimeout(() => {
|
|
15157
15173
|
signal?.removeEventListener("abort", onAbort);
|
|
15158
|
-
|
|
15174
|
+
resolve22();
|
|
15159
15175
|
}, ms);
|
|
15160
15176
|
const onAbort = () => {
|
|
15161
15177
|
clearTimeout(t);
|
|
@@ -15341,8 +15357,394 @@ async function collectHiperf(run, device, remotePerf, localPerf) {
|
|
|
15341
15357
|
return { ...parsed, data };
|
|
15342
15358
|
}
|
|
15343
15359
|
|
|
15360
|
+
// src/docs/search.ts
|
|
15361
|
+
var fs63 = __toESM(require("fs"), 1);
|
|
15362
|
+
var path60 = __toESM(require("path"), 1);
|
|
15363
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set(["figures", "figure", "images", "image", "public_sys-resources"]);
|
|
15364
|
+
function listMarkdown(tree) {
|
|
15365
|
+
const out = [];
|
|
15366
|
+
const walk3 = (dir) => {
|
|
15367
|
+
let entries;
|
|
15368
|
+
try {
|
|
15369
|
+
entries = fs63.readdirSync(dir, { withFileTypes: true });
|
|
15370
|
+
} catch {
|
|
15371
|
+
return;
|
|
15372
|
+
}
|
|
15373
|
+
for (const e of entries) {
|
|
15374
|
+
if (e.isDirectory()) {
|
|
15375
|
+
if (!SKIP_DIRS.has(e.name)) walk3(path60.join(dir, e.name));
|
|
15376
|
+
} else if (e.isFile() && e.name.endsWith(".md")) {
|
|
15377
|
+
out.push(path60.join(dir, e.name));
|
|
15378
|
+
}
|
|
15379
|
+
}
|
|
15380
|
+
};
|
|
15381
|
+
walk3(tree);
|
|
15382
|
+
return out.sort();
|
|
15383
|
+
}
|
|
15384
|
+
var WORD = /[a-z0-9_@.]+/g;
|
|
15385
|
+
function docTokens(text) {
|
|
15386
|
+
const out = [];
|
|
15387
|
+
for (const m of text.toLowerCase().matchAll(WORD)) {
|
|
15388
|
+
const w = m[0].replace(/^[.@]+|[.@]+$/g, "");
|
|
15389
|
+
if (w.length >= 2 && w.length <= 40 && !/^\d{13,}$/.test(w)) out.push(w);
|
|
15390
|
+
}
|
|
15391
|
+
return out;
|
|
15392
|
+
}
|
|
15393
|
+
function docQueryTerms(query) {
|
|
15394
|
+
const out = /* @__PURE__ */ new Map();
|
|
15395
|
+
const add = (t, w) => {
|
|
15396
|
+
if (t.length >= 2 && (out.get(t) ?? 0) < w) out.set(t, w);
|
|
15397
|
+
};
|
|
15398
|
+
for (const w of docTokens(query)) {
|
|
15399
|
+
add(w, 1);
|
|
15400
|
+
for (const p of w.split(/[._]/)) if (p.length >= 3 && p !== w) add(p, 0.4);
|
|
15401
|
+
}
|
|
15402
|
+
for (const m of query.matchAll(/[A-Z][a-z]+|[a-z]+|[A-Z]+(?![a-z])|[0-9]+/g)) {
|
|
15403
|
+
if (m[0].length >= 3) add(m[0].toLowerCase(), 0.4);
|
|
15404
|
+
}
|
|
15405
|
+
return [...out].map(([term, weight]) => ({ term, weight }));
|
|
15406
|
+
}
|
|
15407
|
+
function wordIn(text, term) {
|
|
15408
|
+
let i = text.indexOf(term);
|
|
15409
|
+
while (i >= 0) {
|
|
15410
|
+
const before = i === 0 ? "" : text[i - 1] ?? "";
|
|
15411
|
+
const after = text[i + term.length] ?? "";
|
|
15412
|
+
if (!/[a-z0-9]/.test(before) && !/[a-z]/.test(after)) return true;
|
|
15413
|
+
i = text.indexOf(term, i + 1);
|
|
15414
|
+
}
|
|
15415
|
+
return false;
|
|
15416
|
+
}
|
|
15417
|
+
var flat = (s) => Buffer.from(s, "utf8").toString("utf8");
|
|
15418
|
+
function stripMd(line) {
|
|
15419
|
+
return line.replace(/!\[[^\]]*\]\([^)]*\)/g, "").replace(/<[^>]+>/g, "").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[`*_]/g, "").trim();
|
|
15420
|
+
}
|
|
15421
|
+
function parseDoc(rel, text) {
|
|
15422
|
+
const lines = text.split("\n");
|
|
15423
|
+
let title = "";
|
|
15424
|
+
const headings = [];
|
|
15425
|
+
for (let i = 0; i < lines.length; i++) {
|
|
15426
|
+
const m = /^(#{1,4})\s+(.+?)\s*#*\s*$/.exec(lines[i] ?? "");
|
|
15427
|
+
if (!m) continue;
|
|
15428
|
+
const level = (m[1] ?? "#").length;
|
|
15429
|
+
const text2 = flat(stripMd(m[2] ?? ""));
|
|
15430
|
+
if (level === 1 && !title) title = text2;
|
|
15431
|
+
else headings.push({ line: i + 1, level, text: text2 });
|
|
15432
|
+
}
|
|
15433
|
+
if (!title) title = path60.basename(rel, ".md");
|
|
15434
|
+
return { path: rel, title, headings, bytes: text.length };
|
|
15435
|
+
}
|
|
15436
|
+
function docWords(rel, text) {
|
|
15437
|
+
const words = /* @__PURE__ */ new Set();
|
|
15438
|
+
const add = (w) => {
|
|
15439
|
+
words.add(w);
|
|
15440
|
+
const stem = /^([a-z_]{3,})\d{1,2}$/.exec(w)?.[1];
|
|
15441
|
+
if (stem !== void 0) words.add(stem);
|
|
15442
|
+
};
|
|
15443
|
+
for (const w of docTokens(text)) {
|
|
15444
|
+
add(w);
|
|
15445
|
+
if (w.includes(".")) {
|
|
15446
|
+
for (const p of w.split(".")) if (p.length >= 3) add(p);
|
|
15447
|
+
}
|
|
15448
|
+
}
|
|
15449
|
+
for (const w of docTokens(rel.replace(/[-/]/g, " "))) words.add(w);
|
|
15450
|
+
return words;
|
|
15451
|
+
}
|
|
15452
|
+
var cache = /* @__PURE__ */ new Map();
|
|
15453
|
+
var DocsIndex = class _DocsIndex {
|
|
15454
|
+
constructor(tree, docs, words, buildMs) {
|
|
15455
|
+
this.tree = tree;
|
|
15456
|
+
this.docs = docs;
|
|
15457
|
+
this.buildMs = buildMs;
|
|
15458
|
+
const lists = /* @__PURE__ */ new Map();
|
|
15459
|
+
let id = 0;
|
|
15460
|
+
for (const set of words) {
|
|
15461
|
+
for (const w of set) {
|
|
15462
|
+
const list = lists.get(w);
|
|
15463
|
+
if (list) list.push(id);
|
|
15464
|
+
else lists.set(flat(w), [id]);
|
|
15465
|
+
}
|
|
15466
|
+
id++;
|
|
15467
|
+
}
|
|
15468
|
+
for (const [w, list] of lists) this.postings.set(w, Int32Array.from(list));
|
|
15469
|
+
}
|
|
15470
|
+
tree;
|
|
15471
|
+
docs;
|
|
15472
|
+
buildMs;
|
|
15473
|
+
/** word → ascending document ids (packed: 4 bytes per occurrence). */
|
|
15474
|
+
postings = /* @__PURE__ */ new Map();
|
|
15475
|
+
/** The index of a tree, built on the first call of a process and kept. */
|
|
15476
|
+
static load(tree) {
|
|
15477
|
+
const key3 = path60.resolve(tree);
|
|
15478
|
+
const hit = cache.get(key3);
|
|
15479
|
+
if (hit) return hit;
|
|
15480
|
+
const started = Date.now();
|
|
15481
|
+
const docs = [];
|
|
15482
|
+
const words = [];
|
|
15483
|
+
for (const abs of listMarkdown(key3)) {
|
|
15484
|
+
const rel = path60.relative(key3, abs).split(path60.sep).join("/");
|
|
15485
|
+
const text = fs63.readFileSync(abs, "utf8");
|
|
15486
|
+
docs.push(parseDoc(rel, text));
|
|
15487
|
+
words.push(docWords(rel, text));
|
|
15488
|
+
}
|
|
15489
|
+
const idx = new _DocsIndex(key3, docs, words, Date.now() - started);
|
|
15490
|
+
cache.set(key3, idx);
|
|
15491
|
+
return idx;
|
|
15492
|
+
}
|
|
15493
|
+
/** An index over in-memory documents (tests). `tree` is used by `show` for reading files. */
|
|
15494
|
+
static fromDocs(tree, docs) {
|
|
15495
|
+
return new _DocsIndex(
|
|
15496
|
+
tree,
|
|
15497
|
+
docs.map((d) => parseDoc(d.path, d.text)),
|
|
15498
|
+
docs.map((d) => docWords(d.path, d.text)),
|
|
15499
|
+
0
|
|
15500
|
+
);
|
|
15501
|
+
}
|
|
15502
|
+
/** Forget the cached index of a tree (after a sync). */
|
|
15503
|
+
static forget(tree) {
|
|
15504
|
+
cache.delete(path60.resolve(tree));
|
|
15505
|
+
}
|
|
15506
|
+
get size() {
|
|
15507
|
+
return this.docs.length;
|
|
15508
|
+
}
|
|
15509
|
+
has(term) {
|
|
15510
|
+
return this.postings.get(term) ?? [];
|
|
15511
|
+
}
|
|
15512
|
+
/**
|
|
15513
|
+
* Documents containing every word of the query (any of them when none does), scored by
|
|
15514
|
+
* where the words occur: title, headings, path, body; a document whose title is exactly a
|
|
15515
|
+
* query word, or that contains the whole query in a title or heading, ranks higher; the
|
|
15516
|
+
* generated API reference ranks a little below the guides, system-API pages and tables of
|
|
15517
|
+
* contents below everything.
|
|
15518
|
+
*/
|
|
15519
|
+
search(query, o = {}) {
|
|
15520
|
+
const terms = docQueryTerms(query);
|
|
15521
|
+
const full = terms.filter((t) => t.weight === 1);
|
|
15522
|
+
const result = { query, terms: terms.map((t) => t.term), total: 0, hits: [] };
|
|
15523
|
+
if (!terms.length) return result;
|
|
15524
|
+
const limit = Math.max(1, Math.min(o.limit ?? 8, 30));
|
|
15525
|
+
const section = o.section?.replace(/^\/+|\/+$/g, "").toLowerCase();
|
|
15526
|
+
const inScope = (d) => !section || d.path.toLowerCase().startsWith(`${section}/`) || d.path.toLowerCase().includes(`/${section}/`);
|
|
15527
|
+
const phrase = query.trim().toLowerCase();
|
|
15528
|
+
const presentBy = /* @__PURE__ */ new Map();
|
|
15529
|
+
for (const t of terms) {
|
|
15530
|
+
for (const id of this.has(t.term)) {
|
|
15531
|
+
const l = presentBy.get(id);
|
|
15532
|
+
if (l) l.push(t);
|
|
15533
|
+
else presentBy.set(id, [t]);
|
|
15534
|
+
}
|
|
15535
|
+
}
|
|
15536
|
+
const scored = (requireAll) => {
|
|
15537
|
+
const out = [];
|
|
15538
|
+
for (const [id, present] of presentBy) {
|
|
15539
|
+
const d = this.docs[id];
|
|
15540
|
+
if (!d) continue;
|
|
15541
|
+
const fullPresent = present.filter((t) => t.weight === 1).length;
|
|
15542
|
+
if (!inScope(d) || requireAll && fullPresent < full.length) continue;
|
|
15543
|
+
const title = d.title.toLowerCase();
|
|
15544
|
+
const p = d.path.toLowerCase();
|
|
15545
|
+
let score = 0;
|
|
15546
|
+
const headingHits = [];
|
|
15547
|
+
for (const h of d.headings) {
|
|
15548
|
+
const ht = h.text.toLowerCase();
|
|
15549
|
+
const n = present.reduce((a, t) => a + (wordIn(ht, t.term) ? t.weight : 0), 0);
|
|
15550
|
+
if (n) headingHits.push({ line: h.line, text: h.text, n });
|
|
15551
|
+
}
|
|
15552
|
+
for (const t of present) {
|
|
15553
|
+
if (wordIn(title, t.term)) score += 8 * t.weight;
|
|
15554
|
+
if (wordIn(p, t.term)) score += 3 * t.weight;
|
|
15555
|
+
score += t.weight;
|
|
15556
|
+
}
|
|
15557
|
+
if (full.some((t) => title === t.term || title.replace(/\s*\(.*\)$/, "") === t.term)) score += 6;
|
|
15558
|
+
if (headingHits.length) score += Math.min(12, headingHits.reduce((a, h) => a + h.n * 2, 0));
|
|
15559
|
+
if (phrase.length > 3) {
|
|
15560
|
+
if (title.includes(phrase)) score += 20;
|
|
15561
|
+
else if (headingHits.some((h) => h.text.toLowerCase().includes(phrase))) score += 10;
|
|
15562
|
+
}
|
|
15563
|
+
if (p.startsWith("reference/apis-")) score -= 2;
|
|
15564
|
+
if (/-sys\.md$/.test(p) || /\(system api\)/i.test(title)) score -= 12;
|
|
15565
|
+
if (/\/(readme|summary)\.md$/i.test(p) || /^readme/i.test(p)) score -= 6;
|
|
15566
|
+
if (fullPresent === full.length) score += 4;
|
|
15567
|
+
headingHits.sort((a, b) => b.n - a.n || a.line - b.line);
|
|
15568
|
+
out.push({
|
|
15569
|
+
d,
|
|
15570
|
+
score: Math.round(score * 10) / 10,
|
|
15571
|
+
headings: headingHits.slice(0, 6).map(({ line, text }) => ({ line, text }))
|
|
15572
|
+
});
|
|
15573
|
+
}
|
|
15574
|
+
return out;
|
|
15575
|
+
};
|
|
15576
|
+
let hits = scored(true);
|
|
15577
|
+
if (!hits.length) hits = scored(false);
|
|
15578
|
+
hits.sort((a, b) => b.score - a.score || a.d.path.localeCompare(b.d.path));
|
|
15579
|
+
result.total = hits.length;
|
|
15580
|
+
result.hits = hits.slice(0, limit).map(({ d, score, headings }) => ({
|
|
15581
|
+
path: d.path,
|
|
15582
|
+
title: d.title,
|
|
15583
|
+
score,
|
|
15584
|
+
headings,
|
|
15585
|
+
snippet: this.snippet(d)
|
|
15586
|
+
}));
|
|
15587
|
+
return result;
|
|
15588
|
+
}
|
|
15589
|
+
snippet(d) {
|
|
15590
|
+
let text;
|
|
15591
|
+
try {
|
|
15592
|
+
text = fs63.readFileSync(path60.join(this.tree, d.path), "utf8");
|
|
15593
|
+
} catch {
|
|
15594
|
+
return "";
|
|
15595
|
+
}
|
|
15596
|
+
const lines = text.split("\n");
|
|
15597
|
+
for (let i = lines.findIndex((l) => /^#\s/.test(l)) + 1; i < lines.length; i++) {
|
|
15598
|
+
const s = stripMd(lines[i] ?? "");
|
|
15599
|
+
if (s && !/^[#>|<-]/.test(s)) return s.length > 220 ? `${s.slice(0, 217)}\u2026` : s;
|
|
15600
|
+
}
|
|
15601
|
+
return "";
|
|
15602
|
+
}
|
|
15603
|
+
/**
|
|
15604
|
+
* A document, or one of its sections: from the heading that matches `heading`
|
|
15605
|
+
* (exactly, else by substring, case-insensitive) to the next heading of the same or a
|
|
15606
|
+
* higher level. Image lines and inline HTML are dropped; the text is cut at `maxLines`
|
|
15607
|
+
* with a note of what was left out.
|
|
15608
|
+
*/
|
|
15609
|
+
show(rel, o = {}) {
|
|
15610
|
+
const clean2 = rel.replace(/\\/g, "/").replace(/^\/+/, "").replace(/^en\/application-dev\//, "");
|
|
15611
|
+
const abs = path60.resolve(this.tree, clean2);
|
|
15612
|
+
const inside = abs.startsWith(this.tree + path60.sep);
|
|
15613
|
+
if (!inside || !fs63.existsSync(abs) || !fs63.statSync(abs).isFile()) {
|
|
15614
|
+
const base = path60.basename(clean2, ".md").toLowerCase();
|
|
15615
|
+
let suggestions = this.docs.filter((d) => d.path.toLowerCase().includes(base)).slice(0, 5).map((d) => d.path);
|
|
15616
|
+
if (!suggestions.length) suggestions = this.search(base.replace(/[-_]/g, " "), { limit: 5 }).hits.map((h) => h.path);
|
|
15617
|
+
return { found: false, path: clean2, error: `No document at ${clean2}.`, suggestions };
|
|
15618
|
+
}
|
|
15619
|
+
const text = fs63.readFileSync(abs, "utf8");
|
|
15620
|
+
const entry = this.docs.find((d) => d.path === clean2) ?? parseDoc(clean2, text);
|
|
15621
|
+
const lines = text.split("\n");
|
|
15622
|
+
let from = 0;
|
|
15623
|
+
let to = lines.length;
|
|
15624
|
+
if (o.heading) {
|
|
15625
|
+
const needle = o.heading.toLowerCase().replace(/^#+\s*/, "").trim();
|
|
15626
|
+
const h = entry.headings.find((x2) => x2.text.toLowerCase() === needle) ?? entry.headings.find((x2) => x2.text.toLowerCase().includes(needle));
|
|
15627
|
+
if (!h) {
|
|
15628
|
+
return {
|
|
15629
|
+
found: false,
|
|
15630
|
+
path: clean2,
|
|
15631
|
+
error: `No heading matching "${o.heading}" in ${clean2}.`,
|
|
15632
|
+
suggestions: entry.headings.slice(0, 30).map((x2) => x2.text)
|
|
15633
|
+
};
|
|
15634
|
+
}
|
|
15635
|
+
from = h.line - 1;
|
|
15636
|
+
const next2 = entry.headings.find((x2) => x2.line > h.line && x2.level <= h.level);
|
|
15637
|
+
to = next2 ? next2.line - 1 : lines.length;
|
|
15638
|
+
}
|
|
15639
|
+
const max = Math.max(20, Math.min(o.maxLines ?? 250, 1200));
|
|
15640
|
+
const body = lines.slice(from, to).filter((l) => !/^\s*!\[[^\]]*\]\([^)]*\)\s*$/.test(l) && !/^\s*<img\b/i.test(l)).map((l) => l.replace(/<br\s*\/?>/gi, " ").replace(/<\/?(p|div|span|b|i|em|strong|sup|sub)>/gi, ""));
|
|
15641
|
+
const truncated = body.length > max;
|
|
15642
|
+
const shown = body.slice(0, max).join("\n") + (truncated ? `
|
|
15643
|
+
|
|
15644
|
+
[\u2026 ${body.length - max} more lines; ask for one section with heading]` : "");
|
|
15645
|
+
return {
|
|
15646
|
+
found: true,
|
|
15647
|
+
path: clean2,
|
|
15648
|
+
text: shown,
|
|
15649
|
+
truncated,
|
|
15650
|
+
lines: body.length,
|
|
15651
|
+
headings: entry.headings.filter((h) => h.line > from && h.line <= to).map(({ line, text: t }) => ({ line, text: t }))
|
|
15652
|
+
};
|
|
15653
|
+
}
|
|
15654
|
+
};
|
|
15655
|
+
|
|
15656
|
+
// src/docs/sync.ts
|
|
15657
|
+
var fs64 = __toESM(require("fs"), 1);
|
|
15658
|
+
var path61 = __toESM(require("path"), 1);
|
|
15659
|
+
var DOCS_REPO = "https://gitcode.com/openharmony/docs";
|
|
15660
|
+
var DOCS_SPARSE_PATH = "en/application-dev";
|
|
15661
|
+
var DOCS_SPARSE_PATTERNS = [
|
|
15662
|
+
`/${DOCS_SPARSE_PATH}/`,
|
|
15663
|
+
"!**/figures/",
|
|
15664
|
+
"!**/*.png",
|
|
15665
|
+
"!**/*.gif",
|
|
15666
|
+
"!**/*.jpg",
|
|
15667
|
+
"!**/*.jpeg"
|
|
15668
|
+
];
|
|
15669
|
+
function docsRefFor(sdk) {
|
|
15670
|
+
const m = sdk.version ? /^(\d+)\.(\d+)\.(\d+)/.exec(sdk.version) : null;
|
|
15671
|
+
if (m) {
|
|
15672
|
+
const [, major, minor, patch] = m;
|
|
15673
|
+
return `OpenHarmony-${Number(major) >= 6 ? `${major}.${minor}` : `${major}.${minor}.${patch}`}-Release`;
|
|
15674
|
+
}
|
|
15675
|
+
const api = sdk.api;
|
|
15676
|
+
if (api === void 0) return "master";
|
|
15677
|
+
if (api <= 18) return "OpenHarmony-5.1.0-Release";
|
|
15678
|
+
if (api <= 20) return "OpenHarmony-6.0-Release";
|
|
15679
|
+
if (api <= 23) return "OpenHarmony-6.1-Release";
|
|
15680
|
+
if (api <= 26) return "OpenHarmony-7.0-Release";
|
|
15681
|
+
return "master";
|
|
15682
|
+
}
|
|
15683
|
+
function readSdkRelease(sdkDir) {
|
|
15684
|
+
try {
|
|
15685
|
+
const pkg = JSON.parse(fs64.readFileSync(path61.join(sdkDir, "ets", "oh-uni-package.json"), "utf8"));
|
|
15686
|
+
const api = Number(pkg.apiVersion);
|
|
15687
|
+
return { api: Number.isFinite(api) ? api : void 0, version: typeof pkg.version === "string" ? pkg.version : void 0 };
|
|
15688
|
+
} catch {
|
|
15689
|
+
return {};
|
|
15690
|
+
}
|
|
15691
|
+
}
|
|
15692
|
+
function getDocsRootDir(config) {
|
|
15693
|
+
return config.get("docsDir", path61.join(getSdkRootDir(config), "docs"));
|
|
15694
|
+
}
|
|
15695
|
+
function docsDirFor(config, ref) {
|
|
15696
|
+
return path61.join(getDocsRootDir(config), ref);
|
|
15697
|
+
}
|
|
15698
|
+
function docsTree(docsDir) {
|
|
15699
|
+
const tree = path61.join(docsDir, DOCS_SPARSE_PATH);
|
|
15700
|
+
return fs64.existsSync(tree) ? tree : null;
|
|
15701
|
+
}
|
|
15702
|
+
async function syncDocs(opts) {
|
|
15703
|
+
const { ref, dir } = opts;
|
|
15704
|
+
const repo = opts.repo ?? DOCS_REPO;
|
|
15705
|
+
const logger = opts.logger;
|
|
15706
|
+
const git = async (args, cwd) => {
|
|
15707
|
+
const r = await runProcess({
|
|
15708
|
+
command: "git",
|
|
15709
|
+
args,
|
|
15710
|
+
cwd,
|
|
15711
|
+
timeoutMs: opts.timeoutMs ?? 6e5,
|
|
15712
|
+
abortSignal: opts.abortSignal,
|
|
15713
|
+
onOutput: (chunk) => {
|
|
15714
|
+
for (const line of chunk.split(/\r?\n/)) if (line.trim()) logger?.debug(`git: ${line.trim()}`);
|
|
15715
|
+
}
|
|
15716
|
+
}).catch((err) => {
|
|
15717
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
15718
|
+
throw new OniroError(/ENOENT/.test(msg) ? "git is not installed or not on the PATH; `docs sync` needs it." : msg);
|
|
15719
|
+
});
|
|
15720
|
+
if (r.code !== 0) {
|
|
15721
|
+
const tail = (r.stderr || r.stdout).trim().split("\n").filter(Boolean).slice(-3).join(" | ");
|
|
15722
|
+
throw new OniroError(`git ${args[0]} failed (exit ${r.code}): ${tail}`);
|
|
15723
|
+
}
|
|
15724
|
+
return r.stdout;
|
|
15725
|
+
};
|
|
15726
|
+
const exists = fs64.existsSync(path61.join(dir, ".git"));
|
|
15727
|
+
if (exists) {
|
|
15728
|
+
logger?.info(`Updating the ${ref} docs in ${dir}`);
|
|
15729
|
+
await git(["fetch", "--depth", "1", "origin", ref], dir);
|
|
15730
|
+
await git(["sparse-checkout", "set", "--no-cone", ...DOCS_SPARSE_PATTERNS], dir);
|
|
15731
|
+
await git(["reset", "--hard", "FETCH_HEAD"], dir);
|
|
15732
|
+
} else {
|
|
15733
|
+
logger?.info(`Cloning the ${ref} docs (${DOCS_SPARSE_PATH} only) into ${dir}`);
|
|
15734
|
+
fs64.mkdirSync(path61.dirname(dir), { recursive: true });
|
|
15735
|
+
await git(["clone", "--depth", "1", "--filter=blob:none", "--no-checkout", "--branch", ref, repo, dir]);
|
|
15736
|
+
await git(["sparse-checkout", "set", "--no-cone", ...DOCS_SPARSE_PATTERNS], dir);
|
|
15737
|
+
await git(["checkout", ref], dir);
|
|
15738
|
+
}
|
|
15739
|
+
const commit = (await git(["rev-parse", "--short", "HEAD"], dir)).trim() || void 0;
|
|
15740
|
+
const tree = docsTree(dir);
|
|
15741
|
+
const files = tree ? listMarkdown(tree).length : 0;
|
|
15742
|
+
if (!files) throw new OniroError(`The ${ref} clone at ${dir} holds no Markdown under ${DOCS_SPARSE_PATH}.`);
|
|
15743
|
+
return { dir, ref, files, updated: exists, commit };
|
|
15744
|
+
}
|
|
15745
|
+
|
|
15344
15746
|
// src/index.ts
|
|
15345
|
-
var VERSION = "0.
|
|
15747
|
+
var VERSION = "0.18.0";
|
|
15346
15748
|
// Annotate the CommonJS export names for ESM import in node:
|
|
15347
15749
|
0 && (module.exports = {
|
|
15348
15750
|
ALL_SDKS,
|
|
@@ -15367,6 +15769,10 @@ var VERSION = "0.17.0";
|
|
|
15367
15769
|
DEFAULT_SMOKE_PID_TIMEOUT_MS,
|
|
15368
15770
|
DEFAULT_TRACE_BUFFER_KB,
|
|
15369
15771
|
DEFAULT_TRACE_CATEGORIES,
|
|
15772
|
+
DOCS_REPO,
|
|
15773
|
+
DOCS_SPARSE_PATH,
|
|
15774
|
+
DOCS_SPARSE_PATTERNS,
|
|
15775
|
+
DocsIndex,
|
|
15370
15776
|
EMULATOR_KERNEL_APPEND,
|
|
15371
15777
|
FAULTLOG_DIR,
|
|
15372
15778
|
FAULTLOG_TEMP_DIR,
|
|
@@ -15489,6 +15895,12 @@ var VERSION = "0.17.0";
|
|
|
15489
15895
|
diffHapAssets,
|
|
15490
15896
|
diffLayouts,
|
|
15491
15897
|
discoverHaps,
|
|
15898
|
+
docQueryTerms,
|
|
15899
|
+
docTokens,
|
|
15900
|
+
docWords,
|
|
15901
|
+
docsDirFor,
|
|
15902
|
+
docsRefFor,
|
|
15903
|
+
docsTree,
|
|
15492
15904
|
downloadAndInstallSdk,
|
|
15493
15905
|
downloadFile,
|
|
15494
15906
|
dumpLayout,
|
|
@@ -15549,6 +15961,7 @@ var VERSION = "0.17.0";
|
|
|
15549
15961
|
getDefaultInstanceStatus,
|
|
15550
15962
|
getDeviceInfo,
|
|
15551
15963
|
getDisplaySize,
|
|
15964
|
+
getDocsRootDir,
|
|
15552
15965
|
getEmulatorDir,
|
|
15553
15966
|
getEmulatorStatus,
|
|
15554
15967
|
getFreeSpaceBytes,
|
|
@@ -15612,6 +16025,7 @@ var VERSION = "0.17.0";
|
|
|
15612
16025
|
listDevices,
|
|
15613
16026
|
listFaultLogs,
|
|
15614
16027
|
listLayoutWindows,
|
|
16028
|
+
listMarkdown,
|
|
15615
16029
|
listModules,
|
|
15616
16030
|
listPoolInstanceNumbers,
|
|
15617
16031
|
listPoolInstanceStatuses,
|
|
@@ -15652,6 +16066,7 @@ var VERSION = "0.17.0";
|
|
|
15652
16066
|
parseCrashRecordHeads,
|
|
15653
16067
|
parseDeviceList,
|
|
15654
16068
|
parseDeviceTime,
|
|
16069
|
+
parseDoc,
|
|
15655
16070
|
parseDocBlock,
|
|
15656
16071
|
parseFaultLogList,
|
|
15657
16072
|
parseFaultLogName,
|
|
@@ -15708,6 +16123,7 @@ var VERSION = "0.17.0";
|
|
|
15708
16123
|
readPoolState,
|
|
15709
16124
|
readProvisionProfile,
|
|
15710
16125
|
readSdkPkg,
|
|
16126
|
+
readSdkRelease,
|
|
15711
16127
|
readTestModuleName,
|
|
15712
16128
|
readZipEntry,
|
|
15713
16129
|
reboot,
|
|
@@ -15770,6 +16186,7 @@ var VERSION = "0.17.0";
|
|
|
15770
16186
|
summarizeDivergenceLayout,
|
|
15771
16187
|
summarizeLayout,
|
|
15772
16188
|
summarizeTrace,
|
|
16189
|
+
syncDocs,
|
|
15773
16190
|
takeScreenshot,
|
|
15774
16191
|
testHapPath,
|
|
15775
16192
|
toLongPath,
|
|
@@ -15793,6 +16210,7 @@ var VERSION = "0.17.0";
|
|
|
15793
16210
|
windowSubtree,
|
|
15794
16211
|
withHapZip,
|
|
15795
16212
|
withoutWindow,
|
|
16213
|
+
wordIn,
|
|
15796
16214
|
writeJson5File,
|
|
15797
16215
|
writeJsonFile,
|
|
15798
16216
|
writePoolState
|