unplugin-dingtalk 0.1.8 → 0.2.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/README.md +6 -0
- package/dist/astro.cjs +73 -16
- package/dist/astro.js +1 -1
- package/dist/{chunk-YU6RRDIU.js → chunk-GRAT7SP7.js} +73 -16
- package/dist/{chunk-JVGHIAFT.js → chunk-IN7LDV4O.js} +1 -1
- package/dist/{chunk-GCW3A6BF.js → chunk-N4ZALPAK.js} +1 -1
- package/dist/esbuild.cjs +73 -16
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +73 -16
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +73 -16
- package/dist/nuxt.js +3 -3
- package/dist/rollup.cjs +73 -16
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +73 -16
- package/dist/rspack.js +1 -1
- package/dist/types.d.cts +3 -0
- package/dist/types.d.ts +3 -0
- package/dist/vite.cjs +73 -16
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +73 -16
- package/dist/webpack.js +2 -2
- package/package.json +6 -3
package/dist/nuxt.cjs
CHANGED
|
@@ -44,27 +44,52 @@ var import_node_process = __toESM(require("process"), 1);
|
|
|
44
44
|
var import_unplugin = require("unplugin");
|
|
45
45
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
46
46
|
var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
|
|
47
|
+
var import_cookie = __toESM(require("cookie"), 1);
|
|
48
|
+
var import_chii = require("chii");
|
|
49
|
+
var import_get_port_please = require("get-port-please");
|
|
47
50
|
var config;
|
|
48
51
|
var devtoolsInstance;
|
|
49
52
|
var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
53
|
+
var availablePort;
|
|
50
54
|
var unpluginFactory = (options) => {
|
|
51
55
|
var _a;
|
|
56
|
+
const {
|
|
57
|
+
chii: enableChii = true
|
|
58
|
+
} = options || {};
|
|
59
|
+
function debug(...args) {
|
|
60
|
+
if (options == null ? void 0 : options.debug) {
|
|
61
|
+
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
52
64
|
const unpluginDing = {
|
|
53
65
|
name: "unplugin-dingtalk",
|
|
54
66
|
enforce: "pre",
|
|
55
67
|
transformInclude(id) {
|
|
56
68
|
return id.endsWith("main.ts") || id.endsWith("main.js");
|
|
57
69
|
},
|
|
58
|
-
transform(_source) {
|
|
70
|
+
async transform(_source) {
|
|
59
71
|
var _a2, _b, _c;
|
|
72
|
+
if ((options == null ? void 0 : options.enable) && enableChii) {
|
|
73
|
+
availablePort = await (0, import_get_port_please.getRandomPort)();
|
|
74
|
+
debug(`chii server port: ${JSON.stringify({ availablePort })}`);
|
|
75
|
+
(0, import_chii.start)({
|
|
76
|
+
port: availablePort
|
|
77
|
+
});
|
|
78
|
+
}
|
|
60
79
|
if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
const codes = [
|
|
81
|
+
`/* eslint-disable */;
|
|
82
|
+
import { devtools } from '@vue/devtools'
|
|
83
|
+
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});`,
|
|
84
|
+
(options == null ? void 0 : options.enable) && enableChii ? `(() => {
|
|
85
|
+
const script = document.createElement('script');
|
|
86
|
+
script.src="http://localhost:${availablePort}/target.js";
|
|
87
|
+
document.body.appendChild(script);
|
|
88
|
+
})()` : "",
|
|
89
|
+
`/* eslint-enable */${_source};`
|
|
90
|
+
];
|
|
66
91
|
return {
|
|
67
|
-
code,
|
|
92
|
+
code: codes.join("\n"),
|
|
68
93
|
map: null
|
|
69
94
|
// support source map
|
|
70
95
|
};
|
|
@@ -79,16 +104,11 @@ var unpluginFactory = (options) => {
|
|
|
79
104
|
configResolved(_config) {
|
|
80
105
|
config = _config;
|
|
81
106
|
},
|
|
82
|
-
configureServer(server) {
|
|
107
|
+
async configureServer(server) {
|
|
83
108
|
var _a2, _b;
|
|
84
109
|
if (!(options == null ? void 0 : options.enable)) {
|
|
85
110
|
return;
|
|
86
111
|
}
|
|
87
|
-
function debug(...args) {
|
|
88
|
-
if (options == null ? void 0 : options.debug) {
|
|
89
|
-
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
112
|
const _printUrls = server.printUrls.bind(server);
|
|
93
113
|
let source = `localhost:${config.server.port || 5173}`;
|
|
94
114
|
const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
|
|
@@ -104,12 +124,48 @@ var unpluginFactory = (options) => {
|
|
|
104
124
|
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
|
|
105
125
|
`Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
|
|
106
126
|
)}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
|
|
127
|
+
if (enableChii) {
|
|
128
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
|
|
129
|
+
"Click to open chrome devtools"
|
|
130
|
+
)}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
|
|
131
|
+
}
|
|
107
132
|
};
|
|
108
133
|
const targetURL = new URL(_targetUrl);
|
|
109
134
|
targetURL.searchParams.append("ddtab", "true");
|
|
110
135
|
if (options == null ? void 0 : options.corpId) {
|
|
111
136
|
targetURL.searchParams.append("corpId", options.corpId);
|
|
112
137
|
}
|
|
138
|
+
if (options.debugCookies && options.debugCookies.length > 0) {
|
|
139
|
+
server.middlewares.use((req, res, next) => {
|
|
140
|
+
const cookies = import_cookie.default.parse(req.headers.cookie || "");
|
|
141
|
+
for (const [name, value] of Object.entries(cookies)) {
|
|
142
|
+
if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
143
|
+
const serializedCookie = import_cookie.default.serialize(name, value, {
|
|
144
|
+
httpOnly: false
|
|
145
|
+
});
|
|
146
|
+
res.setHeader("Set-Cookie", serializedCookie);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
next();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (enableChii) {
|
|
153
|
+
server.middlewares.use("/__chrome_devtools", async (_req, res) => {
|
|
154
|
+
try {
|
|
155
|
+
const raw = await fetch(`http://localhost:${availablePort}/targets`);
|
|
156
|
+
const data = await raw.json();
|
|
157
|
+
if ((data == null ? void 0 : data.targets.length) > 0) {
|
|
158
|
+
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`;
|
|
159
|
+
res.writeHead(302, { Location: devToolsUrl });
|
|
160
|
+
res.end();
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
debug(`${error}`);
|
|
164
|
+
res.writeHead(502);
|
|
165
|
+
res.end();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
113
169
|
server.middlewares.use("/open-dingtalk", (req, res) => {
|
|
114
170
|
var _a3;
|
|
115
171
|
debug(targetURL.toString());
|
|
@@ -133,11 +189,12 @@ var unpluginFactory = (options) => {
|
|
|
133
189
|
}
|
|
134
190
|
}
|
|
135
191
|
};
|
|
192
|
+
const plugins = [];
|
|
136
193
|
if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
|
|
137
|
-
|
|
138
|
-
} else {
|
|
139
|
-
return unpluginDing;
|
|
194
|
+
plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
|
|
140
195
|
}
|
|
196
|
+
plugins.push(unpluginDing);
|
|
197
|
+
return plugins;
|
|
141
198
|
};
|
|
142
199
|
|
|
143
200
|
// src/vite.ts
|
package/dist/nuxt.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
webpack_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IN7LDV4O.js";
|
|
4
4
|
import {
|
|
5
5
|
vite_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-N4ZALPAK.js";
|
|
7
|
+
import "./chunk-GRAT7SP7.js";
|
|
8
8
|
|
|
9
9
|
// src/nuxt.ts
|
|
10
10
|
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
|
package/dist/rollup.cjs
CHANGED
|
@@ -41,27 +41,52 @@ var import_node_process = __toESM(require("process"), 1);
|
|
|
41
41
|
var import_unplugin = require("unplugin");
|
|
42
42
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
43
43
|
var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
|
|
44
|
+
var import_cookie = __toESM(require("cookie"), 1);
|
|
45
|
+
var import_chii = require("chii");
|
|
46
|
+
var import_get_port_please = require("get-port-please");
|
|
44
47
|
var config;
|
|
45
48
|
var devtoolsInstance;
|
|
46
49
|
var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
50
|
+
var availablePort;
|
|
47
51
|
var unpluginFactory = (options) => {
|
|
48
52
|
var _a;
|
|
53
|
+
const {
|
|
54
|
+
chii: enableChii = true
|
|
55
|
+
} = options || {};
|
|
56
|
+
function debug(...args) {
|
|
57
|
+
if (options == null ? void 0 : options.debug) {
|
|
58
|
+
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
49
61
|
const unpluginDing = {
|
|
50
62
|
name: "unplugin-dingtalk",
|
|
51
63
|
enforce: "pre",
|
|
52
64
|
transformInclude(id) {
|
|
53
65
|
return id.endsWith("main.ts") || id.endsWith("main.js");
|
|
54
66
|
},
|
|
55
|
-
transform(_source) {
|
|
67
|
+
async transform(_source) {
|
|
56
68
|
var _a2, _b, _c;
|
|
69
|
+
if ((options == null ? void 0 : options.enable) && enableChii) {
|
|
70
|
+
availablePort = await (0, import_get_port_please.getRandomPort)();
|
|
71
|
+
debug(`chii server port: ${JSON.stringify({ availablePort })}`);
|
|
72
|
+
(0, import_chii.start)({
|
|
73
|
+
port: availablePort
|
|
74
|
+
});
|
|
75
|
+
}
|
|
57
76
|
if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
77
|
+
const codes = [
|
|
78
|
+
`/* eslint-disable */;
|
|
79
|
+
import { devtools } from '@vue/devtools'
|
|
80
|
+
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});`,
|
|
81
|
+
(options == null ? void 0 : options.enable) && enableChii ? `(() => {
|
|
82
|
+
const script = document.createElement('script');
|
|
83
|
+
script.src="http://localhost:${availablePort}/target.js";
|
|
84
|
+
document.body.appendChild(script);
|
|
85
|
+
})()` : "",
|
|
86
|
+
`/* eslint-enable */${_source};`
|
|
87
|
+
];
|
|
63
88
|
return {
|
|
64
|
-
code,
|
|
89
|
+
code: codes.join("\n"),
|
|
65
90
|
map: null
|
|
66
91
|
// support source map
|
|
67
92
|
};
|
|
@@ -76,16 +101,11 @@ var unpluginFactory = (options) => {
|
|
|
76
101
|
configResolved(_config) {
|
|
77
102
|
config = _config;
|
|
78
103
|
},
|
|
79
|
-
configureServer(server) {
|
|
104
|
+
async configureServer(server) {
|
|
80
105
|
var _a2, _b;
|
|
81
106
|
if (!(options == null ? void 0 : options.enable)) {
|
|
82
107
|
return;
|
|
83
108
|
}
|
|
84
|
-
function debug(...args) {
|
|
85
|
-
if (options == null ? void 0 : options.debug) {
|
|
86
|
-
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
109
|
const _printUrls = server.printUrls.bind(server);
|
|
90
110
|
let source = `localhost:${config.server.port || 5173}`;
|
|
91
111
|
const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
|
|
@@ -101,12 +121,48 @@ var unpluginFactory = (options) => {
|
|
|
101
121
|
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
|
|
102
122
|
`Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
|
|
103
123
|
)}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
|
|
124
|
+
if (enableChii) {
|
|
125
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
|
|
126
|
+
"Click to open chrome devtools"
|
|
127
|
+
)}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
|
|
128
|
+
}
|
|
104
129
|
};
|
|
105
130
|
const targetURL = new URL(_targetUrl);
|
|
106
131
|
targetURL.searchParams.append("ddtab", "true");
|
|
107
132
|
if (options == null ? void 0 : options.corpId) {
|
|
108
133
|
targetURL.searchParams.append("corpId", options.corpId);
|
|
109
134
|
}
|
|
135
|
+
if (options.debugCookies && options.debugCookies.length > 0) {
|
|
136
|
+
server.middlewares.use((req, res, next) => {
|
|
137
|
+
const cookies = import_cookie.default.parse(req.headers.cookie || "");
|
|
138
|
+
for (const [name, value] of Object.entries(cookies)) {
|
|
139
|
+
if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
140
|
+
const serializedCookie = import_cookie.default.serialize(name, value, {
|
|
141
|
+
httpOnly: false
|
|
142
|
+
});
|
|
143
|
+
res.setHeader("Set-Cookie", serializedCookie);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
next();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (enableChii) {
|
|
150
|
+
server.middlewares.use("/__chrome_devtools", async (_req, res) => {
|
|
151
|
+
try {
|
|
152
|
+
const raw = await fetch(`http://localhost:${availablePort}/targets`);
|
|
153
|
+
const data = await raw.json();
|
|
154
|
+
if ((data == null ? void 0 : data.targets.length) > 0) {
|
|
155
|
+
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`;
|
|
156
|
+
res.writeHead(302, { Location: devToolsUrl });
|
|
157
|
+
res.end();
|
|
158
|
+
}
|
|
159
|
+
} catch (error) {
|
|
160
|
+
debug(`${error}`);
|
|
161
|
+
res.writeHead(502);
|
|
162
|
+
res.end();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
110
166
|
server.middlewares.use("/open-dingtalk", (req, res) => {
|
|
111
167
|
var _a3;
|
|
112
168
|
debug(targetURL.toString());
|
|
@@ -130,11 +186,12 @@ var unpluginFactory = (options) => {
|
|
|
130
186
|
}
|
|
131
187
|
}
|
|
132
188
|
};
|
|
189
|
+
const plugins = [];
|
|
133
190
|
if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
|
|
134
|
-
|
|
135
|
-
} else {
|
|
136
|
-
return unpluginDing;
|
|
191
|
+
plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
|
|
137
192
|
}
|
|
193
|
+
plugins.push(unpluginDing);
|
|
194
|
+
return plugins;
|
|
138
195
|
};
|
|
139
196
|
|
|
140
197
|
// src/rollup.ts
|
package/dist/rollup.js
CHANGED
package/dist/rspack.cjs
CHANGED
|
@@ -41,27 +41,52 @@ var import_node_process = __toESM(require("process"), 1);
|
|
|
41
41
|
var import_unplugin = require("unplugin");
|
|
42
42
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
43
43
|
var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
|
|
44
|
+
var import_cookie = __toESM(require("cookie"), 1);
|
|
45
|
+
var import_chii = require("chii");
|
|
46
|
+
var import_get_port_please = require("get-port-please");
|
|
44
47
|
var config;
|
|
45
48
|
var devtoolsInstance;
|
|
46
49
|
var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
50
|
+
var availablePort;
|
|
47
51
|
var unpluginFactory = (options) => {
|
|
48
52
|
var _a;
|
|
53
|
+
const {
|
|
54
|
+
chii: enableChii = true
|
|
55
|
+
} = options || {};
|
|
56
|
+
function debug(...args) {
|
|
57
|
+
if (options == null ? void 0 : options.debug) {
|
|
58
|
+
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
49
61
|
const unpluginDing = {
|
|
50
62
|
name: "unplugin-dingtalk",
|
|
51
63
|
enforce: "pre",
|
|
52
64
|
transformInclude(id) {
|
|
53
65
|
return id.endsWith("main.ts") || id.endsWith("main.js");
|
|
54
66
|
},
|
|
55
|
-
transform(_source) {
|
|
67
|
+
async transform(_source) {
|
|
56
68
|
var _a2, _b, _c;
|
|
69
|
+
if ((options == null ? void 0 : options.enable) && enableChii) {
|
|
70
|
+
availablePort = await (0, import_get_port_please.getRandomPort)();
|
|
71
|
+
debug(`chii server port: ${JSON.stringify({ availablePort })}`);
|
|
72
|
+
(0, import_chii.start)({
|
|
73
|
+
port: availablePort
|
|
74
|
+
});
|
|
75
|
+
}
|
|
57
76
|
if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
77
|
+
const codes = [
|
|
78
|
+
`/* eslint-disable */;
|
|
79
|
+
import { devtools } from '@vue/devtools'
|
|
80
|
+
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});`,
|
|
81
|
+
(options == null ? void 0 : options.enable) && enableChii ? `(() => {
|
|
82
|
+
const script = document.createElement('script');
|
|
83
|
+
script.src="http://localhost:${availablePort}/target.js";
|
|
84
|
+
document.body.appendChild(script);
|
|
85
|
+
})()` : "",
|
|
86
|
+
`/* eslint-enable */${_source};`
|
|
87
|
+
];
|
|
63
88
|
return {
|
|
64
|
-
code,
|
|
89
|
+
code: codes.join("\n"),
|
|
65
90
|
map: null
|
|
66
91
|
// support source map
|
|
67
92
|
};
|
|
@@ -76,16 +101,11 @@ var unpluginFactory = (options) => {
|
|
|
76
101
|
configResolved(_config) {
|
|
77
102
|
config = _config;
|
|
78
103
|
},
|
|
79
|
-
configureServer(server) {
|
|
104
|
+
async configureServer(server) {
|
|
80
105
|
var _a2, _b;
|
|
81
106
|
if (!(options == null ? void 0 : options.enable)) {
|
|
82
107
|
return;
|
|
83
108
|
}
|
|
84
|
-
function debug(...args) {
|
|
85
|
-
if (options == null ? void 0 : options.debug) {
|
|
86
|
-
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
109
|
const _printUrls = server.printUrls.bind(server);
|
|
90
110
|
let source = `localhost:${config.server.port || 5173}`;
|
|
91
111
|
const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
|
|
@@ -101,12 +121,48 @@ var unpluginFactory = (options) => {
|
|
|
101
121
|
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
|
|
102
122
|
`Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
|
|
103
123
|
)}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
|
|
124
|
+
if (enableChii) {
|
|
125
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
|
|
126
|
+
"Click to open chrome devtools"
|
|
127
|
+
)}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
|
|
128
|
+
}
|
|
104
129
|
};
|
|
105
130
|
const targetURL = new URL(_targetUrl);
|
|
106
131
|
targetURL.searchParams.append("ddtab", "true");
|
|
107
132
|
if (options == null ? void 0 : options.corpId) {
|
|
108
133
|
targetURL.searchParams.append("corpId", options.corpId);
|
|
109
134
|
}
|
|
135
|
+
if (options.debugCookies && options.debugCookies.length > 0) {
|
|
136
|
+
server.middlewares.use((req, res, next) => {
|
|
137
|
+
const cookies = import_cookie.default.parse(req.headers.cookie || "");
|
|
138
|
+
for (const [name, value] of Object.entries(cookies)) {
|
|
139
|
+
if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
140
|
+
const serializedCookie = import_cookie.default.serialize(name, value, {
|
|
141
|
+
httpOnly: false
|
|
142
|
+
});
|
|
143
|
+
res.setHeader("Set-Cookie", serializedCookie);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
next();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (enableChii) {
|
|
150
|
+
server.middlewares.use("/__chrome_devtools", async (_req, res) => {
|
|
151
|
+
try {
|
|
152
|
+
const raw = await fetch(`http://localhost:${availablePort}/targets`);
|
|
153
|
+
const data = await raw.json();
|
|
154
|
+
if ((data == null ? void 0 : data.targets.length) > 0) {
|
|
155
|
+
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`;
|
|
156
|
+
res.writeHead(302, { Location: devToolsUrl });
|
|
157
|
+
res.end();
|
|
158
|
+
}
|
|
159
|
+
} catch (error) {
|
|
160
|
+
debug(`${error}`);
|
|
161
|
+
res.writeHead(502);
|
|
162
|
+
res.end();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
110
166
|
server.middlewares.use("/open-dingtalk", (req, res) => {
|
|
111
167
|
var _a3;
|
|
112
168
|
debug(targetURL.toString());
|
|
@@ -130,11 +186,12 @@ var unpluginFactory = (options) => {
|
|
|
130
186
|
}
|
|
131
187
|
}
|
|
132
188
|
};
|
|
189
|
+
const plugins = [];
|
|
133
190
|
if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
|
|
134
|
-
|
|
135
|
-
} else {
|
|
136
|
-
return unpluginDing;
|
|
191
|
+
plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
|
|
137
192
|
}
|
|
193
|
+
plugins.push(unpluginDing);
|
|
194
|
+
return plugins;
|
|
138
195
|
};
|
|
139
196
|
|
|
140
197
|
// src/rspack.ts
|
package/dist/rspack.js
CHANGED
package/dist/types.d.cts
CHANGED
package/dist/types.d.ts
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -41,27 +41,52 @@ var import_node_process = __toESM(require("process"), 1);
|
|
|
41
41
|
var import_unplugin = require("unplugin");
|
|
42
42
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
43
43
|
var import_vite_plugin_vconsole = require("vite-plugin-vconsole");
|
|
44
|
+
var import_cookie = __toESM(require("cookie"), 1);
|
|
45
|
+
var import_chii = require("chii");
|
|
46
|
+
var import_get_port_please = require("get-port-please");
|
|
44
47
|
var config;
|
|
45
48
|
var devtoolsInstance;
|
|
46
49
|
var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
50
|
+
var availablePort;
|
|
47
51
|
var unpluginFactory = (options) => {
|
|
48
52
|
var _a;
|
|
53
|
+
const {
|
|
54
|
+
chii: enableChii = true
|
|
55
|
+
} = options || {};
|
|
56
|
+
function debug(...args) {
|
|
57
|
+
if (options == null ? void 0 : options.debug) {
|
|
58
|
+
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
49
61
|
const unpluginDing = {
|
|
50
62
|
name: "unplugin-dingtalk",
|
|
51
63
|
enforce: "pre",
|
|
52
64
|
transformInclude(id) {
|
|
53
65
|
return id.endsWith("main.ts") || id.endsWith("main.js");
|
|
54
66
|
},
|
|
55
|
-
transform(_source) {
|
|
67
|
+
async transform(_source) {
|
|
56
68
|
var _a2, _b, _c;
|
|
69
|
+
if ((options == null ? void 0 : options.enable) && enableChii) {
|
|
70
|
+
availablePort = await (0, import_get_port_please.getRandomPort)();
|
|
71
|
+
debug(`chii server port: ${JSON.stringify({ availablePort })}`);
|
|
72
|
+
(0, import_chii.start)({
|
|
73
|
+
port: availablePort
|
|
74
|
+
});
|
|
75
|
+
}
|
|
57
76
|
if ((options == null ? void 0 : options.enable) && ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable)) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
77
|
+
const codes = [
|
|
78
|
+
`/* eslint-disable */;
|
|
79
|
+
import { devtools } from '@vue/devtools'
|
|
80
|
+
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});`,
|
|
81
|
+
(options == null ? void 0 : options.enable) && enableChii ? `(() => {
|
|
82
|
+
const script = document.createElement('script');
|
|
83
|
+
script.src="http://localhost:${availablePort}/target.js";
|
|
84
|
+
document.body.appendChild(script);
|
|
85
|
+
})()` : "",
|
|
86
|
+
`/* eslint-enable */${_source};`
|
|
87
|
+
];
|
|
63
88
|
return {
|
|
64
|
-
code,
|
|
89
|
+
code: codes.join("\n"),
|
|
65
90
|
map: null
|
|
66
91
|
// support source map
|
|
67
92
|
};
|
|
@@ -76,16 +101,11 @@ var unpluginFactory = (options) => {
|
|
|
76
101
|
configResolved(_config) {
|
|
77
102
|
config = _config;
|
|
78
103
|
},
|
|
79
|
-
configureServer(server) {
|
|
104
|
+
async configureServer(server) {
|
|
80
105
|
var _a2, _b;
|
|
81
106
|
if (!(options == null ? void 0 : options.enable)) {
|
|
82
107
|
return;
|
|
83
108
|
}
|
|
84
|
-
function debug(...args) {
|
|
85
|
-
if (options == null ? void 0 : options.debug) {
|
|
86
|
-
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
109
|
const _printUrls = server.printUrls.bind(server);
|
|
90
110
|
let source = `localhost:${config.server.port || 5173}`;
|
|
91
111
|
const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
|
|
@@ -101,12 +121,48 @@ var unpluginFactory = (options) => {
|
|
|
101
121
|
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
|
|
102
122
|
`Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
|
|
103
123
|
)}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
|
|
124
|
+
if (enableChii) {
|
|
125
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
|
|
126
|
+
"Click to open chrome devtools"
|
|
127
|
+
)}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
|
|
128
|
+
}
|
|
104
129
|
};
|
|
105
130
|
const targetURL = new URL(_targetUrl);
|
|
106
131
|
targetURL.searchParams.append("ddtab", "true");
|
|
107
132
|
if (options == null ? void 0 : options.corpId) {
|
|
108
133
|
targetURL.searchParams.append("corpId", options.corpId);
|
|
109
134
|
}
|
|
135
|
+
if (options.debugCookies && options.debugCookies.length > 0) {
|
|
136
|
+
server.middlewares.use((req, res, next) => {
|
|
137
|
+
const cookies = import_cookie.default.parse(req.headers.cookie || "");
|
|
138
|
+
for (const [name, value] of Object.entries(cookies)) {
|
|
139
|
+
if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
140
|
+
const serializedCookie = import_cookie.default.serialize(name, value, {
|
|
141
|
+
httpOnly: false
|
|
142
|
+
});
|
|
143
|
+
res.setHeader("Set-Cookie", serializedCookie);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
next();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (enableChii) {
|
|
150
|
+
server.middlewares.use("/__chrome_devtools", async (_req, res) => {
|
|
151
|
+
try {
|
|
152
|
+
const raw = await fetch(`http://localhost:${availablePort}/targets`);
|
|
153
|
+
const data = await raw.json();
|
|
154
|
+
if ((data == null ? void 0 : data.targets.length) > 0) {
|
|
155
|
+
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`;
|
|
156
|
+
res.writeHead(302, { Location: devToolsUrl });
|
|
157
|
+
res.end();
|
|
158
|
+
}
|
|
159
|
+
} catch (error) {
|
|
160
|
+
debug(`${error}`);
|
|
161
|
+
res.writeHead(502);
|
|
162
|
+
res.end();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
110
166
|
server.middlewares.use("/open-dingtalk", (req, res) => {
|
|
111
167
|
var _a3;
|
|
112
168
|
debug(targetURL.toString());
|
|
@@ -130,11 +186,12 @@ var unpluginFactory = (options) => {
|
|
|
130
186
|
}
|
|
131
187
|
}
|
|
132
188
|
};
|
|
189
|
+
const plugins = [];
|
|
133
190
|
if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
|
|
134
|
-
|
|
135
|
-
} else {
|
|
136
|
-
return unpluginDing;
|
|
191
|
+
plugins.push((0, import_vite_plugin_vconsole.viteVConsole)(options == null ? void 0 : options.vconsole));
|
|
137
192
|
}
|
|
193
|
+
plugins.push(unpluginDing);
|
|
194
|
+
return plugins;
|
|
138
195
|
};
|
|
139
196
|
|
|
140
197
|
// src/vite.ts
|