unplugin-dingtalk 1007.0.1 → 1007.0.3

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 (38) hide show
  1. package/README.md +1 -0
  2. package/dist/{__chrome_devtools-CJ3sXpVj.cjs → __chrome_devtools-DXNY3hbb.cjs} +2 -2
  3. package/dist/{__chrome_devtools-CIQ5zFZx.js → __chrome_devtools-DtQ6IXAu.js} +2 -2
  4. package/dist/__chrome_devtools.cjs +1 -1
  5. package/dist/__chrome_devtools.d.cts +1 -1
  6. package/dist/__chrome_devtools.d.ts +1 -1
  7. package/dist/__chrome_devtools.js +1 -1
  8. package/dist/astro.cjs +3 -3
  9. package/dist/astro.js +3 -3
  10. package/dist/esbuild.cjs +3 -3
  11. package/dist/esbuild.js +3 -3
  12. package/dist/index.cjs +7 -3
  13. package/dist/index.d.cts +6 -2
  14. package/dist/index.d.ts +6 -2
  15. package/dist/index.js +4 -4
  16. package/dist/inject-script.cjs +5 -1
  17. package/dist/inject-script.js +5 -1
  18. package/dist/nuxt.cjs +28 -10
  19. package/dist/nuxt.js +28 -10
  20. package/dist/rollup.cjs +3 -3
  21. package/dist/rollup.js +3 -3
  22. package/dist/rspack.cjs +13 -6
  23. package/dist/rspack.js +13 -6
  24. package/dist/{src-DJcUe9oP.js → src-Di-Yrx8R.js} +67 -42
  25. package/dist/{src-CXHMJspk.cjs → src-DunrtlNd.cjs} +90 -41
  26. package/dist/{utils-CmfBxo4J.cjs → utils-3gBRwB2B.cjs} +10 -0
  27. package/dist/{utils-Chlbb6jf.js → utils-DORRNjr1.js} +5 -1
  28. package/dist/utils.cjs +2 -1
  29. package/dist/utils.d.cts +2 -1
  30. package/dist/utils.d.ts +2 -1
  31. package/dist/utils.js +2 -2
  32. package/dist/{vite-qeAmx9J4.js → vite-DMPIH2uS.js} +2 -2
  33. package/dist/{vite-ytxVicjL.cjs → vite-DxvX4RJ9.cjs} +2 -2
  34. package/dist/vite.cjs +4 -4
  35. package/dist/vite.js +4 -4
  36. package/dist/webpack.cjs +12 -6
  37. package/dist/webpack.js +12 -6
  38. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # unplugin-dingtalk
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/unplugin-dingtalk?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-dingtalk)
4
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/zcf0508/unplugin-dingtalk)
4
5
 
5
6
  一键启动钉钉内调试。支持 `vite`、`vue-cli`、`rsbuild`。
