@uni-helper/vite-plugin-uni-pages 0.3.8 → 0.3.10

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/client.d.ts CHANGED
@@ -6,6 +6,8 @@ declare module 'virtual:uni-pages' {
6
6
  export const subPackages: SubPackage[]
7
7
  }
8
8
 
9
- declare namespace globalThis {
10
- export const definePage: import('.').DefinePage
9
+ declare global {
10
+ const definePage: import('.').DefinePage
11
11
  }
12
+
13
+ export {}
package/dist/index.cjs CHANGED
@@ -81,8 +81,11 @@ function getDeclaration(ctx) {
81
81
  // @ts-nocheck
82
82
  // Generated by vite-plugin-uni-pages
83
83
 
84
+ type _LocationUrl =
85
+ ${allPagesPath.join(" |\n ")};
86
+
84
87
  interface NavigateToOptions {
85
- url: ${allPagesPath.join(" |\n ")};
88
+ url: _LocationUrl;
86
89
  }
87
90
  interface RedirectToOptions extends NavigateToOptions {}
88
91
 
@@ -98,6 +101,10 @@ declare interface Uni {
98
101
  switchTab(options: UniNamespace.SwitchTabOptions & SwitchTabOptions): void;
99
102
  reLaunch(options: UniNamespace.ReLaunchOptions & ReLaunchOptions): void;
100
103
  }
104
+
105
+ declare module "virtual:uni-pages" {
106
+ export type LocationUrl = _LocationUrl;
107
+ }
101
108
  `;
102
109
  return code;
103
110
  }
@@ -497,21 +504,21 @@ async function tryPageMetaFromCustomBlock(sfc, routeBlockLang) {
497
504
  return pageMeta;
498
505
  }
499
506
  function findMacro(stmts, filename) {
500
- const nodes = stmts.map((raw) => {
501
- let node = raw;
502
- if (raw.type === "ExpressionStatement")
503
- node = raw.expression;
504
- return astKit.isCallOf(node, "definePage") ? node : void 0;
505
- }).filter((node) => !!node);
506
- if (!nodes.length)
507
- return;
508
- if (nodes.length > 1) {
509
- throw new Error(`\u6BCF\u4E2A\u6587\u4EF6\u53EA\u5141\u8BB8\u8C03\u7528\u4E00\u6B21 definePage(): ${filename}`);
507
+ let macro;
508
+ for (const stmt of stmts) {
509
+ let node = stmt;
510
+ if (stmt.type === "ExpressionStatement")
511
+ node = stmt.expression;
512
+ if (astKit.isCallOf(node, "definePage")) {
513
+ macro = node;
514
+ break;
515
+ }
510
516
  }
511
- const macro = nodes[0];
517
+ if (!macro)
518
+ return;
512
519
  const [opt] = macro.arguments;
513
520
  if (opt && !t__namespace.isFunctionExpression(opt) && !t__namespace.isArrowFunctionExpression(opt) && !t__namespace.isObjectExpression(opt)) {
514
- debug.definePage(`definePage() only accept argument in function or object: ${filename}`);
521
+ debug.definePage(`definePage() \u53C2\u6570\u4EC5\u652F\u6301\u51FD\u6570\u6216\u5BF9\u8C61\uFF1A${filename}`);
515
522
  return;
516
523
  }
517
524
  return macro;
package/dist/index.mjs CHANGED
@@ -47,8 +47,11 @@ function getDeclaration(ctx) {
47
47
  // @ts-nocheck
48
48
  // Generated by vite-plugin-uni-pages
49
49
 
50
+ type _LocationUrl =
51
+ ${allPagesPath.join(" |\n ")};
52
+
50
53
  interface NavigateToOptions {
51
- url: ${allPagesPath.join(" |\n ")};
54
+ url: _LocationUrl;
52
55
  }
53
56
  interface RedirectToOptions extends NavigateToOptions {}
54
57
 
@@ -64,6 +67,10 @@ declare interface Uni {
64
67
  switchTab(options: UniNamespace.SwitchTabOptions & SwitchTabOptions): void;
65
68
  reLaunch(options: UniNamespace.ReLaunchOptions & ReLaunchOptions): void;
66
69
  }
70
+
71
+ declare module "virtual:uni-pages" {
72
+ export type LocationUrl = _LocationUrl;
73
+ }
67
74
  `;
68
75
  return code;
69
76
  }
@@ -463,21 +470,21 @@ async function tryPageMetaFromCustomBlock(sfc, routeBlockLang) {
463
470
  return pageMeta;
464
471
  }
465
472
  function findMacro(stmts, filename) {
466
- const nodes = stmts.map((raw) => {
467
- let node = raw;
468
- if (raw.type === "ExpressionStatement")
469
- node = raw.expression;
470
- return isCallOf(node, "definePage") ? node : void 0;
471
- }).filter((node) => !!node);
472
- if (!nodes.length)
473
- return;
474
- if (nodes.length > 1) {
475
- throw new Error(`\u6BCF\u4E2A\u6587\u4EF6\u53EA\u5141\u8BB8\u8C03\u7528\u4E00\u6B21 definePage(): ${filename}`);
473
+ let macro;
474
+ for (const stmt of stmts) {
475
+ let node = stmt;
476
+ if (stmt.type === "ExpressionStatement")
477
+ node = stmt.expression;
478
+ if (isCallOf(node, "definePage")) {
479
+ macro = node;
480
+ break;
481
+ }
476
482
  }
477
- const macro = nodes[0];
483
+ if (!macro)
484
+ return;
478
485
  const [opt] = macro.arguments;
479
486
  if (opt && !t.isFunctionExpression(opt) && !t.isArrowFunctionExpression(opt) && !t.isObjectExpression(opt)) {
480
- debug.definePage(`definePage() only accept argument in function or object: ${filename}`);
487
+ debug.definePage(`definePage() \u53C2\u6570\u4EC5\u652F\u6301\u51FD\u6570\u6216\u5BF9\u8C61\uFF1A${filename}`);
481
488
  return;
482
489
  }
483
490
  return macro;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uni-helper/vite-plugin-uni-pages",
3
3
  "type": "module",
4
- "version": "0.3.8",
4
+ "version": "0.3.10",
5
5
  "description": "File system based routing for uni-app applications using Vite",
6
6
  "author": "KeJun",
7
7
  "maintainers": [