unplugin-dingtalk 0.2.0 → 0.3.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/astro.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Options } from './types.cjs';
2
+ import 'webpack-dev-server';
2
3
  import 'vite-plugin-vconsole';
3
4
 
4
5
  declare const _default: (options: Options) => {
package/dist/astro.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Options } from './types.js';
2
+ import 'webpack-dev-server';
2
3
  import 'vite-plugin-vconsole';
3
4
 
4
5
  declare const _default: (options: Options) => {
package/dist/astro.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-GRAT7SP7.js";
3
+ } from "./chunk-XTDXIGYG.js";
4
+ import "./chunk-PMOTCIQR.js";
4
5
 
5
6
  // src/astro.ts
6
7
  var astro_default = (options) => ({
@@ -0,0 +1,83 @@
1
+ import {
2
+ fetch,
3
+ resovedInfo,
4
+ unpluginFactory
5
+ } from "./chunk-XTDXIGYG.js";
6
+
7
+ // src/webpack.ts
8
+ import { exec } from "child_process";
9
+ import process from "process";
10
+ import { createWebpackPlugin } from "unplugin";
11
+ import cookie from "cookie";
12
+ import c from "picocolors";
13
+ var webpack_default = (options) => {
14
+ function debug(...args) {
15
+ if (options == null ? void 0 : options.debug) {
16
+ console.log(` ${c.yellow("DEBUG")} `, ...args);
17
+ }
18
+ }
19
+ const {
20
+ chii: enableChii = true
21
+ } = options || {};
22
+ const injectSetupMiddlewares = (middlewares, devServer) => {
23
+ if (options.debugCookies && options.debugCookies.length > 0) {
24
+ devServer.app.use((req, res, next) => {
25
+ const cookies = cookie.parse(req.headers.cookie || "");
26
+ for (const [name, value] of Object.entries(cookies)) {
27
+ if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
28
+ const serializedCookie = cookie.serialize(name, value, {
29
+ httpOnly: false
30
+ });
31
+ res.setHeader("Set-Cookie", serializedCookie);
32
+ }
33
+ }
34
+ next();
35
+ });
36
+ }
37
+ if (enableChii) {
38
+ devServer.app.get("/__chrome_devtools", async (_req, res) => {
39
+ const availablePort = resovedInfo.availablePort;
40
+ try {
41
+ const raw = await fetch(`http://localhost:${availablePort}/targets`);
42
+ const data = await raw.json();
43
+ if ((data == null ? void 0 : data.targets.length) > 0) {
44
+ 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`;
45
+ res.writeHead(302, { Location: devToolsUrl });
46
+ res.end();
47
+ }
48
+ } catch (error) {
49
+ debug(`${error}`);
50
+ res.writeHead(502);
51
+ res.end();
52
+ }
53
+ });
54
+ }
55
+ devServer.app.get("/open-dingtalk", (req, res) => {
56
+ var _a;
57
+ const targetURL = resovedInfo.targetURL;
58
+ console.debug(targetURL.toString());
59
+ res.writeHead(302, {
60
+ Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
61
+ });
62
+ if (((_a = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a.enable) && !resovedInfo.devtoolsInstance) {
63
+ resovedInfo.devtoolsInstance = exec("npx vue-devtools");
64
+ console.log(` ${c.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
65
+ resovedInfo.devtoolsInstance.on("exit", () => {
66
+ resovedInfo.devtoolsInstance = void 0;
67
+ });
68
+ process.on("exit", () => {
69
+ if (resovedInfo.devtoolsInstance) {
70
+ resovedInfo.devtoolsInstance.kill();
71
+ }
72
+ });
73
+ }
74
+ res.end();
75
+ });
76
+ return middlewares;
77
+ };
78
+ return [injectSetupMiddlewares, createWebpackPlugin(unpluginFactory)(options)];
79
+ };
80
+
81
+ export {
82
+ webpack_default
83
+ };