unplugin-dingtalk 0.3.1 → 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/vite.cjs CHANGED
@@ -6516,6 +6516,7 @@ var import_picocolors = __toESM(require("picocolors"), 1);
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 = {
@@ -6548,17 +6549,18 @@ var unpluginFactory = (options) => {
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"),
@@ -6688,6 +6690,34 @@ var unpluginFactory = (options) => {
6688
6690
  if (options == null ? void 0 : options.corpId) {
6689
6691
  resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6690
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
+ }
6691
6721
  }
6692
6722
  };
6693
6723
  return unpluginDing;
package/dist/vite.d.cts CHANGED
@@ -1,6 +1,7 @@
1
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
7
  declare const _default: (options: Options) => Plugin<any>[];
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,7 @@
1
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
7
  declare const _default: (options: Options) => Plugin<any>[];
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-Q26XYG3E.js";
4
- import "./chunk-E34H52KV.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
@@ -6517,6 +6517,7 @@ var import_picocolors = __toESM(require("picocolors"), 1);
6517
6517
  var import_cookie = __toESM(require("cookie"), 1);
6518
6518
  var import_chii = require("chii");
6519
6519
  var import_get_port_please = require("get-port-please");
6520
+ var cwd = import_node_process.default.cwd();
6520
6521
  var config;
6521
6522
  var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
6522
6523
  var resovedInfo = {
@@ -6549,17 +6550,18 @@ var unpluginFactory = (options) => {
6549
6550
  port: resovedInfo.availablePort
6550
6551
  });
6551
6552
  }
6552
- 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) {
6553
6554
  const codes = [
6554
- `/* eslint-disable */;
6555
- 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});`,
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});` : "",
6557
6558
  (options == null ? void 0 : options.enable) && enableChii ? `(() => {
6558
6559
  const script = document.createElement('script');
6559
6560
  script.src="http://localhost:${resovedInfo.availablePort}/target.js";
6560
6561
  document.body.appendChild(script);
6561
6562
  })()` : "",
6562
- `/* eslint-enable */${_source};`
6563
+ "/* eslint-enable */",
6564
+ `${_source};`
6563
6565
  ];
6564
6566
  return {
6565
6567
  code: codes.join("\n"),
@@ -6689,6 +6691,34 @@ var unpluginFactory = (options) => {
6689
6691
  if (options == null ? void 0 : options.corpId) {
6690
6692
  resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
6691
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
+ }
6692
6722
  }
6693
6723
  };
6694
6724
  return unpluginDing;
@@ -6740,7 +6770,7 @@ var webpack_default = (options) => {
6740
6770
  devServer.app.get("/open-dingtalk", (req, res) => {
6741
6771
  var _a4;
6742
6772
  const targetURL = resovedInfo.targetURL;
6743
- console.debug(targetURL.toString());
6773
+ debug(targetURL.toString());
6744
6774
  res.writeHead(302, {
6745
6775
  Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
6746
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-OVAVOVTT.js";
4
- import "./chunk-E34H52KV.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.1",
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-E34H52KV.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
- };