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/dist/nuxt.cjs CHANGED
@@ -45,27 +45,51 @@ var import_unplugin = require("unplugin");
45
45
  var import_picocolors = __toESM(require("picocolors"), 1);
46
46
  var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
47
47
  var import_cookie = __toESM(require("cookie"), 1);
48
+ var import_chii = require("chii");
49
+ var import_get_port_please = require("get-port-please");
48
50
  var config;
49
51
  var devtoolsInstance;
50
52
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
53
+ var availablePort;
51
54
  var unpluginFactory = (options) => {
52
55
  var _a;
56
+ const {
57
+ chii: enableChii = true
58
+ } = options || {};
59
+ function debug(...args) {
60
+ if (options == null ? void 0 : options.debug) {
61
+ console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
62
+ }
63
+ }
53
64
  const unpluginDing = {
54
65
  name: "unplugin-dingtalk",
55
66
  enforce: "pre",
56
67
  transformInclude(id) {
57
68
  return id.endsWith("main.ts") || id.endsWith("main.js");
58
69
  },
59
- transform(_source) {
70
+ async transform(_source) {
60
71
  var _a2, _b, _c;
72
+ if ((options == null ? void 0 : options.enable) && enableChii) {
73
+ availablePort = await (0, import_get_port_please.getRandomPort)();
74
+ debug(`chii server port: ${JSON.stringify({ availablePort })}`);
75
+ (0, import_chii.start)({
76
+ port: availablePort
77
+ });
78
+ }
61
79
  if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
62
- const code = `/* eslint-disable */;
63
- import { devtools } from '@vue/devtools'
64
- 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})
65
- /* eslint-enable */${_source};
66
- `;
80
+ const codes = [
81
+ `/* eslint-disable */;
82
+ import { devtools } from '@vue/devtools'
83
+ 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});`,
84
+ (options == null ? void 0 : options.enable) && enableChii ? `(() => {
85
+ const script = document.createElement('script');
86
+ script.src="http://localhost:${availablePort}/target.js";
87
+ document.body.appendChild(script);
88
+ })()` : "",
89
+ `/* eslint-enable */${_source};`
90
+ ];
67
91
  return {
68
- code,
92
+ code: codes.join("\n"),
69
93
  map: null
70
94
  // support source map
71
95
  };
@@ -80,16 +104,11 @@ var unpluginFactory = (options) => {
80
104
  configResolved(_config) {
81
105
  config = _config;
82
106
  },
83
- configureServer(server) {
107
+ async configureServer(server) {
84
108
  var _a2, _b;
85
109
  if (!(options == null ? void 0 : options.enable)) {
86
110
  return;
87
111
  }
88
- function debug(...args) {
89
- if (options == null ? void 0 : options.debug) {
90
- console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
91
- }
92
- }
93
112
  const _printUrls = server.printUrls.bind(server);
94
113
  let source = `localhost:${config.server.port || 5173}`;
95
114
  const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
@@ -105,6 +124,11 @@ var unpluginFactory = (options) => {
105
124
  console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
106
125
  `Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
107
126
  )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
127
+ if (enableChii) {
128
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
129
+ "Click to open chrome devtools"
130
+ )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
131
+ }
108
132
  };
109
133
  const targetURL = new URL(_targetUrl);
110
134
  targetURL.searchParams.append("ddtab", "true");
@@ -125,6 +149,23 @@ var unpluginFactory = (options) => {
125
149
  next();
126
150
  });
127
151
  }
152
+ if (enableChii) {
153
+ server.middlewares.use("/__chrome_devtools", async (_req, res) => {
154
+ try {
155
+ const raw = await fetch(`http://localhost:${availablePort}/targets`);
156
+ const data = await raw.json();
157
+ if ((data == null ? void 0 : data.targets.length) > 0) {
158
+ 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`;
159
+ res.writeHead(302, { Location: devToolsUrl });
160
+ res.end();
161
+ }
162
+ } catch (error) {
163
+ debug(`${error}`);
164
+ res.writeHead(502);
165
+ res.end();
166
+ }
167
+ });
168
+ }
128
169
  server.middlewares.use("/open-dingtalk", (req, res) => {
129
170
  var _a3;
130
171
  debug(targetURL.toString());
@@ -148,11 +189,12 @@ var unpluginFactory = (options) => {
148
189
  }
149
190
  }
150
191
  };
192
+ const plugins = [];
151
193
  if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
152
- return [(0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole), unpluginDing];
153
- } else {
154
- return unpluginDing;
194
+ plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
155
195
  }
196
+ plugins.push(unpluginDing);
197
+ return plugins;
156
198
  };
157
199
 
158
200
  // src/vite.ts
package/dist/nuxt.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  webpack_default
3
- } from "./chunk-3GLWV5IZ.js";
3
+ } from "./chunk-IN7LDV4O.js";
4
4
  import {
5
5
  vite_default
6
- } from "./chunk-U5NNQ27H.js";
7
- import "./chunk-PSBADVC6.js";
6
+ } from "./chunk-N4ZALPAK.js";
7
+ import "./chunk-GRAT7SP7.js";
8
8
 
9
9
  // src/nuxt.ts
10
10
  import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
package/dist/rollup.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/rollup.ts
package/dist/rollup.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/rollup.ts
6
6
  import { createRollupPlugin } from "unplugin";
package/dist/rspack.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/rspack.ts
package/dist/rspack.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/rspack.ts
6
6
  import { createRspackPlugin } from "unplugin";
package/dist/types.d.cts CHANGED
@@ -6,6 +6,8 @@ interface Options {
6
6
  corpId?: string;
7
7
  debug?: boolean;
8
8
  vconsole?: viteVConsoleOptions;
9
+ /** default `true` */
10
+ chii?: boolean;
9
11
  debugCookies?: string[];
10
12
  vueDevtools?: {
11
13
  enable?: boolean;
package/dist/types.d.ts CHANGED
@@ -6,6 +6,8 @@ interface Options {
6
6
  corpId?: string;
7
7
  debug?: boolean;
8
8
  vconsole?: viteVConsoleOptions;
9
+ /** default `true` */
10
+ chii?: boolean;
9
11
  debugCookies?: string[];
10
12
  vueDevtools?: {
11
13
  enable?: boolean;
package/dist/vite.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/vite.ts
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-U5NNQ27H.js";
4
- import "./chunk-PSBADVC6.js";
3
+ } from "./chunk-N4ZALPAK.js";
4
+ import "./chunk-GRAT7SP7.js";
5
5
  export {
6
6
  vite_default as default
7
7
  };