unplugin-dingtalk 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as webpack_dev_server from 'webpack-dev-server';
2
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
3
  import { viteVConsoleOptions } from 'vite-plugin-vconsole';
3
4
 
4
5
  interface Options {
@@ -18,5 +19,18 @@ interface Options {
18
19
  };
19
20
  }
20
21
  type SetupMiddlewares = (middlewares: webpack_dev_server.Middleware[], devServer: webpack_dev_server) => webpack_dev_server.Middleware[];
22
+ type NextFunction = () => void;
23
+ type RequestHandler = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
24
+ interface ServerAPIs {
25
+ sockWrite: (type: string, data?: string | boolean | Record<string, any>) => void;
26
+ }
27
+ type RspackSetupMiddlewares = (
28
+ /** Order: `unshift` => internal middlewares => `push` */
29
+ middlewares: {
30
+ /** Use the `unshift` method if you want to run a middleware before all other middlewares */
31
+ unshift: (...handlers: RequestHandler[]) => void;
32
+ /** Use the `push` method if you want to run a middleware after all other middlewares */
33
+ push: (...handlers: RequestHandler[]) => void;
34
+ }, server: ServerAPIs) => void;
21
35
 
22
- export type { Options, SetupMiddlewares };
36
+ export type { Options, RspackSetupMiddlewares, SetupMiddlewares };
package/dist/vite.cjs CHANGED
@@ -5212,6 +5212,7 @@ __export(vite_exports, {
5212
5212
  });
5213
5213
  module.exports = __toCommonJS(vite_exports);
5214
5214
  var import_unplugin2 = require("unplugin");
5215
+ var import_vite_plugin_vconsole = __toESM(require("vite-plugin-vconsole"), 1);
5215
5216
 
5216
5217
  // src/index.ts
5217
5218
  var import_node_child_process = require("child_process");
@@ -6512,10 +6513,10 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
6512
6513
  // src/index.ts
6513
6514
  var import_unplugin = require("unplugin");
6514
6515
  var import_picocolors = __toESM(require("picocolors"), 1);
6515
- var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
6516
6516
  var import_cookie = __toESM(require("cookie"), 1);
6517
6517
  var import_chii = require("chii");
6518
6518
  var import_get_port_please = require("get-port-please");
6519
+ var cwd = import_node_process.default.cwd();
6519
6520
  var config;
6520
6521
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
6521
6522
  var resovedInfo = {
@@ -6532,7 +6533,6 @@ var unpluginFactory = (options) => {
6532
6533
  console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
6533
6534
  }
6534
6535
  }
