vite-plugin-debugger 0.2.0-beta.3 → 0.3.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.
@@ -0,0 +1,22 @@
1
+ import { InitOptions } from 'eruda';
2
+ export { InitOptions } from 'eruda';
3
+ import { S as SharedConfig, C as CommonConfig } from './index.d-D0Oa6UqJ.js';
4
+ import { Plugin } from 'vite';
5
+
6
+ interface ErudaConfig extends CommonConfig {
7
+ /**
8
+ * eruda options
9
+ *
10
+ * @see https://github.com/liriliri/eruda/blob/master/doc/API.md
11
+ */
12
+ options?: InitOptions;
13
+ }
14
+ interface ErudaDebuggerOptions extends SharedConfig {
15
+ /**
16
+ * eruda config
17
+ */
18
+ config?: ErudaConfig;
19
+ }
20
+ declare function vDebugger(options: ErudaDebuggerOptions): Plugin;
21
+
22
+ export { vDebugger as default, vDebugger };
package/dist/eruda.js ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ eruda_default,
3
+ vDebugger
4
+ } from "./chunk-M5FN5N6N.js";
5
+ import "./chunk-WG6FWYWY.js";
6
+ export {
7
+ eruda_default as default,
8
+ vDebugger
9
+ };
@@ -0,0 +1,48 @@
1
+ type CDN = 'jsdelivr' | 'unpkg' | 'cdnjs' | 'staticfile'
2
+
3
+ interface CommonConfig {
4
+ /**
5
+ * cdn services
6
+ */
7
+ cdn?: CDN
8
+ /**
9
+ * custom cdn url
10
+ */
11
+ src?: string
12
+ }
13
+
14
+ interface ActiveConfig {
15
+ /**
16
+ * define is active override debug
17
+ */
18
+ override?: boolean
19
+ /**
20
+ * use url or storage
21
+ */
22
+ mode: 'url' | 'storage'
23
+ /**
24
+ * parameter name
25
+ */
26
+ param: string
27
+ }
28
+
29
+ interface SharedConfig {
30
+ /**
31
+ * debug or not
32
+ */
33
+ debug?: boolean
34
+ /**
35
+ * active debugger
36
+ */
37
+ active?: ActiveConfig
38
+ /**
39
+ * use node_modules
40
+ */
41
+ local?: boolean
42
+ /**
43
+ * if local is true, use this to specify the path
44
+ */
45
+ entry?: string | string[]
46
+ }
47
+
48
+ export type { CommonConfig as C, SharedConfig as S };
package/dist/index.d.ts CHANGED
@@ -1,89 +1,6 @@
1
- import { Plugin } from 'vite';
2
- import { InitOptions } from 'eruda';
3
- import { VConsoleOptions } from 'core/options.interface';
4
-
5
- type CDN = 'jsdelivr' | 'unpkg' | 'cdnjs';
6
-
7
- type ErudaPlugin = 'fps' | 'features' | 'timing' | 'memory' | 'code' | 'benchmark' | 'geolocation' | 'dom' | 'orientation' | 'touches';
8
- interface ErudaConfig extends CommonConfig {
9
- /**
10
- * eruda options
11
- *
12
- * see also https://github.com/liriliri/eruda/blob/master/doc/API.md
13
- */
14
- options?: InitOptions;
15
- /**
16
- * eruda plugins
17
- *
18
- * see also https://github.com/liriliri/eruda#plugins
19
- */
20
- plugins?: ErudaPlugin[] | {
21
- name: ErudaPlugin;
22
- src: string;
23
- }[];
24
- }
25
-
26
- interface VConsoleConfig extends CommonConfig {
27
- /**
28
- * vConsole options
29
- *
30
- * see also https://github.com/Tencent/vConsole/blob/dev/doc/public_properties_methods.md#vconsoleoption
31
- */
32
- options?: VConsoleOptions;
33
- }
34
-
35
- interface CommonConfig {
36
- /**
37
- * cdn services
38
- */
39
- cdn?: CDN
40
- /**
41
- * custom cdn url
42
- */
43
- src?: string
44
- }
45
-
46
- interface ActiveConfig {
47
- /**
48
- * define is active override debug
49
- */
50
- override?: boolean
51
- /**
52
- * use url or storage
53
- */
54
- mode: 'url' | 'storage'
55
- /**
56
- * parameter name
57
- */
58
- param: string
59
- }
60
- interface DebuggerOptions {
61
- /**
62
- * debug or not
63
- */
64
- debug?: boolean
65
- /**
66
- * active debugger
67
- */
68
- active?: ActiveConfig
69
- /**
70
- * use node_modules
71
- */
72
- local?: boolean
73
- /**
74
- * if local is true, use this to specify the path
75
- */
76
- entry?: string | string[]
77
- /**
78
- * eruda config
79
- */
80
- eruda?: ErudaConfig
81
- /**
82
- * vConsole config
83
- */
84
- vConsole?: VConsoleConfig
85
- }
86
-
87
- declare const vDebugger: (options: DebuggerOptions) => Plugin;
88
-
89
- export { vDebugger as default, vDebugger };
1
+ export { default as eruda } from './eruda.js';
2
+ export { default as vConsole } from './vconsole.js';
3
+ import 'eruda';
4
+ import './index.d-D0Oa6UqJ.js';
5
+ import 'vite';
6
+ import 'core/options.interface';
package/dist/index.js CHANGED
@@ -1,248 +1,11 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/index.ts
20
- var src_exports = {};
21
- __export(src_exports, {
22
- default: () => src_default,
23
- vDebugger: () => vDebugger
24
- });
25
- module.exports = __toCommonJS(src_exports);
26
- var import_vite = require("vite");
27
-
28
- // src/helpers/index.ts
29
- var capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
30
- var transformCDN = (pkg, cdn) => {
31
- if (cdn === "jsdelivr") {
32
- if (Array.isArray(pkg)) {
33
- return `https://cdn.jsdelivr.net/combine/${pkg.map((p) => `npm/${p}`).join(",")}`;
34
- }
35
- return `https://cdn.jsdelivr.net/npm/${pkg}`;
36
- }
37
- if (cdn === "unpkg") {
38
- return `https://unpkg.com/${pkg}`;
39
- }
40
- if (cdn === "cdnjs") {
41
- if (!Array.isArray(pkg)) {
42
- if (pkg === "eruda") {
43
- return "https://cdnjs.cloudflare.com/ajax/libs/eruda/3.0.1/eruda.min.js";
44
- }
45
- throw new Error(`[vite-plugin-debugger]: ${cdn} only support eruda without its plugins.`);
46
- }
47
- return `https://cdnjs.cloudflare.com/ajax/libs/${pkg}`;
48
- }
49
- return "";
50
- };
51
- var debugInit = (debug, active) => {
52
- return `
53
- const activeConfig = ${!!active}
54
- const activePriority = ${active == null ? void 0 : active.override}
55
- let showDebug = false;
56
- let storageStr = ''
57
- if(${(active == null ? void 0 : active.mode) === "url"}){
58
- let queryStr='';
59
- const result = (window.location.href || '').match(new RegExp('[?&]${active == null ? void 0 : active.param}=([^&]+)', 'i'));
60
- if (Array.isArray(result) && result.length > 1) queryStr = result[1];
61
- if (queryStr) localStorage.setItem('${active == null ? void 0 : active.param}', queryStr);
62
- }
63
- if(${(active == null ? void 0 : active.mode) === "url" || (active == null ? void 0 : active.mode) === "storage"}){
64
- storageStr = localStorage.getItem('${active == null ? void 0 : active.param}')
65
- }
66
- if(activeConfig){
67
- if(activePriority){
68
- if (storageStr){ showDebug = true };
69
- } else {
70
- if (${debug} && storageStr){ showDebug = true };
71
- }
72
- } else {
73
- showDebug = ${debug}
74
- }
75
- `;
76
- };
77
-
78
- // src/plugins/eruda.ts
79
- var transformErudaOptions = (html, opts) => {
80
- const { debug, active } = opts;
81
- const { options, plugins, cdn = "jsdelivr", src } = opts.eruda;
82
- const tags = [];
83
- tags.push({
84
- tag: "script",
85
- attrs: {
86
- src: src || transformCDN("eruda", cdn)
87
- },
88
- injectTo: "head"
89
- });
90
- let erudaScript = `eruda.init(${JSON.stringify(options || {})});`;
91
- if (plugins && plugins.length > 0) {
92
- if (cdn === "jsdelivr") {
93
- tags.push({
94
- tag: "script",
95
- attrs: {
96
- src: transformCDN(
97
- plugins.map((plugin) => `eruda-${plugin}`),
98
- cdn
99
- )
100
- },
101
- injectTo: "head"
102
- });
103
- } else {
104
- plugins.forEach((plugin) => {
105
- tags.push({
106
- tag: "script",
107
- attrs: {
108
- src: typeof plugin === "string" ? transformCDN(`eruda-${plugin}`, cdn) : plugin.src
109
- },
110
- injectTo: "head"
111
- });
112
- });
113
- }
114
- plugins.forEach((plugin) => {
115
- erudaScript += `eruda.add(eruda${capitalize(typeof plugin === "string" ? plugin : plugin.name)});
116
- `;
117
- });
118
- }
119
- tags.push({
120
- tag: "script",
121
- children: `${debugInit(debug, active)}
122
- if(showDebug===true){ ${erudaScript}}`,
123
- injectTo: "head"
124
- });
125
- if (debug !== void 0) {
126
- return {
127
- html,
128
- tags
129
- };
130
- }
131
- if (process.env.NODE_ENV !== "production") {
132
- return {
133
- html,
134
- tags
135
- };
136
- }
137
- };
138
- var transformErudaImport = (code, opts) => {
139
- const { debug, active } = opts;
140
- const { options = {}, plugins } = opts.eruda;
141
- let importCode = "import eruda from 'eruda';";
142
- let erudaScript = `eruda.init(${JSON.stringify(options)});`;
143
- if (plugins && plugins.length > 0) {
144
- plugins.forEach((plugin) => {
145
- importCode += `import eruda${capitalize(typeof plugin === "string" ? plugin : plugin.name)} from 'eruda-${typeof plugin === "string" ? plugin : plugin.name}';`;
146
- erudaScript += `eruda.add(eruda${capitalize(typeof plugin === "string" ? plugin : plugin.name)});`;
147
- });
148
- }
149
- return {
150
- code: `/* eslint-disable */;
151
- ${importCode}
152
- ${debugInit(
153
- debug,
154
- active
155
- )}if(showDebug===true){${erudaScript}}
156
- /* eslint-enable */
157
- ${code}`,
158
- map: null
159
- };
160
- };
161
-
162
- // src/plugins/vConsole.ts
163
- var transformVConsoleOptions = (html, opts) => {
164
- const { debug, active } = opts;
165
- const { options, cdn = "jsdelivr", src } = opts.vConsole;
166
- const tags = [];
167
- tags.push({
168
- tag: "script",
169
- attrs: {
170
- src: src || transformCDN("vconsole", cdn)
171
- },
172
- injectTo: "head"
173
- });
174
- tags.push({
175
- tag: "script",
176
- children: `${debugInit(debug, active)}
177
- if(showDebug===true){var vConsole = new VConsole(${JSON.stringify(
178
- options || {}
179
- )})};`,
180
- injectTo: "head"
181
- });
182
- if (debug !== void 0) {
183
- return {
184
- html,
185
- tags
186
- };
187
- }
188
- if (process.env.NODE_ENV !== "production") {
189
- return {
190
- html,
191
- tags
192
- };
193
- }
194
- };
195
- var transformVConsoleImport = (code, opts) => {
196
- const { debug, active } = opts;
197
- const { options = {} } = opts.vConsole;
198
- return {
199
- code: `/* eslint-disable */;import VConsole from 'vconsole'; ${debugInit(
200
- debug,
201
- active
202
- )}
203
- if(showDebug===true){new VConsole(${JSON.stringify(options)})};/* eslint-enable */${code}`,
204
- map: null
205
- };
206
- };
207
-
208
- // src/index.ts
209
- var vDebugger = (options) => {
210
- const { eruda, vConsole, local, entry } = options;
211
- const entryPath = entry ? (Array.isArray(entry) ? entry : [entry]).map((path) => (0, import_vite.normalizePath)(path)) : [];
212
- if (eruda && vConsole) {
213
- throw new Error("[vite-plugin-debugger]: You'd better use only one debugger tool at a time.");
214
- }
215
- if (!eruda && !vConsole) {
216
- throw new Error("[vite-plugin-debugger]: Which one do you prefer? eruda or vConsole?");
217
- }
218
- return {
219
- name: "vite-plugin-debugger",
220
- transformIndexHtml(html) {
221
- if (!local) {
222
- if (eruda) {
223
- return transformErudaOptions(html, options);
224
- }
225
- if (vConsole) {
226
- return transformVConsoleOptions(html, options);
227
- }
228
- }
229
- return html;
230
- },
231
- transform(code, id) {
232
- if (local) {
233
- if (eruda && entryPath.includes(id)) {
234
- return transformErudaImport(code, options);
235
- }
236
- if (vConsole && entryPath.includes(id)) {
237
- return transformVConsoleImport(code, options);
238
- }
239
- }
240
- return { code, map: null };
241
- }
242
- };
243
- };
244
- var src_default = vDebugger;
245
- // Annotate the CommonJS export names for ESM import in node:
246
- 0 && (module.exports = {
1
+ import {
247
2
  vDebugger
248
- });
3
+ } from "./chunk-M5FN5N6N.js";
4
+ import {
5
+ vDebugger as vDebugger2
6
+ } from "./chunk-AY5SPOLM.js";
7
+ import "./chunk-WG6FWYWY.js";
8
+ export {
9
+ vDebugger as eruda,
10
+ vDebugger2 as vConsole
11
+ };
@@ -0,0 +1 @@
1
+ _show&&import("eruda").then((function(t){var i;t.default.init(options||{})}));
@@ -0,0 +1 @@
1
+ if(_show){var n=document.createElement("script");n.src=cdn,n.async=!0,document.head.prepend(n),n.onload=function(){eruda.init(options||{})}}
@@ -0,0 +1 @@
1
+ var e,a,i,_show=!1,o="";if("url"===(null===(e=active)||void 0===e?void 0:e.mode)){var t="",r=window.location.href.match(new RegExp("[?&]".concat(active.param,"=([^&]+)"),"i"));Array.isArray(r)&&r.length>1&&(t=r[1]),t&&sessionStorage.setItem(active.param,t)}"url"!==(null===(a=active)||void 0===a?void 0:a.mode)&&"storage"!==(null===(i=active)||void 0===i?void 0:i.mode)||(o=sessionStorage.getItem(active.param)),active?active.override?o&&(_show=!0):debug&&o&&(_show=!0):_show=debug;
@@ -0,0 +1 @@
1
+ _show&&import("vconsole").then((function(o){var n,t=new(0,o.default)(options||{})}));
@@ -0,0 +1 @@
1
+ if(_show){var n=document.createElement("script");n.src=cdn,n.async=!0,document.head.prepend(n),n.onload=function(){var n=new VConsole(options||{})}}
@@ -0,0 +1,22 @@
1
+ import { VConsoleOptions } from 'core/options.interface';
2
+ export { VConsoleOptions } from 'core/options.interface';
3
+ import { S as SharedConfig, C as CommonConfig } from './index.d-D0Oa6UqJ.js';
4
+ import { Plugin } from 'vite';
5
+
6
+ interface VConsoleConfig extends CommonConfig {
7
+ /**
8
+ * vConsole options
9
+ *
10
+ * @see https://github.com/Tencent/vConsole/blob/dev/doc/public_properties_methods.md#vconsoleoption
11
+ */
12
+ options?: VConsoleOptions;
13
+ }
14
+ interface VConsoleDebuggerOptions extends SharedConfig {
15
+ /**
16
+ * vConsole config
17
+ */
18
+ config?: VConsoleConfig;
19
+ }
20
+ declare function vDebugger(options: VConsoleDebuggerOptions): Plugin;
21
+
22
+ export { vDebugger as default, vDebugger };
@@ -0,0 +1,9 @@
1
+ import {
2
+ vDebugger,
3
+ vconsole_default
4
+ } from "./chunk-AY5SPOLM.js";
5
+ import "./chunk-WG6FWYWY.js";
6
+ export {
7
+ vconsole_default as default,
8
+ vDebugger
9
+ };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "vite-plugin-debugger",
3
- "version": "0.2.0-beta.3",
3
+ "type": "module",
4
+ "version": "0.3.0",
4
5
  "description": "A vite plugin provide the debugger tools for mobile devices.",