6
7
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region src/__chrome_devtools.ts
3
- function getChromeDevtoolsHtml(targetPort) {
3
+ function getChromeDevtoolsHtml(targetPort, proxyPath) {
4
4
  return `<!DOCTYPE html>
5
5
  <html>
6
6
 
@@ -54,7 +54,7 @@ function getChromeDevtoolsHtml(targetPort) {
54
54
  const list = document.getElementById("target-list");
55
55
  list.innerHTML = "<li>加载中...</li>";
56
56
  try {
57
- const resp = await fetch("/__chii_proxy/targets");
57
+ const resp = await fetch("${proxyPath}/targets");
58
58
  const data = await resp.json();
59
59
  const targets = data.targets || [];
60
60
  if (targets.length === 0) {
@@ -1,5 +1,5 @@
1
1
  //#region src/__chrome_devtools.ts
2
- function getChromeDevtoolsHtml(targetPort) {
2
+ function getChromeDevtoolsHtml(targetPort, proxyPath) {
3
3
  return `<!DOCTYPE html>
4
4
  <html>
5
5
 
@@ -53,7 +53,7 @@ function getChromeDevtoolsHtml(targetPort) {
53
53
  const list = document.getElementById("target-list");
54
54
  list.innerHTML = "<li>加载中...</li>";
55
55
  try {
56
- const resp = await fetch("/__chii_proxy/targets");
56
+ const resp = await fetch("${proxyPath}/targets");
57
57
  const data = await resp.json();
58
58
  const targets = data.targets || [];
59
59
  if (targets.length === 0) {
@@ -1,3 +1,3 @@
1
- const require___chrome_devtools = require('./__chrome_devtools-CJ3sXpVj.cjs');
1
+ const require___chrome_devtools = require('./__chrome_devtools-DXNY3hbb.cjs');
2
2
 
3
3
  exports.getChromeDevtoolsHtml = require___chrome_devtools.getChromeDevtoolsHtml;
@@ -1,4 +1,4 @@
1
1
  //#region src/__chrome_devtools.d.ts
2
- declare function getChromeDevtoolsHtml(targetPort: number): string;
2
+ declare function getChromeDevtoolsHtml(targetPort: number, proxyPath: string): string;
3
3
  //#endregion
4
4
  export { getChromeDevtoolsHtml };
@@ -1,4 +1,4 @@
1
1
  //#region src/__chrome_devtools.d.ts
2
- declare function getChromeDevtoolsHtml(targetPort: number): string;
2
+ declare function getChromeDevtoolsHtml(targetPort: number, proxyPath: string): string;
3
3
  //#endregion
4
4
  export { getChromeDevtoolsHtml };
@@ -1,3 +1,3 @@
1
- import { getChromeDevtoolsHtml } from "./__chrome_devtools-CIQ5zFZx.js";
1
+ import { getChromeDevtoolsHtml } from "./__chrome_devtools-DtQ6IXAu.js";
2
2
 
3
3
  export { getChromeDevtoolsHtml };
package/dist/astro.cjs CHANGED
@@ -1,6 +1,6 @@
1
- require('./__chrome_devtools-CJ3sXpVj.cjs');
2
- const require_src = require('./src-CXHMJspk.cjs');
3
- require('./utils-CmfBxo4J.cjs');
1
+ require('./__chrome_devtools-DXNY3hbb.cjs');
2
+ const require_src = require('./src-DunrtlNd.cjs');
3
+ require('./utils-3gBRwB2B.cjs');
4
4
 
5
5
  //#region src/astro.ts
6
6
  var astro_default = (options) => ({
package/dist/astro.js CHANGED
@@ -1,6 +1,6 @@
1
- import "./__chrome_devtools-CIQ5zFZx.js";
2
- import { src_default } from "./src-DJcUe9oP.js";
3
- import "./utils-Chlbb6jf.js";
1
+ import "./__chrome_devtools-DtQ6IXAu.js";
2
+ import { src_default } from "./src-Di-Yrx8R.js";
3
+ import "./utils-DORRNjr1.js";
4
4
 
5
5
  //#region src/astro.ts
6
6
  var astro_default = (options) => ({
package/dist/esbuild.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- require('./__chrome_devtools-CJ3sXpVj.cjs');
3
- const require_src = require('./src-CXHMJspk.cjs');
4
- require('./utils-CmfBxo4J.cjs');
2
+ require('./__chrome_devtools-DXNY3hbb.cjs');
3
+ const require_src = require('./src-DunrtlNd.cjs');
4
+ require('./utils-3gBRwB2B.cjs');
5
5
  const unplugin = require_chunk.__toESM(require("unplugin"));
6
6
 
7
7
  //#region src/esbuild.ts
package/dist/esbuild.js CHANGED
@@ -1,6 +1,6 @@
1
- import "./__chrome_devtools-CIQ5zFZx.js";
2
- import { unpluginFactory } from "./src-DJcUe9oP.js";
3
- import "./utils-Chlbb6jf.js";
1
+ import "./__chrome_devtools-DtQ6IXAu.js";
2
+ import { unpluginFactory } from "./src-Di-Yrx8R.js";
3
+ import "./utils-DORRNjr1.js";
4
4
  import { createEsbuildPlugin } from "unplugin";
5
5
 
6
6
  //#region src/esbuild.ts
package/dist/index.cjs CHANGED
@@ -1,10 +1,14 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
- require('./__chrome_devtools-CJ3sXpVj.cjs');
3
- const require_src = require('./src-CXHMJspk.cjs');
4
- require('./utils-CmfBxo4J.cjs');
2
+ require('./__chrome_devtools-DXNY3hbb.cjs');
3
+ const require_src = require('./src-DunrtlNd.cjs');
4
+ require('./utils-3gBRwB2B.cjs');
5
5
 
6
+ exports.CHII_DEVTOOLS_PATH = require_src.CHII_DEVTOOLS_PATH;
7
+ exports.CHII_PROXY_PATH = require_src.CHII_PROXY_PATH;
8
+ exports.VIRTUAL_CHII_CLIENT = require_src.VIRTUAL_CHII_CLIENT;
6
9
  exports.createProxyMiddleware = require_src.createProxyMiddleware;
7
10
  exports.default = require_src.src_default;
11
+ exports.getChiiClientModuleCode = require_src.getChiiClientModuleCode;
8
12
  exports.resovedInfo = require_src.resovedInfo;
9
13
  exports.unplugin = require_src.unplugin;
10
14
  exports.unpluginFactory = require_src.unpluginFactory;
package/dist/index.d.cts CHANGED
@@ -4,14 +4,18 @@ import { UnpluginFactory } from "unplugin";
4
4
  import { Connect } from "vite";
5
5
 
6
6
  //#region src/index.d.ts
7
+ declare const CHII_PROXY_PATH: string;
8
+ declare const CHII_DEVTOOLS_PATH: string;
9
+ declare const VIRTUAL_CHII_CLIENT: string;
7
10
  declare const resovedInfo: {
8
11
  availablePort: number | undefined;
9
12
  targetURL: undefined | URL;
10
13
  };
11
- declare function createProxyMiddleware(debug: typeof console.debug): (resolvedInfo: {
14
+ declare function createProxyMiddleware(debug: typeof console.debug, proxyPath: string): (resolvedInfo: {
12
15
  availablePort?: number;
13
16
  }) => Connect.NextHandleFunction;
17
+ declare function getChiiClientModuleCode(embedded: boolean): string;
14
18
  declare const unpluginFactory: UnpluginFactory<Options | undefined, boolean>;
15
19
  declare const unplugin: unplugin0.UnpluginInstance<Options | undefined, boolean>;
16
20
  //#endregion
17
- export { createProxyMiddleware, unplugin as default, unplugin, resovedInfo, unpluginFactory };
21
+ export { CHII_DEVTOOLS_PATH, CHII_PROXY_PATH, VIRTUAL_CHII_CLIENT, createProxyMiddleware, unplugin as default, unplugin, getChiiClientModuleCode, resovedInfo, unpluginFactory };
package/dist/index.d.ts CHANGED
@@ -4,14 +4,18 @@ import { UnpluginFactory } from "unplugin";
4
4
  import { Connect } from "vite";
5
5
 
6
6
  //#region src/index.d.ts
7
+ declare const CHII_PROXY_PATH: string;
8
+ declare const CHII_DEVTOOLS_PATH: string;
9
+ declare const VIRTUAL_CHII_CLIENT: string;
7
10
  declare const resovedInfo: {
8
11
  availablePort: number | undefined;
9
12
  targetURL: undefined | URL;
10
13
  };
11
- declare function createProxyMiddleware(debug: typeof console.debug): (resolvedInfo: {
14
+ declare function createProxyMiddleware(debug: typeof console.debug, proxyPath: string): (resolvedInfo: {
12
15
  availablePort?: number;
13
16
  }) => Connect.NextHandleFunction;
17
+ declare function getChiiClientModuleCode(embedded: boolean): string;
14
18
  declare const unpluginFactory: UnpluginFactory<Options | undefined, boolean>;
15
19
  declare const unplugin: unplugin0.UnpluginInstance<Options | undefined, boolean>;
16
20
  //#endregion
17
- export { createProxyMiddleware, unplugin as default, unplugin, resovedInfo, unpluginFactory };
21
+ export { CHII_DEVTOOLS_PATH, CHII_PROXY_PATH, VIRTUAL_CHII_CLIENT, createProxyMiddleware, unplugin as default, unplugin, getChiiClientModuleCode, resovedInfo, unpluginFactory };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./__chrome_devtools-CIQ5zFZx.js";
2
- import { createProxyMiddleware, resovedInfo, src_default, unplugin, unpluginFactory } from "./src-DJcUe9oP.js";
3
- import "./utils-Chlbb6jf.js";
1
+ import "./__chrome_devtools-DtQ6IXAu.js";
2
+ import { CHII_DEVTOOLS_PATH, CHII_PROXY_PATH, VIRTUAL_CHII_CLIENT, createProxyMiddleware, getChiiClientModuleCode, resovedInfo, src_default, unplugin, unpluginFactory } from "./src-Di-Yrx8R.js";
3
+ import "./utils-DORRNjr1.js";
4
4
 
5
- export { createProxyMiddleware, src_default as default, resovedInfo, unplugin, unpluginFactory };
5
+ export { CHII_DEVTOOLS_PATH, CHII_PROXY_PATH, VIRTUAL_CHII_CLIENT, createProxyMiddleware, src_default as default, getChiiClientModuleCode, resovedInfo, unplugin, unpluginFactory };
@@ -6,7 +6,11 @@ var inject_script_default = (0, __imports.defineNitroPlugin)((nitroApp) => {
6
6
  nitroApp.hooks.hook("render:html", (html) => {
7
7
  const config = (0, __imports.useRuntimeConfig)();
8
8
  const embedded = config.unpluginDingtalk?.chiiEmbedded ?? false;
9
- const scriptTag = embedded ? "<script src=\"/__chii_proxy/target.js\" embedded=\"true\"><\/script>" : "<script src=\"/__chii_proxy/target.js\"><\/script>";
9
+ const proxyPath = config.unpluginDingtalk?.chiiProxyPath || "/__chii_proxy";
10
+ const clientPath = config.unpluginDingtalk?.chiiClientPath;
11
+ let scriptTag = "";
12
+ if (clientPath) scriptTag = `<script type="module">import '${clientPath}';<\/script>`;
13
+ else scriptTag = embedded ? `<script src="${proxyPath}/target.js" embedded="true"><\/script>` : `<script src="${proxyPath}/target.js"><\/script>`;
10
14
  html.bodyAppend.push(scriptTag);
11
15
  });
12
16
  });
@@ -5,7 +5,11 @@ var inject_script_default = defineNitroPlugin((nitroApp) => {
5
5
  nitroApp.hooks.hook("render:html", (html) => {
6
6
  const config = useRuntimeConfig();
7
7
  const embedded = config.unpluginDingtalk?.chiiEmbedded ?? false;
8
- const scriptTag = embedded ? "<script src=\"/__chii_proxy/target.js\" embedded=\"true\"><\/script>" : "<script src=\"/__chii_proxy/target.js\"><\/script>";
8
+ const proxyPath = config.unpluginDingtalk?.chiiProxyPath || "/__chii_proxy";
9
+ const clientPath = config.unpluginDingtalk?.chiiClientPath;
10
+ let scriptTag = "";
11
+ if (clientPath) scriptTag = `<script type="module">import '${clientPath}';<\/script>`;
12
+ else scriptTag = embedded ? `<script src="${proxyPath}/target.js" embedded="true"><\/script>` : `<script src="${proxyPath}/target.js"><\/script>`;
9
13
  html.bodyAppend.push(scriptTag);
10
14
  });
11
15
  });
package/dist/nuxt.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- require('./__chrome_devtools-CJ3sXpVj.cjs');
3
- const require_src = require('./src-CXHMJspk.cjs');
4
- const require_utils = require('./utils-CmfBxo4J.cjs');
5
- const require_vite = require('./vite-ytxVicjL.cjs');
2
+ require('./__chrome_devtools-DXNY3hbb.cjs');
3
+ const require_src = require('./src-DunrtlNd.cjs');
4
+ const require_utils = require('./utils-3gBRwB2B.cjs');
5
+ const require_vite = require('./vite-DxvX4RJ9.cjs');
6
6
  const http_proxy = require_chunk.__toESM(require("http-proxy"));
7
7
  const picocolors = require_chunk.__toESM(require("picocolors"));
8
8
  const __nuxt_kit = require_chunk.__toESM(require("@nuxt/kit"));
@@ -24,22 +24,26 @@ var nuxt_default = (0, __nuxt_kit.defineNuxtModule)({
24
24
  }
25
25
  const { chii } = options || {};
26
26
  const enableChii = chii?.enable !== false;
27
- _nuxt.options.runtimeConfig.unpluginDingtalk = { chiiEmbedded: chii?.embedded ?? false };
27
+ _nuxt.options.runtimeConfig.unpluginDingtalk = {
28
+ chiiEmbedded: chii?.embedded ?? false,
29
+ chiiProxyPath: require_src.CHII_PROXY_PATH,
30
+ chiiClientPath: require_src.VIRTUAL_CHII_CLIENT
31
+ };
28
32
  if (enableChii) {
29
33
  const resolver = (0, __nuxt_kit.createResolver)(require("url").pathToFileURL(__filename).href);
30
34
  (0, __nuxt_kit.addServerPlugin)(resolver.resolve("./inject-script"));
31
35
  let proxy = null;
32
36
  (0, __nuxt_kit.addDevServerHandler)({
33
- route: "/__chii_proxy",
37
+ route: require_src.CHII_PROXY_PATH,
34
38
  handler: defineEventHandler(async (event) => {
35
- if (require_src.resovedInfo.availablePort) return proxyRequest(event, `http://localhost:${require_src.resovedInfo.availablePort}${event.path}`);
39
+ if (require_src.resovedInfo.availablePort) return proxyRequest(event, `http://localhost:${require_src.resovedInfo.availablePort}${event.path.replace(require_src.CHII_PROXY_PATH, "")}`);
36
40
  })
37
41
  });
38
42
  _nuxt.hook("listen", (server) => {
39
43
  const originalUpgradeListeners = server.listeners("upgrade").slice();
40
44
  server.removeAllListeners("upgrade");
41
45
  server.on("upgrade", (req, socket, head) => {
42
- if (req.url?.startsWith("/__chii_proxy")) {
46
+ if (req.url?.startsWith(require_src.CHII_PROXY_PATH)) {
43
47
  debug("WS upgrade:", req.url);
44
48
  if (!proxy && require_src.resovedInfo.availablePort) {
45
49
  proxy = http_proxy.default.createProxyServer({
@@ -51,7 +55,7 @@ var nuxt_default = (0, __nuxt_kit.defineNuxtModule)({
51
55
  });
52
56
  }
53
57
  if (proxy) {
54
- req.url = req.url.replace("/__chii_proxy", "");
58
+ req.url = req.url.replace(require_src.CHII_PROXY_PATH, "");
55
59
  socket.on("error", (err) => {
56
60
  debug("Socket error:", err.message);
57
61
  });
@@ -67,13 +71,27 @@ var nuxt_default = (0, __nuxt_kit.defineNuxtModule)({
67
71
  for (const listener of originalUpgradeListeners) listener.call(server, req, socket, head);
68
72
  });
69
73
  });
74
+ (0, __nuxt_kit.addDevServerHandler)({
75
+ route: require_src.VIRTUAL_CHII_CLIENT,
76
+ handler: defineEventHandler(async () => {
77
+ return require_src.getChiiClientModuleCode(!!options?.chii?.embedded);
78
+ })
79
+ });
80
+ (0, __nuxt_kit.addDevServerHandler)({
81
+ route: require_src.CHII_DEVTOOLS_PATH,
82
+ handler: defineEventHandler(async (event) => {
83
+ if (!require_src.resovedInfo.availablePort) return "Server not started";
84
+ const { getChromeDevtoolsHtml } = await Promise.resolve().then(() => require("./__chrome_devtools.cjs"));
85
+ return getChromeDevtoolsHtml(require_src.resovedInfo.availablePort, require_src.CHII_PROXY_PATH);
86
+ })
87
+ });
70
88
  }
71
89
  const vitePlugins = await require_vite.vite_default(options);
72
90
  (0, __nuxt_kit.addVitePlugin)(vitePlugins);
73
91
  _nuxt.hook("listen", (_, listener) => {
74
92
  const url = listener.url;
75
93
  const source = new URL(url).host;
76
- if (enableChii) console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Click to open chrome devtools")}: ${require_utils.colorUrl(`http://${source.replace("0.0.0.0", "localhost")}/__chrome_devtools`)}`);
94
+ if (enableChii) console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Click to open chrome devtools")}: ${require_utils.colorUrl(`http://${source.replace("0.0.0.0", "localhost")}${require_src.CHII_DEVTOOLS_PATH}`)}`);
77
95
  });
78
96
  }
79
97
  });
package/dist/nuxt.js CHANGED
@@ -1,7 +1,7 @@
1
- import "./__chrome_devtools-CIQ5zFZx.js";
2
- import { resovedInfo } from "./src-DJcUe9oP.js";
3
- import { colorUrl, interopDefault } from "./utils-Chlbb6jf.js";
4
- import { vite_default } from "./vite-qeAmx9J4.js";
1
+ import "./__chrome_devtools-DtQ6IXAu.js";
2
+ import { CHII_DEVTOOLS_PATH, CHII_PROXY_PATH, VIRTUAL_CHII_CLIENT, getChiiClientModuleCode, resovedInfo } from "./src-Di-Yrx8R.js";
3
+ import { colorUrl, interopDefault } from "./utils-DORRNjr1.js";
4
+ import { vite_default } from "./vite-DMPIH2uS.js";
5
5
  import httpProxy from "http-proxy";
6
6
  import c from "picocolors";
7
7
  import { addDevServerHandler, addServerPlugin, addVitePlugin, createResolver, defineNuxtModule } from "@nuxt/kit";
@@ -23,22 +23,26 @@ var nuxt_default = defineNuxtModule({
23
23
  }
24
24
  const { chii } = options || {};
25
25
  const enableChii = chii?.enable !== false;
26
- _nuxt.options.runtimeConfig.unpluginDingtalk = { chiiEmbedded: chii?.embedded ?? false };
26
+ _nuxt.options.runtimeConfig.unpluginDingtalk = {
27
+ chiiEmbedded: chii?.embedded ?? false,
28
+ chiiProxyPath: CHII_PROXY_PATH,
29
+ chiiClientPath: VIRTUAL_CHII_CLIENT
30
+ };
27
31
  if (enableChii) {
28
32
  const resolver = createResolver(import.meta.url);
29
33
  addServerPlugin(resolver.resolve("./inject-script"));
30
34
  let proxy = null;
31
35
  addDevServerHandler({
32
- route: "/__chii_proxy",
36
+ route: CHII_PROXY_PATH,
33
37
  handler: defineEventHandler(async (event) => {
34
- if (resovedInfo.availablePort) return proxyRequest(event, `http://localhost:${resovedInfo.availablePort}${event.path}`);
38
+ if (resovedInfo.availablePort) return proxyRequest(event, `http://localhost:${resovedInfo.availablePort}${event.path.replace(CHII_PROXY_PATH, "")}`);
35
39
  })
36
40
  });
37
41
  _nuxt.hook("listen", (server) => {
38
42
  const originalUpgradeListeners = server.listeners("upgrade").slice();
39
43
  server.removeAllListeners("upgrade");
40
44
  server.on("upgrade", (req, socket, head) => {
41
- if (req.url?.startsWith("/__chii_proxy")) {
45
+ if (req.url?.startsWith(CHII_PROXY_PATH)) {
42
46
  debug("WS upgrade:", req.url);
43
47
  if (!proxy && resovedInfo.availablePort) {
44
48
  proxy = httpProxy.createProxyServer({
@@ -50,7 +54,7 @@ var nuxt_default = defineNuxtModule({
50
54
  });
51
55
  }
52
56
  if (proxy) {
53
- req.url = req.url.replace("/__chii_proxy", "");
57
+ req.url = req.url.replace(CHII_PROXY_PATH, "");
54
58
  socket.on("error", (err) => {
55
59
  debug("Socket error:", err.message);
56
60
  });
@@ -66,13 +70,27 @@ var nuxt_default = defineNuxtModule({
66
70
  for (const listener of originalUpgradeListeners) listener.call(server, req, socket, head);
67
71
  });
68
72
  });
73
+ addDevServerHandler({
74
+ route: VIRTUAL_CHII_CLIENT,
75
+ handler: defineEventHandler(async () => {
76
+ return getChiiClientModuleCode(!!options?.chii?.embedded);
77
+ })
78
+ });
79
+ addDevServerHandler({
80
+ route: CHII_DEVTOOLS_PATH,
81
+ handler: defineEventHandler(async (event) => {
82
+ if (!resovedInfo.availablePort) return "Server not started";
83
+ const { getChromeDevtoolsHtml } = await import("./__chrome_devtools.js");
84
+ return getChromeDevtoolsHtml(resovedInfo.availablePort, CHII_PROXY_PATH);
85
+ })
86
+ });
69
87
  }
70
88
  const vitePlugins = await vite_default(options);
71
89
  addVitePlugin(vitePlugins);
72
90
  _nuxt.hook("listen", (_, listener) => {
73
91
  const url = listener.url;
74
92
  const source = new URL(url).host;
75
- if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source.replace("0.0.0.0", "localhost")}/__chrome_devtools`)}`);
93
+ if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source.replace("0.0.0.0", "localhost")}${CHII_DEVTOOLS_PATH}`)}`);
76
94
  });
77
95
  }
78
96
  });
package/dist/rollup.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- require('./__chrome_devtools-CJ3sXpVj.cjs');
3
- const require_src = require('./src-CXHMJspk.cjs');
4
- require('./utils-CmfBxo4J.cjs');
2
+ require('./__chrome_devtools-DXNY3hbb.cjs');
3
+ const require_src = require('./src-DunrtlNd.cjs');
4
+ require('./utils-3gBRwB2B.cjs');
5
5
  const unplugin = require_chunk.__toESM(require("unplugin"));
6
6
 
7
7
  //#region src/rollup.ts
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
- import "./__chrome_devtools-CIQ5zFZx.js";
2
- import { unpluginFactory } from "./src-DJcUe9oP.js";
3
- import "./utils-Chlbb6jf.js";
1
+ import "./__chrome_devtools-DtQ6IXAu.js";
2
+ import { unpluginFactory } from "./src-Di-Yrx8R.js";
3
+ import "./utils-DORRNjr1.js";
4
4
  import { createRollupPlugin } from "unplugin";
5
5
 
6
6
  //#region src/rollup.ts
package/dist/rspack.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require___chrome_devtools = require('./__chrome_devtools-CJ3sXpVj.cjs');
3
- const require_src = require('./src-CXHMJspk.cjs');
4
- require('./utils-CmfBxo4J.cjs');
2
+ const require___chrome_devtools = require('./__chrome_devtools-DXNY3hbb.cjs');
3
+ const require_src = require('./src-DunrtlNd.cjs');
4
+ require('./utils-3gBRwB2B.cjs');
5
5
  const cookie = require_chunk.__toESM(require("cookie"));
6
6
  const picocolors = require_chunk.__toESM(require("picocolors"));
7
7
  const unplugin = require_chunk.__toESM(require("unplugin"));
@@ -25,10 +25,17 @@ var rspack_default = (options) => {
25
25
  });
26
26
  if (enableChii) {
27
27
  middlewares.unshift(async (req, res, next) => {
28
- if (req.url !== "/__chrome_devtools") return next();
28
+ if (req.url !== require_src.VIRTUAL_CHII_CLIENT) return next();
29
+ const content = require_src.getChiiClientModuleCode(!!options?.chii?.embedded);
30
+ res.writeHead(200, { "Content-Type": "application/javascript; charset=utf-8" });
31
+ res.write(content);
32
+ res.end();
33
+ });
34
+ middlewares.unshift(async (req, res, next) => {
35
+ if (req.url !== require_src.CHII_DEVTOOLS_PATH) return next();
29
36
  try {
30
37
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
31
- res.write(require___chrome_devtools.getChromeDevtoolsHtml(require_src.resovedInfo.availablePort));
38
+ res.write(require___chrome_devtools.getChromeDevtoolsHtml(require_src.resovedInfo.availablePort, require_src.CHII_PROXY_PATH));
32
39
  res.end();
33
40
  } catch (error) {
34
41
  debug(`${error}`);
@@ -36,7 +43,7 @@ var rspack_default = (options) => {
36
43
  res.end();
37
44
  }
38
45
  });
39
- const proxyMiddleware = require_src.createProxyMiddleware(debug);
46
+ const proxyMiddleware = require_src.createProxyMiddleware(debug, require_src.CHII_PROXY_PATH);
40
47
  middlewares.unshift(proxyMiddleware(require_src.resovedInfo));
41
48
  }
42
49
  middlewares.unshift((req, res, next) => {
package/dist/rspack.js CHANGED
@@ -1,6 +1,6 @@
1
- import { getChromeDevtoolsHtml } from "./__chrome_devtools-CIQ5zFZx.js";
2
- import { createProxyMiddleware, resovedInfo, unpluginFactory } from "./src-DJcUe9oP.js";
3
- import "./utils-Chlbb6jf.js";
1
+ import { getChromeDevtoolsHtml } from "./__chrome_devtools-DtQ6IXAu.js";
2
+ import { CHII_DEVTOOLS_PATH, CHII_PROXY_PATH, VIRTUAL_CHII_CLIENT, createProxyMiddleware, getChiiClientModuleCode, resovedInfo, unpluginFactory } from "./src-Di-Yrx8R.js";
3
+ import "./utils-DORRNjr1.js";
4
4
  import cookie from "cookie";
5
5
  import c from "picocolors";
6
6
  import { createRspackPlugin } from "unplugin";
@@ -24,10 +24,17 @@ var rspack_default = (options) => {
24
24
  });
25
25
  if (enableChii) {
26
26
  middlewares.unshift(async (req, res, next) => {
27
- if (req.url !== "/__chrome_devtools") return next();
27
+ if (req.url !== VIRTUAL_CHII_CLIENT) return next();
28
+ const content = getChiiClientModuleCode(!!options?.chii?.embedded);
29
+ res.writeHead(200, { "Content-Type": "application/javascript; charset=utf-8" });
30
+ res.write(content);
31
+ res.end();
32
+ });
33
+ middlewares.unshift(async (req, res, next) => {
34
+ if (req.url !== CHII_DEVTOOLS_PATH) return next();
28
35
  try {
29
36
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
30
- res.write(getChromeDevtoolsHtml(resovedInfo.availablePort));
37
+ res.write(getChromeDevtoolsHtml(resovedInfo.availablePort, CHII_PROXY_PATH));
31
38
  res.end();
32
39
  } catch (error) {
33
40
  debug(`${error}`);
@@ -35,7 +42,7 @@ var rspack_default = (options) => {
35
42
  res.end();
36
43
  }
37
44
  });
38
- const proxyMiddleware = createProxyMiddleware(debug);
45
+ const proxyMiddleware = createProxyMiddleware(debug, CHII_PROXY_PATH);
39
46
  middlewares.unshift(proxyMiddleware(resovedInfo));
40
47
  }
41
48
  middlewares.unshift((req, res, next) => {
@@ -1,5 +1,5 @@
1
- import { getChromeDevtoolsHtml } from "./__chrome_devtools-CIQ5zFZx.js";
2
- import { colorUrl, isNuxtProject } from "./utils-Chlbb6jf.js";
1
+ import { getChromeDevtoolsHtml } from "./__chrome_devtools-DtQ6IXAu.js";
2
+ import { colorUrl, getProjectHash, isNuxtProject } from "./utils-DORRNjr1.js";
3
3
  import { ServerResponse } from "node:http";
4
4
  import { Socket, createServer } from "node:net";
5
5
  import process$1 from "node:process";
@@ -157,23 +157,27 @@ async function checkPort(port, host = process.env.HOST, verbose) {
157
157
  //#endregion
158
158
  //#region src/index.ts
159
159
  const cwd = process$1.cwd();
160
+ const projectHash = getProjectHash();
161
+ const CHII_PROXY_PATH = `/__chii_proxy_${projectHash}`;
162
+ const CHII_DEVTOOLS_PATH = `/__chrome_devtools_${projectHash}`;
163
+ const VIRTUAL_CHII_CLIENT = `/__chii_client_${projectHash}.js`;
160
164
  let config;
161
165
  const resovedInfo = {
162
166
  availablePort: void 0,
163
167
  targetURL: void 0
164
168
  };
165
- function createProxyMiddleware(debug) {
169
+ function createProxyMiddleware(debug, proxyPath) {
166
170
  let proxy = null;
167
171
  const handleUpgrade = (req, socket, head) => {
168
- if (proxy && req.url?.startsWith("/__chii_proxy")) {
172
+ if (proxy && req.url?.startsWith(proxyPath)) {
169
173
  debug("WS upgrade:", req.url);
170
- req.url = req.url.replace("/__chii_proxy", "");
174
+ req.url = req.url.replace(proxyPath, "");
171
175
  proxy.ws(req, socket, head);
172
176
  }
173
177
  };
174
178
  return (resolvedInfo) => {
175
179
  return (req, res, next) => {
176
- if (req.url?.startsWith("/__chii_proxy")) req._skip_transform = true;
180
+ if (req.url?.startsWith(proxyPath)) req._skip_transform = true;
177
181
  if (!proxy && resolvedInfo.availablePort) {
178
182
  proxy = httpProxy.createProxyServer({
179
183
  target: `http://localhost:${resolvedInfo.availablePort}`,
@@ -188,38 +192,28 @@ function createProxyMiddleware(debug) {
188
192
  });
189
193
  if (req.socket.server) req.socket.server.on("upgrade", handleUpgrade);
190
194
  }
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();
195
+ if (proxy && req.url) {
196
+ const url = new URL(req.url, "http://localhost");
197
+ if (url.pathname.startsWith(proxyPath)) {
198
+ debug("Proxying request:", req.url);
199
+ req.url = req.url.replace(proxyPath, "");
200
+ proxy.web(req, res);
201
+ return;
202
+ }
203
+ }
204
+ next();
196
205
  };
197
206
  };
198
207
  }
199
208
  const isNuxt = isNuxtProject();
200
- const unpluginFactory = (options) => {
201
- const { chii } = options || {};
202
- const enableChii = chii?.enable !== false;
203
- function debug(...args) {
204
- if (options?.debug) console.log(` ${c.yellow("DEBUG")} `, ...args);
205
- }
206
- const unpluginDing = {
207
- name: "unplugin-dingtalk",
208
- enforce: "pre",
209
- resolveId(source) {
210
- if (source === "chii-client") return source;
211
- },
212
- loadInclude(id) {
213
- return id === "chii-client";
214
- },
215
- load(id) {
216
- if (id === "chii-client") return `
209
+ function getChiiClientModuleCode(embedded) {
210
+ return `
217
211
  ;(function(){
218
212
  if (document.getElementById('__chii_client')) return;
219
213
  const script = document.createElement('script');
220
214
  script.id = '__chii_client';
221
- script.src="/__chii_proxy/target.js";
222
- ${options?.chii?.embedded ? "script.setAttribute('embedded','true');" : ""}
215
+ script.src="${CHII_PROXY_PATH}/target.js";
216
+ ${embedded ? "script.setAttribute('embedded','true');" : ""}
223
217
  document.body.appendChild(script);
224
218
  })();
225
219
  if (import.meta.hot) {
@@ -228,12 +222,30 @@ if (import.meta.hot) {
228
222
  if (old) old.remove();
229
223
  const script = document.createElement('script');
230
224
  script.id = '__chii_client';
231
- script.src="/__chii_proxy/target.js";
232
- ${options?.chii?.embedded ? "script.setAttribute('embedded','true');" : ""}
225
+ script.src="${CHII_PROXY_PATH}/target.js";
226
+ ${embedded ? "script.setAttribute('embedded','true');" : ""}
233
227
  document.body.appendChild(script);
234
228
  });
235
229
  }
236
- `;
230
+ `;
231
+ }
232
+ const unpluginFactory = (options) => {
233
+ const { chii } = options || {};
234
+ const enableChii = chii?.enable !== false;
235
+ function debug(...args) {
236
+ if (options?.debug) console.log(` ${c.yellow("DEBUG")} `, ...args);
237
+ }
238
+ const unpluginDing = {
239
+ name: "unplugin-dingtalk",
240
+ enforce: "pre",
241
+ resolveId(source) {
242
+ if (source === "chii-client" || source === VIRTUAL_CHII_CLIENT) return VIRTUAL_CHII_CLIENT;
243
+ },
244
+ loadInclude(id) {
245
+ return id === VIRTUAL_CHII_CLIENT;
246
+ },
247
+ load(id) {
248
+ if (id === VIRTUAL_CHII_CLIENT || id.endsWith(VIRTUAL_CHII_CLIENT)) return getChiiClientModuleCode(!!options?.chii?.embedded);
237
249
  },
238
250
  transformInclude(id) {
239
251
  return !!id.split("?")[0].match(/\.[t|j]s$/);
@@ -247,7 +259,7 @@ if (import.meta.hot) {
247
259
  if (options?.enable && enableChii) {
248
260
  const file = id.split("?")[0];
249
261
  if (file.startsWith(config?.root || cwd) && !file.includes("node_modules") && file.match(/\.[t|j]s$/) && !isNuxt) return {
250
- code: `import 'chii-client';\n${source}`,
262
+ code: `import '${VIRTUAL_CHII_CLIENT}';\n${source}`,
251
263
  map: null
252
264
  };
253
265
  }
@@ -262,7 +274,7 @@ if (import.meta.hot) {
262
274
  },
263
275
  transformIndexHtml(html) {
264
276
  if (options?.enable && enableChii && !isNuxt) {
265
- const tag = "<script type=\"module\">import 'chii-client';<\/script>";
277
+ const tag = `<script type="module">import '${VIRTUAL_CHII_CLIENT}';<\/script>`;
266
278
  if (!html.includes(tag)) return html.replace("</body>", `</body>${tag}\n`);
267
279
  }
268
280
  return html;
@@ -281,7 +293,7 @@ if (import.meta.hot) {
281
293
  server.printUrls = () => {
282
294
  _printUrls();
283
295
  console.log(` ${c.green("➜")} ${c.bold("Open in dingtalk")}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
284
- if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
296
+ if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source}${base}${CHII_DEVTOOLS_PATH.replace(/^\//, "")}`)}`);
285
297
  };
286
298
  const targetURL = new URL(_targetUrl);
287
299
  targetURL.searchParams.append("ddtab", "true");
@@ -295,18 +307,31 @@ if (import.meta.hot) {
295
307
  next();
296
308
  });
297
309
  if (enableChii) {
298
- server.middlewares.use("/__chrome_devtools", async (_req, res) => {
310
+ server.middlewares.use(VIRTUAL_CHII_CLIENT, async (_req, res) => {
311
+ const code = unpluginDing.load?.call(unpluginDing, VIRTUAL_CHII_CLIENT);
312
+ debug("load virtual chii client:", VIRTUAL_CHII_CLIENT, !!code);
313
+ if (code) {
314
+ const content = typeof code === "string" ? code : code.code ?? getChiiClientModuleCode(!!options?.chii?.embedded);
315
+ res.writeHead(200, { "Content-Type": "application/javascript; charset=utf-8" });
316
+ res.write(content || "");
317
+ res.end();
318
+ return;
319
+ }
320
+ res.writeHead(404);
321
+ res.end();
322
+ });
323
+ server.middlewares.use(CHII_DEVTOOLS_PATH, async (_req, res) => {
299
324
  if (!resovedInfo.availablePort) {
300
325
  res.writeHead(500, { "Content-Type": "text/plain" });
301
326
  res.end("Server not started");
302
327
  return;
303
328
  }
304
329
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
305
- res.write(getChromeDevtoolsHtml(resovedInfo.availablePort));
330
+ res.write(getChromeDevtoolsHtml(resovedInfo.availablePort, CHII_PROXY_PATH));
306
331
  res.end();
307
332
  });
308
333
  if (!isNuxt) {
309
- const proxyMiddleware = createProxyMiddleware(debug);
334
+ const proxyMiddleware = createProxyMiddleware(debug, CHII_PROXY_PATH);
310
335
  server.middlewares.use(proxyMiddleware(resovedInfo));
311
336
  }
312
337
  }
@@ -330,7 +355,7 @@ if (import.meta.hot) {
330
355
  const _targetUrl = options?.targetUrl ?? `http://${source}${base}`;
331
356
  compiler.hooks.done.tap("unplugin-dingtalk", () => {
332
357
  console.log(` ${c.green("➜")} ${c.bold("Open in dingtalk")}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
333
- if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
358
+ if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source}${base}${CHII_DEVTOOLS_PATH.replace(/^\//, "")}`)}`);
334
359
  });
335
360
  resovedInfo.targetURL = new URL(_targetUrl);
336
361
  resovedInfo.targetURL.searchParams.append("ddtab", "true");
@@ -351,7 +376,7 @@ if (import.meta.hot) {
351
376
  resovedInfo.targetURL.searchParams.append("ddtab", "true");
352
377
  if (options?.corpId) resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
353
378
  console.log(` ${c.green("➜")} ${c.bold("Open in dingtalk")}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
354
- if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
379
+ if (enableChii) console.log(` ${c.green("➜")} ${c.bold("Click to open chrome devtools")}: ${colorUrl(`http://${source}${base}${CHII_DEVTOOLS_PATH.replace(/^\//, "")}`)}`);
355
380
  }
356
381
  };
357
382
  return unpluginDing;
@@ -360,4 +385,4 @@ const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
360
385
  var src_default = unplugin;
361
386
 
362
387
  //#endregion
363
- export { createProxyMiddleware, resovedInfo, src_default, unplugin, unpluginFactory };
388
+ export { CHII_DEVTOOLS_PATH, CHII_PROXY_PATH, VIRTUAL_CHII_CLIENT, createProxyMiddleware, getChiiClientModuleCode, resovedInfo, src_default, unplugin, unpluginFactory };
@@ -1,6 +1,6 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require___chrome_devtools = require('./__chrome_devtools-CJ3sXpVj.cjs');
3
- const require_utils = require('./utils-CmfBxo4J.cjs');
2
+ const require___chrome_devtools = require('./__chrome_devtools-DXNY3hbb.cjs');
3
+ const require_utils = require('./utils-3gBRwB2B.cjs');
4
4
  const node_http = require_chunk.__toESM(require("node:http"));
5
5
  const node_net = require_chunk.__toESM(require("node:net"));
6
6
  const node_process = require_chunk.__toESM(require("node:process"));
@@ -158,23 +158,27 @@ async function checkPort(port, host = process.env.HOST, verbose) {
158
158
  //#endregion
159
159
  //#region src/index.ts
160
160
  const cwd = node_process.default.cwd();
161
+ const projectHash = require_utils.getProjectHash();
162
+ const CHII_PROXY_PATH = `/__chii_proxy_${projectHash}`;
163
+ const CHII_DEVTOOLS_PATH = `/__chrome_devtools_${projectHash}`;
164
+ const VIRTUAL_CHII_CLIENT = `/__chii_client_${projectHash}.js`;
161
165
  let config;
162
166
  const resovedInfo = {
163
167
  availablePort: void 0,
164
168
  targetURL: void 0
165
169
  };
166
- function createProxyMiddleware(debug) {
170
+ function createProxyMiddleware(debug, proxyPath) {
167
171
  let proxy = null;
168
172
  const handleUpgrade = (req, socket, head) => {
169
- if (proxy && req.url?.startsWith("/__chii_proxy")) {
173
+ if (proxy && req.url?.startsWith(proxyPath)) {
170
174
  debug("WS upgrade:", req.url);
171
- req.url = req.url.replace("/__chii_proxy", "");
175
+ req.url = req.url.replace(proxyPath, "");
172
176
  proxy.ws(req, socket, head);
173
177
  }
174
178
  };
175
179
  return (resolvedInfo) => {
176
180
  return (req, res, next) => {
177
- if (req.url?.startsWith("/__chii_proxy")) req._skip_transform = true;
181
+ if (req.url?.startsWith(proxyPath)) req._skip_transform = true;
178
182
  if (!proxy && resolvedInfo.availablePort) {
179
183
  proxy = http_proxy.default.createProxyServer({
180
184
  target: `http://localhost:${resolvedInfo.availablePort}`,
@@ -189,38 +193,28 @@ function createProxyMiddleware(debug) {
189
193
  });
190
194
  if (req.socket.server) req.socket.server.on("upgrade", handleUpgrade);
191
195
  }
192
- if (proxy && req.url?.startsWith("/__chii_proxy")) {
193
- debug(req.url);
194
- req.url = req.url.replace("/__chii_proxy", "");
195
- proxy.web(req, res);
196
- } else next();
196
+ if (proxy && req.url) {
197
+ const url = new URL(req.url, "http://localhost");
198
+ if (url.pathname.startsWith(proxyPath)) {
199
+ debug("Proxying request:", req.url);
200
+ req.url = req.url.replace(proxyPath, "");
201
+ proxy.web(req, res);
202
+ return;
203
+ }
204
+ }
205
+ next();
197
206
  };
198
207
  };
199
208
  }
200
209
  const isNuxt = require_utils.isNuxtProject();
201
- const unpluginFactory = (options) => {
202
- const { chii } = options || {};
203
- const enableChii = chii?.enable !== false;
204
- function debug(...args) {
205
- if (options?.debug) console.log(` ${picocolors.default.yellow("DEBUG")} `, ...args);
206
- }
207
- const unpluginDing = {
208
- name: "unplugin-dingtalk",
209
- enforce: "pre",
210
- resolveId(source) {
211
- if (source === "chii-client") return source;
212
- },
213
- loadInclude(id) {
214
- return id === "chii-client";
215
- },
216
- load(id) {
217
- if (id === "chii-client") return `
210
+ function getChiiClientModuleCode(embedded) {
211
+ return `
218
212
  ;(function(){
219
213
  if (document.getElementById('__chii_client')) return;
220
214
  const script = document.createElement('script');
221
215
  script.id = '__chii_client';
222
- script.src="/__chii_proxy/target.js";
223
- ${options?.chii?.embedded ? "script.setAttribute('embedded','true');" : ""}
216
+ script.src="${CHII_PROXY_PATH}/target.js";
217
+ ${embedded ? "script.setAttribute('embedded','true');" : ""}
224
218
  document.body.appendChild(script);
225
219
  })();
226
220
  if (import.meta.hot) {
@@ -229,12 +223,30 @@ if (import.meta.hot) {
229
223
  if (old) old.remove();
230
224
  const script = document.createElement('script');
231
225
  script.id = '__chii_client';
232
- script.src="/__chii_proxy/target.js";
233
- ${options?.chii?.embedded ? "script.setAttribute('embedded','true');" : ""}
226
+ script.src="${CHII_PROXY_PATH}/target.js";
227
+ ${embedded ? "script.setAttribute('embedded','true');" : ""}
234
228
  document.body.appendChild(script);
235
229
  });
236
230
  }
237
- `;
231
+ `;
232
+ }
233
+ const unpluginFactory = (options) => {
234
+ const { chii } = options || {};
235
+ const enableChii = chii?.enable !== false;
236
+ function debug(...args) {
237
+ if (options?.debug) console.log(` ${picocolors.default.yellow("DEBUG")} `, ...args);
238
+ }
239
+ const unpluginDing = {
240
+ name: "unplugin-dingtalk",
241
+ enforce: "pre",
242
+ resolveId(source) {
243
+ if (source === "chii-client" || source === VIRTUAL_CHII_CLIENT) return VIRTUAL_CHII_CLIENT;
244
+ },
245
+ loadInclude(id) {
246
+ return id === VIRTUAL_CHII_CLIENT;
247
+ },
248
+ load(id) {
249
+ if (id === VIRTUAL_CHII_CLIENT || id.endsWith(VIRTUAL_CHII_CLIENT)) return getChiiClientModuleCode(!!options?.chii?.embedded);
238
250
  },
239
251
  transformInclude(id) {
240
252
  return !!id.split("?")[0].match(/\.[t|j]s$/);
@@ -248,7 +260,7 @@ if (import.meta.hot) {
248
260
  if (options?.enable && enableChii) {
249
261
  const file = id.split("?")[0];
250
262
  if (file.startsWith(config?.root || cwd) && !file.includes("node_modules") && file.match(/\.[t|j]s$/) && !isNuxt) return {
251
- code: `import 'chii-client';\n${source}`,
263
+ code: `import '${VIRTUAL_CHII_CLIENT}';\n${source}`,
252
264
  map: null
253
265
  };
254
266
  }
@@ -263,7 +275,7 @@ if (import.meta.hot) {
263
275
  },
264
276
  transformIndexHtml(html) {
265
277
  if (options?.enable && enableChii && !isNuxt) {
266
- const tag = "<script type=\"module\">import 'chii-client';<\/script>";
278
+ const tag = `<script type="module">import '${VIRTUAL_CHII_CLIENT}';<\/script>`;
267
279
  if (!html.includes(tag)) return html.replace("</body>", `</body>${tag}\n`);
268
280
  }
269
281
  return html;
@@ -282,7 +294,7 @@ if (import.meta.hot) {
282
294
  server.printUrls = () => {
283
295
  _printUrls();
284
296
  console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Open in dingtalk")}: ${require_utils.colorUrl(`http://${source}${base}open-dingtalk`)}`);
285
- if (enableChii) console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Click to open chrome devtools")}: ${require_utils.colorUrl(`http://${source}${base}__chrome_devtools`)}`);
297
+ if (enableChii) console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Click to open chrome devtools")}: ${require_utils.colorUrl(`http://${source}${base}${CHII_DEVTOOLS_PATH.replace(/^\//, "")}`)}`);
286
298
  };
287
299
  const targetURL = new URL(_targetUrl);
288
300
  targetURL.searchParams.append("ddtab", "true");
@@ -296,18 +308,31 @@ if (import.meta.hot) {
296
308
  next();
297
309
  });
298
310
  if (enableChii) {
299
- server.middlewares.use("/__chrome_devtools", async (_req, res) => {
311
+ server.middlewares.use(VIRTUAL_CHII_CLIENT, async (_req, res) => {
312
+ const code = unpluginDing.load?.call(unpluginDing, VIRTUAL_CHII_CLIENT);
313
+ debug("load virtual chii client:", VIRTUAL_CHII_CLIENT, !!code);
314
+ if (code) {
315
+ const content = typeof code === "string" ? code : code.code ?? getChiiClientModuleCode(!!options?.chii?.embedded);
316
+ res.writeHead(200, { "Content-Type": "application/javascript; charset=utf-8" });
317
+ res.write(content || "");
318
+ res.end();
319
+ return;
320
+ }
321
+ res.writeHead(404);
322
+ res.end();
323
+ });
324
+ server.middlewares.use(CHII_DEVTOOLS_PATH, async (_req, res) => {
300
325
  if (!resovedInfo.availablePort) {
301
326
  res.writeHead(500, { "Content-Type": "text/plain" });
302
327
  res.end("Server not started");
303
328
  return;
304
329
  }
305
330
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
306
- res.write(require___chrome_devtools.getChromeDevtoolsHtml(resovedInfo.availablePort));
331
+ res.write(require___chrome_devtools.getChromeDevtoolsHtml(resovedInfo.availablePort, CHII_PROXY_PATH));
307
332
  res.end();
308
333
  });
309
334
  if (!isNuxt) {
310
- const proxyMiddleware = createProxyMiddleware(debug);
335
+ const proxyMiddleware = createProxyMiddleware(debug, CHII_PROXY_PATH);
311
336
  server.middlewares.use(proxyMiddleware(resovedInfo));
312
337
  }
313
338
  }
@@ -331,7 +356,7 @@ if (import.meta.hot) {
331
356
  const _targetUrl = options?.targetUrl ?? `http://${source}${base}`;
332
357
  compiler.hooks.done.tap("unplugin-dingtalk", () => {
333
358
  console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Open in dingtalk")}: ${require_utils.colorUrl(`http://${source}${base}open-dingtalk`)}`);
334
- if (enableChii) console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Click to open chrome devtools")}: ${require_utils.colorUrl(`http://${source}${base}__chrome_devtools`)}`);
359
+ if (enableChii) console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Click to open chrome devtools")}: ${require_utils.colorUrl(`http://${source}${base}${CHII_DEVTOOLS_PATH.replace(/^\//, "")}`)}`);
335
360
  });
336
361
  resovedInfo.targetURL = new URL(_targetUrl);
337
362
  resovedInfo.targetURL.searchParams.append("ddtab", "true");
@@ -352,7 +377,7 @@ if (import.meta.hot) {
352
377
  resovedInfo.targetURL.searchParams.append("ddtab", "true");
353
378
  if (options?.corpId) resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
354
379
  console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Open in dingtalk")}: ${require_utils.colorUrl(`http://${source}${base}open-dingtalk`)}`);
355
- if (enableChii) console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Click to open chrome devtools")}: ${require_utils.colorUrl(`http://${source}${base}__chrome_devtools`)}`);
380
+ if (enableChii) console.log(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Click to open chrome devtools")}: ${require_utils.colorUrl(`http://${source}${base}${CHII_DEVTOOLS_PATH.replace(/^\//, "")}`)}`);
356
381
  }
357
382
  };
358
383
  return unpluginDing;
@@ -361,12 +386,36 @@ const unplugin$1 = /* @__PURE__ */ (0, unplugin.createUnplugin)(unpluginFactory)
361
386
  var src_default = unplugin$1;
362
387
 
363
388
  //#endregion
389
+ Object.defineProperty(exports, 'CHII_DEVTOOLS_PATH', {
390
+ enumerable: true,
391
+ get: function () {
392
+ return CHII_DEVTOOLS_PATH;
393
+ }
394
+ });
395
+ Object.defineProperty(exports, 'CHII_PROXY_PATH', {
396
+ enumerable: true,
397
+ get: function () {
398
+ return CHII_PROXY_PATH;
399
+ }
400
+ });
401
+ Object.defineProperty(exports, 'VIRTUAL_CHII_CLIENT', {
402
+ enumerable: true,
403
+ get: function () {
404
+ return VIRTUAL_CHII_CLIENT;
405
+ }
406
+ });
364
407
  Object.defineProperty(exports, 'createProxyMiddleware', {
365
408
  enumerable: true,
366
409
  get: function () {
367
410
  return createProxyMiddleware;
368
411
  }
369
412
  });
413
+ Object.defineProperty(exports, 'getChiiClientModuleCode', {
414
+ enumerable: true,
415
+ get: function () {
416
+ return getChiiClientModuleCode;
417
+ }
418
+ });
370
419
  Object.defineProperty(exports, 'resovedInfo', {
371
420
  enumerable: true,
372
421
  get: function () {
@@ -1,9 +1,13 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
2
  const node_process = require_chunk.__toESM(require("node:process"));
3
3
  const picocolors = require_chunk.__toESM(require("picocolors"));
4
+ const node_crypto = require_chunk.__toESM(require("node:crypto"));
4
5
  const node_fs = require_chunk.__toESM(require("node:fs"));
5
6
 
6
7
  //#region src/utils.ts
8
+ function getProjectHash() {
9
+ return (0, node_crypto.createHash)("md5").update(node_process.default.cwd()).digest("hex").slice(0, 8);
10
+ }
7
11
  async function interopDefault(m) {
8
12
  const resolved = await m;
9
13
  return resolved.default || resolved;
@@ -27,6 +31,12 @@ Object.defineProperty(exports, 'colorUrl', {
27
31
  return colorUrl;
28
32
  }
29
33
  });
34
+ Object.defineProperty(exports, 'getProjectHash', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return getProjectHash;
38
+ }
39
+ });
30
40
  Object.defineProperty(exports, 'interopDefault', {
31
41
  enumerable: true,
32
42
  get: function () {
@@ -1,8 +1,12 @@
1
1
  import process from "node:process";
2
2
  import c from "picocolors";
3
+ import { createHash } from "node:crypto";
3
4
  import { existsSync } from "node:fs";
4
5
 
5
6
  //#region src/utils.ts
7
+ function getProjectHash() {
8
+ return createHash("md5").update(process.cwd()).digest("hex").slice(0, 8);
9
+ }
6
10
  async function interopDefault(m) {
7
11
  const resolved = await m;
8
12
  return resolved.default || resolved;
@@ -20,4 +24,4 @@ function isNuxtProject() {
20
24
  }
21
25
 
22
26
  //#endregion
23
- export { colorUrl, interopDefault, isNuxtProject };
27
+ export { colorUrl, getProjectHash, interopDefault, isNuxtProject };
package/dist/utils.cjs CHANGED
@@ -1,5 +1,6 @@
1
- const require_utils = require('./utils-CmfBxo4J.cjs');
1
+ const require_utils = require('./utils-3gBRwB2B.cjs');
2
2
 
3
3
  exports.colorUrl = require_utils.colorUrl;
4
+ exports.getProjectHash = require_utils.getProjectHash;
4
5
  exports.interopDefault = require_utils.interopDefault;
5
6
  exports.isNuxtProject = require_utils.isNuxtProject;
package/dist/utils.d.cts CHANGED
@@ -1,9 +1,10 @@
1
1
  //#region src/utils.d.ts
2
2
  type Awaitable<T> = T | Promise<T>;
3
+ declare function getProjectHash(): string;
3
4
  declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
4
5
  default: infer U;
5
6
  } ? U : T>;
6
7
  declare const colorUrl: (url: string) => string;
7
8
  declare function isNuxtProject(): boolean;
8
9
  //#endregion
9
- export { Awaitable, colorUrl, interopDefault, isNuxtProject };
10
+ export { Awaitable, colorUrl, getProjectHash, interopDefault, isNuxtProject };
package/dist/utils.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  //#region src/utils.d.ts
2
2
  type Awaitable<T> = T | Promise<T>;
3
+ declare function getProjectHash(): string;
3
4
  declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
4
5
  default: infer U;
5
6
  } ? U : T>;
6
7
  declare const colorUrl: (url: string) => string;
7
8
  declare function isNuxtProject(): boolean;
8
9
  //#endregion
9
- export { Awaitable, colorUrl, interopDefault, isNuxtProject };
10
+ export { Awaitable, colorUrl, getProjectHash, interopDefault, isNuxtProject };
package/dist/utils.js CHANGED
@@ -1,3 +1,3 @@
1
- import { colorUrl, interopDefault, isNuxtProject } from "./utils-Chlbb6jf.js";
1
+ import { colorUrl, getProjectHash, interopDefault, isNuxtProject } from "./utils-DORRNjr1.js";
2
2
 
3
- export { colorUrl, interopDefault, isNuxtProject };
3
+ export { colorUrl, getProjectHash, interopDefault, isNuxtProject };
@@ -1,5 +1,5 @@
1
- import { unpluginFactory } from "./src-DJcUe9oP.js";
2
- import { interopDefault } from "./utils-Chlbb6jf.js";
1
+ import { unpluginFactory } from "./src-Di-Yrx8R.js";
2
+ import { interopDefault } from "./utils-DORRNjr1.js";
3
3
  import { createVitePlugin } from "unplugin";
4
4
 
5
5
  //#region src/vite.ts
@@ -1,6 +1,6 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_src = require('./src-CXHMJspk.cjs');
3
- const require_utils = require('./utils-CmfBxo4J.cjs');
2
+ const require_src = require('./src-DunrtlNd.cjs');
3
+ const require_utils = require('./utils-3gBRwB2B.cjs');
4
4
  const unplugin = require_chunk.__toESM(require("unplugin"));
5
5
 
6
6
  //#region src/vite.ts
package/dist/vite.cjs CHANGED
@@ -1,6 +1,6 @@
1
- require('./__chrome_devtools-CJ3sXpVj.cjs');
2
- require('./src-CXHMJspk.cjs');
3
- require('./utils-CmfBxo4J.cjs');
4
- const require_vite = require('./vite-ytxVicjL.cjs');
1
+ require('./__chrome_devtools-DXNY3hbb.cjs');
2
+ require('./src-DunrtlNd.cjs');
3
+ require('./utils-3gBRwB2B.cjs');
4
+ const require_vite = require('./vite-DxvX4RJ9.cjs');
5
5
 
6
6
  module.exports = require_vite.vite_default;
package/dist/vite.js CHANGED
@@ -1,6 +1,6 @@
1
- import "./__chrome_devtools-CIQ5zFZx.js";
2
- import "./src-DJcUe9oP.js";
3
- import "./utils-Chlbb6jf.js";
4
- import { vite_default } from "./vite-qeAmx9J4.js";
1
+ import "./__chrome_devtools-DtQ6IXAu.js";
2
+ import "./src-Di-Yrx8R.js";
3
+ import "./utils-DORRNjr1.js";
4
+ import { vite_default } from "./vite-DMPIH2uS.js";
5
5
 
6
6
  export { vite_default as default };
package/dist/webpack.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require___chrome_devtools = require('./__chrome_devtools-CJ3sXpVj.cjs');
3
- const require_src = require('./src-CXHMJspk.cjs');
4
- require('./utils-CmfBxo4J.cjs');
2
+ const require___chrome_devtools = require('./__chrome_devtools-DXNY3hbb.cjs');
3
+ const require_src = require('./src-DunrtlNd.cjs');
4
+ require('./utils-3gBRwB2B.cjs');
5
5
  const cookie = require_chunk.__toESM(require("cookie"));
6
6
  const picocolors = require_chunk.__toESM(require("picocolors"));
7
7
  const unplugin = require_chunk.__toESM(require("unplugin"));
@@ -24,10 +24,16 @@ var webpack_default = (options) => {
24
24
  next();
25
25
  });
26
26
  if (enableChii) {
27
- devServer.app.get("/__chrome_devtools", async (_req, res) => {
27
+ devServer.app.get(require_src.VIRTUAL_CHII_CLIENT, async (_req, res) => {
28
+ const content = require_src.getChiiClientModuleCode(!!options?.chii?.embedded);
29
+ res.writeHead(200, { "Content-Type": "application/javascript; charset=utf-8" });
30
+ res.write(content);
31
+ res.end();
32
+ });
33
+ devServer.app.get(require_src.CHII_DEVTOOLS_PATH, async (_req, res) => {
28
34
  try {
29
35
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
30
- res.write(require___chrome_devtools.getChromeDevtoolsHtml(require_src.resovedInfo.availablePort));
36
+ res.write(require___chrome_devtools.getChromeDevtoolsHtml(require_src.resovedInfo.availablePort, require_src.CHII_PROXY_PATH));
31
37
  res.end();
32
38
  } catch (error) {
33
39
  debug(`${error}`);
@@ -35,7 +41,7 @@ var webpack_default = (options) => {
35
41
  res.end();
36
42
  }
37
43
  });
38
- const proxyMiddleware = require_src.createProxyMiddleware(debug);
44
+ const proxyMiddleware = require_src.createProxyMiddleware(debug, require_src.CHII_PROXY_PATH);
39
45
  devServer.app.use(proxyMiddleware(require_src.resovedInfo));
40
46
  }
41
47
  devServer.app.get("/open-dingtalk", (req, res) => {
package/dist/webpack.js CHANGED
@@ -1,6 +1,6 @@
1
- import { getChromeDevtoolsHtml } from "./__chrome_devtools-CIQ5zFZx.js";
2
- import { createProxyMiddleware, resovedInfo, unpluginFactory } from "./src-DJcUe9oP.js";
3
- import "./utils-Chlbb6jf.js";
1
+ import { getChromeDevtoolsHtml } from "./__chrome_devtools-DtQ6IXAu.js";
2
+ import { CHII_DEVTOOLS_PATH, CHII_PROXY_PATH, VIRTUAL_CHII_CLIENT, createProxyMiddleware, getChiiClientModuleCode, resovedInfo, unpluginFactory } from "./src-Di-Yrx8R.js";
3
+ import "./utils-DORRNjr1.js";
4
4
  import cookie from "cookie";
5
5
  import c from "picocolors";
6
6
  import { createWebpackPlugin } from "unplugin";
@@ -23,10 +23,16 @@ var webpack_default = (options) => {
23
23
  next();
24
24
  });
25
25
  if (enableChii) {
26
- devServer.app.get("/__chrome_devtools", async (_req, res) => {
26
+ devServer.app.get(VIRTUAL_CHII_CLIENT, async (_req, res) => {
27
+ const content = getChiiClientModuleCode(!!options?.chii?.embedded);
28
+ res.writeHead(200, { "Content-Type": "application/javascript; charset=utf-8" });
29
+ res.write(content);
30
+ res.end();
31
+ });
32
+ devServer.app.get(CHII_DEVTOOLS_PATH, async (_req, res) => {
27
33
  try {
28
34
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
29
- res.write(getChromeDevtoolsHtml(resovedInfo.availablePort));
35
+ res.write(getChromeDevtoolsHtml(resovedInfo.availablePort, CHII_PROXY_PATH));
30
36
  res.end();
31
37
  } catch (error) {
32
38
  debug(`${error}`);
@@ -34,7 +40,7 @@ var webpack_default = (options) => {
34
40
  res.end();
35
41
  }
36
42
  });
37
- const proxyMiddleware = createProxyMiddleware(debug);
43
+ const proxyMiddleware = createProxyMiddleware(debug, CHII_PROXY_PATH);
38
44
  devServer.app.use(proxyMiddleware(resovedInfo));
39
45
  }
40
46
  devServer.app.get("/open-dingtalk", (req, res) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-dingtalk",
3
3
  "type": "module",
4
- "version": "1007.0.1",
4
+ "version": "1007.0.3",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/zcf0508/unplugin-dingtalk#readme",