vite-uni-dev-tool 0.0.3 → 0.0.5

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.
@@ -2,14 +2,13 @@ import { backup } from '../core';
2
2
  import { DevEvent } from '../devEvent';
3
3
  import type { DevTool } from '../type';
4
4
  import {
5
+ escapeHTML,
5
6
  getCurrentDate,
6
7
  getCurrentPagePath,
7
8
  serializeCircular,
8
9
  } from '../utils/index';
9
10
  import { isObject } from '../utils/language';
10
11
 
11
- import { getCurrentInstance } from 'vue';
12
-
13
12
  /**
14
13
  * 拦截器
15
14
  *
@@ -19,8 +18,6 @@ import { getCurrentInstance } from 'vue';
19
18
  export class DevIntercept {
20
19
  private event: DevEvent;
21
20
 
22
- vue3instance = getCurrentInstance();
23
-
24
21
  initPinia = false;
25
22
 
26
23
  constructor(options: DevTool.DevInterceptOptions) {
@@ -29,14 +26,7 @@ export class DevIntercept {
29
26
  }
30
27
 
31
28
  init(options: DevTool.DevInterceptOptions) {
32
- if (this.vue3instance) {
33
- this.vue3instance.appContext.config.errorHandler = (error) => {
34
- this.interceptErrorApp(error);
35
- };
36
- this.vue3instance.appContext.config.warnHandler = (msg: string) => {
37
- this.interceptWarnApp(msg);
38
- };
39
- }
29
+ this.interceptAppError();
40
30
 
41
31
  this.interceptAppConsole();
42
32
 
@@ -97,25 +87,82 @@ export class DevIntercept {
97
87
  };
98
88
  }
99
89
 
90
+ /**
91
+ * 拦截 vue3 信息
92
+ *
93
+ * @memberof DevIntercept
94
+ */
95
+ interceptVue3(vue3instance: any) {
96
+ if (vue3instance) {
97
+ // 微信小程序触发了该事件
98
+ vue3instance.appContext.config.errorHandler = (
99
+ error: Error,
100
+ vm: any,
101
+ info: string,
102
+ ) => {
103
+ if (this.event.getDevToolDestroy()) {
104
+ return;
105
+ }
106
+ this.interceptErrorVue3(error);
107
+ };
108
+ vue3instance.appContext.config.warnHandler = (
109
+ msg: string,
110
+ vm: any,
111
+ trace: string,
112
+ ) => {
113
+ if (this.event.getDevToolDestroy()) {
114
+ return;
115
+ }
116
+
117
+ this.interceptWarnVue3(msg + '\n' + trace);
118
+ };
119
+ }
120
+ }
121
+
122
+ /**
123
+ * app 中捕获全局错误
124
+ *
125
+ * @memberof DevIntercept
126
+ */
127
+ interceptAppError() {
128
+ uni.onError((error) => {
129
+ if (this.event.getDevToolDestroy()) {
130
+ return;
131
+ }
132
+
133
+ const info = error.toString();
134
+ const stack = (error as unknown as Error)?.stack?.split('\n')?.[1] ?? '';
135
+
136
+ this.event.updateConsoleList([
137
+ {
138
+ type: 'error',
139
+ args: [info],
140
+ position: getCurrentPagePath(),
141
+ time: getCurrentDate(),
142
+ stack,
143
+ },
144
+ ]);
145
+ });
146
+ }
147
+
100
148
  /**
101
149
  * 拦截 app 错误
102
150
  *
103
151
  * @param {*} error
104
152
  * @memberof DevIntercept
105
153
  */
