unplugin-dingtalk 0.4.2 → 0.5.2

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/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as _unplugin from 'unplugin';
2
2
  import { UnpluginFactory } from 'unplugin';
3
3
  import { ChildProcess } from 'node:child_process';
4
+ import dns2 from 'dns2';
4
5
  import { Options } from './types.cjs';
5
6
  import 'webpack-dev-server';
6
7
  import 'node:http';
@@ -8,10 +9,13 @@ import 'vite-plugin-vconsole';
8
9
 
9
10
  declare const resovedInfo: {
10
11
  devtoolsInstance: ChildProcess | undefined;
12
+ dnsServerInstence: ReturnType<typeof dns2.createServer> | undefined;
11
13
  availablePort: number | undefined;
12
14
  targetURL: undefined | URL;
13
15
  };
16
+ declare function startVueDevtools(enable?: boolean): void;
17
+ declare function startDnsServer(options?: Options): void;
14
18
  declare const unpluginFactory: UnpluginFactory<Options | undefined, boolean>;
15
19
  declare const unplugin: _unplugin.UnpluginInstance<Options | undefined, boolean>;
16
20
 
17
- export { unplugin as default, resovedInfo, unplugin, unpluginFactory };
21
+ export { unplugin as default, resovedInfo, startDnsServer, startVueDevtools, unplugin, unpluginFactory };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as _unplugin from 'unplugin';
2
2
  import { UnpluginFactory } from 'unplugin';
3
3
  import { ChildProcess } from 'node:child_process';
4
+ import dns2 from 'dns2';
4
5
  import { Options } from './types.js';
5
6
  import 'webpack-dev-server';
6
7
  import 'node:http';
@@ -8,10 +9,13 @@ import 'vite-plugin-vconsole';
8
9
 
9
10
  declare const resovedInfo: {
10
11
  devtoolsInstance: ChildProcess | undefined;
12
+ dnsServerInstence: ReturnType<typeof dns2.createServer> | undefined;
11
13
  availablePort: number | undefined;
12
14
  targetURL: undefined | URL;
13
15
  };
16
+ declare function startVueDevtools(enable?: boolean): void;
17
+ declare function startDnsServer(options?: Options): void;
14
18
  declare const unpluginFactory: UnpluginFactory<Options | undefined, boolean>;
15
19
  declare const unplugin: _unplugin.UnpluginInstance<Options | undefined, boolean>;
16
20
 
17
- export { unplugin as default, resovedInfo, unplugin, unpluginFactory };
21
+ export { unplugin as default, resovedInfo, startDnsServer, startVueDevtools, unplugin, unpluginFactory };
package/dist/index.js CHANGED
@@ -1,13 +1,17 @@
1
1
  import {
2
+ index_default,
2
3
  resovedInfo,
3
- src_default,
4
+ startDnsServer,
5
+ startVueDevtools,
4
6
  unplugin,
5
7
  unpluginFactory
6
- } from "./chunk-RDTWBIQD.js";
7
- import "./chunk-PMOTCIQR.js";
8
+ } from "./chunk-QU7HLXVD.js";
9
+ import "./chunk-ZEHXGFFH.js";
8
10
  export {
9
- src_default as default,
11
+ index_default as default,
10
12
  resovedInfo,
13
+ startDnsServer,
14
+ startVueDevtools,
11
15
  unplugin,
12
16
  unpluginFactory
13
17
  };
@@ -2,7 +2,7 @@ import {
2
2
  FormData,
3
3
  __forAwait,
4
4
  file_default
5
- } from "./chunk-PMOTCIQR.js";
5
+ } from "./chunk-ZEHXGFFH.js";
6
6
 
7
7
  // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/multipart-parser.js
8
8
  var s = 0;
