unplugin-dingtalk 1006.0.0 → 1007.0.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.
Files changed (67) hide show
  1. package/dist/{chunk-2YQKM4BX.js → __chrome_devtools-CIQ5zFZx.js} +11 -12
  2. package/dist/__chrome_devtools-CJ3sXpVj.cjs +95 -0
  3. package/dist/__chrome_devtools.cjs +2 -114
  4. package/dist/__chrome_devtools.d.cts +3 -2
  5. package/dist/__chrome_devtools.d.ts +3 -2
  6. package/dist/__chrome_devtools.js +3 -7
  7. package/dist/astro.cjs +12 -676
  8. package/dist/astro.d.cts +7 -10
  9. package/dist/astro.d.ts +8 -10
  10. package/dist/astro.js +12 -17
  11. package/dist/chunk-CUT6urMc.cjs +30 -0
  12. package/dist/esbuild.cjs +9 -667
  13. package/dist/esbuild.d.cts +5 -8
  14. package/dist/esbuild.d.ts +6 -8
  15. package/dist/esbuild.js +8 -10
  16. package/dist/index.cjs +10 -676
  17. package/dist/index.d.cts +11 -13
  18. package/dist/index.d.ts +11 -13
  19. package/dist/index.js +5 -16
  20. package/dist/inject-script.cjs +15 -0
  21. package/dist/inject-script.d.cts +3 -0
  22. package/dist/inject-script.d.ts +4 -0
  23. package/dist/inject-script.js +14 -0
  24. package/dist/main-BvTybYko.js +99 -0
  25. package/dist/main-DQgEHuwp.cjs +101 -0
  26. package/dist/nuxt.cjs +459 -825
  27. package/dist/nuxt.d.cts +7 -10
  28. package/dist/nuxt.d.ts +7 -10
  29. package/dist/nuxt.js +474 -24
  30. package/dist/rollup.cjs +9 -667
  31. package/dist/rollup.d.cts +5 -8
  32. package/dist/rollup.d.ts +6 -8
  33. package/dist/rollup.js +8 -10
  34. package/dist/rspack.cjs +54 -728
  35. package/dist/rspack.d.cts +5 -8
  36. package/dist/rspack.d.ts +6 -8
  37. package/dist/rspack.js +50 -74
  38. package/dist/src-BVX_Roo9.js +364 -0
  39. package/dist/src-hLDO4Q22.cjs +394 -0
  40. package/dist/types-D6mfGNG_.d.ts +38 -0
  41. package/dist/types-DodDHiEA.d.cts +38 -0
  42. package/dist/types.cjs +0 -19
  43. package/dist/types.d.cts +2 -38
  44. package/dist/types.d.ts +2 -38
  45. package/dist/types.js +1 -0
  46. package/dist/utils-Chlbb6jf.js +23 -0
  47. package/dist/utils-CmfBxo4J.cjs +41 -0
  48. package/dist/utils.cjs +4 -33
  49. package/dist/utils.d.cts +6 -3
  50. package/dist/utils.d.ts +6 -3
  51. package/dist/utils.js +3 -7
  52. package/dist/vite-CKIDsKJ-.cjs +24 -0
  53. package/dist/vite-DoBUfGyY.js +18 -0
  54. package/dist/vite.cjs +5 -824
  55. package/dist/vite.d.cts +4 -7
  56. package/dist/vite.d.ts +5 -7
  57. package/dist/vite.js +6 -10
  58. package/dist/webpack.cjs +52 -722
  59. package/dist/webpack.d.cts +5 -8
  60. package/dist/webpack.d.ts +6 -8
  61. package/dist/webpack.js +48 -68
  62. package/package.json +12 -10
  63. package/dist/chunk-5JBD5THX.js +0 -20
  64. package/dist/chunk-EG2ZYJ3S.js +0 -542
  65. package/dist/chunk-KQOHODTC.js +0 -9
  66. package/dist/chunk-LMNMIIAV.js +0 -26
  67. package/dist/main-Q4R5NCQC.js +0 -129