5
6
  "author": "jade-gjz",
6
7
  "license": "MIT",
7
8
  "repository": {
8
9
  "type": "git",
9
- "url": "https://github.com/jaderd-jh/vite-plugin-debugger.git"
10
+ "url": "git+https://github.com/jaderd-jh/vite-plugin-debugger.git"
10
11
  },
11
12
  "keywords": [
12
13
  "vite",
@@ -16,7 +17,22 @@
16
17
  "vConsole",
17
18
  "mobile"
18
19
  ],
19
- "main": "dist/index.js",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ },
25
+ "./eruda": {
26
+ "types": "./dist/eruda.d.ts",
27
+ "import": "./dist/eruda.js"
28
+ },
29
+ "./vconsole": {
30
+ "types": "./dist/vconsole.d.ts",
31
+ "import": "./dist/vconsole.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "module": "dist/index.js",
20
36
  "types": "dist/index.d.ts",
21
37
  "files": [
22
38
  "dist"
@@ -24,7 +40,7 @@
24
40
  "peerDependencies": {
25
41
  "eruda": "^3.0.0",
26
42
  "vconsole": "^3.14.0",
27
- "vite": "^3.0.0 || ^4.0.0 || ^5.0.0"
43
+ "vite": "^6.0.0"
28
44
  },
29
45
  "peerDependenciesMeta": {
30
46
  "eruda": {
@@ -34,11 +50,18 @@
34
50
  "optional": true
35
51
  }
36
52
  },
53
+ "devDependencies": {
54
+ "@types/node": "^22.10.2",
55
+ "local-pkg": "^0.5.1",
56
+ "terser": "^5.37.0",
57
+ "tsup": "^8.3.5"
58
+ },
37
59
  "scripts": {
38
60
  "dev": "tsup --watch",
39
61
  "build": "tsup",
40
62
  "prepublish": "pnpm build",
41
63
  "lint": "eslint . --fix",
42
- "release": "bumpp"
64
+ "release": "bumpp",
65
+ "publint": "npx publint"
43
66
  }
44
67
  }