unplugin-dingtalk 0.4.2 → 0.5.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
@@ -4389,15 +4389,15 @@ var require_streams = __commonJS({
4389
4389
  var POOL_SIZE2 = 65536;
4390
4390
  if (!globalThis.ReadableStream) {
4391
4391
  try {
4392
- const process4 = require("process");
4393
- const { emitWarning } = process4;
4392
+ const process3 = require("process");
4393
+ const { emitWarning } = process3;
4394
4394
  try {
4395
- process4.emitWarning = () => {
4395
+ process3.emitWarning = () => {
4396
4396
  };
4397
4397
  Object.assign(globalThis, require("stream/web"));
4398
- process4.emitWarning = emitWarning;
4398
+ process3.emitWarning = emitWarning;
4399
4399
  } catch (error) {
4400
- process4.emitWarning = emitWarning;
4400
+ process3.emitWarning = emitWarning;
4401
4401
  throw error;
4402
4402
  }
4403
4403
  } catch (error) {
@@ -5211,8 +5211,6 @@ __export(webpack_exports, {
5211
5211
  default: () => webpack_default
5212
5212
  });
5213
5213
  module.exports = __toCommonJS(webpack_exports);
5214
- var import_node_child_process2 = require("child_process");
5215
- var import_node_process2 = __toESM(require("process"), 1);
5216
5214
  var import_unplugin2 = require("unplugin");
5217
5215
  var import_cookie2 = __toESM(require("cookie"), 1);
5218
5216
  var import_picocolors2 = __toESM(require("picocolors"), 1);
@@ -6516,19 +6514,92 @@ var import_unplugin = require("unplugin");
6516
6514
  var import_picocolors = __toESM(require("picocolors"), 1);
6517
6515
  var import_cookie = __toESM(require("cookie"), 1);
6518
6516
  var import_chii = require("chii");
6517
+ var import_dns2 = __toESM(require("dns2"), 1);
6519
6518
  var import_get_port_please = require("get-port-please");
6520
6519
  var cwd = import_node_process.default.cwd();
6521
6520
  var config;
6522
6521
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
6523
6522
  var resovedInfo = {
6524
6523
  devtoolsInstance: void 0,
6524
+ dnsServerInstence: void 0,
6525
6525
  availablePort: void 0,
6526
6526
  targetURL: void 0
6527
6527
  };
6528
+ function startVueDevtools(enable) {
6529
+ if (enable && !resovedInfo.devtoolsInstance) {
6530
+ resovedInfo.devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
6531
+ console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
6532
+ resovedInfo.devtoolsInstance.on("exit", () => {
6533
+ resovedInfo.devtoolsInstance = void 0;
6534
+ });
6535
+ import_node_process.default.on("exit", () => {
6536
+ if (resovedInfo.devtoolsInstance) {
6537
+ resovedInfo.devtoolsInstance.kill();
6538
+ }
6539
+ });
6540
+ }
6541
+ }
6542
+ function startDnsServer(options) {
6543
+ function debug(...args) {
6544
+ if (options == null ? void 0 : options.debug) {
6545
+ console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
6546
+ }
6547
+ }
6548
+ if ((options == null ? void 0 : options.enable) && (options == null ? void 0 : options.dns) && !resovedInfo.dnsServerInstence) {
6549
+ const { Packet } = import_dns2.default;
6550
+ resovedInfo.dnsServerInstence = import_dns2.default.createServer({
6551
+ tcp: true,
6552
+ udp: true,
6553
+ handle: (request, send, rinfo) => {
6554
+ var _a4;
6555
+ const response = Packet.createResponseFromRequest(request);
6556
+ const [question] = request.questions;
6557
+ const { name } = question;
6558
+ if (name === options.dns.host) {
6559
+ response.answers.push({
6560
+ name,
6561
+ type: Packet.TYPE.A,
6562
+ class: Packet.CLASS.IN,
6563
+ ttl: 300,
6564
+ address: (_a4 = options.dns) == null ? void 0 : _a4.ip
6565
+ });
6566
+ debug(`dns request from ${rinfo.address}:${rinfo.port} for ${name} => ${options.dns.ip}`);
6567
+ }
6568
+ send(response);
6569
+ }
6570
+ });
6571
+ resovedInfo.dnsServerInstence.listen({
6572
+ udp: { address: "0.0.0.0", port: 53 },
6573
+ tcp: { address: "0.0.0.0", port: 53 }
6574
+ }).then(() => {
6575
+ debug("DNS server is running.");
6576
+ const dns = new import_dns2.default({
6577
+ port: 53,
6578
+ nameServers: ["127.0.0.1", "8.8.8.8"]
6579
+ });
6580
+ dns.resolveA(options.dns.host).then((addresses) => {
6581
+ var _a4;
6582
+ if (((_a4 = addresses.answers[0]) == null ? void 0 : _a4.address) === options.dns.ip) {
6583
+ startDnsServer(options);
6584
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(`DNS server is started, please modify the DNS of the remote device to ${options.dns.ip}`)}`);
6585
+ } else {
6586
+ debug(addresses.answers[0].address);
6587
+ throw new Error("DNS server started failed");
6588
+ }
6589
+ }).catch((e2) => {
6590
+ throw e2;
6591
+ });
6592
+ }).catch((e2) => {
6593
+ debug(e2);
6594
+ console.log(` ${import_picocolors.default.red("\u279C")} ${import_picocolors.default.bold((e2 == null ? void 0 : e2.message) || e2)}`);
6595
+ });
6596
+ }
6597
+ }
6528
6598
  var unpluginFactory = (options) => {
6529
6599
  const {
6530
- chii: enableChii = true
6600
+ chii
6531
6601
  } = options || {};
6602
+ const enableChii = (chii == null ? void 0 : chii.enable) !== false;
6532
6603
  function debug(...args) {
6533
6604
  if (options == null ? void 0 : options.debug) {
6534
6605
  console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
@@ -6544,20 +6615,19 @@ var unpluginFactory = (options) => {
6544
6615
  var _a4, _b, _c;
6545
6616
  if ((options == null ? void 0 : options.enable) && enableChii && !resovedInfo.availablePort) {
6546
6617
  resovedInfo.availablePort = await (0, import_get_port_please.getRandomPort)();
6547
- debug(`chii server port: ${JSON.stringify({ availablePort: resovedInfo.availablePort })}`);
6548
6618
  (0, import_chii.start)({
6549
- host: "0.0.0.0",
6550
6619
  port: resovedInfo.availablePort
6551
6620
  });
6621
+ debug(`chii server port: ${resovedInfo.availablePort}`);
6552
6622
  }
6553
6623
  if (options == null ? void 0 : options.enable) {
6554
6624
  const codes = [
6555
6625
  "/* eslint-disable */;",
6556
6626
  ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) ? `import { devtools } from '@vue/devtools'
6557
- 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});` : "",
6627
+ devtools.connect(${((_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host) ? `"${options.vueDevtools.host}"` : void 0}, ${((_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port) ? `${options.vueDevtools.port}` : void 0});` : "",
6558
6628
  (options == null ? void 0 : options.enable) && enableChii ? `(() => {
6559
6629
  const script = document.createElement('script');
6560
- script.src="http://localhost:${resovedInfo.availablePort}/target.js";
6630
+ script.src="http://${(chii == null ? void 0 : chii.host) || "127.0.0.1"}:${resovedInfo.availablePort}/target.js";
6561
6631
  document.body.appendChild(script);
6562
6632
  })()` : "",
6563
6633
  "/* eslint-enable */",
@@ -6633,6 +6703,9 @@ var unpluginFactory = (options) => {
6633
6703
  const devToolsUrl = `http://localhost:${resovedInfo.availablePort}/front_end/chii_app.html?ws=localhost:${resovedInfo.availablePort}/client/${Math.random().toString(20).substring(2, 8)}?target=${data.targets[0].id}&rtc=false`;
6634
6704
  res.writeHead(302, { Location: devToolsUrl });
6635
6705
  res.end();
6706
+ } else {
6707
+ res.writeHead(404);
6708
+ res.end();
6636
6709
  }
6637
6710
  } catch (error) {
6638
6711
  debug(`${error}`);
@@ -6647,20 +6720,10 @@ var unpluginFactory = (options) => {
6647
6720
  res.writeHead(302, {
6648
6721
  Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
6649
6722
  });
6650
- if (((_a5 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a5.enable) && !resovedInfo.devtoolsInstance) {
6651
- resovedInfo.devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
6652
- console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
6653
- resovedInfo.devtoolsInstance.on("exit", () => {
6654
- resovedInfo.devtoolsInstance = void 0;
6655
- });
6656
- import_node_process.default.on("exit", () => {
6657
- if (resovedInfo.devtoolsInstance) {
6658
- resovedInfo.devtoolsInstance.kill();
6659
- }
6660
- });
6661
- }
6723
+ startVueDevtools((_a5 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a5.enable);
6662
6724
  res.end();
6663
6725
  });
6726
+ startDnsServer(options);
6664
6727
  }
6665
6728
  },
6666
6729
  webpack(compiler) {
@@ -6691,6 +6754,7 @@ var unpluginFactory = (options) => {
6691
6754
  if (options == null ? void 0 : options.corpId) {
6692
6755
  resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6693
6756
  }
6757
+ startDnsServer(options);
6694
6758
  },
6695
6759
  async rspack(compiler) {
6696
6760
  var _a4, _b, _c, _d2, _e;
@@ -6719,6 +6783,7 @@ var unpluginFactory = (options) => {
6719
6783
  "Click to open chrome devtools"
6720
6784
  )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
6721
6785
  }
6786
+ startDnsServer(options);
6722
6787
  }
6723
6788
  };
6724
6789
  return unpluginDing;
@@ -6732,8 +6797,9 @@ var webpack_default = (options) => {
6732
6797
  }
6733
6798
  }
6734
6799
  const {
6735
- chii: enableChii = true
6800
+ chii
6736
6801
  } = options || {};
6802
+ const enableChii = (chii == null ? void 0 : chii.enable) !== false;
6737
6803
  const injectSetupMiddlewares = (middlewares, devServer) => {
6738
6804
  if (options.debugCookies && options.debugCookies.length > 0) {
6739
6805
  devServer.app.use((req, res, next) => {
@@ -6759,6 +6825,9 @@ var webpack_default = (options) => {
6759
6825
  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`;
6760
6826
  res.writeHead(302, { Location: devToolsUrl });
6761
6827
  res.end();
6828
+ } else {
6829
+ res.writeHead(404);
6830
+ res.end();
6762
6831
  }
6763
6832
  } catch (error) {
6764
6833
  debug(`${error}`);
@@ -6774,18 +6843,7 @@ var webpack_default = (options) => {
6774
6843
  res.writeHead(302, {
6775
6844
  Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
6776
6845
  });
6777
- if (((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) && !resovedInfo.devtoolsInstance) {
6778
- resovedInfo.devtoolsInstance = (0, import_node_child_process2.exec)("npx vue-devtools");
6779
- console.log(` ${import_picocolors2.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
6780
- resovedInfo.devtoolsInstance.on("exit", () => {
6781
- resovedInfo.devtoolsInstance = void 0;
6782
- });
6783
- import_node_process2.default.on("exit", () => {
6784
- if (resovedInfo.devtoolsInstance) {
6785
- resovedInfo.devtoolsInstance.kill();
6786
- }
6787
- });
6788
- }
6846
+ startVueDevtools((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable);
6789
6847
  res.end();
6790
6848
  });
6791
6849
  return middlewares;
package/dist/webpack.js CHANGED
@@ -1,13 +1,12 @@
1
1
  import {
2
2
  fetch,
3
3
  resovedInfo,
4
+ startVueDevtools,
4
5
  unpluginFactory
5
- } from "./chunk-RDTWBIQD.js";
6
+ } from "./chunk-OSHJOAQB.js";
6
7
  import "./chunk-PMOTCIQR.js";
7
8
 
8
9
  // src/webpack.ts
9
- import { exec } from "child_process";
10
- import process from "process";
11
10
  import { createWebpackPlugin } from "unplugin";
12
11
  import cookie from "cookie";
13
12
  import c from "picocolors";
@@ -18,8 +17,9 @@ var webpack_default = (options) => {
18
17
  }
19
18
  }
20
19
  const {
21
- chii: enableChii = true
20
+ chii
22
21
  } = options || {};
22
+ const enableChii = (chii == null ? void 0 : chii.enable) !== false;
23
23
  const injectSetupMiddlewares = (middlewares, devServer) => {
24
24
  if (options.debugCookies && options.debugCookies.length > 0) {
25
25
  devServer.app.use((req, res, next) => {
@@ -45,6 +45,9 @@ var webpack_default = (options) => {
45
45
  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`;
46
46
  res.writeHead(302, { Location: devToolsUrl });
47
47
  res.end();
48
+ } else {
49
+ res.writeHead(404);
50
+ res.end();
48
51
  }
49
52
  } catch (error) {
50
53
  debug(`${error}`);
@@ -60,18 +63,7 @@ var webpack_default = (options) => {
60
63
  res.writeHead(302, {
61
64
  Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
62
65
  });
63
- if (((_a = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a.enable) && !resovedInfo.devtoolsInstance) {
64
- resovedInfo.devtoolsInstance = exec("npx vue-devtools");
65
- console.log(` ${c.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
66
- resovedInfo.devtoolsInstance.on("exit", () => {
67
- resovedInfo.devtoolsInstance = void 0;
68
- });
69
- process.on("exit", () => {
70
- if (resovedInfo.devtoolsInstance) {
71
- resovedInfo.devtoolsInstance.kill();
72
- }
73
- });
74
- }
66
+ startVueDevtools((_a = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a.enable);
75
67
  res.end();
76
68
  });
77
69
  return middlewares;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-dingtalk",
3
3
  "type": "module",
4
- "version": "0.4.2",
4
+ "version": "0.5.0",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/zcf0508/unplugin-dingtalk#readme",
@@ -125,6 +125,7 @@
125
125
  "@antfu/eslint-config": "^2.18.1",
126
126
  "chii": "^1.10.0",
127
127
  "cookie": "^0.6.0",
128
+ "dns2": "^2.1.0",
128
129
  "eslint-plugin-security": "^3.0.0",
129
130
  "get-port-please": "^3.1.2",
130
131
  "picocolors": "^1.0.1",
@@ -134,6 +135,7 @@
134
135
  "devDependencies": {
135
136
  "@nuxt/kit": "^3.8.2",
136
137
  "@nuxt/schema": "^3.8.2",
138
+ "@types/dns2": "^2.0.9",
137
139
  "@types/node": "^20.10.3",
138
140
  "bumpp": "^9.2.0",
139
141
  "chalk": "^5.3.0",
@@ -146,7 +148,7 @@
146
148
  "rollup": "^4.6.1",
147
149
  "tsup": "^8.0.1",
148
150
  "vite": "^5.0.4",
149
- "vitest": "^0.34.6",
151
+ "vitest": "^1.6.0",
150
152
  "webpack": "^5.89.0",
151
153
  "webpack-dev-server": "^5.0.4"
152
154
  },