package/dist/rspack.cjs CHANGED
@@ -1,729 +1,55 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __export = (target, all) => {
23
- for (var name in all)
24
- __defProp(target, name, { get: all[name], enumerable: true });
25
- };
26
- var __copyProps = (to, from, except, desc) => {
27
- if (from && typeof from === "object" || typeof from === "function") {
28
- for (let key of __getOwnPropNames(from))
29
- if (!__hasOwnProp.call(to, key) && key !== except)
30
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
- }
32
- return to;
33
- };
34
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
- // If the importer is in node compatibility mode or this is not an ESM
36
- // file that has been converted to a CommonJS file using a Babel-
37
- // compatible transform (i.e. "__esModule" has not been set), then set
38
- // "default" to the CommonJS "module.exports" for node compatibility.
39
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
- mod
41
- ));
42
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
43
-
44
- // src/rspack.ts
45
- var rspack_exports = {};
46
- __export(rspack_exports, {
47
- default: () => rspack_default
48
- });
49
- module.exports = __toCommonJS(rspack_exports);
50
- var import_unplugin2 = require("unplugin");
51
- var import_cookie2 = __toESM(require("cookie"), 1);
52
- var import_picocolors2 = __toESM(require("picocolors"), 1);
53
-
54
- // src/__chrome_devtools.ts
55
- function getChromeDevtoolsHtml(targetPort) {
56
- return `<!DOCTYPE html>
57
- <html>
58
-
59
- <head>
60
- <meta charset="utf-8">
61
- <title>DevTools Targets</title>
62
- <style>
63
- body {
64
- font-family: sans-serif;
65
- padding: 2em;
66
- }
67
-
68
- ul {
69
- padding: 0;
70
- }
71
-
72
- li {
73
- margin-bottom: 1.2em;
74
- list-style: none;
75
- line-height: 1.5;
76
- }
77
-
78
- a.button {
79
- display: inline-block;
80
- background: #409eff;
81
- color: #fff;
82
- padding: 0.2em 0.5em;
83
- text-decoration: none;
84
- border-radius: 4px;
85
- margin-top: 0.5em;
86
- font-size: 14px;
87
- }
88
-
89
- a.button:hover {
90
- background: #66b1ff;
91
- }
92
-
93
- #refresh {
94
- margin-bottom: 1.5em;
95
- }
96
- </style>
97
- </head>
98
-
99
- <body>
100
- <h2>\u53EF\u7528 DevTools Targets</h2><button id="refresh">\u5237\u65B0</button>
101
- <ul id="target-list">
102
- <li>\u52A0\u8F7D\u4E2D...</li>
103
- </ul>
104
- <script>
105
- async function fetchTargets() {
106
- const list = document.getElementById("target-list");
107
- list.innerHTML = "<li>\u52A0\u8F7D\u4E2D...</li>";
108
- try {
109
- const resp = await fetch("/__chii_proxy/targets");
110
- const data = await resp.json();
111
- const targets = data.targets || [];
112
- if (targets.length === 0) {
113
- list.innerHTML = "<li>\u6682\u65E0\u53EF\u7528\u7684\u8C03\u8BD5\u76EE\u6807\u3002</li>";
114
- } else {
115
- list.innerHTML = "";
116
- for (const target of targets) {
117
- console.log(target)
118
- const devToolsUrl = "http://localhost:${targetPort}/front_end/chii_app.html?ws=localhost:${targetPort}/client/" + Math.random().toString(20).substring(2, 8) + "?target=" + encodeURIComponent(target.id) + "&rtc=false";
119
- const item = document.createElement("li");
120
- item.innerHTML =
121
- "<div><strong>" + (target.title) + "</strong></div>" +
122
- "<div>URL: " + (target.url || "") + "</div>" +
123
- "<div>UA: <code>" + (target.userAgent || "unknown") + "</code></div>" +
124
- "<a href='" + devToolsUrl + "' target='_blank' class='button'>\u6253\u5F00\u8C03\u8BD5</a>";
125
- list.appendChild(item);
126
- }
127
- }
128
- } catch (e) {
129
- list.innerHTML = "<li>\u83B7\u53D6\u8C03\u8BD5\u76EE\u6807\u5931\u8D25</li>";
130
- }
131
- }
132
- document.getElementById("refresh").onclick = () => window.location.reload();
133
- window.onload = fetchTargets;
134
- document.addEventListener('visibilitychange', window.location.reload);
135
- </script>
136
- </body>
137
-
138
- </html>`;
139
- }
140
-
141
- // src/index.ts
142
- var import_node_process = __toESM(require("process"), 1);
143
- var import_node_http = require("http");
144
- var import_node_net2 = require("net");
145
- var import_unplugin = require("unplugin");
146
- var import_picocolors = __toESM(require("picocolors"), 1);
147
- var import_cookie = __toESM(require("cookie"), 1);
148
- var import_z_chii = require("z-chii");
149
-
150
- // node_modules/.pnpm/get-port-please@3.1.2/node_modules/get-port-please/dist/index.mjs
151
- var import_node_net = require("net");
152
- var import_node_os = require("os");
153
- var unsafePorts = /* @__PURE__ */ new Set([
154
- 1,
155
- // tcpmux
156
- 7,
157
- // echo
158
- 9,
159
- // discard
160
- 11,
161
- // systat
162
- 13,
163
- // daytime
164
- 15,
165
- // netstat
166
- 17,
167
- // qotd
168
- 19,
169
- // chargen
170
- 20,
171
- // ftp data
172
- 21,
173
- // ftp access
174
- 22,
175
- // ssh
176
- 23,
177
- // telnet
178
- 25,
179
- // smtp
180
- 37,
181
- // time
182
- 42,
183
- // name
184
- 43,
185
- // nicname
186
- 53,
187
- // domain
188
- 69,
189
- // tftp
190
- 77,
191
- // priv-rjs
192
- 79,
193
- // finger
194
- 87,
195
- // ttylink
196
- 95,
197
- // supdup
198
- 101,
199
- // hostriame
200
- 102,
201
- // iso-tsap
202
- 103,
203
- // gppitnp
204
- 104,
205
- // acr-nema
206
- 109,
207
- // pop2
208
- 110,
209
- // pop3
210
- 111,
211
- // sunrpc
212
- 113,
213
- // auth
214
- 115,
215
- // sftp
216
- 117,
217
- // uucp-path
218
- 119,
219
- // nntp
220
- 123,
221
- // NTP
222
- 135,
223
- // loc-srv /epmap
224
- 137,
225
- // netbios
226
- 139,
227
- // netbios
228
- 143,
229
- // imap2
230
- 161,
231
- // snmp
232
- 179,
233
- // BGP
234
- 389,
235
- // ldap
236
- 427,
237
- // SLP (Also used by Apple Filing Protocol)
238
- 465,
239
- // smtp+ssl
240
- 512,
241
- // print / exec
242
- 513,
243
- // login
244
- 514,
245
- // shell
246
- 515,
247
- // printer
248
- 526,
249
- // tempo
250
- 530,
251
- // courier
252
- 531,
253
- // chat
254
- 532,
255
- // netnews
256
- 540,
257
- // uucp
258
- 548,
259
- // AFP (Apple Filing Protocol)
260
- 554,
261
- // rtsp
262
- 556,
263
- // remotefs
264
- 563,
265
- // nntp+ssl
266
- 587,
267
- // smtp (rfc6409)
268
- 601,
269
- // syslog-conn (rfc3195)
270
- 636,
271
- // ldap+ssl
272
- 989,
273
- // ftps-data
274
- 990,
275
- // ftps
276
- 993,
277
- // ldap+ssl
278
- 995,
279
- // pop3+ssl
280
- 1719,
281
- // h323gatestat
282
- 1720,
283
- // h323hostcall
284
- 1723,
285
- // pptp
286
- 2049,
287
- // nfs
288
- 3659,
289
- // apple-sasl / PasswordServer
290
- 4045,
291
- // lockd
292
- 5060,
293
- // sip
294
- 5061,
295
- // sips
296
- 6e3,
297
- // X11
298
- 6566,
299
- // sane-port
300
- 6665,
301
- // Alternate IRC [Apple addition]
302
- 6666,
303
- // Alternate IRC [Apple addition]
304
- 6667,
305
- // Standard IRC [Apple addition]
306
- 6668,
307
- // Alternate IRC [Apple addition]
308
- 6669,
309
- // Alternate IRC [Apple addition]
310
- 6697,
311
- // IRC + TLS
312
- 10080
313
- // Amanda
314
- ]);
315
- function isUnsafePort(port) {
316
- return unsafePorts.has(port);
317
- }
318
- function isSafePort(port) {
319
- return !isUnsafePort(port);
320
- }
321
- var __defProp2 = Object.defineProperty;
322
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
323
- var __publicField = (obj, key, value) => {
324
- __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
325
- return value;
326
- };
327
- var GetPortError = class extends Error {
328
- constructor(message, opts) {
329
- super(message, opts);
330
- this.message = message;
331
- __publicField(this, "name", "GetPortError");
332
- }
333
- };
334
- function _log(verbose, message) {
335
- if (verbose) {
336
- console.log(`[get-port] ${message}`);
337
- }
338
- }
339
- function _tryPort(port, host) {
340
- return new Promise((resolve) => {
341
- const server = (0, import_node_net.createServer)();
342
- server.unref();
343
- server.on("error", () => {
344
- resolve(false);
345
- });
346
- server.listen({ port, host }, () => {
347
- const { port: port2 } = server.address();
348
- server.close(() => {
349
- resolve(isSafePort(port2) && port2);
350
- });
351
- });
352
- });
353
- }
354
- function _getLocalHosts(additional) {
355
- const hosts = new Set(additional);
356
- for (const _interface of Object.values((0, import_node_os.networkInterfaces)())) {
357
- for (const config2 of _interface || []) {
358
- if (config2.address && !config2.internal && !config2.address.startsWith("fe80::")) {
359
- hosts.add(config2.address);
360
- }
361
- }
362
- }
363
- return [...hosts];
364
- }
365
- function _fmtOnHost(hostname) {
366
- return hostname ? `on host ${JSON.stringify(hostname)}` : "on any host";
367
- }
368
- var HOSTNAME_RE = new RegExp("^(?!-)[\\d.:A-Za-z-]{1,63}(?<!-)$");
369
- async function getRandomPort(host) {
370
- const port = await checkPort(0, host);
371
- if (port === false) {
372
- throw new GetPortError(`Unable to find a random port ${_fmtOnHost(host)}`);
373
- }
374
- return port;
375
- }
376
- async function checkPort(port, host = process.env.HOST, verbose) {
377
- if (!host) {
378
- host = _getLocalHosts([void 0, "0.0.0.0"]);
379
- }
380
- if (!Array.isArray(host)) {
381
- return _tryPort(port, host);
382
- }
383
- for (const _host of host) {
384
- const _port = await _tryPort(port, _host);
385
- if (_port === false) {
386
- if (port < 1024 && verbose) {
387
- _log(
388
- verbose,
389
- `Unable to listen to the privileged port ${port} ${_fmtOnHost(
390
- _host
391
- )}`
392
- );
393
- }
394
- return false;
395
- }
396
- if (port === 0 && _port !== 0) {
397
- port = _port;
398
- }
399
- }
400
- return port;
401
- }
402
-
403
- // src/index.ts
404
- var import_http_proxy = __toESM(require("http-proxy"), 1);
405
- var cwd = import_node_process.default.cwd();
406
- var config;
407
- var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
408
- var resovedInfo = {
409
- availablePort: void 0,
410
- targetURL: void 0
411
- };
412
- function createProxyMiddleware(debug) {
413
- let proxy = null;
414
- const handleUpgrade = (req, socket, head) => {
415
- var _a;
416
- if (proxy && ((_a = req.url) == null ? void 0 : _a.startsWith("/__chii_proxy"))) {
417
- debug("WS upgrade:", req.url);
418
- req.url = req.url.replace("/__chii_proxy", "");
419
- proxy.ws(req, socket, head);
420
- }
421
- };
422
- return (resolvedInfo) => {
423
- return (req, res, next) => {
424
- var _a;
425
- if (!proxy && resolvedInfo.availablePort) {
426
- proxy = import_http_proxy.default.createProxyServer({
427
- target: `http://localhost:${resolvedInfo.availablePort}`,
428
- ws: true
429
- });
430
- proxy.on("error", (err, req2, res2) => {
431
- console.error("Proxy error:", err);
432
- if (res2 instanceof import_node_http.ServerResponse) {
433
- if (!res2.headersSent) {
434
- res2.writeHead(500, { "Content-Type": "text/plain" });
435
- }
436
- res2.end(`Proxy error: ${err.message}`);
437
- } else if (res2 instanceof import_node_net2.Socket) {
438
- res2.destroy();
439
- }
440
- });
441
- if (req.socket.server) {
442
- req.socket.server.on("upgrade", handleUpgrade);
443
- }
444
- }
445
- if (proxy && ((_a = req.url) == null ? void 0 : _a.startsWith("/__chii_proxy"))) {
446
- debug(req.url);
447
- req.url = req.url.replace("/__chii_proxy", "");
448
- proxy.web(req, res);
449
- } else {
450
- next();
451
- }
452
- };
453
- };
454
- }
455
- var unpluginFactory = (options) => {
456
- const {
457
- chii
458
- } = options || {};
459
- const enableChii = (chii == null ? void 0 : chii.enable) !== false;
460
- function debug(...args) {
461
- if (options == null ? void 0 : options.debug) {
462
- console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
463
- }
464
- }
465
- const unpluginDing = {
466
- name: "unplugin-dingtalk",
467
- enforce: "pre",
468
- resolveId(source) {
469
- if (source === "chii-client") {
470
- return source;
471
- }
472
- },
473
- loadInclude(id) {
474
- return id === "chii-client";
475
- },
476
- load(id) {
477
- var _a, _b;
478
- if (id === "chii-client") {
479
- return `
480
- ;(function(){
481
- if (document.getElementById('__chii_client')) return;
482
- const script = document.createElement('script');
483
- script.id = '__chii_client';
484
- script.src="/__chii_proxy/target.js";
485
- ${((_a = options == null ? void 0 : options.chii) == null ? void 0 : _a.embedded) ? "script.setAttribute('embedded','true');" : ""}
486
- document.body.appendChild(script);
487
- })();
488
- if (import.meta.hot) {
489
- import.meta.hot.accept(() => {
490
- const old = document.getElementById('__chii_client');
491
- if (old) old.remove();
492
- const script = document.createElement('script');
493
- script.id = '__chii_client';
494
- script.src="/__chii_proxy/target.js";
495
- ${((_b = options == null ? void 0 : options.chii) == null ? void 0 : _b.embedded) ? "script.setAttribute('embedded','true');" : ""}
496
- document.body.appendChild(script);
497
- });
498
- }
499
- `;
500
- }
501
- },
502
- transformInclude(id) {
503
- return !!id.split("?")[0].match(/\.[t|j]s$/);
504
- },
505
- async transform(source, id) {
506
- if ((options == null ? void 0 : options.enable) && enableChii && !resovedInfo.availablePort) {
507
- resovedInfo.availablePort = await getRandomPort();
508
- (0, import_z_chii.start)({ port: resovedInfo.availablePort });
509
- debug(`chii server port: ${resovedInfo.availablePort}`);
510
- }
511
- if ((options == null ? void 0 : options.enable) && enableChii) {
512
- const file = id.split("?")[0];
513
- if (file.startsWith((config == null ? void 0 : config.root) || cwd) && !file.includes("node_modules") && file.match(/\.[t|j]s$/)) {
514
- return {
515
- code: `import 'chii-client';
516
- ${source}`,
517
- map: null
518
- };
519
- }
520
- }
521
- return { code: source, map: null };
522
- },
523
- vite: {
524
- configResolved(_config) {
525
- config = _config;
526
- },
527
- transformIndexHtml(html) {
528
- if ((options == null ? void 0 : options.enable) && enableChii) {
529
- const tag = `<script type="module">import 'chii-client';</script>`;
530
- if (!html.includes(tag)) {
531
- return html.replace(
532
- "</body>",
533
- `</body>${tag}
534
- `
535
- );
536
- }
537
- }
538
- return html;
539
- },
540
- async configureServer(server) {
541
- var _a, _b;
542
- if (!(options == null ? void 0 : options.enable)) {
543
- return;
544
- }
545
- const _printUrls = server.printUrls.bind(server);
546
- let source = `localhost:${config.server.port || 5173}`;
547
- const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
548
- if (url) {
549
- const u = new URL(url);
550
- source = u.host;
551
- }
552
- const base = server.config.base || "/";
553
- const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
554
- server.printUrls = () => {
555
- _printUrls();
556
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
557
- "Open in dingtalk"
558
- )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
559
- if (enableChii) {
560
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
561
- "Click to open chrome devtools"
562
- )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
563
- }
564
- };
565
- const targetURL = new URL(_targetUrl);
566
- targetURL.searchParams.append("ddtab", "true");
567
- if (options == null ? void 0 : options.corpId) {
568
- targetURL.searchParams.append("corpId", options.corpId);
569
- }
570
- if (options.debugCookies && options.debugCookies.length > 0) {
571
- server.middlewares.use((req, res, next) => {
572
- const cookies = import_cookie.default.parse(req.headers.cookie || "");
573
- for (const [name, value] of Object.entries(cookies)) {
574
- if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
575
- const serializedCookie = import_cookie.default.serialize(name, value, {
576
- httpOnly: false
577
- });
578
- res.setHeader("Set-Cookie", serializedCookie);
579
- }
580
- }
581
- next();
582
- });
583
- }
584
- if (enableChii) {
585
- server.middlewares.use("/__chrome_devtools", async (_req, res) => {
586
- if (!resovedInfo.availablePort) {
587
- res.writeHead(500, { "Content-Type": "text/plain" });
588
- res.end("Server not started");
589
- return;
590
- }
591
- res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
592
- res.write(getChromeDevtoolsHtml(resovedInfo.availablePort));
593
- res.end();
594
- });
595
- const proxyMiddleware = createProxyMiddleware(debug);
596
- server.middlewares.use(proxyMiddleware(resovedInfo));
597
- }
598
- server.middlewares.use("/open-dingtalk", (req, res) => {
599
- debug(targetURL.toString());
600
- res.writeHead(302, {
601
- Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
602
- });
603
- res.end();
604
- });
605
- }
606
- },
607
- webpack(compiler) {
608
- var _a, _b;
609
- if (!(options == null ? void 0 : options.enable)) {
610
- return;
611
- }
612
- const devServerOptions = __spreadValues(__spreadValues({
613
- host: "localhost",
614
- port: 8080
615
- }, compiler.options.devServer), (_a = import_node_process.default.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer);
616
- const source = `${devServerOptions.host === "0.0.0.0" ? "127.0.0.1" : devServerOptions.host}:${devServerOptions.port}`;
617
- const base = compiler.options.output.publicPath || "/";
618
- const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
619
- compiler.hooks.done.tap("unplugin-dingtalk", () => {
620
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
621
- "Open in dingtalk"
622
- )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
623
- if (enableChii) {
624
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
625
- "Click to open chrome devtools"
626
- )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
627
- }
628
- });
629
- resovedInfo.targetURL = new URL(_targetUrl);
630
- resovedInfo.targetURL.searchParams.append("ddtab", "true");
631
- if (options == null ? void 0 : options.corpId) {
632
- resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
633
- }
634
- },
635
- async rspack(compiler) {
636
- var _a, _b, _c, _d;
637
- if (!(options == null ? void 0 : options.enable)) {
638
- return;
639
- }
640
- const devServerOptions = __spreadValues(__spreadValues({
641
- host: "localhost",
642
- port: 8080
643
- }, compiler.options.devServer), (_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
644
- cwd
645
- }))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
646
- const source = `${devServerOptions.host === "0.0.0.0" ? "127.0.0.1" : devServerOptions.host}:${devServerOptions.port}`;
647
- const base = compiler.options.output.publicPath || "/";
648
- const _targetUrl = (_d = options == null ? void 0 : options.targetUrl) != null ? _d : `http://${source}${base}`;
649
- resovedInfo.targetURL = new URL(_targetUrl);
650
- resovedInfo.targetURL.searchParams.append("ddtab", "true");
651
- if (options == null ? void 0 : options.corpId) {
652
- resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
653
- }
654
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
655
- "Open in dingtalk"
656
- )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
657
- if (enableChii) {
658
- console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
659
- "Click to open chrome devtools"
660
- )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
661
- }
662
- }
663
- };
664
- return unpluginDing;
665
- };
666
-
667
- // src/rspack.ts
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const require___chrome_devtools = require('./__chrome_devtools-CJ3sXpVj.cjs');
3
+ const require_src = require('./src-hLDO4Q22.cjs');
4
+ require('./utils-CmfBxo4J.cjs');
5
+ const cookie = require_chunk.__toESM(require("cookie"));
6
+ const picocolors = require_chunk.__toESM(require("picocolors"));
7
+ const unplugin = require_chunk.__toESM(require("unplugin"));
8
+
9
+ //#region src/rspack.ts
668
10
  var rspack_default = (options) => {
669
- function debug(...args) {
670
- if (options == null ? void 0 : options.debug) {
671
- console.log(` ${import_picocolors2.default.yellow("DEBUG")} `, ...args);
672
- }
673
- }
674
- const {
675
- chii
676
- } = options || {};
677
- const enableChii = (chii == null ? void 0 : chii.enable) !== false;
678
- const injectSetupMiddlewares = (middlewares, _devServer) => {
679
- if (!(options == null ? void 0 : options.enable)) {
680
- return middlewares;
681
- }
682
- if (options.debugCookies && options.debugCookies.length > 0) {
683
- middlewares.unshift((req, res, next) => {
684
- const cookies = import_cookie2.default.parse(req.headers.cookie || "");
685
- for (const [name, value] of Object.entries(cookies)) {
686
- if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
687
- const serializedCookie = import_cookie2.default.serialize(name, value, {
688
- httpOnly: false
689
- });
690
- res.setHeader("Set-Cookie", serializedCookie);
691
- }
692
- }
693
- next();
694
- });
695
- }
696
- if (enableChii) {
697
- middlewares.unshift(async (req, res, next) => {
698
- if (req.url !== "/__chrome_devtools") {
699
- return next();
700
- }
701
- try {
702
- res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
703
- res.write(getChromeDevtoolsHtml(resovedInfo.availablePort));
704
- res.end();
705
- } catch (error) {
706
- debug(`${error}`);
707
- res.writeHead(502);
708
- res.end();
709
- }
710
- });
711
- const proxyMiddleware = createProxyMiddleware(debug);
712
- middlewares.unshift(proxyMiddleware(resovedInfo));
713
- }
714
- middlewares.unshift((req, res, next) => {
715
- if (req.url !== "/open-dingtalk") {
716
- return next();
717
- }
718
- const targetURL = resovedInfo.targetURL;
719
- debug(targetURL.toString());
720
- res.writeHead(302, {
721
- Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
722
- });
723
- res.end();
724
- });
725
- return middlewares;
726
- };
727
- return [injectSetupMiddlewares, (0, import_unplugin2.createRspackPlugin)(unpluginFactory)(options)];
728
- };
729
- exports.default = module.exports;
11
+ function debug(...args) {
12
+ if (options?.debug) console.log(` ${picocolors.default.yellow("DEBUG")} `, ...args);
13
+ }
14
+ const { chii } = options || {};
15
+ const enableChii = chii?.enable !== false;
16
+ const injectSetupMiddlewares = (middlewares, _devServer) => {
17
+ if (!options?.enable) return middlewares;
18
+ if (options.debugCookies && options.debugCookies.length > 0) middlewares.unshift((req, res, next) => {
19
+ const cookies = cookie.default.parse(req.headers.cookie || "");
20
+ for (const [name, value] of Object.entries(cookies)) if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
21
+ const serializedCookie = cookie.default.serialize(name, value, { httpOnly: false });
22
+ res.setHeader("Set-Cookie", serializedCookie);
23
+ }
24
+ next();
25
+ });
26
+ if (enableChii) {
27
+ middlewares.unshift(async (req, res, next) => {
28
+ if (req.url !== "/__chrome_devtools") return next();
29
+ try {
30
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
31
+ res.write(require___chrome_devtools.getChromeDevtoolsHtml(require_src.resovedInfo.availablePort));
32
+ res.end();
33
+ } catch (error) {
34
+ debug(`${error}`);
35
+ res.writeHead(502);
36
+ res.end();
37
+ }
38
+ });
39
+ const proxyMiddleware = require_src.createProxyMiddleware(debug);
40
+ middlewares.unshift(proxyMiddleware(require_src.resovedInfo));
41
+ }
42
+ middlewares.unshift((req, res, next) => {
43
+ if (req.url !== "/open-dingtalk") return next();
44
+ const targetURL = require_src.resovedInfo.targetURL;
45
+ debug(targetURL.toString());
46
+ res.writeHead(302, { Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}` });
47
+ res.end();
48
+ });
49
+ return middlewares;
50
+ };
51
+ return [injectSetupMiddlewares, (0, unplugin.createRspackPlugin)(require_src.unpluginFactory)(options)];
52
+ };
53
+
54
+ //#endregion
55
+ module.exports = rspack_default;