vite-plugin-debugger 0.0.7 → 0.0.9

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 金华青鸟
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 金华青鸟
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -2,9 +2,9 @@ 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';
5
+ type CDN = 'jsdelivr' | 'unpkg' | 'cdnjs';
6
6
 
7
- declare type ErudaPlugin = 'fps' | 'features' | 'timing' | 'memory' | 'code' | 'benchmark' | 'geolocation' | 'dom' | 'orientation' | 'touches';
7
+ type ErudaPlugin = 'fps' | 'features' | 'timing' | 'memory' | 'code' | 'benchmark' | 'geolocation' | 'dom' | 'orientation' | 'touches';
8
8
  interface ErudaConfig extends CommonConfig {
9
9
  /**
10
10
  * eruda options
@@ -44,6 +44,10 @@ interface CommonConfig {
44
44
  }
45
45
 
46
46
  interface ActiveConfig {
47
+ /**
48
+ * define is active override debug
49
+ */
50
+ override?: boolean
47
51
  /**
48
52
  * use url or storage
49
53
  */
@@ -51,7 +55,7 @@ interface ActiveConfig {
51
55
  /**
52
56
  * parameter name
53
57
  */
54
- param?: string
58
+ param: string
55
59
  }
56
60
  interface DebuggerOptions {
57
61
  /**
package/dist/index.js CHANGED
@@ -50,17 +50,28 @@ var transformCDN = (pkg, cdn) => {
50
50
  };
51
51
  var debugInit = (debug, active) => {
52
52
  return `
53
- let showDebug=${debug};
53
+ const activeConfig = ${!!active}
54
+ const activePriority = ${active == null ? void 0 : active.override}
55
+ let showDebug = false;
54
56
  let storageStr = ''
55
57
  if(${(active == null ? void 0 : active.mode) === "url"}){
56
58
  let queryStr='';
57
- const result = (window.location.href || '').match(new RegExp('[?&]${(active == null ? void 0 : active.param) || "debugwhatever"}=([^&]+)', 'i'));
58
- if (Array.isArray(result) && result.length > 1) queryStr= result[1];
59
- if (queryStr === 'true') localStorage.setItem('${(active == null ? void 0 : active.param) || "debugwhatever"}', 'true');
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}
60
74
  }
61
- if(${(active == null ? void 0 : active.mode) === "url" || (active == null ? void 0 : active.mode) === "storage"})
62
- storageStr = localStorage.getItem('${(active == null ? void 0 : active.param) || "debugwhatever"}')
63
- if (storageStr === 'true'){ showDebug=true };
64
75
  `;
65
76
  };
66
77
 
@@ -83,7 +94,10 @@ var transformErudaOptions = (html, opts) => {
83
94
  tags.push({
84
95
  tag: "script",
85
96
  attrs: {
86
- src: transformCDN(plugins.map((plugin) => `eruda-${plugin}`), cdn)
97
+ src: transformCDN(
98
+ plugins.map((plugin) => `eruda-${plugin}`),
99
+ cdn
100
+ )
87
101
  },
88
102
  injectTo: "head"
89
103
  });
@@ -109,7 +123,7 @@ var transformErudaOptions = (html, opts) => {
109
123
  if(showDebug===true){ ${erudaScript}}`,
110
124
  injectTo: "head"
111
125
  });
112
- if (debug === true || debug === false) {
126
+ if (debug !== void 0) {
113
127
  return {
114
128
  html,
115
129
  tags
@@ -136,7 +150,10 @@ var transformErudaImport = (code, opts) => {
136
150
  return {
137
151
  code: `/* eslint-disable */;
138
152
  ${importCode}
139
- ${debugInit(debug, active)}if(showDebug===true){${erudaScript}}
153
+ ${debugInit(
154
+ debug,
155
+ active
156
+ )}if(showDebug===true){${erudaScript}}
140
157
  /* eslint-enable */
141
158
  ${code}`,
142
159
  map: null
@@ -159,10 +176,12 @@ var transformVConsoleOptions = (html, opts) => {
159
176
  tags.push({
160
177
  tag: "script",
161
178
  children: `${debugInit(debug, active)}
162
- if(showDebug===true){var vConsole = new VConsole(${JSON.stringify(options || {})})};`,
179
+ if(showDebug===true){var vConsole = new VConsole(${JSON.stringify(
180
+ options || {}
181
+ )})};`,
163
182
  injectTo: "head"
164
183
  });
165
- if (debug === true || debug === false) {
184
+ if (debug !== void 0) {
166
185
  return {
167
186
  html,
168
187
  tags
@@ -179,7 +198,10 @@ var transformVConsoleImport = (code, opts) => {
179
198
  const { debug, active } = opts;
180
199
  const { options = {} } = opts.vConsole;
181
200
  return {
182
- code: `/* eslint-disable */;import VConsole from 'vconsole'; ${debugInit(debug, active)}
201
+ code: `/* eslint-disable */;import VConsole from 'vconsole'; ${debugInit(
202
+ debug,
203
+ active
204
+ )}
183
205
  if(showDebug===true){new VConsole(${JSON.stringify(options)})};/* eslint-enable */${code}`,
184
206
  map: null
185
207
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-debugger",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "A vite plugin provide the debugger tools for mobile devices.",
5
5
  "author": "jade-gjz",
6
6
  "license": "MIT",