unplugin-dingtalk 0.1.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
1
  import * as webpack from 'webpack';
2
- import { Options } from './types.cjs';
2
+ import { Options, SetupMiddlewares } from './types.cjs';
3
+ import 'webpack-dev-server';
3
4
  import 'vite-plugin-vconsole';
4
5
 
5
- declare const _default: (options?: Options | undefined) => webpack.WebpackPluginInstance;
6
+ declare const _default: (options: Options) => readonly [SetupMiddlewares, webpack.WebpackPluginInstance];
6
7
 
7
8
  export { _default as default };
package/dist/webpack.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as webpack from 'webpack';
2
- import { Options } from './types.js';
2
+ import { Options, SetupMiddlewares } from './types.js';
3
+ import 'webpack-dev-server';
3
4
  import 'vite-plugin-vconsole';
4
5
 
5
- declare const _default: (options?: Options | undefined) => webpack.WebpackPluginInstance;
6
+ declare const _default: (options: Options) => readonly [SetupMiddlewares, webpack.WebpackPluginInstance];
6
7
 
7
8
  export { _default as default };
package/dist/webpack.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  webpack_default
3
- } from "./chunk-3GLWV5IZ.js";
4
- import "./chunk-PSBADVC6.js";
3
+ } from "./chunk-FMGOYX4F.js";
4
+ import "./chunk-XTDXIGYG.js";
5
+ import "./chunk-PMOTCIQR.js";
5
6
  export {
6
7
  webpack_default as default
7
8
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unplugin-dingtalk",
3
3
  "type": "module",
4
- "version": "0.1.9",
4
+ "version": "0.3.0",
5
5
  "description": "",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/zcf0508/unplugin-dingtalk#readme",
@@ -119,8 +119,10 @@
119
119
  },
120
120
  "dependencies": {
121
121
  "@antfu/eslint-config": "^2.18.1",
122
+ "chii": "^1.10.0",
122
123
  "cookie": "^0.6.0",
123
124
  "eslint-plugin-security": "^3.0.0",
125
+ "get-port-please": "^3.1.2",
124
126
  "picocolors": "^1.0.1",
125
127
  "unplugin": "^1.5.1",
126
128
  "vite-plugin-vconsole": "^2.1.1"
@@ -134,13 +136,15 @@
134
136
  "eslint": "^8.55.0",
135
137
  "esno": "^4.0.0",
136
138
  "fast-glob": "^3.3.2",
139
+ "node-fetch": "^3.3.2",
137
140
  "nodemon": "^3.0.2",
138
141
  "rimraf": "^5.0.5",
139
142
  "rollup": "^4.6.1",
140
143
  "tsup": "^8.0.1",
141
144
  "vite": "^5.0.4",
142
145
  "vitest": "^0.34.6",
143
- "webpack": "^5.89.0"
146
+ "webpack": "^5.89.0",
147
+ "webpack-dev-server": "^5.0.4"
144
148
  },
145
149
  "scripts": {
146
150
  "build": "tsup",
@@ -1,11 +0,0 @@
1
- import {
2
- unpluginFactory
3
- } from "./chunk-PSBADVC6.js";
4
-
5
- // src/webpack.ts
6
- import { createWebpackPlugin } from "unplugin";
7
- var webpack_default = createWebpackPlugin(unpluginFactory);
8
-
9
- export {
10
- webpack_default
11
- };
@@ -1,124 +0,0 @@
1
- // src/index.ts
2
- import { exec } from "child_process";
3
- import process from "process";
4
- import { createUnplugin } from "unplugin";
5
- import c from "picocolors";
6
- import { viteVConsole } from "vite-plugin-vconsole";
7
- import cookie from "cookie";
8
- var config;
9
- var devtoolsInstance;
10
- var colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
11
- var unpluginFactory = (options) => {
12
- var _a;
13
- const unpluginDing = {
14
- name: "unplugin-dingtalk",
15
- enforce: "pre",
16
- transformInclude(id) {
17
- return id.endsWith("main.ts") || id.endsWith("main.js");
18
- },
19
- transform(_source) {
20
- var _a2, _b, _c;
21
- if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
22
- const code = `/* eslint-disable */;
23
- import { devtools } from '@vue/devtools'
24
- 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})
25
- /* eslint-enable */${_source};
26
- `;
27
- return {
28
- code,
29
- map: null
30
- // support source map
31
- };
32
- }
33
- return {
34
- code: _source,
35
- map: null
36
- // support source map
37
- };
38
- },
39
- vite: {
40
- configResolved(_config) {
41
- config = _config;
42
- },
43
- configureServer(server) {
44
- var _a2, _b;
45
- if (!(options == null ? void 0 : options.enable)) {
46
- return;
47
- }
48
- function debug(...args) {
49
- if (options == null ? void 0 : options.debug) {
50
- console.log(` ${c.yellow("DEBUG")} `, ...args);
51
- }
52
- }
53
- const _printUrls = server.printUrls.bind(server);
54
- let source = `localhost:${config.server.port || 5173}`;
55
- const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
56
- if (url) {
57
- const u = new URL(url);
58
- source = u.host;
59
- }
60
- const base = server.config.base || "/";
61
- const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
62
- server.printUrls = () => {
63
- var _a3;
64
- _printUrls();
65
- console.log(` ${c.green("\u279C")} ${c.bold(
66
- `Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
67
- )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
68
- };
69
- const targetURL = new URL(_targetUrl);
70
- targetURL.searchParams.append("ddtab", "true");
71
- if (options == null ? void 0 : options.corpId) {
72
- targetURL.searchParams.append("corpId", options.corpId);
73
- }
74
- if (options.debugCookies && options.debugCookies.length > 0) {
75
- server.middlewares.use((req, res, next) => {
76
- const cookies = cookie.parse(req.headers.cookie || "");
77
- for (const [name, value] of Object.entries(cookies)) {
78
- if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
79
- const serializedCookie = cookie.serialize(name, value, {
80
- httpOnly: false
81
- });
82
- res.setHeader("Set-Cookie", serializedCookie);
83
- }
84
- }
85
- next();
86
- });
87
- }
88
- server.middlewares.use("/open-dingtalk", (req, res) => {
89
- var _a3;
90
- debug(targetURL.toString());
91
- res.writeHead(302, {
92
- Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
93
- });
94
- if (((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) && !devtoolsInstance) {
95
- devtoolsInstance = exec("npx vue-devtools");
96
- console.log(` ${c.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
97
- devtoolsInstance.on("exit", () => {
98
- devtoolsInstance = void 0;
99
- });
100
- process.on("exit", () => {
101
- if (devtoolsInstance) {
102
- devtoolsInstance.kill();
103
- }
104
- });
105
- }
106
- res.end();
107
- });
108
- }
109
- }
110
- };
111
- if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
112
- return [viteVConsole(options == null ? void 0 : options.vconsole), unpluginDing];
113
- } else {
114
- return unpluginDing;
115
- }
116
- };
117
- var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
118
- var src_default = unplugin;
119
-
120
- export {
121
- unpluginFactory,
122
- unplugin,
123
- src_default
124
- };