weapp-ide-cli 5.2.3 → 5.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { $ as removeCustomConfigKey, B as resolveDevtoolsAutomationDefaults, C as configureLocaleFromArgv, G as colors, I as bootstrapWechatDevtoolsSettings, J as createAutoTrustProjectConfig, K as logger_default, L as resolveCliPath, Q as readCustomConfig, T as validateLocaleOption, U as isOperatingSystemSupported, W as operatingSystemName, X as createLocaleConfig, Y as createCustomConfig, Z as overwriteCustomConfig, a as navigateBack, c as pageStack, d as remote, f as scrollTo, g as tap, i as input, l as reLaunch, m as systemInfo, n as captureScreenshotBuffer, nt as resolvePath, o as navigateTo, p as switchTab, q as createAutoBootstrapDevtoolsConfig, r as currentPage, s as pageData, t as audit, tt as defaultCustomConfigFilePath, u as redirectTo, w as i18nText, y as connectMiniProgram, z as getConfiguredLocale } from "./commands-BNdodULv.js";
1
+ import { $ as readCustomConfig, B as getConfiguredLocale, C as configureLocaleFromArgv, G as operatingSystemName, I as bootstrapWechatDevtoolsSettings, J as createAutoBootstrapDevtoolsConfig, K as colors, Q as overwriteCustomConfig, R as resolveCliPath, T as validateLocaleOption, V as resolveDevtoolsAutomationDefaults, W as isOperatingSystemSupported, X as createCustomConfig, Y as createAutoTrustProjectConfig, Z as createLocaleConfig, a as navigateBack, c as pageStack, d as remote, et as removeCustomConfigKey, f as scrollTo, g as tap, i as input, l as reLaunch, m as systemInfo, n as captureScreenshotBuffer, nt as defaultCustomConfigFilePath, o as navigateTo, p as switchTab, q as logger_default, r as currentPage, rt as resolvePath, s as pageData, t as audit, u as redirectTo, w as i18nText, y as connectMiniProgram } from "./commands-XD_wemcg.js";
2
2
  import fs from "node:fs/promises";
3
- import { fs as fs$1 } from "@weapp-core/shared";
3
+ import { fs as fs$1 } from "@weapp-core/shared/fs";
4
4
  import process, { stdin, stdout } from "node:process";
5
5
  import { PNG } from "pngjs";
6
6
  import pixelmatch from "pixelmatch";
@@ -402,7 +402,7 @@ async function runScreenshot(argv) {
402
402
  }
403
403
  const options = parseScreenshotArgs(argv);
404
404
  const isJsonOutput = argv.includes("--json");
405
- const { takeScreenshot } = await import("./commands-HAEyDfmU.js");
405
+ const { takeScreenshot } = await import("./commands-CVibHgp4.js");
406
406
  const result = await takeScreenshot(options);