6535
- const plugins = [];
6536
6536
  const unpluginDing = {
6537
6537
  name: "unplugin-dingtalk",
6538
6538
  enforce: "pre",
@@ -6545,20 +6545,22 @@ var unpluginFactory = (options) => {
6545
6545
  resovedInfo.availablePort = await (0, import_get_port_please.getRandomPort)();
6546
6546
  debug(`chii server port: ${JSON.stringify({ availablePort: resovedInfo.availablePort })}`);
6547
6547
  (0, import_chii.start)({
6548
+ host: "0.0.0.0",
6548
6549
  port: resovedInfo.availablePort
6549
6550
  });
6550
6551
  }
6551
- if ((options == null ? void 0 : options.enable) && ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable)) {
6552
+ if (options == null ? void 0 : options.enable) {
6552
6553
  const codes = [
6553
- `/* eslint-disable */;
6554
- import { devtools } from '@vue/devtools'
6555
- devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port});`,
6554
+ "/* eslint-disable */;",
6555
+ ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) ? `import { devtools } from '@vue/devtools'
6556
+ devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port});` : "",
6556
6557
  (options == null ? void 0 : options.enable) && enableChii ? `(() => {
6557
6558
  const script = document.createElement('script');
6558
6559
  script.src="http://localhost:${resovedInfo.availablePort}/target.js";
6559
6560
  document.body.appendChild(script);
6560
6561
  })()` : "",
6561
- `/* eslint-enable */${_source};`
6562
+ "/* eslint-enable */",
6563
+ `${_source};`
6562
6564
  ];
6563
6565
  return {
6564
6566
  code: codes.join("\n"),
@@ -6577,23 +6579,19 @@ var unpluginFactory = (options) => {
6577
6579
  config = _config;
6578
6580
  },
6579
6581
  async configureServer(server) {
6580
- var _a4, _b, _c;
6582
+ var _a4, _b;
6581
6583
  if (!(options == null ? void 0 : options.enable)) {
6582
6584
  return;
6583
6585
  }
6584
- const availablePort = resovedInfo.availablePort;
6585
- if ((options == null ? void 0 : options.enable) && ((_a4 = options == null ? void 0 : options.vconsole) == null ? void 0 : _a4.enabled)) {
6586
- plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
6587
- }
6588
6586
  const _printUrls = server.printUrls.bind(server);
6589
6587
  let source = `localhost:${config.server.port || 5173}`;
6590
- const url = (_b = server.resolvedUrls) == null ? void 0 : _b.local[0];
6588
+ const url = (_a4 = server.resolvedUrls) == null ? void 0 : _a4.local[0];
6591
6589
  if (url) {
6592
6590
  const u = new URL(url);
6593
6591
  source = u.host;
6594
6592
  }
6595
6593
  const base = server.config.base || "/";
6596
- const _targetUrl = (_c = options == null ? void 0 : options.targetUrl) != null ? _c : `http://${source}${base}`;
6594
+ const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
6597
6595
  server.printUrls = () => {
6598
6596
  var _a5;
6599
6597
  _printUrls();
@@ -6628,10 +6626,10 @@ var unpluginFactory = (options) => {
6628
6626
  if (enableChii) {
6629
6627
  server.middlewares.use("/__chrome_devtools", async (_req, res) => {
6630
6628
  try {
6631
- const raw = await fetch(`http://localhost:${availablePort}/targets`);
6629
+ const raw = await fetch(`http://localhost:${resovedInfo.availablePort}/targets`);
6632
6630
  const data = await raw.json();
6633
6631
  if ((data == null ? void 0 : data.targets.length) > 0) {
6634
- 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`;
6632
+ const devToolsUrl = `http://localhost:${resovedInfo.availablePort}/front_end/chii_app.html?ws=localhost:${resovedInfo.availablePort}/client/${Math.random().toString(20).substring(2, 8)}?target=${data.targets[0].id}&rtc=false`;
6635
6633
  res.writeHead(302, { Location: devToolsUrl });
6636
6634
  res.end();
6637
6635
  }
@@ -6692,14 +6690,48 @@ var unpluginFactory = (options) => {
6692
6690
  if (options == null ? void 0 : options.corpId) {
6693
6691
  resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6694
6692
  }
6693
+ },
6694
+ async rspack(compiler) {
6695
+ var _a4, _b, _c, _d2, _e;
6696
+ if (!(options == null ? void 0 : options.enable)) {
6697
+ return;
6698
+ }
6699
+ const devServerOptions = __spreadValues(__spreadValues({
6700
+ host: "localhost",
6701
+ port: 8080
6702
+ }, compiler.options.devServer), (_c = (_b = await ((_a4 = await import("@rsbuild/core")) == null ? void 0 : _a4.loadConfig({
6703
+ cwd
6704
+ }))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
6705
+ const source = `${devServerOptions.host === "0.0.0.0" ? "127.0.0.1" : devServerOptions.host}:${devServerOptions.port}`;
6706
+ const base = compiler.options.output.publicPath || "/";
6707
+ const _targetUrl = (_d2 = options == null ? void 0 : options.targetUrl) != null ? _d2 : `http://${source}${base}`;
6708
+ resovedInfo.targetURL = new URL(_targetUrl);
6709
+ resovedInfo.targetURL.searchParams.append("ddtab", "true");
6710
+ if (options == null ? void 0 : options.corpId) {
6711
+ resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6712
+ }
6713
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
6714
+ `Open in dingtalk${((_e = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _e.enable) ? " (with vue-devtools)" : ""}`
6715
+ )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
6716
+ if (enableChii) {
6717
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
6718
+ "Click to open chrome devtools"
6719
+ )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
6720
+ }
6695
6721
  }
6696
6722
  };
6697
- plugins.push(unpluginDing);
6698
- return plugins;
6723
+ return unpluginDing;
6699
6724
  };
6700
6725
 
6701
6726
  // src/vite.ts
6702
- var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
6727
+ var vite_default = (options) => {
6728
+ var _a4;
6729
+ const plugins = [(0, import_unplugin2.createVitePlugin)(unpluginFactory)(options)];
6730
+ if ((options == null ? void 0 : options.enable) && ((_a4 = options == null ? void 0 : options.vconsole) == null ? void 0 : _a4.enabled)) {
6731
+ plugins.push((0, import_vite_plugin_vconsole.default)(options == null ? void 0 : options.vconsole));
6732
+ }
6733
+ return plugins;
6734
+ };
6703
6735
  /*! Bundled license information:
6704
6736
 
6705
6737
  web-streams-polyfill/dist/ponyfill.es2018.js:
package/dist/vite.d.cts CHANGED
@@ -1,8 +1,9 @@
1
- import * as vite from 'vite';
1
+ import { Plugin } from 'vite';
2
2
  import { Options } from './types.cjs';
3
3
  import 'webpack-dev-server';
4
+ import 'node:http';
4
5
  import 'vite-plugin-vconsole';
5
6
 
6
- declare const _default: (options?: Options | undefined) => vite.Plugin<any> | vite.Plugin<any>[];
7
+ declare const _default: (options: Options) => Plugin<any>[];
7
8
 
8
9
  export { _default as default };
package/dist/vite.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import * as vite from 'vite';
1
+ import { Plugin } from 'vite';
2
2
  import { Options } from './types.js';
3
3
  import 'webpack-dev-server';
4
+ import 'node:http';
4
5
  import 'vite-plugin-vconsole';
5
6
 
6
- declare const _default: (options?: Options | undefined) => vite.Plugin<any> | vite.Plugin<any>[];
7
+ declare const _default: (options: Options) => Plugin<any>[];
7
8
 
8
9
  export { _default as default };
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-ZV272SZK.js";
4
- import "./chunk-XTDXIGYG.js";
3
+ } from "./chunk-2OB7UBRW.js";
4
+ import "./chunk-RDTWBIQD.js";
5
5
  import "./chunk-PMOTCIQR.js";
6
6
  export {
7
7
  vite_default as default
package/dist/webpack.cjs CHANGED
@@ -6514,10 +6514,10 @@ var import_node_child_process = require("child_process");
6514
6514
  var import_node_process = __toESM(require("process"), 1);
6515
6515
  var import_unplugin = require("unplugin");
6516
6516
  var import_picocolors = __toESM(require("picocolors"), 1);
6517
- var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
6518
6517
  var import_cookie = __toESM(require("cookie"), 1);
6519
6518
  var import_chii = require("chii");
6520
6519
  var import_get_port_please = require("get-port-please");
6520
+ var cwd = import_node_process.default.cwd();
6521
6521
  var config;
6522
6522
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
6523
6523
  var resovedInfo = {
@@ -6534,7 +6534,6 @@ var unpluginFactory = (options) => {
6534
6534
  console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
6535
6535
  }
6536
6536
  }
6537
- const plugins = [];
6538
6537
  const unpluginDing = {
6539
6538
  name: "unplugin-dingtalk",
6540
6539
  enforce: "pre",
@@ -6547,20 +6546,22 @@ var unpluginFactory = (options) => {
6547
6546
  resovedInfo.availablePort = await (0, import_get_port_please.getRandomPort)();
6548
6547
  debug(`chii server port: ${JSON.stringify({ availablePort: resovedInfo.availablePort })}`);
6549
6548
  (0, import_chii.start)({
6549
+ host: "0.0.0.0",
6550
6550
  port: resovedInfo.availablePort
6551
6551
  });
6552
6552
  }
6553
- if ((options == null ? void 0 : options.enable) && ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable)) {
6553
+ if (options == null ? void 0 : options.enable) {
6554
6554
  const codes = [
6555
- `/* eslint-disable */;
6556
- import { devtools } from '@vue/devtools'
6557
- devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port});`,
6555
+ "/* eslint-disable */;",
6556
+ ((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) ? `import { devtools } from '@vue/devtools'
6557
+ devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port});` : "",
6558
6558
  (options == null ? void 0 : options.enable) && enableChii ? `(() => {
6559
6559
  const script = document.createElement('script');
6560
6560
  script.src="http://localhost:${resovedInfo.availablePort}/target.js";
6561
6561
  document.body.appendChild(script);
6562
6562
  })()` : "",
6563
- `/* eslint-enable */${_source};`
6563
+ "/* eslint-enable */",
6564
+ `${_source};`
6564
6565
  ];
6565
6566
  return {
6566
6567
  code: codes.join("\n"),
@@ -6579,23 +6580,19 @@ var unpluginFactory = (options) => {
6579
6580
  config = _config;
6580
6581
  },
6581
6582
  async configureServer(server) {
6582
- var _a4, _b, _c;
6583
+ var _a4, _b;
6583
6584
  if (!(options == null ? void 0 : options.enable)) {
6584
6585
  return;
6585
6586
  }
6586
- const availablePort = resovedInfo.availablePort;
6587
- if ((options == null ? void 0 : options.enable) && ((_a4 = options == null ? void 0 : options.vconsole) == null ? void 0 : _a4.enabled)) {
6588
- plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
6589
- }
6590
6587
  const _printUrls = server.printUrls.bind(server);
6591
6588
  let source = `localhost:${config.server.port || 5173}`;
6592
- const url = (_b = server.resolvedUrls) == null ? void 0 : _b.local[0];
6589
+ const url = (_a4 = server.resolvedUrls) == null ? void 0 : _a4.local[0];
6593
6590
  if (url) {
6594
6591
  const u = new URL(url);
6595
6592
  source = u.host;
6596
6593
  }
6597
6594
  const base = server.config.base || "/";
6598
- const _targetUrl = (_c = options == null ? void 0 : options.targetUrl) != null ? _c : `http://${source}${base}`;
6595
+ const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
6599
6596
  server.printUrls = () => {
6600
6597
  var _a5;
6601
6598
  _printUrls();
@@ -6630,10 +6627,10 @@ var unpluginFactory = (options) => {
6630
6627
  if (enableChii) {
6631
6628
  server.middlewares.use("/__chrome_devtools", async (_req, res) => {
6632
6629
  try {
6633
- const raw = await fetch(`http://localhost:${availablePort}/targets`);
6630
+ const raw = await fetch(`http://localhost:${resovedInfo.availablePort}/targets`);
6634
6631
  const data = await raw.json();
6635
6632
  if ((data == null ? void 0 : data.targets.length) > 0) {
6636
- 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`;
6633
+ const devToolsUrl = `http://localhost:${resovedInfo.availablePort}/front_end/chii_app.html?ws=localhost:${resovedInfo.availablePort}/client/${Math.random().toString(20).substring(2, 8)}?target=${data.targets[0].id}&rtc=false`;
6637
6634
  res.writeHead(302, { Location: devToolsUrl });
6638
6635
  res.end();
6639
6636
  }
@@ -6694,10 +6691,37 @@ var unpluginFactory = (options) => {
6694
6691
  if (options == null ? void 0 : options.corpId) {
6695
6692
  resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6696
6693
  }
6694
+ },
6695
+ async rspack(compiler) {
6696
+ var _a4, _b, _c, _d2, _e;
6697
+ if (!(options == null ? void 0 : options.enable)) {
6698
+ return;
6699
+ }
6700
+ const devServerOptions = __spreadValues(__spreadValues({
6701
+ host: "localhost",
6702
+ port: 8080
6703
+ }, compiler.options.devServer), (_c = (_b = await ((_a4 = await import("@rsbuild/core")) == null ? void 0 : _a4.loadConfig({
6704
+ cwd
6705
+ }))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
6706
+ const source = `${devServerOptions.host === "0.0.0.0" ? "127.0.0.1" : devServerOptions.host}:${devServerOptions.port}`;
6707
+ const base = compiler.options.output.publicPath || "/";
6708
+ const _targetUrl = (_d2 = options == null ? void 0 : options.targetUrl) != null ? _d2 : `http://${source}${base}`;
6709
+ resovedInfo.targetURL = new URL(_targetUrl);
6710
+ resovedInfo.targetURL.searchParams.append("ddtab", "true");
6711
+ if (options == null ? void 0 : options.corpId) {
6712
+ resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6713
+ }
6714
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
6715
+ `Open in dingtalk${((_e = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _e.enable) ? " (with vue-devtools)" : ""}`
6716
+ )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
6717
+ if (enableChii) {
6718
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
6719
+ "Click to open chrome devtools"
6720
+ )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
6721
+ }
6697
6722
  }
6698
6723
  };
6699
- plugins.push(unpluginDing);
6700
- return plugins;
6724
+ return unpluginDing;
6701
6725
  };
6702
6726
 
6703
6727
  // src/webpack.ts
@@ -6746,7 +6770,7 @@ var webpack_default = (options) => {
6746
6770
  devServer.app.get("/open-dingtalk", (req, res) => {
6747
6771
  var _a4;
6748
6772
  const targetURL = resovedInfo.targetURL;
6749
- console.debug(targetURL.toString());
6773
+ debug(targetURL.toString());
6750
6774
  res.writeHead(302, {
6751
6775
  Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
6752
6776
  });
@@ -1,6 +1,7 @@
1
1
  import * as webpack from 'webpack';
2
2
  import { Options, SetupMiddlewares } from './types.cjs';
3
3
  import 'webpack-dev-server';
4
+ import 'node:http';
4
5
  import 'vite-plugin-vconsole';
5
6
 
6
7
  declare const _default: (options: Options) => readonly [SetupMiddlewares, webpack.WebpackPluginInstance];
package/dist/webpack.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as webpack from 'webpack';
2
2
  import { Options, SetupMiddlewares } from './types.js';
3
3
  import 'webpack-dev-server';
4
+ import 'node:http';
4
5
  import 'vite-plugin-vconsole';
5
6
 
6
7
  declare const _default: (options: Options) => readonly [SetupMiddlewares, webpack.WebpackPluginInstance];
package/dist/webpack.js CHANGED
@@ -1,8 +1,83 @@
1
1
  import {
2
- webpack_default
3
- } from "./chunk-FMGOYX4F.js";
4
- import "./chunk-XTDXIGYG.js";
2
+ fetch,
3
+ resovedInfo,
4
+ unpluginFactory
5
+ } from "./chunk-RDTWBIQD.js";
5
6
  import "./chunk-PMOTCIQR.js";
7
+
8
+ // src/webpack.ts
9
+ import { exec } from "child_process";
10
+ import process from "process";
11
+ import { createWebpackPlugin } from "unplugin";
12
+ import cookie from "cookie";
13
+ import c from "picocolors";
14
+ var webpack_default = (options) => {
15
+ function debug(...args) {
16
+ if (options == null ? void 0 : options.debug) {
17
+ console.log(` ${c.yellow("DEBUG")} `, ...args);
18
+ }
19
+ }
20
+ const {
21
+ chii: enableChii = true
22
+ } = options || {};
23
+ const injectSetupMiddlewares = (middlewares, devServer) => {
24
+ if (options.debugCookies && options.debugCookies.length > 0) {
25
+ devServer.app.use((req, res, next) => {
26
+ const cookies = cookie.parse(req.headers.cookie || "");
27
+ for (const [name, value] of Object.entries(cookies)) {
28
+ if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
29
+ const serializedCookie = cookie.serialize(name, value, {
30
+ httpOnly: false
31
+ });
32
+ res.setHeader("Set-Cookie", serializedCookie);
33
+ }
34
+ }
35
+ next();
36
+ });
37
+ }
38
+ if (enableChii) {
39
+ devServer.app.get("/__chrome_devtools", async (_req, res) => {
40
+ const availablePort = resovedInfo.availablePort;
41
+ try {
42
+ const raw = await fetch(`http://localhost:${availablePort}/targets`);
43
+ const data = await raw.json();
44
+ if ((data == null ? void 0 : data.targets.length) > 0) {
45
+ 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`;
46
+ res.writeHead(302, { Location: devToolsUrl });
47
+ res.end();
48
+ }
49
+ } catch (error) {
50
+ debug(`${error}`);
51
+ res.writeHead(502);
52
+ res.end();
53
+ }
54
+ });
55
+ }
56
+ devServer.app.get("/open-dingtalk", (req, res) => {
57
+ var _a;
58
+ const targetURL = resovedInfo.targetURL;
59
+ debug(targetURL.toString());
60
+ res.writeHead(302, {
61
+ Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
62
+ });
63
+ if (((_a = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a.enable) && !resovedInfo.devtoolsInstance) {
64
+ resovedInfo.devtoolsInstance = exec("npx vue-devtools");
65
+ console.log(` ${c.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
66
+ resovedInfo.devtoolsInstance.on("exit", () => {
67
+ resovedInfo.devtoolsInstance = void 0;
68
+ });
69
+ process.on("exit", () => {
70
+ if (resovedInfo.devtoolsInstance) {
71
+ resovedInfo.devtoolsInstance.kill();
72
+ }
73
+ });
74
+ }
75
+ res.end();
76
+ });
77
+ return middlewares;
78
+ };
79
+ return [injectSetupMiddlewares, createWebpackPlugin(unpluginFactory)(options)];
80
+ };
6
81
  export {
7
82
  webpack_default as default
8
83
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-dingtalk",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/zcf0508/unplugin-dingtalk#readme",
@@ -84,6 +84,7 @@
84
84
  "peerDependencies": {
85
85
  "@nuxt/kit": "^3",
86
86
  "@nuxt/schema": "^3",
87
+ "@rsbuild/core": "^0.7.9",
87
88
  "@vue/devtools": "^7.2.1",
88
89
  "esbuild": "*",
89
90
  "rollup": "^3",
@@ -98,6 +99,9 @@
98
99
  "@nuxt/schema": {
99
100
  "optional": true
100
101
  },
102
+ "@rsbuild/core": {
103
+ "optional": true
104
+ },
101
105
  "@vue/devtools": {
102
106
  "optional": true
103
107
  },
@@ -1,83 +0,0 @@
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
- };
@@ -1,11 +0,0 @@
1
- import {
2
- unpluginFactory
3
- } from "./chunk-XTDXIGYG.js";
4
-
5
- // src/vite.ts
6
- import { createVitePlugin } from "unplugin";
7
- var vite_default = createVitePlugin(unpluginFactory);
8
-
9
- export {
10
- vite_default
11
- };