vite-plugin-debugger 0.0.4 → 0.0.8

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.d.ts CHANGED
@@ -2,15 +2,19 @@ import { Plugin } from 'vite';
2
2
  import { InitOptions } from 'eruda';
3
3
  import { VConsoleOptions } from 'core/options.interface';
4
4
 
5
+ declare type CDN = 'jsdelivr' | 'unpkg' | 'cdnjs';
6
+
5
7
  declare type ErudaPlugin = 'fps' | 'features' | 'timing' | 'memory' | 'code' | 'benchmark' | 'geolocation' | 'dom' | 'orientation' | 'touches';
6
- interface ErudaOptions extends CommonOptions {
8
+ interface ErudaConfig extends CommonConfig {
7
9
  /**
8
10
  * eruda options
11
+ *
9
12
  * see also https://github.com/liriliri/eruda/blob/master/doc/API.md
10
13
  */
11
14
  options?: InitOptions;
12
15
  /**
13
16
  * eruda plugins
17
+ *
14
18
  * see also https://github.com/liriliri/eruda#plugins
15
19
  */
16
20
  plugins?: ErudaPlugin[] | {
@@ -19,44 +23,67 @@ interface ErudaOptions extends CommonOptions {
19
23
  }[];
20
24
  }
21
25
 
22
- interface vConsoleOptions extends CommonOptions {
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
+ */
23
32
  options?: VConsoleOptions;
24
33
  }
25
34
 
26
- declare type CDN = 'jsdelivr' | 'unpkg' | 'cdnjs';
35
+ interface CommonConfig {
36
+ /**
37
+ * cdn services
38
+ */
39
+ cdn?: CDN
40
+ /**
41
+ * custom cdn url
42
+ */
43
+ src?: string
44
+ }
27
45
 
28
- interface CommonOptions {
29
- /**
30
- * cdn services
31
- */
32
- cdn?: CDN;
33
- /**
34
- * custom cdn url
35
- */
36
- src?: string;
37
- }
38
- interface DebuggerOptions {
39
- /**
40
- * debug or not
41
- */
42
- debug?: boolean;
43
- /**
44
- * use node_modules
45
- */
46
- local?: boolean;
47
- /**
48
- * if local is true, use this to specify the path
49
- */
50
- entry?: string | string[];
51
- /**
52
- * eruda options
53
- */
54
- eruda?: ErudaOptions;
55
- /**
56
- * vConsole options
57
- */
58
- vConsole?: vConsoleOptions;
59
- }
60
- declare const _default: (options: DebuggerOptions) => Plugin;
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;
61
88
 
62
- export { CommonOptions, DebuggerOptions, _default as default };
89
+ export { vDebugger as default, vDebugger };
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,16 +14,16 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
18
 
22
19
  // src/index.ts
23
20
  var src_exports = {};
24
21
  __export(src_exports, {
25
- default: () => src_default
22
+ default: () => src_default,
23
+ vDebugger: () => vDebugger
26
24
  });
27
25
  module.exports = __toCommonJS(src_exports);
28
- var import_slash = __toESM(require("slash"));
26
+ var import_vite = require("vite");
29
27
 
30
28
  // src/helpers/index.ts
31
29
  var capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
@@ -42,7 +40,7 @@ var transformCDN = (pkg, cdn) => {
42
40
  if (cdn === "cdnjs") {
43
41
  if (!Array.isArray(pkg)) {
44
42
  if (pkg === "eruda") {
45
- return "https://cdnjs.cloudflare.com/ajax/libs/eruda/2.4.1/eruda.min.js";
43
+ return "https://cdnjs.cloudflare.com/ajax/libs/eruda/2.5.0/eruda.min.js";
46
44
  }
47
45
  throw new Error(`[vite-plugin-debugger]: ${cdn} only support eruda without its plugins.`);
48
46
  }
@@ -50,10 +48,37 @@ var transformCDN = (pkg, cdn) => {
50
48
  }
51
49
  return "";
52
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
+ };
53
77
 
54
78
  // src/plugins/eruda.ts
79
+ var import_meta = {};
55
80
  var transformErudaOptions = (html, opts) => {
56
- const { debug } = opts;
81
+ const { debug, active } = opts;
57
82
  const { options, plugins, cdn = "jsdelivr", src } = opts.eruda;
58
83
  const tags = [];
59
84
  tags.push({
@@ -63,14 +88,13 @@ var transformErudaOptions = (html, opts) => {
63
88
  },
64
89
  injectTo: "head"
65
90
  });
66
- let erudaScript = `eruda.init(${JSON.stringify(options)});
67
- `;
91
+ let erudaScript = `eruda.init(${JSON.stringify(options || {})});`;
68
92
  if (plugins && plugins.length > 0) {
69
93
  if (cdn === "jsdelivr") {
70
94
  tags.push({
71
95
  tag: "script",
72
96
  attrs: {
73
- src: transformCDN(plugins.map((plugin) => `eruda-${plugin}`))
97
+ src: transformCDN(plugins.map((plugin) => `eruda-${plugin}`), cdn)
74
98
  },
75
99
  injectTo: "head"
76
100
  });
@@ -92,19 +116,17 @@ var transformErudaOptions = (html, opts) => {
92
116
  }
93
117
  tags.push({
94
118
  tag: "script",
95
- children: erudaScript,
119
+ children: `${debugInit(debug, active)}
120
+ if(showDebug===true){ ${erudaScript}}`,
96
121
  injectTo: "head"
97
122
  });
98
- if (debug === true) {
123
+ if (debug !== void 0) {
99
124
  return {
100
125
  html,
101
126
  tags
102
127
  };
103
128
  }
104
- if (debug === false) {
105
- return html;
106
- }
107
- if (process.env.NODE_ENV !== "production") {
129
+ if (!import_meta.env.PROD) {
108
130
  return {
109
131
  html,
110
132
  tags
@@ -112,7 +134,7 @@ var transformErudaOptions = (html, opts) => {
112
134
  }
113
135
  };
114
136
  var transformErudaImport = (code, opts) => {
115
- const { debug } = opts;
137
+ const { debug, active } = opts;
116
138
  const { options = {}, plugins } = opts.eruda;
117
139
  let importCode = "import eruda from 'eruda';";
118
140
  let erudaScript = `eruda.init(${JSON.stringify(options)});`;
@@ -123,14 +145,19 @@ var transformErudaImport = (code, opts) => {
123
145
  });
124
146
  }
125
147
  return {
126
- code: debug ? `/* eslint-disable */;${importCode}${erudaScript}/* eslint-enable */${code}` : code,
148
+ code: `/* eslint-disable */;
149
+ ${importCode}
150
+ ${debugInit(debug, active)}if(showDebug===true){${erudaScript}}
151
+ /* eslint-enable */
152
+ ${code}`,
127
153
  map: null
128
154
  };
129
155
  };
130
156
 
131
157
  // src/plugins/vConsole.ts
158
+ var import_meta2 = {};
132
159
  var transformVConsoleOptions = (html, opts) => {
133
- const { debug } = opts;
160
+ const { debug, active } = opts;
134
161
  const { options, cdn = "jsdelivr", src } = opts.vConsole;
135
162
  const tags = [];
136
163
  tags.push({
@@ -142,19 +169,17 @@ var transformVConsoleOptions = (html, opts) => {
142
169
  });
143
170
  tags.push({
144
171
  tag: "script",
145
- children: `var vConsole = new VConsole(${JSON.stringify(options)});`,
172
+ children: `${debugInit(debug, active)}
173
+ if(showDebug===true){var vConsole = new VConsole(${JSON.stringify(options || {})})};`,
146
174
  injectTo: "head"
147
175
  });
148
- if (debug === true) {
176
+ if (debug !== void 0) {
149
177
  return {
150
178
  html,
151
179
  tags
152
180
  };
153
181
  }
154
- if (debug === false) {
155
- return html;
156
- }
157
- if (process.env.NODE_ENV !== "production") {
182
+ if (!import_meta2.env.PROD) {
158
183
  return {
159
184
  html,
160
185
  tags
@@ -162,21 +187,25 @@ var transformVConsoleOptions = (html, opts) => {
162
187
  }
163
188
  };
164
189
  var transformVConsoleImport = (code, opts) => {
165
- const { debug } = opts;
190
+ const { debug, active } = opts;
166
191
  const { options = {} } = opts.vConsole;
167
192
  return {
168
- code: debug ? `/* eslint-disable */;import VConsole from 'vconsole';new VConsole(${JSON.stringify(options)});/* eslint-enable */${code}` : code,
193
+ code: `/* eslint-disable */;import VConsole from 'vconsole'; ${debugInit(debug, active)}
194
+ if(showDebug===true){new VConsole(${JSON.stringify(options)})};/* eslint-enable */${code}`,
169
195
  map: null
170
196
  };
171
197
  };
172
198
 
173
199
  // src/index.ts
174
- var src_default = (options) => {
200
+ var vDebugger = (options) => {
175
201
  const { eruda, vConsole, local, entry } = options;
176
- const entryPath = entry ? (Array.isArray(entry) ? entry : [entry]).map((path) => (0, import_slash.default)(path)) : [];
202
+ const entryPath = entry ? (Array.isArray(entry) ? entry : [entry]).map((path) => (0, import_vite.normalizePath)(path)) : [];
177
203
  if (eruda && vConsole) {
178
204
  throw new Error("[vite-plugin-debugger]: You'd better use only one debugger tool at a time.");
179
205
  }
206
+ if (!eruda && !vConsole) {
207
+ throw new Error("[vite-plugin-debugger]: Which one do you prefer? eruda or vConsole?");
208
+ }
180
209
  return {
181
210
  name: "vite-plugin-debugger",
182
211
  transformIndexHtml(html) {
@@ -203,5 +232,8 @@ var src_default = (options) => {
203
232
  }
204
233
  };
205
234
  };
235
+ var src_default = vDebugger;
206
236
  // Annotate the CommonJS export names for ESM import in node:
207
- 0 && (module.exports = {});
237
+ 0 && (module.exports = {
238
+ vDebugger
239
+ });
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "vite-plugin-debugger",
3
- "version": "0.0.4",
3
+ "version": "0.0.8",
4
4
  "description": "A vite plugin provide the debugger tools for mobile devices.",
5
5
  "author": "jade-gjz",
6
6
  "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/jaderd-jh/vite-plugin-debugger.git"
10
+ },
7
11
  "keywords": [
8
12
  "vite",
9
13
  "debugger",
@@ -20,7 +24,7 @@
20
24
  "peerDependencies": {
21
25
  "eruda": "^2.4.0",
22
26
  "vconsole": "^3.14.0",
23
- "vite": "^2.0.0"
27
+ "vite": "^2.0.0 || ^3.0.0"
24
28
  },
25
29
  "peerDependenciesMeta": {
26
30
  "eruda": {
@@ -30,20 +34,6 @@
30
34
  "optional": true
31
35
  }
32
36
  },
33
- "dependencies": {
34
- "slash": "^4.0.0"
35
- },
36
- "devDependencies": {
37
- "@jhqn/eslint-config-ts": "^0.0.30",
38
- "bumpp": "^8.2.1",
39
- "conventional-changelog-cli": "^2.2.2",
40
- "eruda": "https://github.com/liriliri/eruda.git",
41
- "eslint": "^8.19.0",
42
- "tsup": "^6.1.3",
43
- "typescript": "^4.7.4",
44
- "vconsole": "^3.14.6",
45
- "vite": "^2.9.13"
46
- },
47
37
  "scripts": {
48
38
  "dev": "tsup src/index.ts --dts --watch",
49
39
  "build": "tsup src/index.ts --dts",
package/README.md DELETED
@@ -1,209 +0,0 @@
1
-
2
-
3
- # vite-plugin-debugger
4
-
5
- A vite plugin provide the debugger tools for mobile devices.
6
-
7
- **English** | [中文](./README.zh_CN.md)
8
-
9
- ## Install
10
-
11
- **node version:** >=14.0.0
12
-
13
- **vite version:** >=2.0.0
14
-
15
-
16
- ```bash
17
- pnpm add vite-plugin-debugger -D
18
- # or
19
- yarn add vite-plugin-debugger -D
20
- # or
21
- npm i vite-plugin-debugger -D
22
- ```
23
-
24
- ## Usage
25
-
26
- ### For [eruda](https://github.com/liriliri/eruda)
27
-
28
- we use eruda with CDN by default since it's unpacked size is 2.38 MB.
29
-
30
- ```typescript
31
- import { fileURLToPath } from 'url'
32
- import vDebugger from 'vite-plugin-debugger'
33
-
34
- const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
35
-
36
- export default defineConfig(({ command, mode }) => ({
37
- plugins: [
38
- vDebugger({
39
- debug: mode !== 'production',
40
- eruda: {
41
- // cdn: 'jsdelivr', // 'jsdelivr' | 'unpkg' | 'cdnjs'
42
- // src: 'custom CDN URL',
43
- options: {
44
- tool: ['console', 'elements'],
45
- useShadowDom: true,
46
- autoScale: true,
47
- defaults: {
48
- displaySize: 50,
49
- transparency: 0.8,
50
- theme: 'Dark',
51
- },
52
- },
53
- plugins: [
54
- 'fps',
55
- 'features',
56
- 'timing',
57
- 'memory',
58
- 'code',
59
- 'benchmark',
60
- 'dom',
61
- 'orientation',
62
- 'touches',
63
- // 'geolocation',
64
- ],
65
- },
66
- })
67
- ]
68
- })
69
- ```
70
-
71
-
72
-
73
- ⚠ cdnjs don't provide eruda related plugins so you can specify every plugin's CDN source like:
74
-
75
- ```
76
- plugins: [
77
- {
78
- name: 'fps',
79
- src: 'https://cdn.jsdelivr.net/npm/eruda-fps',
80
- },
81
- // ...
82
- ],
83
- ```
84
-
85
-
86
-
87
- For more details about eruda options, please check out [eruda API](https://github.com/liriliri/eruda/blob/master/doc/API.md).
88
-
89
- If you prefer use eruda locally, you should install eruda and it's plugins first.
90
-
91
- ```typescript
92
- pnpm add eruda -D
93
- # or
94
- yarn add eruda -D
95
- # or
96
- npm i eruda -D
97
-
98
- # And some optional plugins
99
- pnpm[yarn|npm] add eruda-fps eruda-features eruda-timing eruda-memory eruda-code eruda-benchmark eruda-dom eruda-orientation eruda-touches eruda-geolocation -D
100
- ```
101
-
102
- ```typescript
103
- import { fileURLToPath } from 'url'
104
- import vDebugger from 'vite-plugin-debugger'
105
-
106
- const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
107
-
108
- export default defineConfig(({ command, mode })=>({
109
- plugins:[
110
- vDebugger({
111
- debug: mode !== 'production',
112
- local: true,
113
- entry: resolve('src/main.ts'),// vue or src/main.tsx for react
114
- eruda: {
115
- options: {
116
- tool: ['console', 'elements'],
117
- useShadowDom: true,
118
- autoScale: true,
119
- defaults: {
120
- displaySize: 50,
121
- transparency: 0.8,
122
- theme: 'Dark',
123
- },
124
- },
125
- plugins: [
126
- 'fps',
127
- 'features',
128
- 'timing',
129
- 'memory',
130
- 'code',
131
- 'benchmark',
132
- 'dom',
133
- 'orientation',
134
- 'touches',
135
- // 'geolocation',
136
- ],
137
- })
138
- ]
139
- })
140
- ```
141
-
142
- ### For [vConsole](https://github.com/Tencent/vConsole)
143
-
144
- we use vConsole with CDN by default since it's unpacked size is 344 kB.
145
-
146
- ```typescript
147
- import { fileURLToPath } from 'url'
148
- import vDebugger from 'vite-plugin-debugger'
149
-
150
- const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
151
-
152
- export default defineConfig(({ command, mode })=>({
153
- plugins:[
154
- vDebugger({
155
- debug: mode !== 'production',
156
- vConsole: {
157
- options: {
158
- theme: 'dark',
159
- },
160
- },
161
- })
162
- ]
163
- })
164
- ```
165
-
166
-
167
-
168
- For more details about vConsole options, please check out [vConsole API](https://github.com/Tencent/vConsole/blob/dev/doc/public_properties_methods.md).
169
-
170
- If you prefer use vConsole locally, you should install vConsole first.
171
-
172
- ```bash
173
- pnpm add vconsole -D
174
- # or
175
- yarn add vconsole -D
176
- # or
177
- npm i vconsole -D
178
- ```
179
-
180
-
181
-
182
- ```typescript
183
- import { fileURLToPath } from 'url'
184
- import vDebugger from 'vite-plugin-debugger'
185
-
186
- const resolve = (dir: string) => fileURLToPath(new URL(dir, import.meta.url))
187
-
188
- export default defineConfig(({ command, mode })=>({
189
- plugins:[
190
- vDebugger({
191
- debug: mode !== 'production',
192
- local: true,
193
- entry: resolve('src/main.ts'),// vue or src/main.tsx for react
194
- vConsole: {
195
- options: {
196
- theme: 'dark',
197
- },
198
- },
199
- })
200
- ]
201
- })
202
- ```
203
-
204
-
205
-
206
-
207
- ## License
208
-
209
- [MIT](LICENSE)
package/README.zh_CN.md DELETED
File without changes