@weapp-vite/miniprogram-automator 1.2.19 → 1.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -943,7 +943,7 @@ var Connection = class Connection extends EventEmitter {
943
943
  //#endregion
944
944
  //#region src/headless.ts
945
945
  async function launchHeadlessAutomator(options) {
946
- return await (await import("./launch-CMN_emd-.mjs")).launch({ projectPath: options.projectPath });
946
+ return await (await import("./launch-BNQZTcKo.mjs")).launch({ projectPath: options.projectPath });
947
947
  }
948
948
  //#endregion
949
949
  //#region src/launcher/portLease.ts
@@ -1098,7 +1098,7 @@ function resolveWechatDevtoolsBootstrapArgs(args) {
1098
1098
  }
1099
1099
  //#endregion
1100
1100
  //#region package.json
1101
- var version = "1.2.19";
1101
+ var version = "1.2.20";
1102
1102
  //#endregion
1103
1103
  //#region src/Native.ts
1104
1104
  /** Native 的实现。 */
@@ -1194,7 +1194,7 @@ function linkRenderedParents(root, parent = null) {
1194
1194
  for (const child of root.children ?? []) linkRenderedParents(child, root);
1195
1195
  }
1196
1196
  //#endregion
1197
- //#region ../../node_modules/.pnpm/@babel+parser@8.0.5/node_modules/@babel/parser/lib/index.js
1197
+ //#region ../../node_modules/.pnpm/@babel+parser@8.0.6/node_modules/@babel/parser/lib/index.js
1198
1198
  var Position = class {
1199
1199
  constructor(line, col, index) {
1200
1200
  this.line = void 0;
@@ -2209,16 +2209,30 @@ const types = {
2209
2209
  j_cTag: new TokContext("</tag"),
2210
2210
  j_expr: new TokContext("<tag>...</tag>", true)
2211
2211
  };
2212
- const bmpIdentifierStart = /[\p{ID_Start}\u088f\u0c5c\u0cdc\ua7ce\ua7cf\ua7d2\ua7d4\ua7f1]/u;
2213
- const bmpIdentifier = /[\p{ID_Continue}\u088f\u0c5c\u0cdc\ua7ce\ua7cf\ua7d2\ua7d4\ua7f1\u1acf-\u1add\u1ae0-\u1aeb]/u;
2212
+ const bmpIdentifierStart = /[\p{ID_Start}\u0558\u058b\u058c\u088f\u0c5c\u0cdc\u208f\u209d-\u209f\ua7ce\ua7cf\ua7d2\ua7d4\ua7dd\ua7e2\ua7f1\uab6c\uab6d]/u;
2213
+ const bmpIdentifier = /[\p{ID_Continue}\u0558\u058b\u058c\u088f\u0c5c\u0cdc\u208f\u209d-\u209f\ua7ce\ua7cf\ua7d2\ua7d4\ua7dd\ua7e2\ua7f1\uab6c\uab6d\u05c8\u05c9\u0b53\u0b54\u1acf-\u1af0]/u;
2214
2214
  const supplementaryIdentifierStartCodes = [
2215
- 2368,
2215
+ 1979,
2216
+ 4,
2217
+ 385,
2216
2218
  25,
2217
2219
  1388,
2218
2220
  2,
2219
- 3817,
2221
+ 18,
2222
+ 21,
2223
+ 3100,
2224
+ 0,
2225
+ 678,
2220
2226
  43,
2221
- 20677,
2227
+ 22,
2228
+ 0,
2229
+ 1662,
2230
+ 0,
2231
+ 6,
2232
+ 10,
2233
+ 209,
2234
+ 310,
2235
+ 18458,
2222
2236
  24,
2223
2237
  3,
2224
2238
  24,
@@ -2226,11 +2240,31 @@ const supplementaryIdentifierStartCodes = [
2226
2240
  4,
2227
2241
  6146,
2228
2242
  7,
2229
- 1290,
2230
- 21,
2231
- 98,
2243
+ 1239,
2244
+ 4,
2245
+ 47,
2246
+ 23,
2247
+ 96,
2232
2248
  114,
2233
- 22734,
2249
+ 14,
2250
+ 913,
2251
+ 15,
2252
+ 50,
2253
+ 8017,
2254
+ 5,
2255
+ 64,
2256
+ 0,
2257
+ 9534,
2258
+ 0,
2259
+ 2169,
2260
+ 5,
2261
+ 7,
2262
+ 86,
2263
+ 15,
2264
+ 6,
2265
+ 55,
2266
+ 50,
2267
+ 1729,
2234
2268
  30,
2235
2269
  2,
2236
2270
  2,
@@ -2244,19 +2278,37 @@ const supplementaryIdentifierStartCodes = [
2244
2278
  1,
2245
2279
  53307,
2246
2280
  5,
2247
- 5987,
2281
+ 223,
2282
+ 0,
2283
+ 5764,
2248
2284
  11,
2249
2285
  21763,
2250
- 4297
2286
+ 4297,
2287
+ 39815,
2288
+ 11327
2251
2289
  ];
2252
2290
  const supplementaryIdentifierCodes = [
2253
- 3834,
2254
- 1,
2291
+ 3787,
2292
+ 4,
2293
+ 33,
2294
+ 11,
2255
2295
  3173,
2256
2296
  7,
2257
2297
  633,
2258
2298
  9,
2259
- 51450,
2299
+ 7,
2300
+ 0,
2301
+ 45879,
2302
+ 1,
2303
+ 296,
2304
+ 2,
2305
+ 9,
2306
+ 1,
2307
+ 3,
2308
+ 0,
2309
+ 33,
2310
+ 1,
2311
+ 5218,
2260
2312
  0,
2261
2313
  3,
2262
2314
  0,
@@ -3649,10 +3701,10 @@ const flow = (superClass) => class FlowParserMixin extends superClass {
3649
3701
  const arrows = [];
3650
3702
  while (stack.length !== 0) {
3651
3703
  const node = stack.pop();
3652
- if (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") {
3704
+ if (node.type === "ArrowFunctionExpression") {
3653
3705
  if (node.typeParameters || !node.returnType) this.finishArrowValidation(node);
3654
3706
  else arrows.push(node);
3655
- stack.push(node.body);
3707
+ if (node.body.type !== "BlockStatement") stack.push(node.body);
3656
3708
  } else if (node.type === "ConditionalExpression") {
3657
3709
  stack.push(node.consequent);
3658
3710
  stack.push(node.alternate);
@@ -4720,7 +4772,7 @@ const entities = {
4720
4772
  hearts: "♥",
4721
4773
  diams: "♦"
4722
4774
  };
4723
- const lineBreakG = new RegExp(/\r\n|[\r\n\u2028\u2029]/.source, "g");
4775
+ const lineBreakG = /\r\n|[\r\n\u2028\u2029]/g;
4724
4776
  function isNewLine(code) {
4725
4777
  switch (code) {
4726
4778
  case 10:
@@ -5685,12 +5737,14 @@ function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumS
5685
5737
  else if (_isDigit(code)) val = code - 48;
5686
5738
  else val = Infinity;
5687
5739
  if (val >= radix) {
5688
- if (val <= 9 && bailOnError) return {
5689
- n: null,
5690
- pos
5691
- };
5692
- else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) val = 0;
5693
- else if (forceLen) {
5740
+ if (val <= 9) {
5741
+ if (bailOnError) return {
5742
+ n: null,
5743
+ pos
5744
+ };
5745
+ errors.invalidDigit(pos, lineStart, curLine, radix);
5746
+ val = 0;
5747
+ } else if (forceLen) {
5694
5748
  val = 0;
5695
5749
  invalid = true;
5696
5750
  } else break;
@@ -6520,9 +6574,7 @@ var Tokenizer$1 = class extends CommentsParser {
6520
6574
  }
6521
6575
  errorHandlers_readInt = {
6522
6576
  invalidDigit: (pos, lineStart, curLine, radix) => {
6523
- if (!(this.optionFlags & 4096)) return false;
6524
6577
  this.raise(Errors.InvalidDigit, buildPosition(pos, lineStart, curLine), { radix });
6525
- return true;
6526
6578
  },
6527
6579
  numericSeparatorInEscapeSequence: this.errorBuilder(Errors.NumericSeparatorInEscapeSequence),
6528
6580
  unexpectedNumericSeparator: this.errorBuilder(Errors.UnexpectedNumericSeparator)
@@ -12103,6 +12155,9 @@ const typescript = (superClass) => class TypeScriptParserMixin extends superClas
12103
12155
  }
12104
12156
  fillOptionalPropertiesForTSESLint(node) {
12105
12157
  switch (node.type) {
12158
+ case "ImportDeclaration":
12159
+ node.phase ??= null;
12160
+ return;
12106
12161
  case "ExpressionStatement":
12107
12162
  node.directive ??= void 0;
12108
12163
  return;
@@ -17698,6 +17753,57 @@ function createHeadlessLogManager(runtimeConsole) {
17698
17753
  };
17699
17754
  }
17700
17755
  //#endregion
17756
+ //#region ../../mpcore/packages/simulator/src/host/wx/startupNavigation.ts
17757
+ const queues = /* @__PURE__ */ new WeakMap();
17758
+ /** 冷启动先完成 App 与首屏装载,再顺序提交启动钩子请求的导航。 */
17759
+ var StartupNavigationQueue = class {
17760
+ scheduler;
17761
+ collecting = false;
17762
+ pending = [];
17763
+ constructor(scheduler) {
17764
+ this.scheduler = scheduler;
17765
+ }
17766
+ capture(operation) {
17767
+ this.collecting = true;
17768
+ try {
17769
+ operation();
17770
+ } catch (error) {
17771
+ this.pending.length = 0;
17772
+ throw error;
17773
+ } finally {
17774
+ this.collecting = false;
17775
+ }
17776
+ }
17777
+ run(option, operation) {
17778
+ if (!this.collecting) return operation(option);
17779
+ const defer = (callback) => callback ? (...args) => {
17780
+ this.scheduler.setTimeout(() => callback(...args), 0);
17781
+ } : void 0;
17782
+ const deferred = option && {
17783
+ ...option,
17784
+ success: defer(option.success),
17785
+ fail: defer(option.fail),
17786
+ complete: defer(option.complete)
17787
+ };
17788
+ this.pending.push(() => {
17789
+ operation(deferred);
17790
+ });
17791
+ }
17792
+ flush() {
17793
+ const pending = this.pending.splice(0);
17794
+ for (const operation of pending) operation();
17795
+ }
17796
+ };
17797
+ /** 内部绑定保持 driver 的公开形状不变,两种 runtime 共享启动调度。 */
17798
+ function bindStartupNavigation(driver, queue) {
17799
+ queues.set(driver, queue);
17800
+ return driver;
17801
+ }
17802
+ function runNavigationApi(driver, option, operation) {
17803
+ const queue = queues.get(driver);
17804
+ return queue ? queue.run(option, operation) : operation(option);
17805
+ }
17806
+ //#endregion
17701
17807
  //#region ../../mpcore/packages/simulator/src/host/wx/index.ts
17702
17808
  function invokeWxApi(operation, option) {
17703
17809
  try {
@@ -18095,12 +18201,12 @@ function createHeadlessWx(driver, runtimeConsole = console) {
18095
18201
  hideLoading: (option) => invokeWxApi(() => driver.hideLoading(), option),
18096
18202
  hideToast: () => driver.hideToast(),
18097
18203
  downloadFile: (option) => driver.downloadFile(option),
18098
- navigateBack: (option) => invokeWxApi(() => {
18099
- driver.navigateBack(option);
18100
- }, option),
18101
- navigateTo: (option) => invokeWxApi(() => {
18102
- driver.navigateTo(option);
18103
- }, option),
18204
+ navigateBack: (option) => runNavigationApi(driver, option, (deferred) => invokeWxApi(() => {
18205
+ driver.navigateBack(deferred);
18206
+ }, deferred)),
18207
+ navigateTo: (option) => runNavigationApi(driver, option, (deferred) => invokeWxApi(() => {
18208
+ driver.navigateTo(deferred);
18209
+ }, deferred)),
18104
18210
  nextTick: (callback) => driver.nextTick(callback),
18105
18211
  offAppHide: (callback) => driver.offAppHide(callback),
18106
18212
  offAppShow: (callback) => driver.offAppShow(callback),
@@ -18113,12 +18219,12 @@ function createHeadlessWx(driver, runtimeConsole = console) {
18113
18219
  driver.pageScrollTo(option);
18114
18220
  }, option),
18115
18221
  previewImage: (option) => invokeWxApi(() => driver.previewImage(option), option),
18116
- reLaunch: (option) => invokeWxApi(() => {
18117
- driver.reLaunch(option);
18118
- }, option),
18119
- redirectTo: (option) => invokeWxApi(() => {
18120
- driver.redirectTo(option);
18121
- }, option),
18222
+ reLaunch: (option) => runNavigationApi(driver, option, (deferred) => invokeWxApi(() => {
18223
+ driver.reLaunch(deferred);
18224
+ }, deferred)),
18225
+ redirectTo: (option) => runNavigationApi(driver, option, (deferred) => invokeWxApi(() => {
18226
+ driver.redirectTo(deferred);
18227
+ }, deferred)),
18122
18228
  removeSavedFile: (option) => invokeWxApi(() => driver.removeSavedFile(option), option),
18123
18229
  saveImageToPhotosAlbum: (option) => invokeWxApi(() => driver.saveImageToPhotosAlbum(option), option),
18124
18230
  saveVideoToPhotosAlbum: (option) => invokeWxApi(() => driver.saveVideoToPhotosAlbum(option), option),
@@ -18154,7 +18260,7 @@ function createHeadlessWx(driver, runtimeConsole = console) {
18154
18260
  showToast: (option) => invokeWxApi(() => driver.showToast(option), option),
18155
18261
  startPullDownRefresh: (option) => invokeWxApi(() => driver.startPullDownRefresh(), option),
18156
18262
  stopPullDownRefresh: () => driver.stopPullDownRefresh(),
18157
- switchTab: (option) => driver.switchTab(option),
18263
+ switchTab: (option) => runNavigationApi(driver, option, (deferred) => driver.switchTab(deferred)),
18158
18264
  uploadFile: (option) => driver.uploadFile(option),
18159
18265
  removeTabBarBadge: (option) => invokeWxApi(() => driver.removeTabBarBadge(option), option),
18160
18266
  setTabBarBadge: (option) => invokeWxApi(() => driver.setTabBarBadge(option), option),
@@ -18412,6 +18518,40 @@ function createProjectDescriptor(options) {
18412
18518
  };
18413
18519
  }
18414
18520
  //#endregion
18521
+ //#region ../../mpcore/packages/simulator/src/project/hostConfig.ts
18522
+ /**
18523
+ * @description 根据构建后的 app.json 创建模拟器提供给小程序脚本读取的宿主配置。
18524
+ * 微信开发者工具的 tabBar 页面路径通常带有 `.html` 后缀,保留该形态以覆盖路由归一化边界。
18525
+ */
18526
+ function createMiniProgramHostConfig(appConfig, override) {
18527
+ const appTabBar = appConfig.tabBar && typeof appConfig.tabBar === "object" ? appConfig.tabBar : void 0;
18528
+ const tabBar = appTabBar ? {
18529
+ ...appTabBar,
18530
+ ...Array.isArray(appTabBar.list) ? { list: appTabBar.list.map((item) => {
18531
+ if (!item || typeof item !== "object") return item;
18532
+ const pagePath = typeof item.pagePath === "string" ? item.pagePath.replace(/^\/+/, "").replace(/\.html$/, "") : void 0;
18533
+ return pagePath ? {
18534
+ ...item,
18535
+ pagePath: `${pagePath}.html`
18536
+ } : { ...item };
18537
+ }) } : {}
18538
+ } : void 0;
18539
+ const generated = {
18540
+ ...appConfig,
18541
+ ...tabBar ? { tabBar } : {}
18542
+ };
18543
+ if (!override || typeof override !== "object" || Array.isArray(override)) return generated;
18544
+ const overrideRecord = override;
18545
+ return {
18546
+ ...generated,
18547
+ ...overrideRecord,
18548
+ ...generated.tabBar || overrideRecord.tabBar ? { tabBar: {
18549
+ ...generated.tabBar ?? {},
18550
+ ...overrideRecord.tabBar ?? {}
18551
+ } } : {}
18552
+ };
18553
+ }
18554
+ //#endregion
18415
18555
  //#region ../../mpcore/packages/simulator/src/project/loadProject.ts
18416
18556
  function readJsonObject$1(filePath) {
18417
18557
  try {
@@ -41056,6 +41196,7 @@ function resolveNavigationPath(targetPath, baseRoute) {
41056
41196
  var HeadlessSession = class {
41057
41197
  project;
41058
41198
  kernel = new RuntimeKernel();
41199
+ startupNavigation = new StartupNavigationQueue(this.kernel.scheduler);
41059
41200
  appDefinition = null;
41060
41201
  appInstance = null;
41061
41202
  appLifecycle = new HeadlessAppLifecycle();
@@ -41110,7 +41251,7 @@ var HeadlessSession = class {
41110
41251
  });
41111
41252
  });
41112
41253
  this.tabBarVisible = this.tabBarRoutes.size > 0;
41113
- this.moduleLoader = createModuleLoader(this.registries, () => this.pages.slice(), () => this.getApp(), {
41254
+ this.moduleLoader = createModuleLoader(this.registries, () => this.pages.slice(), () => this.getApp(), bindStartupNavigation({
41114
41255
  chooseImage: (option) => this.wxState.chooseImage(option ?? {}),
41115
41256
  chooseMessageFile: (option) => this.wxState.chooseMessageFile(option ?? {}),
41116
41257
  chooseMedia: (option) => this.wxState.chooseMedia(option ?? {}),
@@ -41189,9 +41330,12 @@ var HeadlessSession = class {
41189
41330
  removeTabBarBadge: (option) => this.removeTabBarBadge(option.index),
41190
41331
  setTabBarBadge: (option) => this.setTabBarBadge(option.index, option.text),
41191
41332
  updateShareMenu: (option) => this.wxState.updateShareMenu(option)
41192
- }, {
41333
+ }, this.startupNavigation), {
41193
41334
  artifactSource: this.project.artifactSource,
41194
- globals: options.globals,
41335
+ globals: {
41336
+ ...options.globals,
41337
+ __wxConfig: createMiniProgramHostConfig(this.project.appConfig, options.globals?.__wxConfig)
41338
+ },
41195
41339
  kernel: this.kernel,
41196
41340
  miniprogramRootPath: this.project.miniprogramRootPath,
41197
41341
  onConsole: (entry) => this.emit("console", entry),
@@ -41645,9 +41789,16 @@ var HeadlessSession = class {
41645
41789
  if (Object.hasOwn(runtimeApp, "routes")) this.appInstance.routes = runtimeApp.routes;
41646
41790
  }
41647
41791
  bootstrapNavigation(launchOptions = createAppLaunchOptions("", {})) {
41648
- const isLaunching = !this.appInstance;
41649
- this.bootstrap(launchOptions);
41650
- return isLaunching ? this.currentPageInstance : null;
41792
+ if (this.appInstance) return null;
41793
+ this.startupNavigation.capture(() => {
41794
+ this.bootstrap(launchOptions);
41795
+ });
41796
+ if (launchOptions.path) {
41797
+ const query = new URLSearchParams(launchOptions.query).toString();
41798
+ this.reLaunch(`/${launchOptions.path}${query ? `?${query}` : ""}`);
41799
+ }
41800
+ this.startupNavigation.flush();
41801
+ return this.currentPageInstance;
41651
41802
  }
41652
41803
  reLaunch(url) {
41653
41804
  const target = this.resolveNavigationTarget(url);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-vite/miniprogram-automator",
3
3
  "type": "module",
4
- "version": "1.2.19",
4
+ "version": "1.2.20",
5
5
  "description": "完全兼容微信 miniprogram-automator 的现代化替代实现",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -44,7 +44,7 @@
44
44
  "node": "^20.19.0 || >=22.12.0"
45
45
  },
46
46
  "dependencies": {
47
- "@weapp-vite/qr": "1.1.4",
47
+ "@weapp-vite/qr": "1.1.5",
48
48
  "obug": "^3.0.0",
49
49
  "ws": "^8.21.3"
50
50
  },