@@ -131,6 +131,7 @@ var MultipartParser = class {
131
131
  state = S.HEADER_FIELD;
132
132
  mark("onHeaderField");
133
133
  index = 0;
134
+ // falls through
134
135
  case S.HEADER_FIELD:
135
136
  if (c === CR) {
136
137
  clear("onHeaderField");
@@ -160,6 +161,7 @@ var MultipartParser = class {
160
161
  }
161
162
  mark("onHeaderValue");
162
163
  state = S.HEADER_VALUE;
164
+ // falls through
163
165
  case S.HEADER_VALUE:
164
166
  if (c === CR) {
165
167
  dataCallback("onHeaderValue", true);
@@ -183,6 +185,7 @@ var MultipartParser = class {
183
185
  case S.PART_DATA_START:
184
186
  state = S.PART_DATA;
185
187
  mark("onPartData");
188
+ // falls through
186
189
  case S.PART_DATA:
187
190
  previousIndex = index;
188
191
  if (index === 0) {
package/dist/nuxt.cjs CHANGED
@@ -5069,6 +5069,7 @@ var init_multipart_parser = __esm({
5069
5069
  state = S.HEADER_FIELD;
5070
5070
  mark("onHeaderField");
5071
5071
  index = 0;
5072
+ // falls through
5072
5073
  case S.HEADER_FIELD:
5073
5074
  if (c2 === CR) {
5074
5075
  clear("onHeaderField");
@@ -5098,6 +5099,7 @@ var init_multipart_parser = __esm({
5098
5099
  }
5099
5100
  mark("onHeaderValue");
5100
5101
  state = S.HEADER_VALUE;
5102
+ // falls through
5101
5103
  case S.HEADER_VALUE:
5102
5104
  if (c2 === CR) {
5103
5105
  dataCallback("onHeaderValue", true);
@@ -5121,6 +5123,7 @@ var init_multipart_parser = __esm({
5121
5123
  case S.PART_DATA_START:
5122
5124
  state = S.PART_DATA;
5123
5125
  mark("onPartData");
5126
+ // falls through
5124
5127
  case S.PART_DATA:
5125
5128
  previousIndex = index;
5126
5129
  if (index === 0) {
@@ -5220,6 +5223,8 @@ var import_vite_plugin_vconsole = __toESM(require("vite-plugin-vconsole"), 1);
5220
5223
  // src/index.ts
5221
5224
  var import_node_child_process = require("child_process");
5222
5225
  var import_node_process = __toESM(require("process"), 1);
5226
+ var import_node_http3 = require("http");
5227
+ var import_node_net2 = require("net");
5223
5228
 
5224
5229
  // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/index.js
5225
5230
  var import_node_http2 = __toESM(require("http"), 1);
@@ -6517,20 +6522,94 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6517
6522
  var import_unplugin = require("unplugin");
6518
6523
  var import_picocolors = __toESM(require("picocolors"), 1);
6519
6524
  var import_cookie = __toESM(require("cookie"), 1);
6520
- var import_chii = require("chii");
6525
+ var import_z_chii = require("z-chii");
6526
+ var import_dns2 = __toESM(require("dns2"), 1);
6521
6527
  var import_get_port_please = require("get-port-please");
6528
+ var import_http_proxy = __toESM(require("http-proxy"), 1);
6522
6529
  var cwd = import_node_process.default.cwd();
6523
6530
  var config;
6524
6531
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
6525
6532
  var resovedInfo = {
6526
6533
  devtoolsInstance: void 0,
6534
+ dnsServerInstence: void 0,
6527
6535
  availablePort: void 0,
6528
6536
  targetURL: void 0
6529
6537
  };
6538
+ function startVueDevtools(enable) {
6539
+ if (enable && !resovedInfo.devtoolsInstance) {
6540
+ resovedInfo.devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
6541
+ console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
6542
+ resovedInfo.devtoolsInstance.on("exit", () => {
6543
+ resovedInfo.devtoolsInstance = void 0;
6544
+ });
6545
+ import_node_process.default.on("exit", () => {
6546
+ if (resovedInfo.devtoolsInstance) {
6547
+ resovedInfo.devtoolsInstance.kill();
6548
+ }
6549
+ });
6550
+ }
6551
+ }
6552
+ function startDnsServer(options) {
6553
+ function debug(...args) {
6554
+ if (options == null ? void 0 : options.debug) {
6555
+ console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
6556
+ }
6557
+ }
6558
+ if ((options == null ? void 0 : options.enable) && (options == null ? void 0 : options.dns) && !resovedInfo.dnsServerInstence) {
6559
+ const { Packet } = import_dns2.default;
6560
+ resovedInfo.dnsServerInstence = import_dns2.default.createServer({
6561
+ tcp: true,
6562
+ udp: true,
6563
+ handle: (request, send, rinfo) => {
6564
+ var _a4;
6565
+ const response = Packet.createResponseFromRequest(request);
6566
+ const [question] = request.questions;
6567
+ const { name } = question;
6568
+ if (name === options.dns.host) {
6569
+ response.answers.push({
6570
+ name,
6571
+ type: Packet.TYPE.A,
6572
+ class: Packet.CLASS.IN,
6573
+ ttl: 300,
6574
+ address: (_a4 = options.dns) == null ? void 0 : _a4.ip
6575
+ });
6576
+ debug(`dns request from ${rinfo.address}:${rinfo.port} for ${name} => ${options.dns.ip}`);
6577
+ }
6578
+ send(response);
6579
+ }
6580
+ });
6581
+ resovedInfo.dnsServerInstence.listen({
6582
+ udp: { address: "0.0.0.0", port: 53 },
6583
+ tcp: { address: "0.0.0.0", port: 53 }
6584
+ }).then(() => {
6585
+ debug("DNS server is running.");
6586
+ const dns = new import_dns2.default({
6587
+ port: 53,
6588
+ nameServers: ["127.0.0.1", "8.8.8.8"]
6589
+ });
6590
+ dns.resolveA(options.dns.host).then((addresses) => {
6591
+ var _a4;
6592
+ if (((_a4 = addresses.answers[0]) == null ? void 0 : _a4.address) === options.dns.ip) {
6593
+ startDnsServer(options);
6594
+ 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}`)}`);
6595
+ } else {
6596
+ debug(addresses.answers[0].address);
6597
+ throw new Error("DNS server started failed");
6598
+ }
6599
+ }).catch((e2) => {
6600
+ throw e2;
6601
+ });
6602
+ }).catch((e2) => {
6603
+ debug(e2);
6604
+ console.log(` ${import_picocolors.default.red("\u279C")} ${import_picocolors.default.bold((e2 == null ? void 0 : e2.message) || e2)}`);
6605
+ });
6606
+ }
6607
+ }
6530
6608
  var unpluginFactory = (options) => {
6531
6609
  const {
6532
- chii: enableChii = true
6610
+ chii
6533
6611
  } = options || {};
6612
+ const enableChii = (chii == null ? void 0 : chii.enable) !== false;
6534
6613
  function debug(...args) {
6535
6614
  if (options == null ? void 0 : options.debug) {
6536
6615
  console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
@@ -6546,22 +6625,16 @@ var unpluginFactory = (options) => {
6546
6625
  var _a4, _b, _c;
6547
6626
  if ((options == null ? void 0 : options.enable) && enableChii && !resovedInfo.availablePort) {
6548
6627
  resovedInfo.availablePort = await (0, import_get_port_please.getRandomPort)();
6549
- debug(`chii server port: ${JSON.stringify({ availablePort: resovedInfo.availablePort })}`);
6550
- (0, import_chii.start)({
6551
- host: "0.0.0.0",
6628
+ (0, import_z_chii.start)({
6552
6629
  port: resovedInfo.availablePort
6553
6630
  });
6631
+ debug(`chii server port: ${resovedInfo.availablePort}`);
6554
6632
  }
6555
6633
  if (options == null ? void 0 : options.enable) {
6556
6634
  const codes = [
6557
6635
  "/* eslint-disable */;",
6558
6636
  ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) ? `import { devtools } from '@vue/devtools'
6559
- 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});` : "",
6560
- (options == null ? void 0 : options.enable) && enableChii ? `(() => {
6561
- const script = document.createElement('script');
6562
- script.src="http://localhost:${resovedInfo.availablePort}/target.js";
6563
- document.body.appendChild(script);
6564
- })()` : "",
6637
+ 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});` : "",
6565
6638
  "/* eslint-enable */",
6566
6639
  `${_source};`
6567
6640
  ];
@@ -6581,6 +6654,22 @@ var unpluginFactory = (options) => {
6581
6654
  configResolved(_config) {
6582
6655
  config = _config;
6583
6656
  },
6657
+ transformIndexHtml(html) {
6658
+ if (enableChii) {
6659
+ return html.replace(
6660
+ "</body>",
6661
+ `</body>
6662
+ <script>
6663
+ (() => {
6664
+ const script = document.createElement('script');
6665
+ script.src="./__chii_proxy/target.js";
6666
+ document.body.appendChild(script);
6667
+ })()
6668
+ </script>
6669
+ `
6670
+ );
6671
+ }
6672
+ },
6584
6673
  async configureServer(server) {
6585
6674
  var _a4, _b;
6586
6675
  if (!(options == null ? void 0 : options.enable)) {
@@ -6616,7 +6705,7 @@ var unpluginFactory = (options) => {
6616
6705
  server.middlewares.use((req, res, next) => {
6617
6706
  const cookies = import_cookie.default.parse(req.headers.cookie || "");
6618
6707
  for (const [name, value] of Object.entries(cookies)) {
6619
- if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6708
+ if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6620
6709
  const serializedCookie = import_cookie.default.serialize(name, value, {
6621
6710
  httpOnly: false
6622
6711
  });
@@ -6627,6 +6716,51 @@ var unpluginFactory = (options) => {
6627
6716
  });
6628
6717
  }
6629
6718
  if (enableChii) {
6719
+ let createProxyMiddleware2 = function() {
6720
+ let proxy = null;
6721
+ const handleUpgrade = (req, socket, head) => {
6722
+ var _a5;
6723
+ if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
6724
+ debug("WS upgrade:", req.url);
6725
+ req.url = req.url.replace("/__chii_proxy", "");
6726
+ proxy.ws(req, socket, head);
6727
+ }
6728
+ };
6729
+ return (resolvedInfo) => {
6730
+ return (req, res, next) => {
6731
+ var _a5;
6732
+ if (!proxy && resolvedInfo.availablePort) {
6733
+ proxy = import_http_proxy.default.createProxyServer({
6734
+ target: `http://localhost:${resolvedInfo.availablePort}`,
6735
+ ws: true
6736
+ // changeOrigin: true, // Consider if you need this
6737
+ });
6738
+ proxy.on("error", (err, req2, res2) => {
6739
+ console.error("Proxy error:", err);
6740
+ if (res2 instanceof import_node_http3.ServerResponse) {
6741
+ if (!res2.headersSent) {
6742
+ res2.writeHead(500, { "Content-Type": "text/plain" });
6743
+ }
6744
+ res2.end(`Proxy error: ${err.message}`);
6745
+ } else if (res2 instanceof import_node_net2.Socket) {
6746
+ res2.destroy();
6747
+ }
6748
+ });
6749
+ if (req.socket.server) {
6750
+ req.socket.server.on("upgrade", handleUpgrade);
6751
+ }
6752
+ }
6753
+ if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
6754
+ debug(req.url);
6755
+ req.url = req.url.replace("/__chii_proxy", "");
6756
+ proxy.web(req, res);
6757
+ } else {
6758
+ next();
6759
+ }
6760
+ };
6761
+ };
6762
+ };
6763
+ var createProxyMiddleware = createProxyMiddleware2;
6630
6764
  server.middlewares.use("/__chrome_devtools", async (_req, res) => {
6631
6765
  try {
6632
6766
  const raw = await fetch(`http://localhost:${resovedInfo.availablePort}/targets`);
@@ -6635,6 +6769,9 @@ var unpluginFactory = (options) => {
6635
6769
  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`;
6636
6770
  res.writeHead(302, { Location: devToolsUrl });
6637
6771
  res.end();
6772
+ } else {
6773
+ res.writeHead(404);
6774
+ res.end();
6638
6775
  }
6639
6776
  } catch (error) {
6640
6777
  debug(`${error}`);
@@ -6642,6 +6779,8 @@ var unpluginFactory = (options) => {
6642
6779
  res.end();
6643
6780
  }
6644
6781
  });
6782
+ const proxyMiddleware = createProxyMiddleware2();
6783
+ server.middlewares.use(proxyMiddleware(resovedInfo));
6645
6784
  }
6646
6785
  server.middlewares.use("/open-dingtalk", (req, res) => {
6647
6786
  var _a5;
@@ -6649,20 +6788,10 @@ var unpluginFactory = (options) => {
6649
6788
  res.writeHead(302, {
6650
6789
  Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
6651
6790
  });
6652
- if (((_a5 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a5.enable) && !resovedInfo.devtoolsInstance) {
6653
- resovedInfo.devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
6654
- console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
6655
- resovedInfo.devtoolsInstance.on("exit", () => {
6656
- resovedInfo.devtoolsInstance = void 0;
6657
- });
6658
- import_node_process.default.on("exit", () => {
6659
- if (resovedInfo.devtoolsInstance) {
6660
- resovedInfo.devtoolsInstance.kill();
6661
- }
6662
- });
6663
- }
6791
+ startVueDevtools((_a5 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a5.enable);
6664
6792
  res.end();
6665
6793
  });
6794
+ startDnsServer(options);
6666
6795
  }
6667
6796
  },
6668
6797
  webpack(compiler) {
@@ -6693,6 +6822,7 @@ var unpluginFactory = (options) => {
6693
6822
  if (options == null ? void 0 : options.corpId) {
6694
6823
  resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6695
6824
  }
6825
+ startDnsServer(options);
6696
6826
  },
6697
6827
  async rspack(compiler) {
6698
6828
  var _a4, _b, _c, _d2, _e;
@@ -6721,6 +6851,7 @@ var unpluginFactory = (options) => {
6721
6851
  "Click to open chrome devtools"
6722
6852
  )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
6723
6853
  }
6854
+ startDnsServer(options);
6724
6855
  }
6725
6856
  };
6726
6857
  return unpluginDing;
package/dist/nuxt.d.cts CHANGED
@@ -6,6 +6,6 @@ import 'vite-plugin-vconsole';
6
6
 
7
7
  interface ModuleOptions extends Options {
8
8
  }
9
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
9
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
10
10
 
11
11
  export { type ModuleOptions, _default as default };
package/dist/nuxt.d.ts CHANGED
@@ -6,6 +6,6 @@ import 'vite-plugin-vconsole';
6
6
 
7
7
  interface ModuleOptions extends Options {
8
8
  }
9
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
9
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
10
10
 
11
11
  export { type ModuleOptions, _default as default };
package/dist/nuxt.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-2OB7UBRW.js";
4
- import "./chunk-RDTWBIQD.js";
5
- import "./chunk-PMOTCIQR.js";
3
+ } from "./chunk-VQXY6FXR.js";
4
+ import "./chunk-QU7HLXVD.js";
5
+ import "./chunk-ZEHXGFFH.js";
6
6
 
7
7
  // src/nuxt.ts
8
8
  import { addVitePlugin, defineNuxtModule } from "@nuxt/kit";