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/webpack.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/webpack.ts
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  webpack_default
3
- } from "./chunk-3GLWV5IZ.js";
4
- import "./chunk-PSBADVC6.js";
3
+ } from "./chunk-IN7LDV4O.js";
4
+ import "./chunk-GRAT7SP7.js";
5
5
  export {
6
6
  webpack_default as default
7
7
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-dingtalk",
3
3
  "type": "module",
4
- "version": "0.1.9",
4
+ "version": "0.2.0",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/zcf0508/unplugin-dingtalk#readme",
@@ -119,8 +119,10 @@
119
119
  },
120
120
  "dependencies": {
121
121
  "@antfu/eslint-config": "^2.18.1",
122
+ "chii": "^1.10.0",
122
123
  "cookie": "^0.6.0",
123
124
  "eslint-plugin-security": "^3.0.0",
125
+ "get-port-please": "^3.1.2",
124
126
  "picocolors": "^1.0.1",
125
127
  "unplugin": "^1.5.1",
126
128
  "vite-plugin-vconsole": "^2.1.1"