106
- interceptErrorApp(error: any) {
107
- const path = getCurrentPagePath();
108
- const argList = error.toString();
154
+ interceptErrorVue3(error: Error) {
155
+ const stackList = error?.stack?.split('\n');
109
156
 
110
- const stack = new Error()?.stack?.split('\n').slice(2)?.[0];
157
+ const stack = stackList?.[1];
111
158
 
112
159
  console.error(error);
113
160
 
114
161
  this.event.updateConsoleList([
115
162
  {
116
163
  type: 'error',
117
- args: [argList],
118
- position: path,
164
+ args: [error.toString()],
165
+ position: getCurrentPagePath(),
119
166
  time: getCurrentDate(),
120
167
  stack,
121
168
  },
@@ -130,18 +177,26 @@ export class DevIntercept {
130
177
  * @return {*}
131
178
  * @memberof DevIntercept
132
179
  */
133
- interceptWarnApp(warn: any) {
180
+ interceptWarnVue3(warn: string) {
134
181
  if (this.preWarn === warn) return;
135
182
  this.preWarn = warn;
136
183
  const path = getCurrentPagePath();
137
- const stack = new Error()?.stack?.split('\n').slice(2)?.[0];
184
+
185
+ const stackList = new Error()?.stack?.split('\n');
186
+
187
+ const stack = stackList?.slice(2)?.[0];
138
188
 
139
189
  console.warn(warn);
140
190
 
191
+ const args = warn
192
+ .split('\n')
193
+ ?.map((item) => escapeHTML(item))
194
+ .join('\n');
195
+
141
196
  this.event.updateConsoleList([
142
197
  {
143
198
  type: 'warn',
144
- args: [warn.toString()],
199
+ args: [args],
145
200
  position: path,
146
201
  time: getCurrentDate(),
147
202
  stack,
@@ -9,6 +9,7 @@ import {
9
9
  getLanIp,
10
10
  getMicroAppIp,
11
11
  getWifiIp,
12
+ isBoolean,
12
13
  } from '../utils/index';
13
14
 
14
15
  /** 数据存储中心 */
@@ -131,6 +132,13 @@ export class DevStore {
131
132
  this.wsDataMaxSize = options.wsDataMaxSize || 1000;
132
133
  this.cacheMaxSize = options.cacheMaxSize || 8 * 1024 * 1024 * 10;
133
134
 
135
+ const devToolVisible = uni.getStorageSync(EVENT_DEV_BUTTON);
136
+ this.devToolVisible = isBoolean(devToolVisible)
137
+ ? devToolVisible
138
+ : (options.initShowDevTool ?? true);
139
+
140
+ this.setDevToolVisible(this.devToolVisible);
141
+
134
142
  const pages =
135
143
  options.pagesJson?.pages.map((page) => {
136
144
  const isNav = options.pagesJson?.tabBar?.list?.some(
@@ -138,9 +146,22 @@ export class DevStore {
138
146
  );
139
147
  return {
140
148
  ...page,
141
- isNav,
149
+ type: isNav ? 'nav' : 'main',
142
150
  };
143
151
  }) ?? [];
152
+
153
+ // 处理 subPackages
154
+ options.pagesJson?.subPackages?.forEach((pack) => {
155
+ pack.pages.forEach((page) => {
156
+ const p = {
157
+ ...page,
158
+ path: `${pack.root}/${page.path}`,
159
+ type: 'sub',
160
+ };
161
+ pages.push(p);
162
+ });
163
+ });
164
+
144
165
  this.setRouteList(pages);
145
166
  }
146
167
 
@@ -426,7 +447,7 @@ export class DevStore {
426
447
  const currentP = currentPath || pages?.[0]?.path || '';
427
448
  this.state.routeList = pages.map((item, index) => {
428
449
  return {
429
- isNav: item.isNav,
450
+ type: item.type,
430
451
  path: item.path,
431
452
  style: item.style,
432
453
  index:
@@ -455,7 +476,7 @@ export class DevStore {
455
476
  this.state.routeList =
456
477
  this.state.routeList?.map((item, index) => {
457
478
  return {
458
- isNav: item.isNav,
479
+ type: item.type,
459
480
  path: item.path,
460
481
  style: item.style,
461
482
  index:
package/dev/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { default as uniGlobalComponents } from './plugins/uniGlobalComponents/uniGlobalComponents';
2
- import { default as uniDevTool } from './plugins/uniDevTool/uniDevTool';
3
-
4
- export { uniDevTool, uniGlobalComponents };
5
- export default uniDevTool;
1
+ import { default as uniGlobalComponents } from './plugins/uniGlobalComponents/uniGlobalComponents';
2
+ import { default as uniDevTool } from './plugins/uniDevTool/uniDevTool';
3
+ export { uniDevTool, uniGlobalComponents };
4
+ export default uniDevTool;
6
5
  //# sourceMappingURL=index.d.ts.map
package/dev/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("./plugins/uniGlobalComponents/uniGlobalComponents.js"),e=require("./plugins/uniDevTool/uniDevTool.js");exports.uniGlobalComponents=o;exports.default=e;exports.uniDevTool=e;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("./plugins/uniGlobalComponents/uniGlobalComponents.js"),e=require("./plugins/uniDevTool/uniDevTool.js");exports.uniGlobalComponents=o;exports.default=e;exports.uniDevTool=e;
@@ -1,66 +1,72 @@
1
- import { Plugin } from 'vite';
2
-
3
- /**
4
- * vite-uni-dev-tool 插件
5
- *
6
- * 自动在 main.ts 中注入调试插件,并在每个页面的模板中注入 DevTool 组件。
7
- *
8
- * 如果组件不是用 template 定义的,则不会被该插件添加。
9
- *
10
- * 如果在编译成微信小程序(开发环境 hbuilder 4.29) 组件 <dev-tool ></dev-tool> 中没有内容,应该开启 supportWX: true, 该属性默认关闭
11
- *
12
- * @export
13
- * @param {{
14
- * pages: {
15
- * pages: {
16
- * path: string;
17
- * }[];
18
- * };
19
- * }} {
20
- * pages,
21
- * }
22
- * @return {*} {Plugin}
23
- */
24
- export default function uniDevTool({ pages, supportWX, ...reset }: {
25
- /** 是否拦截Promise.reject 最好不要拦截 默认禁用 */
26
- enableInterceptPromiseReject?: boolean;
27
- /** 打开窗口时隐藏按钮 */
28
- openWindowHideButton?: boolean;
29
- /** 最大的console条数 */
30
- consoleMaxSize?: number;
31
- /** 最大的网络请求条数 */
32
- networkMaxSize?: number;
33
- /** 最大的上传文件条数 */
34
- uploadMaxSize?: number;
35
- /** 最大的套接字消息条数 */
36
- wsDataMaxSize?: number;
37
- /** 最大占用缓存空间 bytes */
38
- cacheMaxSize?: number;
39
- /** 按钮大小 */
40
- buttonSize?: number;
41
- /** 按钮文本 */
42
- buttonText?: string;
43
- /** 按钮文本颜色 */
44
- buttonColor?: string;
45
- /** 按钮字体大小 */
46
- buttonFontSize?: string;
47
- /** 按钮背景颜色 */
48
- buttonBackgroundColor?: string;
49
- /** 初始化时是否显示调试按钮,默认显示 */
50
- initShowDevTool?: boolean;
51
- /**
52
- * 在 hbuilder 4.29 可开发环境中无法正确的将 DevTool 组件编译完整 只有 wxml 文件其他是缺失的,开启该项将不使用 app.component('DevTool', DevTool) 方式注册组件, 将在每个 page 中直接引入组件
53
- *
54
- * 在 hbuilder 4.66 中还是这样...
55
- *
56
- * 打包构建完成之后 组件编译是完整的,可以关闭该项
57
- */
58
- supportWX?: boolean;
59
- /** 页面配置 用于读取路由 */
60
- pages: {
61
- pages: {
62
- path: string;
63
- }[];
64
- };
65
- }): Plugin;
1
+ import { Plugin } from 'vite';
2
+ /**
3
+ * vite-uni-dev-tool 插件
4
+ *
5
+ * 自动在 main.ts 中注入调试插件,并在每个页面的模板中注入 DevTool 组件。
6
+ *
7
+ * 如果组件不是用 template 定义的,则不会被该插件添加。
8
+ *
9
+ *
10
+ * @export
11
+ * @param {{
12
+ * pages: {
13
+ * pages: {
14
+ * path: string;
15
+ * }[];
16
+ * };
17
+ * }} {
18
+ * pages,
19
+ * }
20
+ * @return {*} {Plugin}
21
+ */
22
+ export default function uniDevTool({ pages, sourceFileServers, ...reset }: {
23
+ /** 是否拦截Promise.reject 最好不要拦截 默认禁用 */
24
+ enableInterceptPromiseReject?: boolean;
25
+ /** 打开窗口时隐藏按钮 */
26
+ openWindowHideButton?: boolean;
27
+ /** 最大的console条数 */
28
+ consoleMaxSize?: number;
29
+ /** 最大的网络请求条数 */
30
+ networkMaxSize?: number;
31
+ /** 最大的上传文件条数 */
32
+ uploadMaxSize?: number;
33
+ /** 最大的套接字消息条数 */
34
+ wsDataMaxSize?: number;
35
+ /** 最大占用缓存空间 bytes */
36
+ cacheMaxSize?: number;
37
+ /** 按钮大小 */
38
+ buttonSize?: number;
39
+ /** 按钮文本 */
40
+ buttonText?: string;
41
+ /** 按钮文本颜色 */
42
+ buttonColor?: string;
43
+ /** 按钮字体大小 */
44
+ buttonFontSize?: string;
45
+ /** 按钮背景颜色 */
46
+ buttonBackgroundColor?: string;
47
+ /** 初始化时是否显示调试按钮,默认显示 */
48
+ initShowDevTool?: boolean;
49
+ /**
50
+ * 该属性处于实验当中,谨慎使用
51
+ * 读取开发环境 source file,source map,默认 禁用
52
+ */
53
+ useDevSource?: boolean;
54
+ /**
55
+ * 该属性处于实验当中,谨慎使用
56
+ * 开发环境 source file 服务器地址,默认 [] ,配合 useDevSource 使用
57
+ */
58
+ sourceFileServers?: string[];
59
+ /** 页面配置 用于读取路由 */
60
+ pages: {
61
+ pages: {
62
+ path: string;
63
+ }[];
64
+ subPackages?: {
65
+ root: string;
66
+ pages: {
67
+ path: string;
68
+ }[];
69
+ }[];
70
+ };
71
+ }): Plugin;
66
72
  //# sourceMappingURL=uniDevTool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uniDevTool.d.ts","sourceRoot":"","sources":["../../../../plugins/src/plugins/uniDevTool/uniDevTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAkBnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,KAAK,EACL,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,qCAAqC;IACrC,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,gBAAgB;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,mBAAmB;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,WAAW;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa;IACb,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,wBAAwB;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,kBAAkB;IAClB,KAAK,EAAE;QACL,KAAK,EAAE;YACL,IAAI,EAAE,MAAM,CAAC;SACd,EAAE,CAAC;KACL,CAAC;CACH,GAAG,MAAM,CAkHT"}
1
+ {"version":3,"file":"uniDevTool.d.ts","sourceRoot":"","sources":["../../../../plugins/src/plugins/uniDevTool/uniDevTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAsBnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,KAAK,EACL,iBAAiB,EACjB,GAAG,KAAK,EACT,EAAE;IACD,qCAAqC;IACrC,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,gBAAgB;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,mBAAmB;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qBAAqB;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa;IACb,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,wBAAwB;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,kBAAkB;IAClB,KAAK,EAAE;QACL,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC1B,WAAW,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAA;aAAE,EAAE,CAAA;SAAE,EAAE,CAAC;KAC7D,CAAC;CACH,GAAG,MAAM,CAiOT"}
@@ -1,13 +1,38 @@
1
- "use strict";const u=/<template[^>]*>([\s\S]*?)<\/template>/,v=/<script[^>]*>([\s\S]*?)<\/script>/;function f(p,s){for(let i=0;i<p.length;i++)if(s(p[i]))return i+1;return-1}function T({pages:p,supportWX:s,...i}){return{name:"vite-uni-dev-tool",enforce:"pre",transform(e,m){if(m.endsWith("/src/main.ts"))try{const r=e.split(`
2
- `);let n=[...r];const c=f(n,t=>t.trim().startsWith("import")||t.trim().startsWith("export"));c!==-1&&n.splice(c,0,s?"":"import DevTool from 'vite-uni-dev-tool/dev/components/DevTool/index.vue';","import { initDevTool } from 'vite-uni-dev-tool/dev/core';","import pagesJson from './pages.json';");const o=f(n,t=>t.includes(".mount(")||t.includes("createApp("));if(o!==-1&&n.splice(o+1,0,s?"":" app.component('DevTool', DevTool);",` initDevTool({
3
- pagesJson,
4
- ...${JSON.stringify(i)}
5
- });`),n.length!==r.length)return{code:n.join(`
6
- `),map:null}}catch(r){return console.error("[DevTool] 转换 main 文件时出错:",r),{code:e,map:null}}if(m.endsWith(".vue")){const r=e.includes("<template>"),n=p.pages.some(o=>m.includes(o.path)),c=["<DevTool />"];if(n&&r){const o=e.match(u);let t=e;if(o&&o[1]){const a=`${o[1].trim()}
7
- ${c.join(`
8
- `)}`;t=e.replace(u,`<template>
9
- ${a}
10
- </template>`)}if(s){const l=e.match(v);if(l&&l[1]){const d=`import DevTool from 'vite-uni-dev-tool/dev/components/DevTool/index.vue';
11
- ${l[1].trim()}`;t=t.replace(v,`<script lang="ts" setup>
12
- ${d}
13
- <\/script>`)}}return{code:t,map:null}}}return{code:e,map:null}}}}module.exports=T;
1
+ "use strict";const I=require("path"),S=require("fs"),l=require("../utils/index.js");function C(a){const d=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const u in a)if(u!=="default"){const e=Object.getOwnPropertyDescriptor(a,u);Object.defineProperty(d,u,e.get?e:{enumerable:!0,get:()=>a[u]})}}return d.default=a,Object.freeze(d)}const D=C(I),y=C(S),_=/<template[^>]*>([\s\S]*?)<\/template>/,h=/<script[^>]*>([\s\S]*?)<\/script>/,g={isReady:!1,urls:[]};function T({pages:a,sourceFileServers:d,...u}){return{name:"vite-uni-dev-tool",enforce:"pre",configureServer(e){var p;e.middlewares.use((s,n,t)=>{const{originalUrl:r}=s;if(u.useDevSource&&(r!=null&&r.includes("__dev_sourcefile__"))){const i=r.replace("/__dev_sourcefile__","");try{const c=e.config.root,m=D.join(c,i),o=y.readFileSync(m,"utf-8");n.setHeader("Content-Type",l.getContentType(m)),n.end(o)}catch{t()}}else t()}),(p=e.httpServer)==null||p.once("listening",()=>{var t;const s=(t=e.httpServer)==null?void 0:t.address(),n=l.getLocalIPs();if(s&&!Array.isArray(s)&&typeof s!="string"){const r=n.map(i=>`http://${i}:${s.port}/__dev_sourcefile__`);g.isReady=!0,g.urls=r,console.warn(`
2
+ ⚡️ vite-uni-dev-tool source file server running at:
3
+ ${n.map(i=>`➜ Source File Network: http://${i}:${s==null?void 0:s.port}/__dev_sourcefile__`).join(`
4
+ `)}
5
+ `)}})},transform(e,p){var s;if(p.endsWith("/src/main.ts"))try{const n=e.split(`
6
+ `);let t=[...n];const r=l.findInsertionIndex(t,c=>c.trim().startsWith("import")||c.trim().startsWith("export"));r!==-1&&t.splice(r,0,"import DevTool from 'vite-uni-dev-tool/dev/components/DevTool/index.vue';");const i=l.findInsertionIndex(t,c=>c.includes(".mount(")||c.includes("createApp("));if(i!==-1&&t.splice(i+1,0," app.component('DevTool', DevTool);"),t.length!==n.length)return{code:t.join(`
7
+ `),map:null}}catch(n){return console.error("[DevTool] 转换 main 文件时出错:",n),{code:e,map:null}}if(p.endsWith("/src/App.vue")){const n=e.match(h);if(n&&n[1]){const t=n[1].trim(),r=l.hasImportCurrentInstance(t),i=l.hasImportOnLaunch(t),c=r?"":"import { getCurrentInstance } from 'vue'",m=i?"":"import { onLaunch } from '@dcloudio/uni-app'",o=`
8
+ import { initDevTool, console } from 'vite-uni-dev-tool/dev/core';
9
+ import pagesJson from './pages.json';
10
+ ${t}
11
+ onLaunch(() => {
12
+ const vue3instance = getCurrentInstance();
13
+ initDevTool({
14
+ pagesJson,
15
+ vue3instance,
16
+ mode: import.meta.env.MODE,
17
+ sourceFileServers: [
18
+ ${[...g.urls??[],...d??[]].map(v=>`'${v}'`)}
19
+ ],
20
+ useDevSource: ${u.useDevSource},
21
+ ...${JSON.stringify(u)},
22
+ });
23
+ });`;return{code:e.replace(h,`
24
+ <script lang="ts" setup>
25
+ ${c}
26
+ ${m}
27
+ ${o}
28
+ <\/script>`),map:null}}return{code:e,map:null}}if(p.endsWith(".vue")){const n=e.includes("<template>"),t=a.pages.some(o=>p.includes(o.path)),r=(s=a.subPackages)==null?void 0:s.some(o=>o.pages.some(f=>p.includes(`${o.root}/${f.path}`))),i=["<DevTool />"],c=l.hasImportConsole(e),m=l.hasUseConsole(e);if(!c&&m&&!p.endsWith("/src/App.vue")){const o=e.match(h);if(o&&o[1]){const v=`
29
+ import { console } from 'vite-uni-dev-tool/dev/core';
30
+ ${o[1]}
31
+ `;e=e.replace(h,`
32
+ <script lang="ts" setup>
33
+ ${v}
34
+ <\/script>`)}}if((t||r)&&n){const o=e.match(_);let f=e;if(o&&o[1]){const $=`${o[1].trim()}
35
+ ${i.join(`
36
+ `)}`;f=e.replace(_,`<template>
37
+ ${$}
38
+ </template>`)}return{code:f,map:null}}}return{code:e,map:null}}}}module.exports=T;
@@ -1,28 +1,33 @@
1
- import { Plugin } from 'vite';
2
-
3
- /**
4
- * uni-global-components 插件,用于在页面中添加全局组件
5
- *
6
- * 该插件会在每个页面的template中添加全局组件,以达到全局组件的效果。
7
- *
8
- * 如果组件不是用 template 定义的,则不会被该插件添加。
9
- *
10
- * @export
11
- * @param {{
12
- * pages: { pages: { path: string }[] };
13
- * components: string[];
14
- * }} {
15
- * pages,
16
- * components
17
- * }
18
- * @return {*} {Plugin}
19
- */
20
- export default function uniGlobalComponents({ pages, components, }: {
21
- pages: {
22
- pages: {
23
- path: string;
24
- }[];
25
- };
26
- components: string[];
27
- }): Plugin;
1
+ import { Plugin } from 'vite';
2
+ /**
3
+ * uni-global-components 插件,用于在页面中添加全局组件
4
+ *
5
+ * 该插件会在每个页面的template中添加全局组件,以达到全局组件的效果。
6
+ *
7
+ * 如果组件不是用 template 定义的,则不会被该插件添加。
8
+ *
9
+ * @export
10
+ * @param {{
11
+ * pages: { pages: { path: string }[] };
12
+ * components: string[];
13
+ * }} {
14
+ * pages,
15
+ * components
16
+ * }
17
+ * @return {*} {Plugin}
18
+ */
19
+ export default function uniGlobalComponents({ pages, components, }: {
20
+ pages: {
21
+ pages: {
22
+ path: string;
23
+ }[];
24
+ subPackages?: {
25
+ root: string;
26
+ pages: {
27
+ path: string;
28
+ }[];
29
+ }[];
30
+ };
31
+ components: string[];
32
+ }): Plugin;
28
33
  //# sourceMappingURL=uniGlobalComponents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uniGlobalComponents.d.ts","sourceRoot":"","sources":["../../../../plugins/src/plugins/uniGlobalComponents/uniGlobalComponents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,KAAK,EACL,UAAU,GACX,EAAE;IACD,KAAK,EAAE;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAAE,CAAC;IACrC,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,GAAG,MAAM,CAmCT"}
1
+ {"version":3,"file":"uniGlobalComponents.d.ts","sourceRoot":"","sources":["../../../../plugins/src/plugins/uniGlobalComponents/uniGlobalComponents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAsBnC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,KAAK,EACL,UAAU,GACX,EAAE;IACD,KAAK,EAAE;QACL,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC1B,WAAW,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAA;aAAE,EAAE,CAAA;SAAE,EAAE,CAAC;KAC7D,CAAC;IACF,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,GAAG,MAAM,CAsFT"}
@@ -1,5 +1,9 @@
1
- "use strict";const o=/<template[^>]*>([\s\S]*?)<\/template>/;function m({pages:s,components:a}){return{name:"uni-global-components",enforce:"pre",transform(t,n){if(n.endsWith(".vue")){const l=t.includes("<template>");if(s.pages.some(e=>n.includes(e.path))&&l){const e=t.match(o);if(e&&e[1]){const p=`${e[1].trim()}
2
- ${a.join(`
3
- `)}`;return{code:t.replace(o,`<template>
4
- ${p}
5
- </template>`),map:null}}}}return{code:t,map:null}}}}module.exports=m;
1
+ "use strict";const d=require("path"),g=require("fs"),f=require("../utils/index.js");function _(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const r=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(a,e,r.get?r:{enumerable:!0,get:()=>s[e]})}}return a.default=s,Object.freeze(a)}const h=_(d),y=_(g),m=/<template[^>]*>([\s\S]*?)<\/template>/;function $({pages:s,components:a}){return{name:"uni-global-components",enforce:"pre",configureServer(e){var r;e.middlewares.use((t,c,i)=>{const{originalUrl:n}=t;if(n!=null&&n.includes("__dev_sourcefile__")){const o=n.replace("/__dev_sourcefile__","");try{const l=e.config.root,u=h.join(l,o),p=y.readFileSync(u,"utf-8");c.setHeader("Content-Type",f.getContentType(u)),c.end(p)}catch{i()}}else i()}),(r=e.httpServer)==null||r.once("listening",()=>{var i;const t=(i=e.httpServer)==null?void 0:i.address(),c=f.getLocalIPs();t&&!Array.isArray(t)&&typeof t!="string"&&(c.map(n=>`http://${n}:${t.port}/__dev_sourcefile__`),console.warn(`
2
+ ⚡️ vite-uni-dev-tool source file server running at:
3
+ ${c.map(n=>`➜ Source File Network: http://${n}:${t==null?void 0:t.port}/__dev_sourcefile__`).join(`
4
+ `)}
5
+ `))})},transform(e,r){var t;if(r.endsWith(".vue")){const c=e.includes("<template>"),i=s.pages.some(o=>r.includes(o.path)),n=(t=s.subPackages)==null?void 0:t.some(o=>o.pages.some(l=>r.includes(`${o.root}/${l.path}`)));if((i||n)&&c){const o=e.match(m);if(o&&o[1]){const u=`${o[1].trim()}
6
+ ${a.join(`
7
+ `)}`;return{code:e.replace(m,`<template>
8
+ ${u}
9
+ </template>`),map:null}}}}return{code:e,map:null}}}}module.exports=$;
@@ -0,0 +1,53 @@
1
+ export declare function findInsertionIndex(lines: string[], condition: (p: string) => boolean): number;
2
+ export declare function getContentType(filePath: string): string;
3
+ export declare function getLocalIPs(): string[];
4
+ export declare function hasImportOnLaunch(str: string): boolean;
5
+ export declare function hasImportCurrentInstance(str: string): boolean;
6
+ export declare function hasImportConsole(str: string): boolean;
7
+ export declare function hasUseConsole(str: string): boolean;
8
+ /**
9
+ * 解析栈信息
10
+ *
11
+ * @export
12
+ * @param {string} stock
13
+ * @return {*}
14
+ */
15
+ export declare function parseStock(stock: string): {
16
+ info: string;
17
+ path: string;
18
+ row: number;
19
+ col: number;
20
+ };
21
+ /**
22
+ * 在字符串中获取url
23
+ *
24
+ * @export
25
+ * @param {string} text
26
+ * @return {*}
27
+ */
28
+ export declare function extractUrl(text: string): string;
29
+ /**
30
+ * 在字符串中获取路径
31
+ *
32
+ * @export
33
+ * @param {string} text
34
+ * @return {*}
35
+ */
36
+ export declare function extractPath(text: string): string;
37
+ /**
38
+ * 获取文件内的行内sourcemap
39
+ *
40
+ * @export
41
+ * @param {string} text
42
+ * @return {*}
43
+ */
44
+ export declare function extractSourceMap(text: string): string;
45
+ /**
46
+ * 解析url中的参数
47
+ *
48
+ * @export
49
+ * @param {string} queryString
50
+ * @return {*}
51
+ */
52
+ export declare function parseQueryString(queryString: string): any;
53
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../plugins/src/plugins/utils/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EAAE,EACf,SAAS,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,GAChC,MAAM,CAOR;AAGD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,UAe9C;AAGD,wBAAgB,WAAW,aAiB1B;AAKD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEtD;AAKD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7D;AAID,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAGD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAID;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM;;;;;EAQvC;AAGD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,UAGtC;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAGvC;AAID;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,UAG5C;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,OA4BnD"}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("path"),a=require("os");function r(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,o.get?o:{enumerable:!0,get:()=>t[e]})}}return n.default=t,Object.freeze(n)}const u=r(c),i=r(a);function p(t,n){for(let e=0;e<t.length;e++)if(n(t[e]))return e+1;return-1}function f(t){const n=u.extname(t).toLowerCase();return{".html":"text/html",".js":"text/javascript",".css":"text/css",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".woff":"font/woff",".woff2":"font/woff2"}[n]||"text/plain"}function l(){const t=i.networkInterfaces(),n=[];return Object.keys(t).forEach(e=>{var o;t!=null&&t[e]&&Array.isArray(t==null?void 0:t[e])&&((o=t==null?void 0:t[e])==null||o.forEach(s=>{s.family==="IPv4"&&!s.internal&&n.push(s.address)}))}),n.push("localhost"),n}const g=/import\s*\{[^}]*onLaunch[^}]*\}\s*from\s+['"]@dcloudio\/uni-app['"];?/;function m(t){return g.test(t)}const h=/import\s*\{[^}]*getCurrentInstance[^}]*\}\s*from\s+['"]vue['"];?/;function I(t){return h.test(t)}const d=/import\s*\{[^}]*console[^}]*\}\s*from\s+['"]vite-uni-dev-tool['"];?/;function y(t){return d.test(t)}const j=/console\.\w+\(/;function C(t){return j.test(t)}exports.findInsertionIndex=p;exports.getContentType=f;exports.getLocalIPs=l;exports.hasImportConsole=y;exports.hasImportCurrentInstance=I;exports.hasImportOnLaunch=m;exports.hasUseConsole=C;
package/dev/type.ts CHANGED
@@ -5,7 +5,7 @@ export declare namespace DevTool {
5
5
  path: string;
6
6
  sort?: number;
7
7
  name?: string;
8
- isNav?: boolean;
8
+ type?: string;
9
9
  style: {
10
10
  navigationBarTitleText?: string;
11
11
  };
@@ -39,6 +39,7 @@ export declare namespace DevTool {
39
39
  };
40
40
  type PagesJSON = {
41
41
  pages: Page[];
42
+ subPackages?: { root: string; pages: Page[] }[];
42
43
  tabBar: {
43
44
  list: Nav[];
44
45
  };
@@ -61,6 +62,17 @@ export declare namespace DevTool {
61
62
  cacheMaxSize?: number;
62
63
  /** 所有路由信息 */
63
64
  pagesJson?: PagesJSON;
65
+ /** 源文件服务地址 */
66
+ sourceFileServers?: string[];
67
+ /** 用于区分生产环境和开发环境,开发环境下,为了获取 Android 异常栈源码会获取本地源码进行展示 */
68
+ mode: string;
69
+ /** 用于捕获 vue3 抛出的错误和警告 */
70
+ vue3instance?: any;
71
+ /**
72
+ * 该属性处于实验当中,谨慎使用
73
+ * 读取开发环境 source file,source map,默认 禁用
74
+ */
75
+ useDevSource?: boolean;
64
76
  } & ButtonOptions;
65
77
 
66
78
  type ButtonOptions = Partial<{
@@ -0,0 +1,6 @@
1
+ export declare function findInsertionIndex(lines: string[], condition: (p: string) => boolean): number;
2
+ export declare function getContentType(filePath: string): string;
3
+ export declare function getLocalIPs(): string[];
4
+ export declare function hasImportOnLaunch(str: string): boolean;
5
+ export declare function hasImportCurrentInstance(str: string): boolean;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -20,6 +20,15 @@ export { getCurrentPagePath } from './page';
20
20
 
21
21
  export { getCurrentDate, formatDate, sleep } from './date';
22
22
 
23
- export { hightLight } from './string';
23
+ export {
24
+ hightLight,
25
+ escapeHTML,
26
+ extractUrl,
27
+ extractRowAndCol,
28
+ parseStock,
29
+ isMockWX,
30
+ } from './string';
24
31
 
25
32
  export { getWifiIp, getDeviceMac, getLanIp, getMicroAppIp } from './ip';
33
+
34
+ export { isAndroid, isH5, isWX } from './platform';