407
407
  if (isJsonOutput) {
408
408
  console.log(JSON.stringify(result, null, 2));
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
- import { K as logger_default } from "./commands-BNdodULv.js";
2
- import { n as parse } from "./cli-DrmbSun7.js";
1
+ import { q as logger_default } from "./commands-XD_wemcg.js";
2
+ import { n as parse } from "./cli-CfovXw-V.js";
3
3
  import process from "node:process";
4
4
  //#region src/cli.ts
5
5
  const argv = process.argv.slice(2);
@@ -0,0 +1,2 @@
1
+ import { h as takeScreenshot } from "./commands-XD_wemcg.js";
2
+ export { takeScreenshot };
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
3
3
  import os from "node:os";
4
4
  import path from "node:path";
5
5
  import { Launcher } from "@weapp-vite/miniprogram-automator";
6
- import { fs as fs$1 } from "@weapp-core/shared";
6
+ import { fs as fs$1 } from "@weapp-core/shared/fs";
7
7
  import process from "node:process";
8
8
  import path$1 from "pathe";
9
9
  import logger, { colors } from "@weapp-core/logger";
@@ -116,7 +116,7 @@ var logger_default = logger;
116
116
  //#endregion
117
117
  //#region src/runtime/platform.ts
118
118
  /**
119
- * @description 官方微信开发者工具只支持 Windows、macOS,Linux 只有社区版
119
+ * @description 官方微信开发者工具只支持 Windows、macOS,Linux 只有社区版。
120
120
  * https://github.com/msojocs/wechat-web-devtools-linux
121
121
  */
122
122
  const SupportedPlatformsMap = {
@@ -125,15 +125,21 @@ const SupportedPlatformsMap = {
125
125
  Linux: "Linux"
126
126
  };
127
127
  /**
128
- * @description 判断当前系统是否支持微信开发者工具
128
+ * @description 判断当前系统是否支持微信开发者工具。
129
129
  */
130
130
  function isOperatingSystemSupported(osName = os.type()) {
131
131
  return osName === SupportedPlatformsMap.Windows_NT || osName === SupportedPlatformsMap.Darwin || osName === SupportedPlatformsMap.Linux;
132
132
  }
133
133
  /**
134
- * @description 当前系统名称
134
+ * @description 当前系统名称。
135
135
  */
136
136
  const operatingSystemName = os.type();
137
+ async function findFirstExistingPath(candidates) {
138
+ for (const candidate of candidates) {
139
+ if (!candidate) continue;
140
+ if (await fs$1.pathExists(candidate)) return candidate;
141
+ }
142
+ }
137
143
  async function getFirstBinaryPath(command) {
138
144
  const pathDirs = (process.env.PATH || "").split(path$1.delimiter);
139
145
  for (const dir of pathDirs) {
@@ -167,16 +173,45 @@ function createLinuxCliResolver() {
167
173
  return pending;
168
174
  };
169
175
  }
176
+ function createWindowsCliResolver() {
177
+ let resolvedPath;
178
+ let attempted = false;
179
+ let pending = null;
180
+ return async () => {
181
+ if (attempted) return resolvedPath;
182
+ if (!pending) pending = (async () => {
183
+ const programFilesX86 = process.env["ProgramFiles(x86)"] || "C:\\Program Files (x86)";
184
+ const programFiles = process.env.ProgramFiles || "C:\\Program Files";
185
+ const localAppData = process.env.LOCALAPPDATA || path$1.join(os.homedir(), "AppData", "Local");
186
+ const candidates = [
187
+ path$1.join(programFilesX86, "Tencent", "微信web开发者工具", "cli.bat"),
188
+ path$1.join(programFiles, "Tencent", "微信web开发者工具", "cli.bat"),
189
+ path$1.join(localAppData, "Programs", "微信开发者工具", "cli.bat"),
190
+ path$1.join(localAppData, "Tencent", "微信web开发者工具", "cli.bat")
191
+ ];
192
+ try {
193
+ resolvedPath = await findFirstExistingPath(candidates);
194
+ } catch (error) {
195
+ const reason = error instanceof Error ? error.message : String(error);
196
+ logger_default.warn(`获取 Windows 微信开发者工具 CLI 路径失败:${reason}`);
197
+ } finally {
198
+ attempted = true;
199
+ }
200
+ return resolvedPath;
201
+ })();
202
+ return pending;
203
+ };
204
+ }
170
205
  const linuxCliResolver = createLinuxCliResolver();
171
- const WINDOWS_DEFAULT_CLI = "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat";
206
+ const windowsCliResolver = createWindowsCliResolver();
172
207
  const DARWIN_DEFAULT_CLI = "/Applications/wechatwebdevtools.app/Contents/MacOS/cli";
173
208
  const cliPathResolvers = {
174
- [SupportedPlatformsMap.Windows_NT]: async () => WINDOWS_DEFAULT_CLI,
209
+ [SupportedPlatformsMap.Windows_NT]: windowsCliResolver,
175
210
  [SupportedPlatformsMap.Darwin]: async () => DARWIN_DEFAULT_CLI,
176
211
  [SupportedPlatformsMap.Linux]: linuxCliResolver
177
212
  };
178
213
  /**
179
- * @description 获取默认 CLI 路径(按系统)
214
+ * @description 获取默认 CLI 路径(按系统)。
180
215
  */
181
216
  async function getDefaultCliPath(targetOs = operatingSystemName) {
182
217
  if (!isOperatingSystemSupported(targetOs)) return;
@@ -264,28 +299,62 @@ async function resolveCliPath() {
264
299
  }
265
300
  //#endregion
266
301
  //#region src/cli/wechatDevtoolsSettings.ts
267
- const DEFAULT_WECHAT_DEVTOOLS_SECURITY_SETTINGS = {
268
- enableServicePort: true,
269
- port: 21992,
270
- allowGetTicket: true,
271
- trustWhenAuto: true
272
- };
273
- const WECHAT_DEVTOOLS_SETTINGS_KEY = "reduxPersist:settings";
274
- function resolveWechatDevtoolsBaseDir(homeDir, platform) {
275
- if (platform !== "darwin") return;
276
- return path.join(homeDir, "Library", "Application Support", "微信开发者工具");
277
- }
278
302
  function createStorageHash(key) {
279
303
  return createHash("md5").update(key).digest("hex");
280
304
  }
305
+ const SETTINGS_STORAGE_HASH = createStorageHash("reduxPersist:settings");
306
+ const SETTINGS_STORAGE_FILE_NAMES = [`localstorage_${SETTINGS_STORAGE_HASH}.json`, `ls_${SETTINGS_STORAGE_HASH}.json`];
307
+ function resolveWechatDevtoolsBaseDir(homeDir, platform, localAppDataDir) {
308
+ if (platform === "darwin") return path.join(homeDir, "Library", "Application Support", "微信开发者工具");
309
+ if (platform === "win32") return path.join(localAppDataDir, "微信开发者工具", "User Data");
310
+ }
311
+ function isRecord(value) {
312
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
313
+ }
314
+ function normalizePort(value) {
315
+ if (typeof value !== "number" || !Number.isInteger(value)) return;
316
+ if (value <= 0 || value > 65535) return;
317
+ return value;
318
+ }
319
+ function normalizeWechatDevtoolsSecuritySettings(value) {
320
+ if (!isRecord(value)) return;
321
+ const normalized = {};
322
+ if (typeof value.enableServicePort === "boolean") normalized.enableServicePort = value.enableServicePort;
323
+ const port = normalizePort(value.port);
324
+ if (port !== void 0) normalized.port = port;
325
+ if (typeof value.allowGetTicket === "boolean") normalized.allowGetTicket = value.allowGetTicket;
326
+ if (typeof value.trustWhenAuto === "boolean") normalized.trustWhenAuto = value.trustWhenAuto;
327
+ return Object.keys(normalized).length > 0 ? normalized : void 0;
328
+ }
329
+ function shouldPreferServicePortCandidate(current, next) {
330
+ if (current.enabled === void 0 && current.port === void 0) return true;
331
+ if (next.enabled === true && current.enabled !== true) return true;
332
+ if (next.enabled === current.enabled && next.port !== void 0 && current.port === void 0) return true;
333
+ return false;
334
+ }
335
+ function createResolvedWechatDevtoolsContext(options = {}) {
336
+ const platform = options.platform ?? process.platform;
337
+ const homeDir = options.homeDir ?? process.env.USERPROFILE ?? process.env.HOME ?? os.homedir();
338
+ if (!homeDir) return;
339
+ const localAppDataDir = options.localAppDataDir ?? process.env.LOCALAPPDATA ?? path.join(homeDir, "AppData", "Local");
340
+ const baseDir = resolveWechatDevtoolsBaseDir(homeDir, platform, localAppDataDir);
341
+ if (!baseDir) return;
342
+ return {
343
+ baseDir,
344
+ homeDir,
345
+ localAppDataDir,
346
+ platform
347
+ };
348
+ }
281
349
  async function readJsonObject(filePath) {
282
350
  try {
283
351
  const raw = await fs.readFile(filePath, "utf8");
284
352
  const parsed = JSON.parse(raw);
285
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
353
+ if (!isRecord(parsed)) return {};
286
354
  return parsed;
287
355
  } catch (error) {
288
356
  if (error.code === "ENOENT") return {};
357
+ if (error instanceof SyntaxError) return {};
289
358
  throw error;
290
359
  }
291
360
  }
@@ -297,12 +366,20 @@ async function resolveWechatDevtoolsInstanceDirs(baseDir) {
297
366
  try {
298
367
  const entries = await fs.readdir(baseDir, { withFileTypes: true });
299
368
  const instanceDirs = [];
300
- for (const entry of entries) {
301
- if (!entry.isDirectory()) continue;
302
- const instanceDir = path.join(baseDir, entry.name);
369
+ const seenDirs = /* @__PURE__ */ new Set();
370
+ const appendInstanceDir = async (instanceDir) => {
371
+ if (seenDirs.has(instanceDir)) return;
303
372
  try {
304
- if ((await fs.stat(path.join(instanceDir, "WeappLocalData"))).isDirectory()) instanceDirs.push(instanceDir);
373
+ if ((await fs.stat(path.join(instanceDir, "WeappLocalData"))).isDirectory()) {
374
+ instanceDirs.push(instanceDir);
375
+ seenDirs.add(instanceDir);
376
+ }
305
377
  } catch {}
378
+ };
379
+ await appendInstanceDir(baseDir);
380
+ for (const entry of entries) {
381
+ if (!entry.isDirectory()) continue;
382
+ await appendInstanceDir(path.join(baseDir, entry.name));
306
383
  }
307
384
  return instanceDirs;
308
385
  } catch (error) {
@@ -320,67 +397,97 @@ async function syncHashKeyMap(localDataDir, key) {
320
397
  }
321
398
  return hash;
322
399
  }
323
- async function updateWechatDevtoolsSecuritySettings(localDataDir) {
324
- const settingsHash = await syncHashKeyMap(localDataDir, WECHAT_DEVTOOLS_SETTINGS_KEY);
325
- const fileNames = [`localstorage_${settingsHash}.json`, `ls_${settingsHash}.json`];
326
- for (const fileName of fileNames) {
327
- const filePath = path.join(localDataDir, fileName);
328
- const current = await readJsonObject(filePath);
329
- const security = current.security && typeof current.security === "object" && !Array.isArray(current.security) ? current.security : {};
330
- await writeJsonObject(filePath, {
331
- ...current,
332
- security: {
333
- ...security,
334
- ...DEFAULT_WECHAT_DEVTOOLS_SECURITY_SETTINGS
335
- }
336
- });
400
+ async function detectWechatDevtoolsSecuritySettings(localDataDir) {
401
+ for (const fileName of SETTINGS_STORAGE_FILE_NAMES) {
402
+ const security = normalizeWechatDevtoolsSecuritySettings((await readJsonObject(path.join(localDataDir, fileName))).security);
403
+ if (security) return security;
337
404
  }
338
405
  }
339
406
  async function trustWechatDevtoolsProject(localDataDir, projectPath) {
340
407
  const normalizedProjectPath = path.resolve(projectPath);
341
408
  const projectHash = await syncHashKeyMap(localDataDir, `project2_${normalizedProjectPath}`);
342
- const projectFilePath = path.join(localDataDir, `localstorage_${projectHash}.json`);
343
- const current = await readJsonObject(projectFilePath);
344
- await writeJsonObject(projectFilePath, {
345
- ...current,
346
- projectid: typeof current.projectid === "string" && current.projectid.length > 0 ? current.projectid : normalizedProjectPath,
347
- projectpath: typeof current.projectpath === "string" && current.projectpath.length > 0 ? current.projectpath : normalizedProjectPath,
348
- isTrusted: true
349
- });
409
+ const fileNames = [`localstorage_${projectHash}.json`, `ls_${projectHash}.json`];
410
+ for (const fileName of fileNames) {
411
+ const projectFilePath = path.join(localDataDir, fileName);
412
+ const current = await readJsonObject(projectFilePath);
413
+ await writeJsonObject(projectFilePath, {
414
+ ...current,
415
+ projectid: typeof current.projectid === "string" && current.projectid.length > 0 ? current.projectid : normalizedProjectPath,
416
+ projectpath: typeof current.projectpath === "string" && current.projectpath.length > 0 ? current.projectpath : normalizedProjectPath,
417
+ isTrusted: true
418
+ });
419
+ }
420
+ }
421
+ async function scanWechatDevtoolsServicePort(context) {
422
+ const instanceDirs = await resolveWechatDevtoolsInstanceDirs(context.baseDir);
423
+ let detectedSecurityCount = 0;
424
+ let detectedServicePort = {};
425
+ for (const instanceDir of instanceDirs) {
426
+ const security = await detectWechatDevtoolsSecuritySettings(path.join(instanceDir, "WeappLocalData"));
427
+ if (!security) continue;
428
+ detectedSecurityCount += 1;
429
+ const candidate = {
430
+ enabled: security.enableServicePort,
431
+ port: security.port
432
+ };
433
+ if (shouldPreferServicePortCandidate(detectedServicePort, candidate)) detectedServicePort = candidate;
434
+ }
435
+ return {
436
+ instanceDirs,
437
+ touchedInstanceCount: instanceDirs.length,
438
+ detectedSecurityCount,
439
+ servicePort: detectedServicePort.port,
440
+ servicePortEnabled: detectedServicePort.enabled
441
+ };
350
442
  }
351
443
  /**
352
- * @description 在微信开发者工具启动前,预写入服务端口与项目可信配置。
444
+ * @description 检测微信开发者工具当前服务端口配置,严格沿用用户已有设置。
353
445
  */
354
- async function bootstrapWechatDevtoolsSettings(options = {}) {
355
- const platform = options.platform ?? process.platform;
356
- const homeDir = options.homeDir ?? process.env.HOME;
357
- if (!homeDir) return {
446
+ async function detectWechatDevtoolsServicePort(options = {}) {
447
+ const context = createResolvedWechatDevtoolsContext(options);
448
+ if (!context) return {
358
449
  touchedInstanceCount: 0,
359
- updatedSecurityCount: 0,
360
- trustedProjectCount: 0
450
+ detectedSecurityCount: 0,
451
+ servicePort: void 0,
452
+ servicePortEnabled: void 0
453
+ };
454
+ const result = await scanWechatDevtoolsServicePort(context);
455
+ return {
456
+ touchedInstanceCount: result.touchedInstanceCount,
457
+ detectedSecurityCount: result.detectedSecurityCount,
458
+ servicePort: result.servicePort,
459
+ servicePortEnabled: result.servicePortEnabled
361
460
  };
362
- const baseDir = resolveWechatDevtoolsBaseDir(homeDir, platform);
363
- if (!baseDir) return {
461
+ }
462
+ /**
463
+ * @description 在启动微信开发者工具前,检测服务端口配置,并按需写入项目信任信息。
464
+ */
465
+ async function bootstrapWechatDevtoolsSettings(options = {}) {
466
+ const context = createResolvedWechatDevtoolsContext(options);
467
+ if (!context) return {
364
468
  touchedInstanceCount: 0,
469
+ detectedSecurityCount: 0,
365
470
  updatedSecurityCount: 0,
366
- trustedProjectCount: 0
471
+ trustedProjectCount: 0,
472
+ servicePort: void 0,
473
+ servicePortEnabled: void 0
367
474
  };
368
- const instanceDirs = await resolveWechatDevtoolsInstanceDirs(baseDir);
369
- let updatedSecurityCount = 0;
475
+ const scanResult = await scanWechatDevtoolsServicePort(context);
370
476
  let trustedProjectCount = 0;
371
- for (const instanceDir of instanceDirs) {
477
+ for (const instanceDir of scanResult.instanceDirs) {
372
478
  const localDataDir = path.join(instanceDir, "WeappLocalData");
373
- await updateWechatDevtoolsSecuritySettings(localDataDir);
374
- updatedSecurityCount += 1;
375
479
  if (options.projectPath && options.trustProject !== false) {
376
480
  await trustWechatDevtoolsProject(localDataDir, options.projectPath);
377
481
  trustedProjectCount += 1;
378
482
  }
379
483
  }
380
484
  return {
381
- touchedInstanceCount: instanceDirs.length,
382
- updatedSecurityCount,
383
- trustedProjectCount
485
+ touchedInstanceCount: scanResult.touchedInstanceCount,
486
+ detectedSecurityCount: scanResult.detectedSecurityCount,
487
+ updatedSecurityCount: 0,
488
+ trustedProjectCount,
489
+ servicePort: scanResult.servicePort,
490
+ servicePortEnabled: scanResult.servicePortEnabled
384
491
  };
385
492
  }
386
493
  //#endregion
@@ -541,10 +648,12 @@ async function launchAutomator(options) {
541
648
  const resolvedTrustProject = options.trustProject ?? config.autoTrustProject ?? false;
542
649
  const launcher = new Launcher();
543
650
  let lastError = null;
544
- if (config.autoBootstrapDevtools !== false) await bootstrapWechatDevtoolsSettings({
651
+ let bootstrapResult;
652
+ if (config.autoBootstrapDevtools !== false) bootstrapResult = await bootstrapWechatDevtoolsSettings({
545
653
  projectPath,
546
654
  trustProject: resolvedTrustProject
547
655
  });
656
+ if (bootstrapResult?.servicePortEnabled === false) throw new Error("Detected WeChat DevTools service port is disabled in current settings. Please enable it manually; existing user settings were not modified.");
548
657
  for (let attempt = 0; attempt < 2; attempt += 1) try {
549
658
  const miniProgram = await launcher.launch({
550
659
  cliPath: resolvedCliPath,
@@ -1094,4 +1203,4 @@ async function remote(options) {
1094
1203
  });
1095
1204
  }
1096
1205
  //#endregion
1097
- export { removeCustomConfigKey as $, isAutomatorProtocolTimeoutError as A, resolveDevtoolsAutomationDefaults as B, configureLocaleFromArgv as C, formatAutomatorLoginError as D, connectOpenedAutomator as E, launchAutomator as F, colors as G, getDefaultCliPath as H, bootstrapWechatDevtoolsSettings as I, createAutoTrustProjectConfig as J, logger_default as K, resolveCliPath as L, isDevtoolsExtensionContextInvalidatedError as M, isDevtoolsHttpPortError as N, getAutomatorProtocolTimeoutMethod as O, isRetryableAutomatorLaunchError as P, readCustomConfig as Q, getConfig as R, withMiniProgram as S, validateLocaleOption as T, isOperatingSystemSupported as U, SupportedPlatformsMap as V, operatingSystemName as W, createLocaleConfig as X, createCustomConfig as Y, overwriteCustomConfig as Z, acquireSharedMiniProgram as _, navigateBack as a, getSharedMiniProgramSessionCount as b, pageStack as c, remote as d, defaultCustomConfigDirPath as et, scrollTo as f, tap as g, takeScreenshot as h, input as i, isAutomatorWsConnectError as j, isAutomatorLoginError as k, reLaunch as l, systemInfo as m, captureScreenshotBuffer as n, resolvePath as nt, navigateTo as o, switchTab as p, createAutoBootstrapDevtoolsConfig as q, currentPage as r, pageData as s, audit as t, defaultCustomConfigFilePath as tt, redirectTo as u, closeSharedMiniProgram as v, i18nText as w, releaseSharedMiniProgram as x, connectMiniProgram as y, getConfiguredLocale as z };
1206
+ export { readCustomConfig as $, isAutomatorProtocolTimeoutError as A, getConfiguredLocale as B, configureLocaleFromArgv as C, formatAutomatorLoginError as D, connectOpenedAutomator as E, launchAutomator as F, operatingSystemName as G, SupportedPlatformsMap as H, bootstrapWechatDevtoolsSettings as I, createAutoBootstrapDevtoolsConfig as J, colors as K, detectWechatDevtoolsServicePort as L, isDevtoolsExtensionContextInvalidatedError as M, isDevtoolsHttpPortError as N, getAutomatorProtocolTimeoutMethod as O, isRetryableAutomatorLaunchError as P, overwriteCustomConfig as Q, resolveCliPath as R, withMiniProgram as S, validateLocaleOption as T, getDefaultCliPath as U, resolveDevtoolsAutomationDefaults as V, isOperatingSystemSupported as W, createCustomConfig as X, createAutoTrustProjectConfig as Y, createLocaleConfig as Z, acquireSharedMiniProgram as _, navigateBack as a, getSharedMiniProgramSessionCount as b, pageStack as c, remote as d, removeCustomConfigKey as et, scrollTo as f, tap as g, takeScreenshot as h, input as i, isAutomatorWsConnectError as j, isAutomatorLoginError as k, reLaunch as l, systemInfo as m, captureScreenshotBuffer as n, defaultCustomConfigFilePath as nt, navigateTo as o, switchTab as p, logger_default as q, currentPage as r, resolvePath as rt, pageData as s, audit as t, defaultCustomConfigDirPath as tt, redirectTo as u, closeSharedMiniProgram as v, i18nText as w, releaseSharedMiniProgram as x, connectMiniProgram as y, getConfig as z };
package/dist/index.d.ts CHANGED
@@ -384,19 +384,35 @@ interface WechatDevtoolsSecuritySettings {
384
384
  allowGetTicket: boolean;
385
385
  trustWhenAuto: boolean;
386
386
  }
387
- interface BootstrapWechatDevtoolsSettingsOptions {
387
+ interface DetectedWechatDevtoolsServicePortSettings {
388
+ enabled?: boolean;
389
+ port?: number;
390
+ }
391
+ interface DetectWechatDevtoolsServicePortOptions {
388
392
  homeDir?: string;
393
+ localAppDataDir?: string;
389
394
  platform?: NodeJS.Platform;
395
+ }
396
+ interface DetectWechatDevtoolsServicePortResult {
397
+ touchedInstanceCount: number;
398
+ detectedSecurityCount: number;
399
+ servicePort?: number;
400
+ servicePortEnabled?: boolean;
401
+ }
402
+ interface BootstrapWechatDevtoolsSettingsOptions extends DetectWechatDevtoolsServicePortOptions {
390
403
  projectPath?: string;
391
404
  trustProject?: boolean;
392
405
  }
393
- interface BootstrapWechatDevtoolsSettingsResult {
394
- touchedInstanceCount: number;
406
+ interface BootstrapWechatDevtoolsSettingsResult extends DetectWechatDevtoolsServicePortResult {
395
407
  updatedSecurityCount: number;
396
408
  trustedProjectCount: number;
397
409
  }
398
410
  /**
399
- * @description 在微信开发者工具启动前,预写入服务端口与项目可信配置。
411
+ * @description 检测微信开发者工具当前服务端口配置,严格沿用用户已有设置。
412
+ */
413
+ declare function detectWechatDevtoolsServicePort(options?: DetectWechatDevtoolsServicePortOptions): Promise<DetectWechatDevtoolsServicePortResult>;
414
+ /**
415
+ * @description 在启动微信开发者工具前,检测服务端口配置,并按需写入项目信任信息。
400
416
  */
401
417
  declare function bootstrapWechatDevtoolsSettings(options?: BootstrapWechatDevtoolsSettingsOptions): Promise<BootstrapWechatDevtoolsSettingsResult>;
402
418
  //#endregion
@@ -493,7 +509,7 @@ declare function getConfiguredLocale(): Promise<"zh" | "en" | undefined>;
493
509
  //#endregion
494
510
  //#region src/runtime/platform.d.ts
495
511
  /**
496
- * @description 官方微信开发者工具只支持 Windows、macOS,Linux 只有社区版
512
+ * @description 官方微信开发者工具只支持 Windows、macOS,Linux 只有社区版。
497
513
  * https://github.com/msojocs/wechat-web-devtools-linux
498
514
  */
499
515
  declare const SupportedPlatformsMap: {
@@ -502,19 +518,19 @@ declare const SupportedPlatformsMap: {
502
518
  readonly Linux: "Linux";
503
519
  };
504
520
  /**
505
- * @description 支持的系统类型
521
+ * @description 支持的系统类型。
506
522
  */
507
523
  type SupportedPlatform = (typeof SupportedPlatformsMap)[keyof typeof SupportedPlatformsMap];
508
524
  /**
509
- * @description 判断当前系统是否支持微信开发者工具
525
+ * @description 判断当前系统是否支持微信开发者工具。
510
526
  */
511
527
  declare function isOperatingSystemSupported(osName?: string): osName is SupportedPlatform;
512
528
  /**
513
- * @description 当前系统名称
529
+ * @description 当前系统名称。
514
530
  */
515
531
  declare const operatingSystemName: string;
516
532
  /**
517
- * @description 获取默认 CLI 路径(按系统)
533
+ * @description 获取默认 CLI 路径(按系统)。
518
534
  */
519
535
  declare function getDefaultCliPath(targetOs?: string): Promise<string | undefined>;
520
536
  //#endregion
@@ -552,4 +568,4 @@ declare function execute(cliPath: string, argv: string[], options?: ExecuteOptio
552
568
  */
553
569
  declare function resolvePath(filePath: string): string;
554
570
  //#endregion
555
- export { AUTOMATOR_COMMAND_NAMES, ArgvTransform, AuditOptions, AutomatorCommandOptions, AutomatorOptions, AutomatorSessionOptions, type BaseConfig, BootstrapWechatDevtoolsSettingsOptions, BootstrapWechatDevtoolsSettingsResult, CONFIG_COMMAND_NAME, type ConfigSource, ForwardConsoleEvent, ForwardConsoleLogLevel, ForwardConsoleOptions, ForwardConsoleSession, InputOptions, LoginRetryMode, MINIDEV_NAMESPACE_COMMAND_NAMES, MiniProgramElement, MiniProgramEventMap, MiniProgramLike, MiniProgramPage, NavigateOptions, PageDataOptions, PageInfoOptions, ParsedAutomatorArgs, RemoteOptions, type ResolvedConfig, RetryKeypressOptions, RetryPromptResult, type ScreenshotOptions, type ScreenshotResult, ScrollOptions, SelectorOptions, SupportedPlatform, SupportedPlatformsMap, TapOptions, WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, WECHAT_CLI_COMMAND_NAMES, WechatDevtoolsSecuritySettings, acquireSharedMiniProgram, audit, bootstrapWechatDevtoolsSettings, captureScreenshotBuffer, closeSharedMiniProgram, connectMiniProgram, connectOpenedAutomator, createAlias, createAutoBootstrapDevtoolsConfig, createAutoTrustProjectConfig, createCli, createCustomConfig, createLocaleConfig, createPathCompat, createWechatIdeLoginRequiredExitError, currentPage, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute, extractExecutionErrorText, formatAutomatorLoginError, formatRetryHotkeyPrompt, formatWechatIdeLoginRequiredError, getAutomatorCommandHelp, getAutomatorProtocolTimeoutMethod, getConfig, getConfiguredLocale, getDefaultCliPath, getSharedMiniProgramSessionCount, handleConfigCommand, input, isAutomatorCommand, isAutomatorLoginError, isAutomatorProtocolTimeoutError, isAutomatorWsConnectError, isDevtoolsExtensionContextInvalidatedError, isDevtoolsHttpPortError, isOperatingSystemSupported, isRetryableAutomatorLaunchError, isWeappIdeTopLevelCommand, isWechatIdeLoginRequiredError, launchAutomator, navigateBack, navigateTo, operatingSystemName, overwriteCustomConfig, pageData, pageStack, parse, parseAutomatorArgs, parseCompareArgs, parseScreenshotArgs, printCompareHelp, printScreenshotHelp, promptForCliPath, reLaunch, readCustomConfig, readOptionValue, redirectTo, releaseSharedMiniProgram, remote, removeCustomConfigKey, removeOption, resolveCliPath, resolveDevtoolsAutomationDefaults, resolvePath, runAutomatorCommand, runMinidev, runWechatCliWithRetry, scrollTo, startForwardConsole, switchTab, systemInfo, takeScreenshot, tap, transformArgv, validateWechatCliCommandArgs, waitForRetryKeypress, withMiniProgram };
571
+ export { AUTOMATOR_COMMAND_NAMES, ArgvTransform, AuditOptions, AutomatorCommandOptions, AutomatorOptions, AutomatorSessionOptions, type BaseConfig, BootstrapWechatDevtoolsSettingsOptions, BootstrapWechatDevtoolsSettingsResult, CONFIG_COMMAND_NAME, type ConfigSource, DetectWechatDevtoolsServicePortOptions, DetectWechatDevtoolsServicePortResult, DetectedWechatDevtoolsServicePortSettings, ForwardConsoleEvent, ForwardConsoleLogLevel, ForwardConsoleOptions, ForwardConsoleSession, InputOptions, LoginRetryMode, MINIDEV_NAMESPACE_COMMAND_NAMES, MiniProgramElement, MiniProgramEventMap, MiniProgramLike, MiniProgramPage, NavigateOptions, PageDataOptions, PageInfoOptions, ParsedAutomatorArgs, RemoteOptions, type ResolvedConfig, RetryKeypressOptions, RetryPromptResult, type ScreenshotOptions, type ScreenshotResult, ScrollOptions, SelectorOptions, SupportedPlatform, SupportedPlatformsMap, TapOptions, WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, WECHAT_CLI_COMMAND_NAMES, WechatDevtoolsSecuritySettings, acquireSharedMiniProgram, audit, bootstrapWechatDevtoolsSettings, captureScreenshotBuffer, closeSharedMiniProgram, connectMiniProgram, connectOpenedAutomator, createAlias, createAutoBootstrapDevtoolsConfig, createAutoTrustProjectConfig, createCli, createCustomConfig, createLocaleConfig, createPathCompat, createWechatIdeLoginRequiredExitError, currentPage, defaultCustomConfigDirPath, defaultCustomConfigFilePath, detectWechatDevtoolsServicePort, execute, extractExecutionErrorText, formatAutomatorLoginError, formatRetryHotkeyPrompt, formatWechatIdeLoginRequiredError, getAutomatorCommandHelp, getAutomatorProtocolTimeoutMethod, getConfig, getConfiguredLocale, getDefaultCliPath, getSharedMiniProgramSessionCount, handleConfigCommand, input, isAutomatorCommand, isAutomatorLoginError, isAutomatorProtocolTimeoutError, isAutomatorWsConnectError, isDevtoolsExtensionContextInvalidatedError, isDevtoolsHttpPortError, isOperatingSystemSupported, isRetryableAutomatorLaunchError, isWeappIdeTopLevelCommand, isWechatIdeLoginRequiredError, launchAutomator, navigateBack, navigateTo, operatingSystemName, overwriteCustomConfig, pageData, pageStack, parse, parseAutomatorArgs, parseCompareArgs, parseScreenshotArgs, printCompareHelp, printScreenshotHelp, promptForCliPath, reLaunch, readCustomConfig, readOptionValue, redirectTo, releaseSharedMiniProgram, remote, removeCustomConfigKey, removeOption, resolveCliPath, resolveDevtoolsAutomationDefaults, resolvePath, runAutomatorCommand, runMinidev, runWechatCliWithRetry, scrollTo, startForwardConsole, switchTab, systemInfo, takeScreenshot, tap, transformArgv, validateWechatCliCommandArgs, waitForRetryKeypress, withMiniProgram };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { $ as removeCustomConfigKey, A as isAutomatorProtocolTimeoutError, B as resolveDevtoolsAutomationDefaults, D as formatAutomatorLoginError, E as connectOpenedAutomator, F as launchAutomator, H as getDefaultCliPath, I as bootstrapWechatDevtoolsSettings, J as createAutoTrustProjectConfig, L as resolveCliPath, M as isDevtoolsExtensionContextInvalidatedError, N as isDevtoolsHttpPortError, O as getAutomatorProtocolTimeoutMethod, P as isRetryableAutomatorLaunchError, Q as readCustomConfig, R as getConfig, S as withMiniProgram, U as isOperatingSystemSupported, V as SupportedPlatformsMap, W as operatingSystemName, X as createLocaleConfig, Y as createCustomConfig, Z as overwriteCustomConfig, _ as acquireSharedMiniProgram, a as navigateBack, b as getSharedMiniProgramSessionCount, c as pageStack, d as remote, et as defaultCustomConfigDirPath, f as scrollTo, g as tap, h as takeScreenshot, i as input, j as isAutomatorWsConnectError, k as isAutomatorLoginError, l as reLaunch, m as systemInfo, n as captureScreenshotBuffer, nt as resolvePath, o as navigateTo, p as switchTab, q as createAutoBootstrapDevtoolsConfig, r as currentPage, s as pageData, t as audit, tt as defaultCustomConfigFilePath, u as redirectTo, v as closeSharedMiniProgram, x as releaseSharedMiniProgram, y as connectMiniProgram, z as getConfiguredLocale } from "./commands-BNdodULv.js";
2
- import { A as parseCompareArgs, C as isWeappIdeTopLevelCommand, D as runAutomatorCommand, E as isAutomatorCommand, M as parseAutomatorArgs, N as readOptionValue, O as parseScreenshotArgs, P as removeOption, S as WECHAT_CLI_COMMAND_NAMES, T as getAutomatorCommandHelp, _ as handleConfigCommand, a as createWechatIdeLoginRequiredExitError, b as MINIDEV_NAMESPACE_COMMAND_NAMES, c as formatWechatIdeLoginRequiredError, d as runMinidev, f as execute, g as startForwardConsole, h as transformArgv, i as runWechatCliWithRetry, j as printCompareHelp, k as printScreenshotHelp, l as isWechatIdeLoginRequiredError, m as createPathCompat, n as parse, o as extractExecutionErrorText, p as createAlias, r as validateWechatCliCommandArgs, s as formatRetryHotkeyPrompt, t as createCli, u as waitForRetryKeypress, v as promptForCliPath, w as AUTOMATOR_COMMAND_NAMES, x as WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, y as CONFIG_COMMAND_NAME } from "./cli-DrmbSun7.js";
3
- export { AUTOMATOR_COMMAND_NAMES, CONFIG_COMMAND_NAME, MINIDEV_NAMESPACE_COMMAND_NAMES, SupportedPlatformsMap, WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, WECHAT_CLI_COMMAND_NAMES, acquireSharedMiniProgram, audit, bootstrapWechatDevtoolsSettings, captureScreenshotBuffer, closeSharedMiniProgram, connectMiniProgram, connectOpenedAutomator, createAlias, createAutoBootstrapDevtoolsConfig, createAutoTrustProjectConfig, createCli, createCustomConfig, createLocaleConfig, createPathCompat, createWechatIdeLoginRequiredExitError, currentPage, defaultCustomConfigDirPath, defaultCustomConfigFilePath, execute, extractExecutionErrorText, formatAutomatorLoginError, formatRetryHotkeyPrompt, formatWechatIdeLoginRequiredError, getAutomatorCommandHelp, getAutomatorProtocolTimeoutMethod, getConfig, getConfiguredLocale, getDefaultCliPath, getSharedMiniProgramSessionCount, handleConfigCommand, input, isAutomatorCommand, isAutomatorLoginError, isAutomatorProtocolTimeoutError, isAutomatorWsConnectError, isDevtoolsExtensionContextInvalidatedError, isDevtoolsHttpPortError, isOperatingSystemSupported, isRetryableAutomatorLaunchError, isWeappIdeTopLevelCommand, isWechatIdeLoginRequiredError, launchAutomator, navigateBack, navigateTo, operatingSystemName, overwriteCustomConfig, pageData, pageStack, parse, parseAutomatorArgs, parseCompareArgs, parseScreenshotArgs, printCompareHelp, printScreenshotHelp, promptForCliPath, reLaunch, readCustomConfig, readOptionValue, redirectTo, releaseSharedMiniProgram, remote, removeCustomConfigKey, removeOption, resolveCliPath, resolveDevtoolsAutomationDefaults, resolvePath, runAutomatorCommand, runMinidev, runWechatCliWithRetry, scrollTo, startForwardConsole, switchTab, systemInfo, takeScreenshot, tap, transformArgv, validateWechatCliCommandArgs, waitForRetryKeypress, withMiniProgram };
1
+ import { $ as readCustomConfig, A as isAutomatorProtocolTimeoutError, B as getConfiguredLocale, D as formatAutomatorLoginError, E as connectOpenedAutomator, F as launchAutomator, G as operatingSystemName, H as SupportedPlatformsMap, I as bootstrapWechatDevtoolsSettings, J as createAutoBootstrapDevtoolsConfig, L as detectWechatDevtoolsServicePort, M as isDevtoolsExtensionContextInvalidatedError, N as isDevtoolsHttpPortError, O as getAutomatorProtocolTimeoutMethod, P as isRetryableAutomatorLaunchError, Q as overwriteCustomConfig, R as resolveCliPath, S as withMiniProgram, U as getDefaultCliPath, V as resolveDevtoolsAutomationDefaults, W as isOperatingSystemSupported, X as createCustomConfig, Y as createAutoTrustProjectConfig, Z as createLocaleConfig, _ as acquireSharedMiniProgram, a as navigateBack, b as getSharedMiniProgramSessionCount, c as pageStack, d as remote, et as removeCustomConfigKey, f as scrollTo, g as tap, h as takeScreenshot, i as input, j as isAutomatorWsConnectError, k as isAutomatorLoginError, l as reLaunch, m as systemInfo, n as captureScreenshotBuffer, nt as defaultCustomConfigFilePath, o as navigateTo, p as switchTab, r as currentPage, rt as resolvePath, s as pageData, t as audit, tt as defaultCustomConfigDirPath, u as redirectTo, v as closeSharedMiniProgram, x as releaseSharedMiniProgram, y as connectMiniProgram, z as getConfig } from "./commands-XD_wemcg.js";
2
+ import { A as parseCompareArgs, C as isWeappIdeTopLevelCommand, D as runAutomatorCommand, E as isAutomatorCommand, M as parseAutomatorArgs, N as readOptionValue, O as parseScreenshotArgs, P as removeOption, S as WECHAT_CLI_COMMAND_NAMES, T as getAutomatorCommandHelp, _ as handleConfigCommand, a as createWechatIdeLoginRequiredExitError, b as MINIDEV_NAMESPACE_COMMAND_NAMES, c as formatWechatIdeLoginRequiredError, d as runMinidev, f as execute, g as startForwardConsole, h as transformArgv, i as runWechatCliWithRetry, j as printCompareHelp, k as printScreenshotHelp, l as isWechatIdeLoginRequiredError, m as createPathCompat, n as parse, o as extractExecutionErrorText, p as createAlias, r as validateWechatCliCommandArgs, s as formatRetryHotkeyPrompt, t as createCli, u as waitForRetryKeypress, v as promptForCliPath, w as AUTOMATOR_COMMAND_NAMES, x as WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, y as CONFIG_COMMAND_NAME } from "./cli-CfovXw-V.js";
3
+ export { AUTOMATOR_COMMAND_NAMES, CONFIG_COMMAND_NAME, MINIDEV_NAMESPACE_COMMAND_NAMES, SupportedPlatformsMap, WEAPP_IDE_TOP_LEVEL_COMMAND_NAMES, WECHAT_CLI_COMMAND_NAMES, acquireSharedMiniProgram, audit, bootstrapWechatDevtoolsSettings, captureScreenshotBuffer, closeSharedMiniProgram, connectMiniProgram, connectOpenedAutomator, createAlias, createAutoBootstrapDevtoolsConfig, createAutoTrustProjectConfig, createCli, createCustomConfig, createLocaleConfig, createPathCompat, createWechatIdeLoginRequiredExitError, currentPage, defaultCustomConfigDirPath, defaultCustomConfigFilePath, detectWechatDevtoolsServicePort, execute, extractExecutionErrorText, formatAutomatorLoginError, formatRetryHotkeyPrompt, formatWechatIdeLoginRequiredError, getAutomatorCommandHelp, getAutomatorProtocolTimeoutMethod, getConfig, getConfiguredLocale, getDefaultCliPath, getSharedMiniProgramSessionCount, handleConfigCommand, input, isAutomatorCommand, isAutomatorLoginError, isAutomatorProtocolTimeoutError, isAutomatorWsConnectError, isDevtoolsExtensionContextInvalidatedError, isDevtoolsHttpPortError, isOperatingSystemSupported, isRetryableAutomatorLaunchError, isWeappIdeTopLevelCommand, isWechatIdeLoginRequiredError, launchAutomator, navigateBack, navigateTo, operatingSystemName, overwriteCustomConfig, pageData, pageStack, parse, parseAutomatorArgs, parseCompareArgs, parseScreenshotArgs, printCompareHelp, printScreenshotHelp, promptForCliPath, reLaunch, readCustomConfig, readOptionValue, redirectTo, releaseSharedMiniProgram, remote, removeCustomConfigKey, removeOption, resolveCliPath, resolveDevtoolsAutomationDefaults, resolvePath, runAutomatorCommand, runMinidev, runWechatCliWithRetry, scrollTo, startForwardConsole, switchTab, systemInfo, takeScreenshot, tap, transformArgv, validateWechatCliCommandArgs, waitForRetryKeypress, withMiniProgram };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-ide-cli",
3
3
  "type": "module",
4
- "version": "5.2.3",
4
+ "version": "5.2.4",
5
5
  "description": "让微信开发者工具,用起来更加方便!",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -68,8 +68,8 @@
68
68
  "pixelmatch": "^7.1.0",
69
69
  "pngjs": "^7.0.0",
70
70
  "@weapp-core/logger": "^3.1.1",
71
- "@weapp-core/shared": "^3.0.3",
72
- "@weapp-vite/miniprogram-automator": "1.0.2"
71
+ "@weapp-core/shared": "^3.0.4",
72
+ "@weapp-vite/miniprogram-automator": "1.0.3"
73
73
  },
74
74
  "scripts": {
75
75
  "dev": "tsdown -w --sourcemap",
@@ -1,2 +0,0 @@
1
- import { h as takeScreenshot } from "./commands-BNdodULv.js";
2
- export { takeScreenshot };