unplugin-dingtalk 0.5.0 → 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/rspack.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 (c3 === 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 (c3 === 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) {
@@ -6510,12 +6513,15 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6510
6513
  // src/index.ts
6511
6514
  var import_node_child_process = require("child_process");
6512
6515
  var import_node_process = __toESM(require("process"), 1);
6516
+ var import_node_http3 = require("http");
6517
+ var import_node_net2 = require("net");
6513
6518
  var import_unplugin = require("unplugin");
6514
6519
  var import_picocolors = __toESM(require("picocolors"), 1);
6515
6520
  var import_cookie = __toESM(require("cookie"), 1);
6516
- var import_chii = require("chii");
6521
+ var import_z_chii = require("z-chii");
6517
6522
  var import_dns2 = __toESM(require("dns2"), 1);
6518
6523
  var import_get_port_please = require("get-port-please");
6524
+ var import_http_proxy = __toESM(require("http-proxy"), 1);
6519
6525
  var cwd = import_node_process.default.cwd();
6520
6526
  var config;
6521
6527
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
@@ -6615,7 +6621,7 @@ var unpluginFactory = (options) => {
6615
6621
  var _a4, _b, _c;
6616
6622
  if ((options == null ? void 0 : options.enable) && enableChii && !resovedInfo.availablePort) {
6617
6623
  resovedInfo.availablePort = await (0, import_get_port_please.getRandomPort)();
6618
- (0, import_chii.start)({
6624
+ (0, import_z_chii.start)({
6619
6625
  port: resovedInfo.availablePort
6620
6626
  });
6621
6627
  debug(`chii server port: ${resovedInfo.availablePort}`);
@@ -6625,11 +6631,6 @@ var unpluginFactory = (options) => {
6625
6631
  "/* eslint-disable */;",
6626
6632
  ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) ? `import { devtools } from '@vue/devtools'
6627
6633
  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});` : "",
6628
- (options == null ? void 0 : options.enable) && enableChii ? `(() => {
6629
- const script = document.createElement('script');
6630
- script.src="http://${(chii == null ? void 0 : chii.host) || "127.0.0.1"}:${resovedInfo.availablePort}/target.js";
6631
- document.body.appendChild(script);
6632
- })()` : "",
6633
6634
  "/* eslint-enable */",
6634
6635
  `${_source};`
6635
6636
  ];
@@ -6649,6 +6650,22 @@ var unpluginFactory = (options) => {
6649
6650
  configResolved(_config) {
6650
6651
  config = _config;
6651
6652
  },
6653
+ transformIndexHtml(html) {
6654
+ if (enableChii) {
6655
+ return html.replace(
6656
+ "</body>",
6657
+ `</body>
6658
+ <script>
6659
+ (() => {
6660
+ const script = document.createElement('script');
6661
+ script.src="./__chii_proxy/target.js";
6662
+ document.body.appendChild(script);
6663
+ })()
6664
+ </script>
6665
+ `
6666
+ );
6667
+ }
6668
+ },
6652
6669
  async configureServer(server) {
6653
6670
  var _a4, _b;
6654
6671
  if (!(options == null ? void 0 : options.enable)) {
@@ -6684,7 +6701,7 @@ var unpluginFactory = (options) => {
6684
6701
  server.middlewares.use((req, res, next) => {
6685
6702
  const cookies = import_cookie.default.parse(req.headers.cookie || "");
6686
6703
  for (const [name, value] of Object.entries(cookies)) {
6687
- if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6704
+ if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6688
6705
  const serializedCookie = import_cookie.default.serialize(name, value, {
6689
6706
  httpOnly: false
6690
6707
  });
@@ -6695,6 +6712,51 @@ var unpluginFactory = (options) => {
6695
6712
  });
6696
6713
  }
6697
6714
  if (enableChii) {
6715
+ let createProxyMiddleware2 = function() {
6716
+ let proxy = null;
6717
+ const handleUpgrade = (req, socket, head) => {
6718
+ var _a5;
6719
+ if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
6720
+ debug("WS upgrade:", req.url);
6721
+ req.url = req.url.replace("/__chii_proxy", "");
6722
+ proxy.ws(req, socket, head);
6723
+ }
6724
+ };
6725
+ return (resolvedInfo) => {
6726
+ return (req, res, next) => {
6727
+ var _a5;
6728
+ if (!proxy && resolvedInfo.availablePort) {
6729
+ proxy = import_http_proxy.default.createProxyServer({
6730
+ target: `http://localhost:${resolvedInfo.availablePort}`,
6731
+ ws: true
6732
+ // changeOrigin: true, // Consider if you need this
6733
+ });
6734
+ proxy.on("error", (err, req2, res2) => {
6735
+ console.error("Proxy error:", err);
6736
+ if (res2 instanceof import_node_http3.ServerResponse) {
6737
+ if (!res2.headersSent) {
6738
+ res2.writeHead(500, { "Content-Type": "text/plain" });
6739
+ }
6740
+ res2.end(`Proxy error: ${err.message}`);
6741
+ } else if (res2 instanceof import_node_net2.Socket) {
6742
+ res2.destroy();
6743
+ }
6744
+ });
6745
+ if (req.socket.server) {
6746
+ req.socket.server.on("upgrade", handleUpgrade);
6747
+ }
6748
+ }
6749
+ if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
6750
+ debug(req.url);
6751
+ req.url = req.url.replace("/__chii_proxy", "");
6752
+ proxy.web(req, res);
6753
+ } else {
6754
+ next();
6755
+ }
6756
+ };
6757
+ };
6758
+ };
6759
+ var createProxyMiddleware = createProxyMiddleware2;
6698
6760
  server.middlewares.use("/__chrome_devtools", async (_req, res) => {
6699
6761
  try {
6700
6762
  const raw = await fetch(`http://localhost:${resovedInfo.availablePort}/targets`);
@@ -6713,6 +6775,8 @@ var unpluginFactory = (options) => {
6713
6775
  res.end();
6714
6776
  }
6715
6777
  });
6778
+ const proxyMiddleware = createProxyMiddleware2();
6779
+ server.middlewares.use(proxyMiddleware(resovedInfo));
6716
6780
  }
6717
6781
  server.middlewares.use("/open-dingtalk", (req, res) => {
6718
6782
  var _a5;
@@ -6805,7 +6869,7 @@ var rspack_default = (options) => {
6805
6869
  middlewares.unshift((req, res, next) => {
6806
6870
  const cookies = import_cookie2.default.parse(req.headers.cookie || "");
6807
6871
  for (const [name, value] of Object.entries(cookies)) {
6808
- if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6872
+ if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6809
6873
  const serializedCookie = import_cookie2.default.serialize(name, value, {
6810
6874
  httpOnly: false
6811
6875
  });
package/dist/rspack.d.cts CHANGED
@@ -1,9 +1,8 @@
1
- import * as _unplugin from 'unplugin';
2
1
  import { Options, RspackSetupMiddlewares } from './types.cjs';
3
2
  import 'webpack-dev-server';
4
3
  import 'node:http';
5
4
  import 'vite-plugin-vconsole';
6
5
 
7
- declare const _default: (options: Options) => readonly [RspackSetupMiddlewares, _unplugin.RspackPluginInstance];
6
+ declare const _default: (options: Options) => readonly [RspackSetupMiddlewares, _rspack_core_dist_config_types.RspackPluginInstance];
8
7
 
9
8
  export { _default as default };
package/dist/rspack.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import * as _unplugin from 'unplugin';
2
1
  import { Options, RspackSetupMiddlewares } from './types.js';
3
2
  import 'webpack-dev-server';
4
3
  import 'node:http';
5
4
  import 'vite-plugin-vconsole';
6
5
 
7
- declare const _default: (options: Options) => readonly [RspackSetupMiddlewares, _unplugin.RspackPluginInstance];
6
+ declare const _default: (options: Options) => readonly [RspackSetupMiddlewares, _rspack_core_dist_config_types.RspackPluginInstance];
8
7
 
9
8
  export { _default as default };
package/dist/rspack.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  resovedInfo,
4
4
  startVueDevtools,
5
5
  unpluginFactory
6
- } from "./chunk-OSHJOAQB.js";
7
- import "./chunk-PMOTCIQR.js";
6
+ } from "./chunk-QU7HLXVD.js";
7
+ import "./chunk-ZEHXGFFH.js";
8
8
 
9
9
  // src/rspack.ts
10
10
  import { createRspackPlugin } from "unplugin";
@@ -25,7 +25,7 @@ var rspack_default = (options) => {
25
25
  middlewares.unshift((req, res, next) => {
26
26
  const cookies = cookie.parse(req.headers.cookie || "");
27
27
  for (const [name, value] of Object.entries(cookies)) {
28
- if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
28
+ if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
29
29
  const serializedCookie = cookie.serialize(name, value, {
30
30
  httpOnly: false
31
31
  });
package/dist/vite.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) {
@@ -5217,6 +5220,8 @@ var import_vite_plugin_vconsole = __toESM(require("vite-plugin-vconsole"), 1);
5217
5220
  // src/index.ts
5218
5221
  var import_node_child_process = require("child_process");
5219
5222
  var import_node_process = __toESM(require("process"), 1);
5223
+ var import_node_http3 = require("http");
5224
+ var import_node_net2 = require("net");
5220
5225
 
5221
5226
  // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/index.js
5222
5227
  var import_node_http2 = __toESM(require("http"), 1);
@@ -6514,9 +6519,10 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6514
6519
  var import_unplugin = require("unplugin");
6515
6520
  var import_picocolors = __toESM(require("picocolors"), 1);
6516
6521
  var import_cookie = __toESM(require("cookie"), 1);
6517
- var import_chii = require("chii");
6522
+ var import_z_chii = require("z-chii");
6518
6523
  var import_dns2 = __toESM(require("dns2"), 1);
6519
6524
  var import_get_port_please = require("get-port-please");
6525
+ var import_http_proxy = __toESM(require("http-proxy"), 1);
6520
6526
  var cwd = import_node_process.default.cwd();
6521
6527
  var config;
6522
6528
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
@@ -6616,7 +6622,7 @@ var unpluginFactory = (options) => {
6616
6622
  var _a4, _b, _c;
6617
6623
  if ((options == null ? void 0 : options.enable) && enableChii && !resovedInfo.availablePort) {
6618
6624
  resovedInfo.availablePort = await (0, import_get_port_please.getRandomPort)();
6619
- (0, import_chii.start)({
6625
+ (0, import_z_chii.start)({
6620
6626
  port: resovedInfo.availablePort
6621
6627
  });
6622
6628
  debug(`chii server port: ${resovedInfo.availablePort}`);
@@ -6626,11 +6632,6 @@ var unpluginFactory = (options) => {
6626
6632
  "/* eslint-disable */;",
6627
6633
  ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) ? `import { devtools } from '@vue/devtools'
6628
6634
  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});` : "",
6629
- (options == null ? void 0 : options.enable) && enableChii ? `(() => {
6630
- const script = document.createElement('script');
6631
- script.src="http://${(chii == null ? void 0 : chii.host) || "127.0.0.1"}:${resovedInfo.availablePort}/target.js";
6632
- document.body.appendChild(script);
6633
- })()` : "",
6634
6635
  "/* eslint-enable */",
6635
6636
  `${_source};`
6636
6637
  ];
@@ -6650,6 +6651,22 @@ var unpluginFactory = (options) => {
6650
6651
  configResolved(_config) {
6651
6652
  config = _config;
6652
6653
  },
6654
+ transformIndexHtml(html) {
6655
+ if (enableChii) {
6656
+ return html.replace(
6657
+ "</body>",
6658
+ `</body>
6659
+ <script>
6660
+ (() => {
6661
+ const script = document.createElement('script');
6662
+ script.src="./__chii_proxy/target.js";
6663
+ document.body.appendChild(script);
6664
+ })()
6665
+ </script>
6666
+ `
6667
+ );
6668
+ }
6669
+ },
6653
6670
  async configureServer(server) {
6654
6671
  var _a4, _b;
6655
6672
  if (!(options == null ? void 0 : options.enable)) {
@@ -6685,7 +6702,7 @@ var unpluginFactory = (options) => {
6685
6702
  server.middlewares.use((req, res, next) => {
6686
6703
  const cookies = import_cookie.default.parse(req.headers.cookie || "");
6687
6704
  for (const [name, value] of Object.entries(cookies)) {
6688
- if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6705
+ if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6689
6706
  const serializedCookie = import_cookie.default.serialize(name, value, {
6690
6707
  httpOnly: false
6691
6708
  });
@@ -6696,6 +6713,51 @@ var unpluginFactory = (options) => {
6696
6713
  });
6697
6714
  }
6698
6715
  if (enableChii) {
6716
+ let createProxyMiddleware2 = function() {
6717
+ let proxy = null;
6718
+ const handleUpgrade = (req, socket, head) => {
6719
+ var _a5;
6720
+ if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
6721
+ debug("WS upgrade:", req.url);
6722
+ req.url = req.url.replace("/__chii_proxy", "");
6723
+ proxy.ws(req, socket, head);
6724
+ }
6725
+ };
6726
+ return (resolvedInfo) => {
6727
+ return (req, res, next) => {
6728
+ var _a5;
6729
+ if (!proxy && resolvedInfo.availablePort) {
6730
+ proxy = import_http_proxy.default.createProxyServer({
6731
+ target: `http://localhost:${resolvedInfo.availablePort}`,
6732
+ ws: true
6733
+ // changeOrigin: true, // Consider if you need this
6734
+ });
6735
+ proxy.on("error", (err, req2, res2) => {
6736
+ console.error("Proxy error:", err);
6737
+ if (res2 instanceof import_node_http3.ServerResponse) {
6738
+ if (!res2.headersSent) {
6739
+ res2.writeHead(500, { "Content-Type": "text/plain" });
6740
+ }
6741
+ res2.end(`Proxy error: ${err.message}`);
6742
+ } else if (res2 instanceof import_node_net2.Socket) {
6743
+ res2.destroy();
6744
+ }
6745
+ });
6746
+ if (req.socket.server) {
6747
+ req.socket.server.on("upgrade", handleUpgrade);
6748
+ }
6749
+ }
6750
+ if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
6751
+ debug(req.url);
6752
+ req.url = req.url.replace("/__chii_proxy", "");
6753
+ proxy.web(req, res);
6754
+ } else {
6755
+ next();
6756
+ }
6757
+ };
6758
+ };
6759
+ };
6760
+ var createProxyMiddleware = createProxyMiddleware2;
6699
6761
  server.middlewares.use("/__chrome_devtools", async (_req, res) => {
6700
6762
  try {
6701
6763
  const raw = await fetch(`http://localhost:${resovedInfo.availablePort}/targets`);
@@ -6714,6 +6776,8 @@ var unpluginFactory = (options) => {
6714
6776
  res.end();
6715
6777
  }
6716
6778
  });
6779
+ const proxyMiddleware = createProxyMiddleware2();
6780
+ server.middlewares.use(proxyMiddleware(resovedInfo));
6717
6781
  }
6718
6782
  server.middlewares.use("/open-dingtalk", (req, res) => {
6719
6783
  var _a5;
package/dist/vite.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-TZDLEHKX.js";
4
- import "./chunk-OSHJOAQB.js";
5
- import "./chunk-PMOTCIQR.js";
3
+ } from "./chunk-VQXY6FXR.js";
4
+ import "./chunk-QU7HLXVD.js";
5
+ import "./chunk-ZEHXGFFH.js";
6
6
  export {
7
7
  vite_default as default
8
8
  };
package/dist/webpack.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 (c3 === 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 (c3 === 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) {
@@ -6510,12 +6513,15 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6510
6513
  // src/index.ts
6511
6514
  var import_node_child_process = require("child_process");
6512
6515
  var import_node_process = __toESM(require("process"), 1);
6516
+ var import_node_http3 = require("http");
6517
+ var import_node_net2 = require("net");
6513
6518
  var import_unplugin = require("unplugin");
6514
6519
  var import_picocolors = __toESM(require("picocolors"), 1);
6515
6520
  var import_cookie = __toESM(require("cookie"), 1);
6516
- var import_chii = require("chii");
6521
+ var import_z_chii = require("z-chii");
6517
6522
  var import_dns2 = __toESM(require("dns2"), 1);
6518
6523
  var import_get_port_please = require("get-port-please");
6524
+ var import_http_proxy = __toESM(require("http-proxy"), 1);
6519
6525
  var cwd = import_node_process.default.cwd();
6520
6526
  var config;
6521
6527
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
@@ -6615,7 +6621,7 @@ var unpluginFactory = (options) => {
6615
6621
  var _a4, _b, _c;
6616
6622
  if ((options == null ? void 0 : options.enable) && enableChii && !resovedInfo.availablePort) {
6617
6623
  resovedInfo.availablePort = await (0, import_get_port_please.getRandomPort)();
6618
- (0, import_chii.start)({
6624
+ (0, import_z_chii.start)({
6619
6625
  port: resovedInfo.availablePort
6620
6626
  });
6621
6627
  debug(`chii server port: ${resovedInfo.availablePort}`);
@@ -6625,11 +6631,6 @@ var unpluginFactory = (options) => {
6625
6631
  "/* eslint-disable */;",
6626
6632
  ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) ? `import { devtools } from '@vue/devtools'
6627
6633
  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});` : "",
6628
- (options == null ? void 0 : options.enable) && enableChii ? `(() => {
6629
- const script = document.createElement('script');
6630
- script.src="http://${(chii == null ? void 0 : chii.host) || "127.0.0.1"}:${resovedInfo.availablePort}/target.js";
6631
- document.body.appendChild(script);
6632
- })()` : "",
6633
6634
  "/* eslint-enable */",
6634
6635
  `${_source};`
6635
6636
  ];
@@ -6649,6 +6650,22 @@ var unpluginFactory = (options) => {
6649
6650
  configResolved(_config) {
6650
6651
  config = _config;
6651
6652
  },
6653
+ transformIndexHtml(html) {
6654
+ if (enableChii) {
6655
+ return html.replace(
6656
+ "</body>",
6657
+ `</body>
6658
+ <script>
6659
+ (() => {
6660
+ const script = document.createElement('script');
6661
+ script.src="./__chii_proxy/target.js";
6662
+ document.body.appendChild(script);
6663
+ })()
6664
+ </script>
6665
+ `
6666
+ );
6667
+ }
6668
+ },
6652
6669
  async configureServer(server) {
6653
6670
  var _a4, _b;
6654
6671
  if (!(options == null ? void 0 : options.enable)) {
@@ -6684,7 +6701,7 @@ var unpluginFactory = (options) => {
6684
6701
  server.middlewares.use((req, res, next) => {
6685
6702
  const cookies = import_cookie.default.parse(req.headers.cookie || "");
6686
6703
  for (const [name, value] of Object.entries(cookies)) {
6687
- if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6704
+ if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6688
6705
  const serializedCookie = import_cookie.default.serialize(name, value, {
6689
6706
  httpOnly: false
6690
6707
  });
@@ -6695,6 +6712,51 @@ var unpluginFactory = (options) => {
6695
6712
  });
6696
6713
  }
6697
6714
  if (enableChii) {
6715
+ let createProxyMiddleware2 = function() {
6716
+ let proxy = null;
6717
+ const handleUpgrade = (req, socket, head) => {
6718
+ var _a5;
6719
+ if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
6720
+ debug("WS upgrade:", req.url);
6721
+ req.url = req.url.replace("/__chii_proxy", "");
6722
+ proxy.ws(req, socket, head);
6723
+ }
6724
+ };
6725
+ return (resolvedInfo) => {
6726
+ return (req, res, next) => {
6727
+ var _a5;
6728
+ if (!proxy && resolvedInfo.availablePort) {
6729
+ proxy = import_http_proxy.default.createProxyServer({
6730
+ target: `http://localhost:${resolvedInfo.availablePort}`,
6731
+ ws: true
6732
+ // changeOrigin: true, // Consider if you need this
6733
+ });
6734
+ proxy.on("error", (err, req2, res2) => {
6735
+ console.error("Proxy error:", err);
6736
+ if (res2 instanceof import_node_http3.ServerResponse) {
6737
+ if (!res2.headersSent) {
6738
+ res2.writeHead(500, { "Content-Type": "text/plain" });
6739
+ }
6740
+ res2.end(`Proxy error: ${err.message}`);
6741
+ } else if (res2 instanceof import_node_net2.Socket) {
6742
+ res2.destroy();
6743
+ }
6744
+ });
6745
+ if (req.socket.server) {
6746
+ req.socket.server.on("upgrade", handleUpgrade);
6747
+ }
6748
+ }
6749
+ if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
6750
+ debug(req.url);
6751
+ req.url = req.url.replace("/__chii_proxy", "");
6752
+ proxy.web(req, res);
6753
+ } else {
6754
+ next();
6755
+ }
6756
+ };
6757
+ };
6758
+ };
6759
+ var createProxyMiddleware = createProxyMiddleware2;
6698
6760
  server.middlewares.use("/__chrome_devtools", async (_req, res) => {
6699
6761
  try {
6700
6762
  const raw = await fetch(`http://localhost:${resovedInfo.availablePort}/targets`);
@@ -6713,6 +6775,8 @@ var unpluginFactory = (options) => {
6713
6775
  res.end();
6714
6776
  }
6715
6777
  });
6778
+ const proxyMiddleware = createProxyMiddleware2();
6779
+ server.middlewares.use(proxyMiddleware(resovedInfo));
6716
6780
  }
6717
6781
  server.middlewares.use("/open-dingtalk", (req, res) => {
6718
6782
  var _a5;
@@ -6805,7 +6869,7 @@ var webpack_default = (options) => {
6805
6869
  devServer.app.use((req, res, next) => {
6806
6870
  const cookies = import_cookie2.default.parse(req.headers.cookie || "");
6807
6871
  for (const [name, value] of Object.entries(cookies)) {
6808
- if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6872
+ if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6809
6873
  const serializedCookie = import_cookie2.default.serialize(name, value, {
6810
6874
  httpOnly: false
6811
6875
  });
package/dist/webpack.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  resovedInfo,
4
4
  startVueDevtools,
5
5
  unpluginFactory
6
- } from "./chunk-OSHJOAQB.js";
7
- import "./chunk-PMOTCIQR.js";
6
+ } from "./chunk-QU7HLXVD.js";
7
+ import "./chunk-ZEHXGFFH.js";
8
8
 
9
9
  // src/webpack.ts
10
10
  import { createWebpackPlugin } from "unplugin";
@@ -25,7 +25,7 @@ var webpack_default = (options) => {
25
25
  devServer.app.use((req, res, next) => {
26
26
  const cookies = cookie.parse(req.headers.cookie || "");
27
27
  for (const [name, value] of Object.entries(cookies)) {
28
- if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
28
+ if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
29
29
  const serializedCookie = cookie.serialize(name, value, {
30
30
  httpOnly: false
31
31
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-dingtalk",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.5.2",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/zcf0508/unplugin-dingtalk#readme",
@@ -123,14 +123,15 @@
123
123
  },
124
124
  "dependencies": {
125
125
  "@antfu/eslint-config": "^2.18.1",
126
- "chii": "^1.10.0",
127
- "cookie": "^0.6.0",
126
+ "cookie": "^1.0.2",
128
127
  "dns2": "^2.1.0",
129
128
  "eslint-plugin-security": "^3.0.0",
130
129
  "get-port-please": "^3.1.2",
130
+ "http-proxy": "^1.18.1",
131
131
  "picocolors": "^1.0.1",
132
132
  "unplugin": "^1.5.1",
133
- "vite-plugin-vconsole": "^2.1.1"
133
+ "vite-plugin-vconsole": "^2.1.1",
134
+ "z-chii": "1.15.5-beta.1"
134
135
  },
135
136
  "devDependencies": {
136
137
  "@nuxt/kit": "^3.8.2",