unplugin-dingtalk 0.1.9 → 0.2.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.
package/README.md CHANGED
@@ -7,7 +7,9 @@
7
7
  ## 功能
8
8
  - [x] 在钉钉内打开调试链接
9
9
  - [x] 可选注入 [vConsole](https://github.com/Tencent/vConsole) 用于调试
10
+ - [x] 可选注入 [chii](https://github.com/liriliri/chii) 用于调试
10
11
  - [x] 可选打开 [vue-devtools](https://github.com/vuejs/devtools) 用于调试
12
+ - [x] 支持调试 `HttpOnly` cookies
11
13
 
12
14
  ![images](https://github.com/zcf0508/unplugin-dingtalk/raw/main/images/Snipaste_2024-05-22_11-25-35.png)
13
15
 
@@ -27,6 +29,8 @@ interface Options {
27
29
  vconsole?: viteVConsoleOptions
28
30
  /** 需要调试的 cookies, 避免无法调试 HttpOnly 的 cookie */
29
31
  debugCookies?: string[]
32
+ /** 默认值 `true` */
33
+ chii?: boolean
30
34
  vueDevtools?: {
31
35
  enable?: boolean
32
36
  host?: string
package/dist/astro.cjs CHANGED
@@ -41,27 +41,51 @@ var import_unplugin = require("unplugin");
41
41
  var import_picocolors = __toESM(require("picocolors"), 1);
42
42
  var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
43
43
  var import_cookie = __toESM(require("cookie"), 1);
44
+ var import_chii = require("chii");
45
+ var import_get_port_please = require("get-port-please");
44
46
  var config;
45
47
  var devtoolsInstance;
46
48
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
49
+ var availablePort;
47
50
  var unpluginFactory = (options) => {
48
51
  var _a;
52
+ const {
53
+ chii: enableChii = true
54
+ } = options || {};
55
+ function debug(...args) {
56
+ if (options == null ? void 0 : options.debug) {
57
+ console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
58
+ }
59
+ }
49
60
  const unpluginDing = {
50
61
  name: "unplugin-dingtalk",
51
62
  enforce: "pre",
52
63
  transformInclude(id) {
53
64
  return id.endsWith("main.ts") || id.endsWith("main.js");
54
65
  },
55
- transform(_source) {
66
+ async transform(_source) {
56
67
  var _a2, _b, _c;
68
+ if ((options == null ? void 0 : options.enable) && enableChii) {
69
+ availablePort = await (0, import_get_port_please.getRandomPort)();
70
+ debug(`chii server port: ${JSON.stringify({ availablePort })}`);
71
+ (0, import_chii.start)({
72
+ port: availablePort
73
+ });
74
+ }
57
75
  if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
58
- const code = `/* eslint-disable */;
59
- import { devtools } from '@vue/devtools'
60
- devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port})
61
- /* eslint-enable */${_source};
62
- `;
76
+ const codes = [
77
+ `/* eslint-disable */;
78
+ import { devtools } from '@vue/devtools'
79
+ devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port});`,
80
+ (options == null ? void 0 : options.enable) && enableChii ? `(() => {
81
+ const script = document.createElement('script');
82
+ script.src="http://localhost:${availablePort}/target.js";
83
+ document.body.appendChild(script);
84
+ })()` : "",
85
+ `/* eslint-enable */${_source};`
86
+ ];
63
87
  return {
64
- code,
88
+ code: codes.join("\n"),
65
89
  map: null
66
90
  // support source map
67
91
  };
@@ -76,16 +100,11 @@ var unpluginFactory = (options) => {
76
100
  configResolved(_config) {
77
101
  config = _config;
78
102
  },
79
- configureServer(server) {
103
+ async configureServer(server) {
80
104
  var _a2, _b;
81
105
  if (!(options == null ? void 0 : options.enable)) {
82
106
  return;
83
107
  }
84
- function debug(...args) {
85
- if (options == null ? void 0 : options.debug) {
86
- console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
87
- }
88
- }
89
108
  const _printUrls = server.printUrls.bind(server);
90
109
  let source = `localhost:${config.server.port || 5173}`;
91
110
  const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
@@ -101,6 +120,11 @@ var unpluginFactory = (options) => {
101
120
  console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
102
121
  `Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
103
122
  )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
123
+ if (enableChii) {
124
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
125
+ "Click to open chrome devtools"
126
+ )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
127
+ }
104
128
  };
105
129
  const targetURL = new URL(_targetUrl);
106
130
  targetURL.searchParams.append("ddtab", "true");
@@ -121,6 +145,23 @@ var unpluginFactory = (options) => {
121
145
  next();
122
146
  });
123
147
  }
148
+ if (enableChii) {
149
+ server.middlewares.use("/__chrome_devtools", async (_req, res) => {
150
+ try {
151
+ const raw = await fetch(`http://localhost:${availablePort}/targets`);
152
+ const data = await raw.json();
153
+ if ((data == null ? void 0 : data.targets.length) > 0) {
154
+ const devToolsUrl = `http://localhost:${availablePort}/front_end/chii_app.html?ws=localhost:${availablePort}/client/${Math.random().toString(20).substring(2, 8)}?target=${data.targets[0].id}&rtc=false`;
155
+ res.writeHead(302, { Location: devToolsUrl });
156
+ res.end();
157
+ }
158
+ } catch (error) {
159
+ debug(`${error}`);
160
+ res.writeHead(502);
161
+ res.end();
162
+ }
163
+ });
164
+ }
124
165
  server.middlewares.use("/open-dingtalk", (req, res) => {
125
166
  var _a3;
126
167
  debug(targetURL.toString());
@@ -144,11 +185,12 @@ var unpluginFactory = (options) => {
144
185
  }
145
186
  }
146
187
  };
188
+ const plugins = [];
147
189
  if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
148
- return [(0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole), unpluginDing];
149
- } else {
150
- return unpluginDing;
190
+ plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
151
191
  }
192
+ plugins.push(unpluginDing);
193
+ return plugins;
152
194
  };
153
195
  var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
154
196
  var src_default = unplugin;
package/dist/astro.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-PSBADVC6.js";
3
+ } from "./chunk-GRAT7SP7.js";
4
4
 
5
5
  // src/astro.ts
6
6
  var astro_default = (options) => ({
@@ -5,27 +5,51 @@ import { createUnplugin } from "unplugin";
5
5
  import c from "picocolors";
6
6
  import { viteVConsole } from "vite-plugin-vconsole";
7
7
  import cookie from "cookie";
8
+ import { start } from "chii";
9
+ import { getRandomPort } from "get-port-please";
8
10
  var config;
9
11
  var devtoolsInstance;
10
12
  var colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
13
+ var availablePort;
11
14
  var unpluginFactory = (options) => {
12
15
  var _a;
16
+ const {
17
+ chii: enableChii = true
18
+ } = options || {};
19
+ function debug(...args) {
20
+ if (options == null ? void 0 : options.debug) {
21
+ console.log(` ${c.yellow("DEBUG")} `, ...args);
22
+ }
23
+ }
13
24
  const unpluginDing = {
14
25
  name: "unplugin-dingtalk",
15
26
  enforce: "pre",
16
27
  transformInclude(id) {
17
28
  return id.endsWith("main.ts") || id.endsWith("main.js");
18
29
  },
19
- transform(_source) {
30
+ async transform(_source) {
20
31
  var _a2, _b, _c;
32
+ if ((options == null ? void 0 : options.enable) && enableChii) {
33
+ availablePort = await getRandomPort();
34
+ debug(`chii server port: ${JSON.stringify({ availablePort })}`);
35
+ start({
36
+ port: availablePort
37
+ });
38
+ }
21
39
  if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
22
- const code = `/* eslint-disable */;
23
- import { devtools } from '@vue/devtools'
24
- devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port})
25
- /* eslint-enable */${_source};
26
- `;
40
+ const codes = [
41
+ `/* eslint-disable */;
42
+ import { devtools } from '@vue/devtools'
43
+ devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port});`,
44
+ (options == null ? void 0 : options.enable) && enableChii ? `(() => {
45
+ const script = document.createElement('script');
46
+ script.src="http://localhost:${availablePort}/target.js";
47
+ document.body.appendChild(script);
48
+ })()` : "",
49
+ `/* eslint-enable */${_source};`
50
+ ];
27
51
  return {
28
- code,
52
+ code: codes.join("\n"),
29
53
  map: null
30
54
  // support source map
31
55
  };
@@ -40,16 +64,11 @@ var unpluginFactory = (options) => {
40
64
  configResolved(_config) {
41
65
  config = _config;
42
66
  },
43
- configureServer(server) {
67
+ async configureServer(server) {
44
68
  var _a2, _b;
45
69
  if (!(options == null ? void 0 : options.enable)) {
46
70
  return;
47
71
  }
48
- function debug(...args) {
49
- if (options == null ? void 0 : options.debug) {
50
- console.log(` ${c.yellow("DEBUG")} `, ...args);
51
- }
52
- }
53
72
  const _printUrls = server.printUrls.bind(server);
54
73
  let source = `localhost:${config.server.port || 5173}`;
55
74
  const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
@@ -65,6 +84,11 @@ var unpluginFactory = (options) => {
65
84
  console.log(` ${c.green("\u279C")} ${c.bold(
66
85
  `Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
67
86
  )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
87
+ if (enableChii) {
88
+ console.log(` ${c.green("\u279C")} ${c.bold(
89
+ "Click to open chrome devtools"
90
+ )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
91
+ }
68
92
  };
69
93
  const targetURL = new URL(_targetUrl);
70
94
  targetURL.searchParams.append("ddtab", "true");
@@ -85,6 +109,23 @@ var unpluginFactory = (options) => {
85
109
  next();
86
110
  });
87
111
  }
112
+ if (enableChii) {
113
+ server.middlewares.use("/__chrome_devtools", async (_req, res) => {
114
+ try {
115
+ const raw = await fetch(`http://localhost:${availablePort}/targets`);
116
+ const data = await raw.json();
117
+ if ((data == null ? void 0 : data.targets.length) > 0) {
118
+ const devToolsUrl = `http://localhost:${availablePort}/front_end/chii_app.html?ws=localhost:${availablePort}/client/${Math.random().toString(20).substring(2, 8)}?target=${data.targets[0].id}&rtc=false`;
119
+ res.writeHead(302, { Location: devToolsUrl });
120
+ res.end();
121
+ }
122
+ } catch (error) {
123
+ debug(`${error}`);
124
+ res.writeHead(502);
125
+ res.end();
126
+ }
127
+ });
128
+ }
88
129
  server.middlewares.use("/open-dingtalk", (req, res) => {
89
130
  var _a3;
90
131
  debug(targetURL.toString());
@@ -108,11 +149,12 @@ var unpluginFactory = (options) => {
108
149
  }
109
150
  }
110
151
  };
152
+ const plugins = [];
111
153
  if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
112
- return [viteVConsole(options == null ? void 0 : options.vconsole), unpluginDing];
113
- } else {
114
- return unpluginDing;
154
+ plugins.push(viteVConsole(options == null ? void 0 : options.vconsole));
115
155
  }
156
+ plugins.push(unpluginDing);
157
+ return plugins;
116
158
  };
117
159
  var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
118
160
  var src_default = unplugin;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-PSBADVC6.js";
3
+ } from "./chunk-GRAT7SP7.js";
4
4
 
5
5
  // src/webpack.ts
6
6
  import { createWebpackPlugin } from "unplugin";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-PSBADVC6.js";
3
+ } from "./chunk-GRAT7SP7.js";
4
4
 
5
5
  // src/vite.ts
6
6
  import { createVitePlugin } from "unplugin";
package/dist/esbuild.cjs CHANGED
@@ -42,27 +42,51 @@ var import_unplugin = require("unplugin");
42
42
  var import_picocolors = __toESM(require("picocolors"), 1);
43
43
  var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
44
44
  var import_cookie = __toESM(require("cookie"), 1);
45
+ var import_chii = require("chii");
46
+ var import_get_port_please = require("get-port-please");
45
47
  var config;
46
48
  var devtoolsInstance;
47
49
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
50
+ var availablePort;
48
51
  var unpluginFactory = (options) => {
49
52
  var _a;
53
+ const {
54
+ chii: enableChii = true
55
+ } = options || {};
56
+ function debug(...args) {
57
+ if (options == null ? void 0 : options.debug) {
58
+ console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
59
+ }
60
+ }
50
61
  const unpluginDing = {
51
62
  name: "unplugin-dingtalk",
52
63
  enforce: "pre",
53
64
  transformInclude(id) {
54
65
  return id.endsWith("main.ts") || id.endsWith("main.js");
55
66
  },
56
- transform(_source) {
67
+ async transform(_source) {
57
68
  var _a2, _b, _c;
69
+ if ((options == null ? void 0 : options.enable) && enableChii) {
70
+ availablePort = await (0, import_get_port_please.getRandomPort)();
71
+ debug(`chii server port: ${JSON.stringify({ availablePort })}`);
72
+ (0, import_chii.start)({
73
+ port: availablePort
74
+ });
75
+ }
58
76
  if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
59
- const code = `/* eslint-disable */;
60
- import { devtools } from '@vue/devtools'
61
- devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port})
62
- /* eslint-enable */${_source};
63
- `;
77
+ const codes = [
78
+ `/* eslint-disable */;
79
+ import { devtools } from '@vue/devtools'
80
+ devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port});`,
81
+ (options == null ? void 0 : options.enable) && enableChii ? `(() => {
82
+ const script = document.createElement('script');
83
+ script.src="http://localhost:${availablePort}/target.js";
84
+ document.body.appendChild(script);
85
+ })()` : "",
86
+ `/* eslint-enable */${_source};`
87
+ ];
64
88
  return {
65
- code,
89
+ code: codes.join("\n"),
66
90
  map: null
67
91
  // support source map
68
92
  };
@@ -77,16 +101,11 @@ var unpluginFactory = (options) => {
77
101
  configResolved(_config) {
78
102
  config = _config;
79
103
  },
80
- configureServer(server) {
104
+ async configureServer(server) {
81
105
  var _a2, _b;
82
106
  if (!(options == null ? void 0 : options.enable)) {
83
107
  return;
84
108
  }
85
- function debug(...args) {
86
- if (options == null ? void 0 : options.debug) {
87
- console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
88
- }
89
- }
90
109
  const _printUrls = server.printUrls.bind(server);
91
110
  let source = `localhost:${config.server.port || 5173}`;
92
111
  const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
@@ -102,6 +121,11 @@ var unpluginFactory = (options) => {
102
121
  console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
103
122
  `Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
104
123
  )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
124
+ if (enableChii) {
125
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
126
+ "Click to open chrome devtools"
127
+ )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
128
+ }
105
129
  };
106
130
  const targetURL = new URL(_targetUrl);
107
131
  targetURL.searchParams.append("ddtab", "true");
@@ -122,6 +146,23 @@ var unpluginFactory = (options) => {
122
146
  next();
123
147
  });
124
148
  }
149
+ if (enableChii) {
150
+ server.middlewares.use("/__chrome_devtools", async (_req, res) => {
151
+ try {
152
+ const raw = await fetch(`http://localhost:${availablePort}/targets`);
153
+ const data = await raw.json();
154
+ if ((data == null ? void 0 : data.targets.length) > 0) {
155
+ const devToolsUrl = `http://localhost:${availablePort}/front_end/chii_app.html?ws=localhost:${availablePort}/client/${Math.random().toString(20).substring(2, 8)}?target=${data.targets[0].id}&rtc=false`;
156
+ res.writeHead(302, { Location: devToolsUrl });
157
+ res.end();
158
+ }
159
+ } catch (error) {
160
+ debug(`${error}`);
161
+ res.writeHead(502);
162
+ res.end();
163
+ }
164
+ });
165
+ }
125
166
  server.middlewares.use("/open-dingtalk", (req, res) => {
126
167
  var _a3;
127
168
  debug(targetURL.toString());
@@ -145,11 +186,12 @@ var unpluginFactory = (options) => {
145
186
  }
146
187
  }
147
188
  };
189
+ const plugins = [];
148
190
  if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
149
- return [(0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole), unpluginDing];
150
- } else {
151
- return unpluginDing;
191
+ plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
152
192
  }
193
+ plugins.push(unpluginDing);
194
+ return plugins;
153
195
  };
154
196
 
155
197
  // src/esbuild.ts
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-PSBADVC6.js";
3
+ } from "./chunk-GRAT7SP7.js";
4
4
 
5
5
  // src/esbuild.ts
6
6
  import { createEsbuildPlugin } from "unplugin";
package/dist/index.cjs CHANGED
@@ -41,27 +41,51 @@ var import_unplugin = require("unplugin");
41
41
  var import_picocolors = __toESM(require("picocolors"), 1);
42
42
  var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
43
43
  var import_cookie = __toESM(require("cookie"), 1);
44
+ var import_chii = require("chii");
45
+ var import_get_port_please = require("get-port-please");
44
46
  var config;
45
47
  var devtoolsInstance;
46
48
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
49
+ var availablePort;
47
50
  var unpluginFactory = (options) => {
48
51
  var _a;
52
+ const {
53
+ chii: enableChii = true
54
+ } = options || {};
55
+ function debug(...args) {
56
+ if (options == null ? void 0 : options.debug) {
57
+ console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
58
+ }
59
+ }
49
60
  const unpluginDing = {
50
61
  name: "unplugin-dingtalk",
51
62
  enforce: "pre",
52
63
  transformInclude(id) {
53
64
  return id.endsWith("main.ts") || id.endsWith("main.js");
54
65
  },
55
- transform(_source) {
66
+ async transform(_source) {
56
67
  var _a2, _b, _c;
68
+ if ((options == null ? void 0 : options.enable) && enableChii) {
69
+ availablePort = await (0, import_get_port_please.getRandomPort)();
70
+ debug(`chii server port: ${JSON.stringify({ availablePort })}`);
71
+ (0, import_chii.start)({
72
+ port: availablePort
73
+ });
74
+ }
57
75
  if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
58
- const code = `/* eslint-disable */;
59
- import { devtools } from '@vue/devtools'
60
- devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port})
61
- /* eslint-enable */${_source};
62
- `;
76
+ const codes = [
77
+ `/* eslint-disable */;
78
+ import { devtools } from '@vue/devtools'
79
+ devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port});`,
80
+ (options == null ? void 0 : options.enable) && enableChii ? `(() => {
81
+ const script = document.createElement('script');
82
+ script.src="http://localhost:${availablePort}/target.js";
83
+ document.body.appendChild(script);
84
+ })()` : "",
85
+ `/* eslint-enable */${_source};`
86
+ ];
63
87
  return {
64
- code,
88
+ code: codes.join("\n"),
65
89
  map: null
66
90
  // support source map
67
91
  };
@@ -76,16 +100,11 @@ var unpluginFactory = (options) => {
76
100
  configResolved(_config) {
77
101
  config = _config;
78
102
  },
79
- configureServer(server) {
103
+ async configureServer(server) {
80
104
  var _a2, _b;
81
105
  if (!(options == null ? void 0 : options.enable)) {
82
106
  return;
83
107
  }
84
- function debug(...args) {
85
- if (options == null ? void 0 : options.debug) {
86
- console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
87
- }
88
- }
89
108
  const _printUrls = server.printUrls.bind(server);
90
109
  let source = `localhost:${config.server.port || 5173}`;
91
110
  const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
@@ -101,6 +120,11 @@ var unpluginFactory = (options) => {
101
120
  console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
102
121
  `Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
103
122
  )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
123
+ if (enableChii) {
124
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
125
+ "Click to open chrome devtools"
126
+ )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
127
+ }
104
128
  };
105
129
  const targetURL = new URL(_targetUrl);
106
130
  targetURL.searchParams.append("ddtab", "true");
@@ -121,6 +145,23 @@ var unpluginFactory = (options) => {
121
145
  next();
122
146
  });
123
147
  }
148
+ if (enableChii) {
149
+ server.middlewares.use("/__chrome_devtools", async (_req, res) => {
150
+ try {
151
+ const raw = await fetch(`http://localhost:${availablePort}/targets`);
152
+ const data = await raw.json();
153
+ if ((data == null ? void 0 : data.targets.length) > 0) {
154
+ const devToolsUrl = `http://localhost:${availablePort}/front_end/chii_app.html?ws=localhost:${availablePort}/client/${Math.random().toString(20).substring(2, 8)}?target=${data.targets[0].id}&rtc=false`;
155
+ res.writeHead(302, { Location: devToolsUrl });
156
+ res.end();
157
+ }
158
+ } catch (error) {
159
+ debug(`${error}`);
160
+ res.writeHead(502);
161
+ res.end();
162
+ }
163
+ });
164
+ }
124
165
  server.middlewares.use("/open-dingtalk", (req, res) => {
125
166
  var _a3;
126
167
  debug(targetURL.toString());
@@ -144,11 +185,12 @@ var unpluginFactory = (options) => {
144
185
  }
145
186
  }
146
187
  };
188
+ const plugins = [];
147
189
  if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
148
- return [(0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole), unpluginDing];
149
- } else {
150
- return unpluginDing;
190
+ plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
151
191
  }
192
+ plugins.push(unpluginDing);
193
+ return plugins;
152
194
  };
153
195
  var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
154
196
  var src_default = unplugin;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  src_default,
3
3
  unplugin,
4
4
  unpluginFactory
5
- } from "./chunk-PSBADVC6.js";
5
+ } from "./chunk-GRAT7SP7.js";
6
6
  export {
7
7
  src_default as default,
8
8
  unplugin,