unplugin-dingtalk 1005.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 (66) 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 +3 -0
  4. package/dist/__chrome_devtools.d.cts +4 -0
  5. package/dist/__chrome_devtools.d.ts +3 -2
  6. package/dist/__chrome_devtools.js +3 -7
  7. package/dist/astro.cjs +15 -0
  8. package/dist/astro.d.cts +10 -0
  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 +11 -0
  13. package/dist/esbuild.d.cts +6 -0
  14. package/dist/esbuild.d.ts +6 -8
  15. package/dist/esbuild.js +8 -10
  16. package/dist/index.cjs +10 -0
  17. package/dist/index.d.cts +17 -0
  18. package/dist/index.d.ts +13 -11
  19. package/dist/index.js +5 -14
  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 +478 -0
  27. package/dist/nuxt.d.cts +8 -0
  28. package/dist/nuxt.d.ts +7 -10
  29. package/dist/nuxt.js +474 -24
  30. package/dist/rollup.cjs +11 -0
  31. package/dist/rollup.d.cts +6 -0
  32. package/dist/rollup.d.ts +6 -8
  33. package/dist/rollup.js +8 -10
  34. package/dist/rspack.cjs +55 -0
  35. package/dist/rspack.d.cts +6 -0
  36. package/dist/rspack.d.ts +6 -7
  37. package/dist/rspack.js +50 -68
  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 -0
  43. package/dist/types.d.cts +2 -0
  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 +5 -0
  49. package/dist/utils.d.cts +9 -0
  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 +6 -0
  55. package/dist/vite.d.cts +6 -0
  56. package/dist/vite.d.ts +5 -7
  57. package/dist/vite.js +6 -10
  58. package/dist/webpack.cjs +53 -0
  59. package/dist/webpack.d.cts +6 -0
  60. package/dist/webpack.d.ts +6 -8
  61. package/dist/webpack.js +48 -62
  62. package/package.json +64 -21
  63. package/dist/chunk-5JBD5THX.js +0 -20
  64. package/dist/chunk-D63IDACA.js +0 -26
  65. package/dist/chunk-KQOHODTC.js +0 -9
  66. package/dist/chunk-ZLK5HLCO.js +0 -537
package/dist/rspack.js CHANGED
@@ -1,72 +1,54 @@
1
- import {
2
- resovedInfo,
3
- unpluginFactory
4
- } from "./chunk-ZLK5HLCO.js";
5
- import {
6
- getChromeDevtoolsHtml
7
- } from "./chunk-2YQKM4BX.js";
8
- import "./chunk-5JBD5THX.js";
9
-
10
- // src/rspack.ts
11
- import { createRspackPlugin } from "unplugin";
1
+ import { getChromeDevtoolsHtml } from "./__chrome_devtools-CIQ5zFZx.js";
2
+ import { createProxyMiddleware, resovedInfo, unpluginFactory } from "./src-BVX_Roo9.js";
3
+ import "./utils-Chlbb6jf.js";
12
4
  import cookie from "cookie";
13
5
  import c from "picocolors";
6
+ import { createRspackPlugin } from "unplugin";
7
+
8
+ //#region src/rspack.ts
14
9
  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
