unplugin-dingtalk 0.3.1 → 0.4.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/rspack.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 process3 = require("process");
4393
- const { emitWarning } = process3;
4392
+ const process4 = require("process");
4393
+ const { emitWarning } = process4;
4394
4394
  try {
4395
- process3.emitWarning = () => {
4395
+ process4.emitWarning = () => {
4396
4396
  };
4397
4397
  Object.assign(globalThis, require("stream/web"));
4398
- process3.emitWarning = emitWarning;
4398
+ process4.emitWarning = emitWarning;
4399
4399
  } catch (error) {
4400
- process3.emitWarning = emitWarning;
4400
+ process4.emitWarning = emitWarning;
4401
4401
  throw error;
4402
4402
  }
4403
4403
  } catch (error) {
@@ -4707,17 +4707,17 @@ var init_file = __esm({
4707
4707
 
4708
4708
  // node_modules/.pnpm/formdata-polyfill@4.0.10/node_modules/formdata-polyfill/esm.min.js
4709
4709
  function formDataToBlob(F2, B = fetch_blob_default) {
4710
- var b = `${r()}${r()}`.replace(/\./g, "").slice(-28).padStart(32, "-"), c2 = [], p = `--${b}\r
4710
+ var b = `${r()}${r()}`.replace(/\./g, "").slice(-28).padStart(32, "-"), c3 = [], p = `--${b}\r
4711
4711
  Content-Disposition: form-data; name="`;
4712
- F2.forEach((v, n) => typeof v == "string" ? c2.push(p + e(n) + `"\r
4712
+ F2.forEach((v, n) => typeof v == "string" ? c3.push(p + e(n) + `"\r
4713
4713
  \r
4714
4714
  ${v.replace(new RegExp("\\r(?!\\n)|(?<!\\r)\\n", "g"), "\r\n")}\r
4715
- `) : c2.push(p + e(n) + `"; filename="${e(v.name, 1)}"\r
4715
+ `) : c3.push(p + e(n) + `"; filename="${e(v.name, 1)}"\r
4716
4716
  Content-Type: ${v.type || "application/octet-stream"}\r
4717
4717
  \r
4718
4718
  `, v, "\r\n"));
4719
- c2.push(`--${b}--`);
4720
- return new B(c2, { type: "multipart/form-data; boundary=" + b });
4719
+ c3.push(`--${b}--`);
4720
+ return new B(c3, { type: "multipart/form-data; boundary=" + b });
4721
4721
  }
4722
4722
  var t, i, h, r, m, f, e, x, _d, _a3, FormData;
4723
4723
  var init_esm_min = __esm({
@@ -4728,8 +4728,8 @@ var init_esm_min = __esm({
4728
4728
  ({ toStringTag: t, iterator: i, hasInstance: h } = Symbol);
4729
4729
  r = Math.random;
4730
4730
  m = "append,set,get,getAll,delete,keys,values,entries,forEach,constructor".split(",");
4731
- f = (a, b, c2) => (a += "", /^(Blob|File)$/.test(b && b[t]) ? [(c2 = c2 !== void 0 ? c2 + "" : b[t] == "File" ? b.name : "blob", a), b.name !== c2 || b[t] == "blob" ? new file_default([b], c2, b) : b] : [a, b + ""]);
4732
- e = (c2, f3) => (f3 ? c2 : c2.replace(/\r?\n|\r/g, "\r\n")).replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
4731
+ f = (a, b, c3) => (a += "", /^(Blob|File)$/.test(b && b[t]) ? [(c3 = c3 !== void 0 ? c3 + "" : b[t] == "File" ? b.name : "blob", a), b.name !== c3 || b[t] == "blob" ? new file_default([b], c3, b) : b] : [a, b + ""]);
4732
+ e = (c3, f3) => (f3 ? c3 : c3.replace(/\r?\n|\r/g, "\r\n")).replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
4733
4733
  x = (n, a, e2) => {
4734
4734
  if (a.length < e2) {
4735
4735
  throw new TypeError(`Failed to execute '${n}' on 'FormData': ${e2} arguments required, but only ${a.length} present.`);
@@ -4761,14 +4761,14 @@ var init_esm_min = __esm({
4761
4761
  get(a) {
4762
4762
  x("get", arguments, 1);
4763
4763
  a += "";
4764
- for (var b = __privateGet(this, _d), l = b.length, c2 = 0; c2 < l; c2++) if (b[c2][0] === a) return b[c2][1];
4764
+ for (var b = __privateGet(this, _d), l = b.length, c3 = 0; c3 < l; c3++) if (b[c3][0] === a) return b[c3][1];
4765
4765
  return null;
4766
4766
  }
4767
4767
  getAll(a, b) {
4768
4768
  x("getAll", arguments, 1);
4769
4769
  b = [];
4770
4770
  a += "";
4771
- __privateGet(this, _d).forEach((c2) => c2[0] === a && b.push(c2[1]));
4771
+ __privateGet(this, _d).forEach((c3) => c3[0] === a && b.push(c3[1]));
4772
4772
  return b;
4773
4773
  }
4774
4774
  has(a) {
@@ -4778,16 +4778,16 @@ var init_esm_min = __esm({
4778
4778
  }
4779
4779
  forEach(a, b) {
4780
4780
  x("forEach", arguments, 1);
4781
- for (var [c2, d] of this) a.call(b, d, c2, this);
4781
+ for (var [c3, d] of this) a.call(b, d, c3, this);
4782
4782
  }
4783
4783
  set(...a) {
4784
4784
  x("set", arguments, 2);
4785
- var b = [], c2 = true;
4785
+ var b = [], c3 = true;
4786
4786
  a = f(...a);
4787
4787
  __privateGet(this, _d).forEach((d) => {
4788
- d[0] === a[0] ? c2 && (c2 = !b.push(a)) : b.push(d);
4788
+ d[0] === a[0] ? c3 && (c3 = !b.push(a)) : b.push(d);
4789
4789
  });
4790
- c2 && b.push(a);
4790
+ c3 && b.push(a);
4791
4791
  __privateSet(this, _d, b);
4792
4792
  }
4793
4793
  *entries() {
@@ -4968,7 +4968,7 @@ var init_multipart_parser = __esm({
4968
4968
  COLON = 58;
4969
4969
  A = 97;
4970
4970
  Z = 122;
4971
- lower = (c2) => c2 | 32;
4971
+ lower = (c3) => c3 | 32;
4972
4972
  noop = () => {
4973
4973
  };
4974
4974
  MultipartParser = class {
@@ -5007,7 +5007,7 @@ var init_multipart_parser = __esm({
5007
5007
  const boundaryLength = this.boundary.length;
5008
5008
  const boundaryEnd = boundaryLength - 1;
5009
5009
  const bufferLength = data.length;
5010
- let c2;
5010
+ let c3;
5011
5011
  let cl;
5012
5012
  const mark = (name) => {
5013
5013
  this[name + "Mark"] = i2;
@@ -5034,22 +5034,22 @@ var init_multipart_parser = __esm({
5034
5034
  }
5035
5035
  };
5036
5036
  for (i2 = 0; i2 < length_; i2++) {
5037
- c2 = data[i2];
5037
+ c3 = data[i2];
5038
5038
  switch (state) {
5039
5039
  case S.START_BOUNDARY:
5040
5040
  if (index === boundary.length - 2) {
5041
- if (c2 === HYPHEN) {
5041
+ if (c3 === HYPHEN) {
5042
5042
  flags |= F.LAST_BOUNDARY;
5043
- } else if (c2 !== CR) {
5043
+ } else if (c3 !== CR) {
5044
5044
  return;
5045
5045
  }
5046
5046
  index++;
5047
5047
  break;
5048
5048
  } else if (index - 1 === boundary.length - 2) {
5049
- if (flags & F.LAST_BOUNDARY && c2 === HYPHEN) {
5049
+ if (flags & F.LAST_BOUNDARY && c3 === HYPHEN) {
5050
5050
  state = S.END;
5051
5051
  flags = 0;
5052
- } else if (!(flags & F.LAST_BOUNDARY) && c2 === LF) {
5052
+ } else if (!(flags & F.LAST_BOUNDARY) && c3 === LF) {
5053
5053
  index = 0;
5054
5054
  callback("onPartBegin");
5055
5055
  state = S.HEADER_FIELD_START;
@@ -5058,10 +5058,10 @@ var init_multipart_parser = __esm({
5058
5058
  }
5059
5059
  break;
5060
5060
  }
5061
- if (c2 !== boundary[index + 2]) {
5061
+ if (c3 !== boundary[index + 2]) {
5062
5062
  index = -2;
5063
5063
  }
5064
- if (c2 === boundary[index + 2]) {
5064
+ if (c3 === boundary[index + 2]) {
5065
5065
  index++;
5066
5066
  }
5067
5067
  break;
@@ -5070,16 +5070,16 @@ var init_multipart_parser = __esm({
5070
5070
  mark("onHeaderField");
5071
5071
  index = 0;
5072
5072
  case S.HEADER_FIELD:
5073
- if (c2 === CR) {
5073
+ if (c3 === CR) {
5074
5074
  clear("onHeaderField");
5075
5075
  state = S.HEADERS_ALMOST_DONE;
5076
5076
  break;
5077
5077
  }
5078
5078
  index++;
5079
- if (c2 === HYPHEN) {
5079
+ if (c3 === HYPHEN) {
5080
5080
  break;
5081
5081
  }
5082
- if (c2 === COLON) {
5082
+ if (c3 === COLON) {
5083
5083
  if (index === 1) {
5084
5084
  return;
5085
5085
  }
@@ -5087,32 +5087,32 @@ var init_multipart_parser = __esm({
5087
5087
  state = S.HEADER_VALUE_START;
5088
5088
  break;
5089
5089
  }
5090
- cl = lower(c2);
5090
+ cl = lower(c3);
5091
5091
  if (cl < A || cl > Z) {
5092
5092
  return;
5093
5093
  }
5094
5094
  break;
5095
5095
  case S.HEADER_VALUE_START:
5096
- if (c2 === SPACE) {
5096
+ if (c3 === SPACE) {
5097
5097
  break;
5098
5098
  }
5099
5099
  mark("onHeaderValue");
5100
5100
  state = S.HEADER_VALUE;
5101
5101
  case S.HEADER_VALUE:
5102
- if (c2 === CR) {
5102
+ if (c3 === CR) {
5103
5103
  dataCallback("onHeaderValue", true);
5104
5104
  callback("onHeaderEnd");
5105
5105
  state = S.HEADER_VALUE_ALMOST_DONE;
5106
5106
  }
5107
5107
  break;
5108
5108
  case S.HEADER_VALUE_ALMOST_DONE:
5109
- if (c2 !== LF) {
5109
+ if (c3 !== LF) {
5110
5110
  return;
5111
5111
  }
5112
5112
  state = S.HEADER_FIELD_START;
5113
5113
  break;
5114
5114
  case S.HEADERS_ALMOST_DONE:
5115
- if (c2 !== LF) {
5115
+ if (c3 !== LF) {
5116
5116
  return;
5117
5117
  }
5118
5118
  callback("onHeadersEnd");
@@ -5129,10 +5129,10 @@ var init_multipart_parser = __esm({
5129
5129
  i2 += boundaryLength;
5130
5130
  }
5131
5131
  i2 -= boundaryEnd;
5132
- c2 = data[i2];
5132
+ c3 = data[i2];
5133
5133
  }
5134
5134
  if (index < boundary.length) {
5135
- if (boundary[index] === c2) {
5135
+ if (boundary[index] === c3) {
5136
5136
  if (index === 0) {
5137
5137
  dataCallback("onPartData", true);
5138
5138
  }
@@ -5142,9 +5142,9 @@ var init_multipart_parser = __esm({
5142
5142
  }
5143
5143
  } else if (index === boundary.length) {
5144
5144
  index++;
5145
- if (c2 === CR) {
5145
+ if (c3 === CR) {
5146
5146
  flags |= F.PART_BOUNDARY;
5147
- } else if (c2 === HYPHEN) {
5147
+ } else if (c3 === HYPHEN) {
5148
5148
  flags |= F.LAST_BOUNDARY;
5149
5149
  } else {
5150
5150
  index = 0;
@@ -5152,7 +5152,7 @@ var init_multipart_parser = __esm({
5152
5152
  } else if (index - 1 === boundary.length) {
5153
5153
  if (flags & F.PART_BOUNDARY) {
5154
5154
  index = 0;
5155
- if (c2 === LF) {
5155
+ if (c3 === LF) {
5156
5156
  flags &= ~F.PART_BOUNDARY;
5157
5157
  callback("onPartEnd");
5158
5158
  callback("onPartBegin");
@@ -5160,7 +5160,7 @@ var init_multipart_parser = __esm({
5160
5160
  break;
5161
5161
  }
5162
5162
  } else if (flags & F.LAST_BOUNDARY) {
5163
- if (c2 === HYPHEN) {
5163
+ if (c3 === HYPHEN) {
5164
5164
  callback("onPartEnd");
5165
5165
  state = S.END;
5166
5166
  flags = 0;
@@ -5172,7 +5172,7 @@ var init_multipart_parser = __esm({
5172
5172
  }
5173
5173
  }
5174
5174
  if (index > 0) {
5175
- lookbehind[index - 1] = c2;
5175
+ lookbehind[index - 1] = c3;
5176
5176
  } else if (previousIndex > 0) {
5177
5177
  const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
5178
5178
  callback("onPartData", 0, previousIndex, _lookbehind);
@@ -5211,11 +5211,11 @@ __export(rspack_exports, {
5211
5211
  default: () => rspack_default
5212
5212
  });
5213
5213
  module.exports = __toCommonJS(rspack_exports);
5214
+ var import_node_child_process2 = require("child_process");
5215
+ var import_node_process2 = __toESM(require("process"), 1);
5214
5216
  var import_unplugin2 = require("unplugin");
5215
-
5216
- // src/index.ts
5217
- var import_node_child_process = require("child_process");
5218
- var import_node_process = __toESM(require("process"), 1);
5217
+ var import_cookie2 = __toESM(require("cookie"), 1);
5218
+ var import_picocolors2 = __toESM(require("picocolors"), 1);
5219
5219
 
5220
5220
  // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/index.js
5221
5221
  var import_node_http2 = __toESM(require("http"), 1);
@@ -5496,7 +5496,7 @@ async function consumeBody(data) {
5496
5496
  }
5497
5497
  if (body.readableEnded === true || body._readableState.ended === true) {
5498
5498
  try {
5499
- if (accum.every((c2) => typeof c2 === "string")) {
5499
+ if (accum.every((c3) => typeof c3 === "string")) {
5500
5500
  return import_node_buffer.Buffer.from(accum.join(""));
5501
5501
  }
5502
5502
  return import_node_buffer.Buffer.concat(accum, accumBytes);
@@ -6510,11 +6510,14 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6510
6510
  }
6511
6511
 
6512
6512
  // src/index.ts
6513
+ var import_node_child_process = require("child_process");
6514
+ var import_node_process = __toESM(require("process"), 1);
6513
6515
  var import_unplugin = require("unplugin");
6514
6516
  var import_picocolors = __toESM(require("picocolors"), 1);
6515
6517
  var import_cookie = __toESM(require("cookie"), 1);
6516
6518
  var import_chii = require("chii");
6517
6519
  var import_get_port_please = require("get-port-please");
6520
+ var cwd = import_node_process.default.cwd();
6518
6521
  var config;
6519
6522
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
6520
6523
  var resovedInfo = {
@@ -6547,17 +6550,18 @@ var unpluginFactory = (options) => {
6547
6550
  port: resovedInfo.availablePort
6548
6551
  });
6549
6552
  }
6550
- if ((options == null ? void 0 : options.enable) && ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable)) {
6553
+ if (options == null ? void 0 : options.enable) {
6551
6554
  const codes = [
6552
- `/* eslint-disable */;
6553
- import { devtools } from '@vue/devtools'
6554
- 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});`,
6555
+ "/* eslint-disable */;",
6556
+ ((_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});` : "",
6555
6558
  (options == null ? void 0 : options.enable) && enableChii ? `(() => {
6556
6559
  const script = document.createElement('script');
6557
6560
  script.src="http://localhost:${resovedInfo.availablePort}/target.js";
6558
6561
  document.body.appendChild(script);
6559
6562
  })()` : "",
6560
- `/* eslint-enable */${_source};`
6563
+ "/* eslint-enable */",
6564
+ `${_source};`
6561
6565
  ];
6562
6566
  return {
6563
6567
  code: codes.join("\n"),
@@ -6687,13 +6691,113 @@ var unpluginFactory = (options) => {
6687
6691
  if (options == null ? void 0 : options.corpId) {
6688
6692
  resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6689
6693
  }
6694
+ },
6695
+ async rspack(compiler) {
6696
+ var _a4, _b, _c, _d2, _e;
6697
+ if (!(options == null ? void 0 : options.enable)) {
6698
+ return;
6699
+ }
6700
+ const devServerOptions = __spreadValues(__spreadValues({
6701
+ host: "localhost",
6702
+ port: 8080
6703
+ }, compiler.options.devServer), (_c = (_b = await ((_a4 = await import("@rsbuild/core")) == null ? void 0 : _a4.loadConfig({
6704
+ cwd
6705
+ }))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
6706
+ const source = `${devServerOptions.host === "0.0.0.0" ? "127.0.0.1" : devServerOptions.host}:${devServerOptions.port}`;
6707
+ const base = compiler.options.output.publicPath || "/";
6708
+ const _targetUrl = (_d2 = options == null ? void 0 : options.targetUrl) != null ? _d2 : `http://${source}${base}`;
6709
+ resovedInfo.targetURL = new URL(_targetUrl);
6710
+ resovedInfo.targetURL.searchParams.append("ddtab", "true");
6711
+ if (options == null ? void 0 : options.corpId) {
6712
+ resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6713
+ }
6714
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
6715
+ `Open in dingtalk${((_e = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _e.enable) ? " (with vue-devtools)" : ""}`
6716
+ )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
6717
+ if (enableChii) {
6718
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
6719
+ "Click to open chrome devtools"
6720
+ )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
6721
+ }
6690
6722
  }
6691
6723
  };
6692
6724
  return unpluginDing;
6693
6725
  };
6694
6726
 
6695
6727
  // src/rspack.ts
6696
- var rspack_default = (0, import_unplugin2.createRspackPlugin)(unpluginFactory);
6728
+ var rspack_default = (options) => {
6729
+ function debug(...args) {
6730
+ if (options == null ? void 0 : options.debug) {
6731
+ console.log(` ${import_picocolors2.default.yellow("DEBUG")} `, ...args);
6732
+ }
6733
+ }
6734
+ const {
6735
+ chii: enableChii = true
6736
+ } = options || {};
6737
+ const injectSetupMiddlewares = (middlewares, _devServer) => {
6738
+ if (options.debugCookies && options.debugCookies.length > 0) {
6739
+ middlewares.unshift((req, res, next) => {
6740
+ const cookies = import_cookie2.default.parse(req.headers.cookie || "");
6741
+ for (const [name, value] of Object.entries(cookies)) {
6742
+ if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
6743
+ const serializedCookie = import_cookie2.default.serialize(name, value, {
6744
+ httpOnly: false
6745
+ });
6746
+ res.setHeader("Set-Cookie", serializedCookie);
6747
+ }
6748
+ }
6749
+ next();
6750
+ });
6751
+ }
6752
+ if (enableChii) {
6753
+ middlewares.unshift(async (req, res, next) => {
6754
+ if (req.url !== "/__chrome_devtools") {
6755
+ return next();
6756
+ }
6757
+ const availablePort = resovedInfo.availablePort;
6758
+ try {
6759
+ const raw = await fetch(`http://localhost:${availablePort}/targets`);
6760
+ const data = await raw.json();
6761
+ if ((data == null ? void 0 : data.targets.length) > 0) {
6762
+ 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`;
6763
+ res.writeHead(302, { Location: devToolsUrl });
6764
+ res.end();
6765
+ }
6766
+ } catch (error) {
6767
+ debug(`${error}`);
6768
+ res.writeHead(502);
6769
+ res.end();
6770
+ }
6771
+ });
6772
+ }
6773
+ middlewares.unshift((req, res, next) => {
6774
+ var _a4;
6775
+ if (req.url !== "/open-dingtalk") {
6776
+ return next();
6777
+ }
6778
+ const targetURL = resovedInfo.targetURL;
6779
+ debug(targetURL.toString());
6780
+ res.writeHead(302, {
6781
+ Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
6782
+ });
6783
+ if (((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) && !resovedInfo.devtoolsInstance) {
6784
+ resovedInfo.devtoolsInstance = (0, import_node_child_process2.exec)("npx vue-devtools");
6785
+ console.log(` ${import_picocolors2.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
6786
+ resovedInfo.devtoolsInstance.on("exit", () => {
6787
+ resovedInfo.devtoolsInstance = void 0;
6788
+ });
6789
+ import_node_process2.default.on("exit", () => {
6790
+ if (resovedInfo.devtoolsInstance) {
6791
+ resovedInfo.devtoolsInstance.kill();
6792
+ }
6793
+ });
6794
+ }
6795
+ res.end();
6796
+ });
6797
+ return middlewares;
6798
+ };
6799
+ return [injectSetupMiddlewares, (0, import_unplugin2.createRspackPlugin)(unpluginFactory)(options)];
6800
+ };
6697
6801
  /*! Bundled license information:
6698
6802
 
6699
6803
  web-streams-polyfill/dist/ponyfill.es2018.js:
package/dist/rspack.d.cts CHANGED
@@ -1,7 +1,9 @@
1
- import { Options } from './types.cjs';
1
+ import * as _unplugin from 'unplugin';
2
+ import { Options, RspackSetupMiddlewares } from './types.cjs';
2
3
  import 'webpack-dev-server';
4
+ import 'node:http';
3
5
  import 'vite-plugin-vconsole';
4
6
 
5
- declare const _default: (options?: Options | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
7
+ declare const _default: (options: Options) => readonly [RspackSetupMiddlewares, _unplugin.RspackPluginInstance];
6
8
 
7
9
  export { _default as default };
package/dist/rspack.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { Options } from './types.js';
1
+ import * as _unplugin from 'unplugin';
2
+ import { Options, RspackSetupMiddlewares } from './types.js';
2
3
  import 'webpack-dev-server';
4
+ import 'node:http';
3
5
  import 'vite-plugin-vconsole';
4
6
 
5
- declare const _default: (options?: Options | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
7
+ declare const _default: (options: Options) => readonly [RspackSetupMiddlewares, _unplugin.RspackPluginInstance];
6
8
 
7
9
  export { _default as default };
package/dist/rspack.js CHANGED
@@ -1,11 +1,89 @@
1
1
  import {
2
+ fetch,
3
+ resovedInfo,
2
4
  unpluginFactory
3
- } from "./chunk-E34H52KV.js";
5
+ } from "./chunk-RDTWBIQD.js";
4
6
  import "./chunk-PMOTCIQR.js";
5
7
 
6
8
  // src/rspack.ts
9
+ import { exec } from "child_process";
10
+ import process from "process";
7
11
  import { createRspackPlugin } from "unplugin";
8
- var rspack_default = createRspackPlugin(unpluginFactory);
12
+ import cookie from "cookie";
13
+ import c from "picocolors";
14
+ var rspack_default = (options) => {
15
+ function debug(...args) {
16
+ if (options == null ? void 0 : options.debug) {
17
+ console.log(` ${c.yellow("DEBUG")} `, ...args);
18
+ }
19
+ }
20
+ const {
21
+ chii: enableChii = true
22
+ } = options || {};
23
+ const injectSetupMiddlewares = (middlewares, _devServer) => {
24
+ if (options.debugCookies && options.debugCookies.length > 0) {
25
+ middlewares.unshift((req, res, next) => {
26
+ const cookies = cookie.parse(req.headers.cookie || "");
27
+ for (const [name, value] of Object.entries(cookies)) {
28
+ if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
29
+ const serializedCookie = cookie.serialize(name, value, {
30
+ httpOnly: false
31
+ });
32
+ res.setHeader("Set-Cookie", serializedCookie);
33
+ }
34
+ }
35
+ next();
36
+ });
37
+ }
38
+ if (enableChii) {
39
+ middlewares.unshift(async (req, res, next) => {
40
+ if (req.url !== "/__chrome_devtools") {
41
+ return next();
42
+ }
43
+ const availablePort = resovedInfo.availablePort;
44
+ try {
45
+ const raw = await fetch(`http://localhost:${availablePort}/targets`);
46
+ const data = await raw.json();
47
+ if ((data == null ? void 0 : data.targets.length) > 0) {
48
+ 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`;
49
+ res.writeHead(302, { Location: devToolsUrl });
50
+ res.end();
51
+ }
52
+ } catch (error) {
53
+ debug(`${error}`);
54
+ res.writeHead(502);
55
+ res.end();
56
+ }
57
+ });
58
+ }
59
+ middlewares.unshift((req, res, next) => {
60
+ var _a;
61
+ if (req.url !== "/open-dingtalk") {
62
+ return next();
63
+ }
64
+ const targetURL = resovedInfo.targetURL;
65
+ debug(targetURL.toString());
66
+ res.writeHead(302, {
67
+ Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
68
+ });
69
+ if (((_a = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a.enable) && !resovedInfo.devtoolsInstance) {
70
+ resovedInfo.devtoolsInstance = exec("npx vue-devtools");
71
+ console.log(` ${c.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
72
+ resovedInfo.devtoolsInstance.on("exit", () => {
73
+ resovedInfo.devtoolsInstance = void 0;
74
+ });
75
+ process.on("exit", () => {
76
+ if (resovedInfo.devtoolsInstance) {
77
+ resovedInfo.devtoolsInstance.kill();
78
+ }
79
+ });
80
+ }
81
+ res.end();
82
+ });
83
+ return middlewares;
84
+ };
85
+ return [injectSetupMiddlewares, createRspackPlugin(unpluginFactory)(options)];
86
+ };
9
87
  export {
10
88
  rspack_default as default
11
89
  };
package/dist/types.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as webpack_dev_server from 'webpack-dev-server';
2
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
3
  import { viteVConsoleOptions } from 'vite-plugin-vconsole';
3
4
 
4
5
  interface Options {
@@ -18,5 +19,18 @@ interface Options {
18
19
  };
19
20
  }
20
21
  type SetupMiddlewares = (middlewares: webpack_dev_server.Middleware[], devServer: webpack_dev_server) => webpack_dev_server.Middleware[];
22
+ type NextFunction = () => void;
23
+ type RequestHandler = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
24
+ interface ServerAPIs {
25
+ sockWrite: (type: string, data?: string | boolean | Record<string, any>) => void;
26
+ }
27
+ type RspackSetupMiddlewares = (
28
+ /** Order: `unshift` => internal middlewares => `push` */
29
+ middlewares: {
30
+ /** Use the `unshift` method if you want to run a middleware before all other middlewares */
31
+ unshift: (...handlers: RequestHandler[]) => void;
32
+ /** Use the `push` method if you want to run a middleware after all other middlewares */
33
+ push: (...handlers: RequestHandler[]) => void;
34
+ }, server: ServerAPIs) => void;
21
35
 
22
- export type { Options, SetupMiddlewares };
36
+ export type { Options, RspackSetupMiddlewares, SetupMiddlewares };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as webpack_dev_server from 'webpack-dev-server';
2
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
3
  import { viteVConsoleOptions } from 'vite-plugin-vconsole';
3
4
 
4
5
  interface Options {
@@ -18,5 +19,18 @@ interface Options {
18
19
  };
19
20
  }
20
21
  type SetupMiddlewares = (middlewares: webpack_dev_server.Middleware[], devServer: webpack_dev_server) => webpack_dev_server.Middleware[];
22
+ type NextFunction = () => void;
23
+ type RequestHandler = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
24
+ interface ServerAPIs {
25
+ sockWrite: (type: string, data?: string | boolean | Record<string, any>) => void;
26
+ }
27
+ type RspackSetupMiddlewares = (
28
+ /** Order: `unshift` => internal middlewares => `push` */
29
+ middlewares: {
30
+ /** Use the `unshift` method if you want to run a middleware before all other middlewares */
31
+ unshift: (...handlers: RequestHandler[]) => void;
32
+ /** Use the `push` method if you want to run a middleware after all other middlewares */
33
+ push: (...handlers: RequestHandler[]) => void;
34
+ }, server: ServerAPIs) => void;
21
35
 
22
- export type { Options, SetupMiddlewares };
36
+ export type { Options, RspackSetupMiddlewares, SetupMiddlewares };