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/webpack.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/webpack.ts
|
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-dingtalk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/zcf0508/unplugin-dingtalk#readme",
|
|
@@ -119,10 +119,13 @@
|
|
|
119
119
|
},
|
|
120
120
|
"dependencies": {
|
|
121
121
|
"@antfu/eslint-config": "^2.18.1",
|
|
122
|
+
"chii": "^1.10.0",
|
|
123
|
+
"cookie": "^0.6.0",
|
|
122
124
|
"eslint-plugin-security": "^3.0.0",
|
|
125
|
+
"get-port-please": "^3.1.2",
|
|
126
|
+
"picocolors": "^1.0.1",
|
|
123
127
|
"unplugin": "^1.5.1",
|
|
124
|
-
"vite-plugin-vconsole": "^2.1.1"
|
|
125
|
-
"picocolors": "^1.0.1"
|
|
128
|
+
"vite-plugin-vconsole": "^2.1.1"
|
|
126
129
|
},
|
|
127
130
|
"devDependencies": {
|
|
128
131
|
"@nuxt/kit": "^3.8.2",
|