22
- } = options || {};
23
- const enableChii = (chii == null ? void 0 : chii.enable) !== false;
24
- const injectSetupMiddlewares = (middlewares, _devServer) => {
25
- if (options.debugCookies && options.debugCookies.length > 0) {
26
- middlewares.unshift((req, res, next) => {
27
- const cookies = cookie.parse(req.headers.cookie || "");
28
- for (const [name, value] of Object.entries(cookies)) {
29
- if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
30
- const serializedCookie = cookie.serialize(name, value, {
31
- httpOnly: false
32
- });
33
- res.setHeader("Set-Cookie", serializedCookie);
34
- }
35
- }
36
- next();
37
- });
38
- }
39
- if (enableChii) {
40
- middlewares.unshift(async (req, res, next) => {
41
- if (req.url !== "/__chrome_devtools") {
42
- return next();
43
- }
44
- try {
45
- res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
46
- res.write(getChromeDevtoolsHtml(resovedInfo.availablePort));
47
- res.end();
48
- } catch (error) {
49
- debug(`${error}`);
50
- res.writeHead(502);
51
- res.end();
52
- }
53
- });
54
- }
55
- middlewares.unshift((req, res, next) => {
56
- if (req.url !== "/open-dingtalk") {
57
- return next();
58
- }
59
- const targetURL = resovedInfo.targetURL;
60
- debug(targetURL.toString());
61
- res.writeHead(302, {
62
- Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
63
- });
64
- res.end();
65
- });
66
- return middlewares;
67
- };
68
- return [injectSetupMiddlewares, createRspackPlugin(unpluginFactory)(options)];
69
- };
70
- export {
71
- rspack_default as default
10
+ function debug(...args) {
11
+ if (options?.debug) console.log(` ${c.yellow("DEBUG")} `, ...args);
12
+ }
13
+ const { chii } = options || {};
14
+ const enableChii = chii?.enable !== false;
15
+ const injectSetupMiddlewares = (middlewares, _devServer) => {
16
+ if (!options?.enable) return middlewares;
17
+ if (options.debugCookies && options.debugCookies.length > 0) middlewares.unshift((req, res, next) => {
18
+ const cookies = cookie.parse(req.headers.cookie || "");
19
+ for (const [name, value] of Object.entries(cookies)) if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
20
+ const serializedCookie = cookie.serialize(name, value, { httpOnly: false });
21
+ res.setHeader("Set-Cookie", serializedCookie);
22
+ }
23
+ next();
24
+ });
25
+ if (enableChii) {
26
+ middlewares.unshift(async (req, res, next) => {
27
+ if (req.url !== "/__chrome_devtools") return next();
28
+ try {
29
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
30
+ res.write(getChromeDevtoolsHtml(resovedInfo.availablePort));
31
+ res.end();
32
+ } catch (error) {
33
+ debug(`${error}`);
34
+ res.writeHead(502);
35
+ res.end();
36
+ }
37
+ });
38
+ const proxyMiddleware = createProxyMiddleware(debug);
39
+ middlewares.unshift(proxyMiddleware(resovedInfo));
40
+ }
41
+ middlewares.unshift((req, res, next) => {
42
+ if (req.url !== "/open-dingtalk") return next();
43
+ const targetURL = resovedInfo.targetURL;
44
+ debug(targetURL.toString());
45
+ res.writeHead(302, { Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}` });
46
+ res.end();
47
+ });
48
+ return middlewares;
49
+ };
50
+ return [injectSetupMiddlewares, createRspackPlugin(unpluginFactory)(options)];
72
51
  };
52
+
53
+ //#endregion
54
+ export { rspack_default as default };
@@ -0,0 +1,364 @@
1
+ import { getChromeDevtoolsHtml } from "./__chrome_devtools-CIQ5zFZx.js";
2
+ import { colorUrl, isNuxtProject } from "./utils-Chlbb6jf.js";
3
+ import { ServerResponse } from "node:http";
4
+ import { Socket, createServer } from "node:net";
5
+ import process$1 from "node:process";
6
+ import cookie from "cookie";
7
+ import { networkInterfaces } from "node:os";
8
+ import httpProxy from "http-proxy";
9
+ import c from "picocolors";
10
+ import { createUnplugin } from "unplugin";
11
+ import { start } from "z-chii";
12
+
13
+ //#region node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs
14
+ const unsafePorts = /* @__PURE__ */ new Set([
15
+ 1,
16
+ 7,
17
+ 9,
18
+ 11,
19
+ 13,
20
+ 15,
21
+ 17,
22
+ 19,
23
+ 20,
24
+ 21,
25
+ 22,
26
+ 23,
27
+ 25,
28
+ 37,
29
+ 42,
30
+ 43,
31
+ 53,
32
+ 69,
33
+ 77,
34
+ 79,
35
+ 87,
36
+ 95,
37
+ 101,
38
+ 102,
39
+ 103,
40
+ 104,
41
+ 109,
42
+ 110,
43
+ 111,
44
+ 113,
45
+ 115,
46
+ 117,
47
+ 119,
48
+ 123,
49
+ 135,
50
+ 137,
51
+ 139,
52
+ 143,
53
+ 161,
54
+ 179,
55
+ 389,
56
+ 427,
57
+ 465,
58
+ 512,
59
+ 513,
60
+ 514,
61
+ 515,
62
+ 526,
63
+ 530,
64
+ 531,
65
+ 532,
66
+ 540,
67
+ 548,
68
+ 554,
69
+ 556,
70
+ 563,
71
+ 587,
72
+ 601,
73
+ 636,
74
+ 989,
75
+ 990,
76
+ 993,
77
+ 995,
78
+ 1719,
79
+ 1720,
80
+ 1723,
81
+ 2049,
82
+ 3659,
83
+ 4045,
84
+ 5060,
85
+ 5061,
86
+ 6e3,
87
+ 6566,
88
+ 6665,
89
+ 6666,
90
+ 6667,
91
+ 6668,
92
+ 6669,
93
+ 6697,
94
+ 10080
95
+ ]);
96
+ function isUnsafePort(port) {
97
+ return unsafePorts.has(port);
98
+ }
99
+ function isSafePort(port) {
100
+ return !isUnsafePort(port);
101
+ }
102
+ var GetPortError = class extends Error {
103
+ constructor(message, opts) {
104
+ super(message, opts);
105
+ this.message = message;
106
+ }
107
+ name = "GetPortError";
108
+ };
109
+ function _log(verbose, message) {
110
+ if (verbose) console.log(`[get-port] ${message}`);
111
+ }
112
+ function _tryPort(port, host) {
113
+ return new Promise((resolve) => {
114
+ const server = createServer();
115
+ server.unref();
116
+ server.on("error", () => {
117
+ resolve(false);
118
+ });
119
+ server.listen({
120
+ port,
121
+ host
122
+ }, () => {
123
+ const { port: port2 } = server.address();
124
+ server.close(() => {
125
+ resolve(isSafePort(port2) && port2);
126
+ });
127
+ });
128
+ });
129
+ }
130
+ function _getLocalHosts(additional) {
131
+ const hosts = new Set(additional);
132
+ for (const _interface of Object.values(networkInterfaces())) for (const config$1 of _interface || []) if (config$1.address && !config$1.internal && !config$1.address.startsWith("fe80::") && !config$1.address.startsWith("169.254")) hosts.add(config$1.address);
133
+ return [...hosts];
134
+ }
135
+ function _fmtOnHost(hostname) {
136
+ return hostname ? `on host ${JSON.stringify(hostname)}` : "on any host";
137
+ }
138
+ async function getRandomPort(host) {
139
+ const port = await checkPort(0, host);
140
+ if (port === false) throw new GetPortError(`Unable to find a random port ${_fmtOnHost(host)}`);
141
+ return port;
142
+ }
143
+ async function checkPort(port, host = process.env.HOST, verbose) {
144
+ if (!host) host = _getLocalHosts([void 0, "0.0.0.0"]);
145
+ if (!Array.isArray(host)) return _tryPort(port, host);
146
+ for (const _host of host) {
147
+ const _port = await _tryPort(port, _host);
148
+ if (_port === false) {
149
+ if (port < 1024 && verbose) _log(verbose, `Unable to listen to the privileged port ${port} ${_fmtOnHost(_host)}`);
150
+ return false;
151
+ }
152
+ if (port === 0 && _port !== 0) port = _port;
153
+ }
154
+ return port;
155
+ }
156
+
157
+ //#endregion
158
+ //#region src/index.ts
159
+ const cwd = process$1.cwd();
160
+ let config;
161
+ const resovedInfo = {
162
+ availablePort: void 0,
163
+ targetURL: void 0
164
+ };
165
+ function createProxyMiddleware(debug) {
166
+ let proxy = null;
167
+ const handleUpgrade = (req, socket, head) => {
168
+ if (proxy && req.url?.startsWith("/__chii_proxy")) {
169
+ debug("WS upgrade:", req.url);
170
+ req.url = req.url.replace("/__chii_proxy", "");
171
+ proxy.ws(req, socket, head);
172
+ }
173
+ };
174
+ return (resolvedInfo) => {
175
+ return (req, res, next) => {
176
+ if (req.url?.startsWith("/__chii_proxy")) req._skip_transform = true;
177
+ if (!proxy && resolvedInfo.availablePort) {
178
+ proxy = httpProxy.createProxyServer({
179
+ target: `http://localhost:${resolvedInfo.availablePort}`,
180
+ ws: true
181
+ });
182
+ proxy.on("error", (err, req$1, res$1) => {
183
+ console.error("Proxy error:", err);
184
+ if (res$1 instanceof ServerResponse) {
185
+ if (!res$1.headersSent) res$1.writeHead(500, { "Content-Type": "text/plain" });
186
+ res$1.end(`Proxy error: ${err.message}`);
187
+ } else if (res$1 instanceof Socket) res$1.destroy();
188
+ });
189
+ if (req.socket.server) req.socket.server.on("upgrade", handleUpgrade);
190
+ }
191
+ if (proxy && req.url?.startsWith("/__chii_proxy")) {
192
+ debug(req.url);
193
+ req.url = req.url.replace("/__chii_proxy", "");
194
+ proxy.web(req, res);
195
+ } else next();
196
+ };
197
+ };
198
+ }
199
+ const unpluginFactory = (options) => {
200
+ const { chii } = options || {};
201
+ const enableChii = chii?.enable !== false;
202
+ function debug(...args) {
203
+ if (options?.debug) console.log(` ${c.yellow("DEBUG")} `, ...args);
204
+ }
205
+ const unpluginDing = {
206
+ name: "unplugin-dingtalk",
207
+ enforce: "pre",
208
+ resolveId(source) {
209
+ if (source === "chii-client") return source;
210
+ },
211
+ loadInclude(id) {
212
+ return id === "chii-client";
213
+ },
214
+ load(id) {
215
+ if (id === "chii-client") return `
216
+ ;(function(){
217
+ if (document.getElementById('__chii_client')) return;
218
+ const script = document.createElement('script');
219
+ script.id = '__chii_client';
220
+ script.src="/__chii_proxy/target.js";
221
+ ${options?.chii?.embedded ? "script.setAttribute('embedded','true');" : ""}
222
+ document.body.appendChild(script);
223
+ })();
224
+ if (import.meta.hot) {
225
+ import.meta.hot.accept(() => {
226
+ const old = document.getElementById('__chii_client');
227
+ if (old) old.remove();
228
+ const script = document.createElement('script');
229
+ script.id = '__chii_client';
230
+ script.src="/__chii_proxy/target.js";
231
+ ${options?.chii?.embedded ? "script.setAttribute('embedded','true');" : ""}
232
+ document.body.appendChild(script);
233
+ });
234
+ }
235
+ `;
236
+ },
237
+ transformInclude(id) {
238
+ return !!id.split("?")[0].match(/\.[t|j]s$/);
239
+ },
240
+ async transform(source, id) {
241
+ if (options?.enable && enableChii && !resovedInfo.availablePort) {
242
+ resovedInfo.availablePort = await getRandomPort();
243
+ start({ port: resovedInfo.availablePort });
244
+ debug(`chii server port: ${resovedInfo.availablePort}`);
245
+ }
246
+ if (options?.enable && enableChii) {
247
+ const file = id.split("?")[0];
248
+ if (file.startsWith(config?.root || cwd) && !file.includes("node_modules") && file.match(/\.[t|j]s$/)) return {
249
+ code: `import 'chii-client';\n${source}`,
250
+ map: null
251
+ };
252
+ }
253
+ return {
254
+ code: source,
255
+ map: null
256
+ };
257
+ },
258
+ vite: {
259
+ configResolved(_config) {
260
+ config = _config;
261
+ },
262
+ transformIndexHtml(html) {
263
+ if (options?.enable && enableChii) {
264
+ const tag = "<script type=\"module\">import 'chii-client';<\/script>";
265
+ if (!html.includes(tag)) return html.replace("</body>", `</body>${tag}\n`);
266
+ }
267
+ return html;
268
+ },
269
+ async configureServer(server) {
270
+ if (!options?.enable) return;
271
+ const _printUrls = server.printUrls.bind(server);
272
+ let source = `localhost:${config.server.port || 5173}`;
273
+ const url = server.resolvedUrls?.local[0];
274
+ if (url) {
275
+ const u = new URL(url);
276
+ source = u.host;
277
+ }
278
+ const base = server.config.base || "/";
279
+ const _targetUrl = options?.targetUrl ?? `http://${source}${base}`;
280
+ server.printUrls = () => {
281
+ _printUrls();
282
+ console.log(` ${c.green("➜")} ${c.bold("Open in dingtalk")}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
283
+ if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
284
+ };
285
+ const targetURL = new URL(_targetUrl);
286
+ targetURL.searchParams.append("ddtab", "true");
287
+ if (options?.corpId) targetURL.searchParams.append("corpId", options.corpId);
288
+ if (options.debugCookies && options.debugCookies.length > 0) server.middlewares.use((req, res, next) => {
289
+ const cookies = cookie.parse(req.headers.cookie || "");
290
+ for (const [name, value] of Object.entries(cookies)) if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
291
+ const serializedCookie = cookie.serialize(name, value, { httpOnly: false });
292
+ res.setHeader("Set-Cookie", serializedCookie);
293
+ }
294
+ next();
295
+ });
296
+ if (enableChii) {
297
+ server.middlewares.use("/__chrome_devtools", async (_req, res) => {
298
+ if (!resovedInfo.availablePort) {
299
+ res.writeHead(500, { "Content-Type": "text/plain" });
300
+ res.end("Server not started");
301
+ return;
302
+ }
303
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
304
+ res.write(getChromeDevtoolsHtml(resovedInfo.availablePort));
305
+ res.end();
306
+ });
307
+ const isNuxt = isNuxtProject();
308
+ console.log("isNuxt", isNuxt);
309
+ if (!isNuxt) {
310
+ const proxyMiddleware = createProxyMiddleware(debug);
311
+ server.middlewares.use(proxyMiddleware(resovedInfo));
312
+ }
313
+ }
314
+ server.middlewares.use("/open-dingtalk", (req, res) => {
315
+ debug(targetURL.toString());
316
+ res.writeHead(302, { Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}` });
317
+ res.end();
318
+ });
319
+ }
320
+ },
321
+ webpack(compiler) {
322
+ if (!options?.enable) return;
323
+ const devServerOptions = {
324
+ host: "localhost",
325
+ port: 8080,
326
+ ...compiler.options.devServer,
327
+ ...process$1.VUE_CLI_SERVICE?.projectOptions.devServer
328
+ };
329
+ const source = `${devServerOptions.host === "0.0.0.0" ? "127.0.0.1" : devServerOptions.host}:${devServerOptions.port}`;
330
+ const base = compiler.options.output.publicPath || "/";
331
+ const _targetUrl = options?.targetUrl ?? `http://${source}${base}`;
332
+ compiler.hooks.done.tap("unplugin-dingtalk", () => {
333
+ console.log(` ${c.green("➜")} ${c.bold("Open in dingtalk")}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
334
+ if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
335
+ });
336
+ resovedInfo.targetURL = new URL(_targetUrl);
337
+ resovedInfo.targetURL.searchParams.append("ddtab", "true");
338
+ if (options?.corpId) resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
339
+ },
340
+ async rspack(compiler) {
341
+ if (!options?.enable) return;
342
+ const devServerOptions = {
343
+ host: "localhost",
344
+ port: 8080,
345
+ ...compiler.options.devServer,
346
+ ...(await (await import("@rsbuild/core"))?.loadConfig({ cwd }))?.content?.server
347
+ };
348
+ const source = `${devServerOptions.host === "0.0.0.0" ? "127.0.0.1" : devServerOptions.host}:${devServerOptions.port}`;
349
+ const base = compiler.options.output.publicPath || "/";
350
+ const _targetUrl = options?.targetUrl ?? `http://${source}${base}`;
351
+ resovedInfo.targetURL = new URL(_targetUrl);
352
+ resovedInfo.targetURL.searchParams.append("ddtab", "true");
353
+ if (options?.corpId) resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
354
+ console.log(` ${c.green("➜")} ${c.bold("Open in dingtalk")}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
355
+ if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
356
+ }
357
+ };
358
+ return unpluginDing;
359
+ };
360
+ const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
361
+ var src_default = unplugin;
362
+
363
+ //#endregion
364
+ export { createProxyMiddleware, resovedInfo, src_default, unplugin, unpluginFactory };