unplugin-dingtalk 0.4.2 → 0.5.2
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/astro.cjs +157 -26
- package/dist/astro.js +4 -4
- package/dist/{chunk-RDTWBIQD.js → chunk-QU7HLXVD.js} +172 -42
- package/dist/{chunk-2OB7UBRW.js → chunk-VQXY6FXR.js} +1 -1
- package/dist/{chunk-PMOTCIQR.js → chunk-ZEHXGFFH.js} +3 -3
- package/dist/esbuild.cjs +155 -24
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +164 -29
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +8 -4
- package/dist/{multipart-parser-HI4LNJC5.js → multipart-parser-VO5TIRQZ.js} +4 -1
- package/dist/nuxt.cjs +155 -24
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +3 -3
- package/dist/rollup.cjs +155 -24
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +167 -45
- package/dist/rspack.d.cts +1 -2
- package/dist/rspack.d.ts +1 -2
- package/dist/rspack.js +10 -18
- package/dist/types.d.cts +13 -2
- package/dist/types.d.ts +13 -2
- package/dist/vite.cjs +155 -24
- package/dist/vite.js +3 -3
- package/dist/webpack.cjs +167 -45
- package/dist/webpack.js +10 -18
- package/package.json +8 -5
package/dist/rollup.cjs
CHANGED
|
@@ -5069,6 +5069,7 @@ var init_multipart_parser = __esm({
|
|
|
5069
5069
|
state = S.HEADER_FIELD;
|
|
5070
5070
|
mark("onHeaderField");
|
|
5071
5071
|
index = 0;
|
|
5072
|
+
// falls through
|
|
5072
5073
|
case S.HEADER_FIELD:
|
|
5073
5074
|
if (c2 === CR) {
|
|
5074
5075
|
clear("onHeaderField");
|
|
@@ -5098,6 +5099,7 @@ var init_multipart_parser = __esm({
|
|
|
5098
5099
|
}
|
|
5099
5100
|
mark("onHeaderValue");
|
|
5100
5101
|
state = S.HEADER_VALUE;
|
|
5102
|
+
// falls through
|
|
5101
5103
|
case S.HEADER_VALUE:
|
|
5102
5104
|
if (c2 === CR) {
|
|
5103
5105
|
dataCallback("onHeaderValue", true);
|
|
@@ -5121,6 +5123,7 @@ var init_multipart_parser = __esm({
|
|
|
5121
5123
|
case S.PART_DATA_START:
|
|
5122
5124
|
state = S.PART_DATA;
|
|
5123
5125
|
mark("onPartData");
|
|
5126
|
+
// falls through
|
|
5124
5127
|
case S.PART_DATA:
|
|
5125
5128
|
previousIndex = index;
|
|
5126
5129
|
if (index === 0) {
|
|
@@ -5216,6 +5219,8 @@ var import_unplugin2 = require("unplugin");
|
|
|
5216
5219
|
// src/index.ts
|
|
5217
5220
|
var import_node_child_process = require("child_process");
|
|
5218
5221
|
var import_node_process = __toESM(require("process"), 1);
|
|
5222
|
+
var import_node_http3 = require("http");
|
|
5223
|
+
var import_node_net2 = require("net");
|
|
5219
5224
|
|
|
5220
5225
|
// node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/index.js
|
|
5221
5226
|
var import_node_http2 = __toESM(require("http"), 1);
|
|
@@ -6513,20 +6518,94 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
|
|
6513
6518
|
var import_unplugin = require("unplugin");
|
|
6514
6519
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
6515
6520
|
var import_cookie = __toESM(require("cookie"), 1);
|
|
6516
|
-
var
|
|
6521
|
+
var import_z_chii = require("z-chii");
|
|
6522
|
+
var import_dns2 = __toESM(require("dns2"), 1);
|
|
6517
6523
|
var import_get_port_please = require("get-port-please");
|
|
6524
|
+
var import_http_proxy = __toESM(require("http-proxy"), 1);
|
|
6518
6525
|
var cwd = import_node_process.default.cwd();
|
|
6519
6526
|
var config;
|
|
6520
6527
|
var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
6521
6528
|
var resovedInfo = {
|
|
6522
6529
|
devtoolsInstance: void 0,
|
|
6530
|
+
dnsServerInstence: void 0,
|
|
6523
6531
|
availablePort: void 0,
|
|
6524
6532
|
targetURL: void 0
|
|
6525
6533
|
};
|
|
6534
|
+
function startVueDevtools(enable) {
|
|
6535
|
+
if (enable && !resovedInfo.devtoolsInstance) {
|
|
6536
|
+
resovedInfo.devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
|
|
6537
|
+
console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
|
|
6538
|
+
resovedInfo.devtoolsInstance.on("exit", () => {
|
|
6539
|
+
resovedInfo.devtoolsInstance = void 0;
|
|
6540
|
+
});
|
|
6541
|
+
import_node_process.default.on("exit", () => {
|
|
6542
|
+
if (resovedInfo.devtoolsInstance) {
|
|
6543
|
+
resovedInfo.devtoolsInstance.kill();
|
|
6544
|
+
}
|
|
6545
|
+
});
|
|
6546
|
+
}
|
|
6547
|
+
}
|
|
6548
|
+
function startDnsServer(options) {
|
|
6549
|
+
function debug(...args) {
|
|
6550
|
+
if (options == null ? void 0 : options.debug) {
|
|
6551
|
+
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
6552
|
+
}
|
|
6553
|
+
}
|
|
6554
|
+
if ((options == null ? void 0 : options.enable) && (options == null ? void 0 : options.dns) && !resovedInfo.dnsServerInstence) {
|
|
6555
|
+
const { Packet } = import_dns2.default;
|
|
6556
|
+
resovedInfo.dnsServerInstence = import_dns2.default.createServer({
|
|
6557
|
+
tcp: true,
|
|
6558
|
+
udp: true,
|
|
6559
|
+
handle: (request, send, rinfo) => {
|
|
6560
|
+
var _a4;
|
|
6561
|
+
const response = Packet.createResponseFromRequest(request);
|
|
6562
|
+
const [question] = request.questions;
|
|
6563
|
+
const { name } = question;
|
|
6564
|
+
if (name === options.dns.host) {
|
|
6565
|
+
response.answers.push({
|
|
6566
|
+
name,
|
|
6567
|
+
type: Packet.TYPE.A,
|
|
6568
|
+
class: Packet.CLASS.IN,
|
|
6569
|
+
ttl: 300,
|
|
6570
|
+
address: (_a4 = options.dns) == null ? void 0 : _a4.ip
|
|
6571
|
+
});
|
|
6572
|
+
debug(`dns request from ${rinfo.address}:${rinfo.port} for ${name} => ${options.dns.ip}`);
|
|
6573
|
+
}
|
|
6574
|
+
send(response);
|
|
6575
|
+
}
|
|
6576
|
+
});
|
|
6577
|
+
resovedInfo.dnsServerInstence.listen({
|
|
6578
|
+
udp: { address: "0.0.0.0", port: 53 },
|
|
6579
|
+
tcp: { address: "0.0.0.0", port: 53 }
|
|
6580
|
+
}).then(() => {
|
|
6581
|
+
debug("DNS server is running.");
|
|
6582
|
+
const dns = new import_dns2.default({
|
|
6583
|
+
port: 53,
|
|
6584
|
+
nameServers: ["127.0.0.1", "8.8.8.8"]
|
|
6585
|
+
});
|
|
6586
|
+
dns.resolveA(options.dns.host).then((addresses) => {
|
|
6587
|
+
var _a4;
|
|
6588
|
+
if (((_a4 = addresses.answers[0]) == null ? void 0 : _a4.address) === options.dns.ip) {
|
|
6589
|
+
startDnsServer(options);
|
|
6590
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(`DNS server is started, please modify the DNS of the remote device to ${options.dns.ip}`)}`);
|
|
6591
|
+
} else {
|
|
6592
|
+
debug(addresses.answers[0].address);
|
|
6593
|
+
throw new Error("DNS server started failed");
|
|
6594
|
+
}
|
|
6595
|
+
}).catch((e2) => {
|
|
6596
|
+
throw e2;
|
|
6597
|
+
});
|
|
6598
|
+
}).catch((e2) => {
|
|
6599
|
+
debug(e2);
|
|
6600
|
+
console.log(` ${import_picocolors.default.red("\u279C")} ${import_picocolors.default.bold((e2 == null ? void 0 : e2.message) || e2)}`);
|
|
6601
|
+
});
|
|
6602
|
+
}
|
|
6603
|
+
}
|
|
6526
6604
|
var unpluginFactory = (options) => {
|
|
6527
6605
|
const {
|
|
6528
|
-
chii
|
|
6606
|
+
chii
|
|
6529
6607
|
} = options || {};
|
|
6608
|
+
const enableChii = (chii == null ? void 0 : chii.enable) !== false;
|
|
6530
6609
|
function debug(...args) {
|
|
6531
6610
|
if (options == null ? void 0 : options.debug) {
|
|
6532
6611
|
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
@@ -6542,22 +6621,16 @@ var unpluginFactory = (options) => {
|
|
|
6542
6621
|
var _a4, _b, _c;
|
|
6543
6622
|
if ((options == null ? void 0 : options.enable) && enableChii && !resovedInfo.availablePort) {
|
|
6544
6623
|
resovedInfo.availablePort = await (0, import_get_port_please.getRandomPort)();
|
|
6545
|
-
|
|
6546
|
-
(0, import_chii.start)({
|
|
6547
|
-
host: "0.0.0.0",
|
|
6624
|
+
(0, import_z_chii.start)({
|
|
6548
6625
|
port: resovedInfo.availablePort
|
|
6549
6626
|
});
|
|
6627
|
+
debug(`chii server port: ${resovedInfo.availablePort}`);
|
|
6550
6628
|
}
|
|
6551
6629
|
if (options == null ? void 0 : options.enable) {
|
|
6552
6630
|
const codes = [
|
|
6553
6631
|
"/* eslint-disable */;",
|
|
6554
6632
|
((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable) ? `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});` : "",
|
|
6556
|
-
(options == null ? void 0 : options.enable) && enableChii ? `(() => {
|
|
6557
|
-
const script = document.createElement('script');
|
|
6558
|
-
script.src="http://localhost:${resovedInfo.availablePort}/target.js";
|
|
6559
|
-
document.body.appendChild(script);
|
|
6560
|
-
})()` : "",
|
|
6633
|
+
devtools.connect(${((_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host) ? `"${options.vueDevtools.host}"` : void 0}, ${((_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port) ? `${options.vueDevtools.port}` : void 0});` : "",
|
|
6561
6634
|
"/* eslint-enable */",
|
|
6562
6635
|
`${_source};`
|
|
6563
6636
|
];
|
|
@@ -6577,6 +6650,22 @@ var unpluginFactory = (options) => {
|
|
|
6577
6650
|
configResolved(_config) {
|
|
6578
6651
|
config = _config;
|
|
6579
6652
|
},
|
|
6653
|
+
transformIndexHtml(html) {
|
|
6654
|
+
if (enableChii) {
|
|
6655
|
+
return html.replace(
|
|
6656
|
+
"</body>",
|
|
6657
|
+
`</body>
|
|
6658
|
+
<script>
|
|
6659
|
+
(() => {
|
|
6660
|
+
const script = document.createElement('script');
|
|
6661
|
+
script.src="./__chii_proxy/target.js";
|
|
6662
|
+
document.body.appendChild(script);
|
|
6663
|
+
})()
|
|
6664
|
+
</script>
|
|
6665
|
+
`
|
|
6666
|
+
);
|
|
6667
|
+
}
|
|
6668
|
+
},
|
|
6580
6669
|
async configureServer(server) {
|
|
6581
6670
|
var _a4, _b;
|
|
6582
6671
|
if (!(options == null ? void 0 : options.enable)) {
|
|
@@ -6612,7 +6701,7 @@ var unpluginFactory = (options) => {
|
|
|
6612
6701
|
server.middlewares.use((req, res, next) => {
|
|
6613
6702
|
const cookies = import_cookie.default.parse(req.headers.cookie || "");
|
|
6614
6703
|
for (const [name, value] of Object.entries(cookies)) {
|
|
6615
|
-
if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
6704
|
+
if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
6616
6705
|
const serializedCookie = import_cookie.default.serialize(name, value, {
|
|
6617
6706
|
httpOnly: false
|
|
6618
6707
|
});
|
|
@@ -6623,6 +6712,51 @@ var unpluginFactory = (options) => {
|
|
|
6623
6712
|
});
|
|
6624
6713
|
}
|
|
6625
6714
|
if (enableChii) {
|
|
6715
|
+
let createProxyMiddleware2 = function() {
|
|
6716
|
+
let proxy = null;
|
|
6717
|
+
const handleUpgrade = (req, socket, head) => {
|
|
6718
|
+
var _a5;
|
|
6719
|
+
if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
|
|
6720
|
+
debug("WS upgrade:", req.url);
|
|
6721
|
+
req.url = req.url.replace("/__chii_proxy", "");
|
|
6722
|
+
proxy.ws(req, socket, head);
|
|
6723
|
+
}
|
|
6724
|
+
};
|
|
6725
|
+
return (resolvedInfo) => {
|
|
6726
|
+
return (req, res, next) => {
|
|
6727
|
+
var _a5;
|
|
6728
|
+
if (!proxy && resolvedInfo.availablePort) {
|
|
6729
|
+
proxy = import_http_proxy.default.createProxyServer({
|
|
6730
|
+
target: `http://localhost:${resolvedInfo.availablePort}`,
|
|
6731
|
+
ws: true
|
|
6732
|
+
// changeOrigin: true, // Consider if you need this
|
|
6733
|
+
});
|
|
6734
|
+
proxy.on("error", (err, req2, res2) => {
|
|
6735
|
+
console.error("Proxy error:", err);
|
|
6736
|
+
if (res2 instanceof import_node_http3.ServerResponse) {
|
|
6737
|
+
if (!res2.headersSent) {
|
|
6738
|
+
res2.writeHead(500, { "Content-Type": "text/plain" });
|
|
6739
|
+
}
|
|
6740
|
+
res2.end(`Proxy error: ${err.message}`);
|
|
6741
|
+
} else if (res2 instanceof import_node_net2.Socket) {
|
|
6742
|
+
res2.destroy();
|
|
6743
|
+
}
|
|
6744
|
+
});
|
|
6745
|
+
if (req.socket.server) {
|
|
6746
|
+
req.socket.server.on("upgrade", handleUpgrade);
|
|
6747
|
+
}
|
|
6748
|
+
}
|
|
6749
|
+
if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
|
|
6750
|
+
debug(req.url);
|
|
6751
|
+
req.url = req.url.replace("/__chii_proxy", "");
|
|
6752
|
+
proxy.web(req, res);
|
|
6753
|
+
} else {
|
|
6754
|
+
next();
|
|
6755
|
+
}
|
|
6756
|
+
};
|
|
6757
|
+
};
|
|
6758
|
+
};
|
|
6759
|
+
var createProxyMiddleware = createProxyMiddleware2;
|
|
6626
6760
|
server.middlewares.use("/__chrome_devtools", async (_req, res) => {
|
|
6627
6761
|
try {
|
|
6628
6762
|
const raw = await fetch(`http://localhost:${resovedInfo.availablePort}/targets`);
|
|
@@ -6631,6 +6765,9 @@ var unpluginFactory = (options) => {
|
|
|
6631
6765
|
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`;
|
|
6632
6766
|
res.writeHead(302, { Location: devToolsUrl });
|
|
6633
6767
|
res.end();
|
|
6768
|
+
} else {
|
|
6769
|
+
res.writeHead(404);
|
|
6770
|
+
res.end();
|
|
6634
6771
|
}
|
|
6635
6772
|
} catch (error) {
|
|
6636
6773
|
debug(`${error}`);
|
|
@@ -6638,6 +6775,8 @@ var unpluginFactory = (options) => {
|
|
|
6638
6775
|
res.end();
|
|
6639
6776
|
}
|
|
6640
6777
|
});
|
|
6778
|
+
const proxyMiddleware = createProxyMiddleware2();
|
|
6779
|
+
server.middlewares.use(proxyMiddleware(resovedInfo));
|
|
6641
6780
|
}
|
|
6642
6781
|
server.middlewares.use("/open-dingtalk", (req, res) => {
|
|
6643
6782
|
var _a5;
|
|
@@ -6645,20 +6784,10 @@ var unpluginFactory = (options) => {
|
|
|
6645
6784
|
res.writeHead(302, {
|
|
6646
6785
|
Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
|
|
6647
6786
|
});
|
|
6648
|
-
|
|
6649
|
-
resovedInfo.devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
|
|
6650
|
-
console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
|
|
6651
|
-
resovedInfo.devtoolsInstance.on("exit", () => {
|
|
6652
|
-
resovedInfo.devtoolsInstance = void 0;
|
|
6653
|
-
});
|
|
6654
|
-
import_node_process.default.on("exit", () => {
|
|
6655
|
-
if (resovedInfo.devtoolsInstance) {
|
|
6656
|
-
resovedInfo.devtoolsInstance.kill();
|
|
6657
|
-
}
|
|
6658
|
-
});
|
|
6659
|
-
}
|
|
6787
|
+
startVueDevtools((_a5 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a5.enable);
|
|
6660
6788
|
res.end();
|
|
6661
6789
|
});
|
|
6790
|
+
startDnsServer(options);
|
|
6662
6791
|
}
|
|
6663
6792
|
},
|
|
6664
6793
|
webpack(compiler) {
|
|
@@ -6689,6 +6818,7 @@ var unpluginFactory = (options) => {
|
|
|
6689
6818
|
if (options == null ? void 0 : options.corpId) {
|
|
6690
6819
|
resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
|
|
6691
6820
|
}
|
|
6821
|
+
startDnsServer(options);
|
|
6692
6822
|
},
|
|
6693
6823
|
async rspack(compiler) {
|
|
6694
6824
|
var _a4, _b, _c, _d2, _e;
|
|
@@ -6717,6 +6847,7 @@ var unpluginFactory = (options) => {
|
|
|
6717
6847
|
"Click to open chrome devtools"
|
|
6718
6848
|
)}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
|
|
6719
6849
|
}
|
|
6850
|
+
startDnsServer(options);
|
|
6720
6851
|
}
|
|
6721
6852
|
};
|
|
6722
6853
|
return unpluginDing;
|
package/dist/rollup.js
CHANGED
package/dist/rspack.cjs
CHANGED
|
@@ -4389,15 +4389,15 @@ var require_streams = __commonJS({
|
|
|
4389
4389
|
var POOL_SIZE2 = 65536;
|
|
4390
4390
|
if (!globalThis.ReadableStream) {
|
|
4391
4391
|
try {
|
|
4392
|
-
const
|
|
4393
|
-
const { emitWarning } =
|
|
4392
|
+
const process3 = require("process");
|
|
4393
|
+
const { emitWarning } = process3;
|
|
4394
4394
|
try {
|
|
4395
|
-
|
|
4395
|
+
process3.emitWarning = () => {
|
|
4396
4396
|
};
|
|
4397
4397
|
Object.assign(globalThis, require("stream/web"));
|
|
4398
|
-
|
|
4398
|
+
process3.emitWarning = emitWarning;
|
|
4399
4399
|
} catch (error) {
|
|
4400
|
-
|
|
4400
|
+
process3.emitWarning = emitWarning;
|
|
4401
4401
|
throw error;
|
|
4402
4402
|
}
|
|
4403
4403
|
} catch (error) {
|
|
@@ -5069,6 +5069,7 @@ var init_multipart_parser = __esm({
|
|
|
5069
5069
|
state = S.HEADER_FIELD;
|
|
5070
5070
|
mark("onHeaderField");
|
|
5071
5071
|
index = 0;
|
|
5072
|
+
// falls through
|
|
5072
5073
|
case S.HEADER_FIELD:
|
|
5073
5074
|
if (c3 === CR) {
|
|
5074
5075
|
clear("onHeaderField");
|
|
@@ -5098,6 +5099,7 @@ var init_multipart_parser = __esm({
|
|
|
5098
5099
|
}
|
|
5099
5100
|
mark("onHeaderValue");
|
|
5100
5101
|
state = S.HEADER_VALUE;
|
|
5102
|
+
// falls through
|
|
5101
5103
|
case S.HEADER_VALUE:
|
|
5102
5104
|
if (c3 === CR) {
|
|
5103
5105
|
dataCallback("onHeaderValue", true);
|
|
@@ -5121,6 +5123,7 @@ var init_multipart_parser = __esm({
|
|
|
5121
5123
|
case S.PART_DATA_START:
|
|
5122
5124
|
state = S.PART_DATA;
|
|
5123
5125
|
mark("onPartData");
|
|
5126
|
+
// falls through
|
|
5124
5127
|
case S.PART_DATA:
|
|
5125
5128
|
previousIndex = index;
|
|
5126
5129
|
if (index === 0) {
|
|
@@ -5211,8 +5214,6 @@ __export(rspack_exports, {
|
|
|
5211
5214
|
default: () => rspack_default
|
|
5212
5215
|
});
|
|
5213
5216
|
module.exports = __toCommonJS(rspack_exports);
|
|
5214
|
-
var import_node_child_process2 = require("child_process");
|
|
5215
|
-
var import_node_process2 = __toESM(require("process"), 1);
|
|
5216
5217
|
var import_unplugin2 = require("unplugin");
|
|
5217
5218
|
var import_cookie2 = __toESM(require("cookie"), 1);
|
|
5218
5219
|
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
@@ -6512,23 +6513,99 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
|
|
6512
6513
|
// src/index.ts
|
|
6513
6514
|
var import_node_child_process = require("child_process");
|
|
6514
6515
|
var import_node_process = __toESM(require("process"), 1);
|
|
6516
|
+
var import_node_http3 = require("http");
|
|
6517
|
+
var import_node_net2 = require("net");
|
|
6515
6518
|
var import_unplugin = require("unplugin");
|
|
6516
6519
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
6517
6520
|
var import_cookie = __toESM(require("cookie"), 1);
|
|
6518
|
-
var
|
|
6521
|
+
var import_z_chii = require("z-chii");
|
|
6522
|
+
var import_dns2 = __toESM(require("dns2"), 1);
|
|
6519
6523
|
var import_get_port_please = require("get-port-please");
|
|
6524
|
+
var import_http_proxy = __toESM(require("http-proxy"), 1);
|
|
6520
6525
|
var cwd = import_node_process.default.cwd();
|
|
6521
6526
|
var config;
|
|
6522
6527
|
var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
6523
6528
|
var resovedInfo = {
|
|
6524
6529
|
devtoolsInstance: void 0,
|
|
6530
|
+
dnsServerInstence: void 0,
|
|
6525
6531
|
availablePort: void 0,
|
|
6526
6532
|
targetURL: void 0
|
|
6527
6533
|
};
|
|
6534
|
+
function startVueDevtools(enable) {
|
|
6535
|
+
if (enable && !resovedInfo.devtoolsInstance) {
|
|
6536
|
+
resovedInfo.devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
|
|
6537
|
+
console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
|
|
6538
|
+
resovedInfo.devtoolsInstance.on("exit", () => {
|
|
6539
|
+
resovedInfo.devtoolsInstance = void 0;
|
|
6540
|
+
});
|
|
6541
|
+
import_node_process.default.on("exit", () => {
|
|
6542
|
+
if (resovedInfo.devtoolsInstance) {
|
|
6543
|
+
resovedInfo.devtoolsInstance.kill();
|
|
6544
|
+
}
|
|
6545
|
+
});
|
|
6546
|
+
}
|
|
6547
|
+
}
|
|
6548
|
+
function startDnsServer(options) {
|
|
6549
|
+
function debug(...args) {
|
|
6550
|
+
if (options == null ? void 0 : options.debug) {
|
|
6551
|
+
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
6552
|
+
}
|
|
6553
|
+
}
|
|
6554
|
+
if ((options == null ? void 0 : options.enable) && (options == null ? void 0 : options.dns) && !resovedInfo.dnsServerInstence) {
|
|
6555
|
+
const { Packet } = import_dns2.default;
|
|
6556
|
+
resovedInfo.dnsServerInstence = import_dns2.default.createServer({
|
|
6557
|
+
tcp: true,
|
|
6558
|
+
udp: true,
|
|
6559
|
+
handle: (request, send, rinfo) => {
|
|
6560
|
+
var _a4;
|
|
6561
|
+
const response = Packet.createResponseFromRequest(request);
|
|
6562
|
+
const [question] = request.questions;
|
|
6563
|
+
const { name } = question;
|
|
6564
|
+
if (name === options.dns.host) {
|
|
6565
|
+
response.answers.push({
|
|
6566
|
+
name,
|
|
6567
|
+
type: Packet.TYPE.A,
|
|
6568
|
+
class: Packet.CLASS.IN,
|
|
6569
|
+
ttl: 300,
|
|
6570
|
+
address: (_a4 = options.dns) == null ? void 0 : _a4.ip
|
|
6571
|
+
});
|
|
6572
|
+
debug(`dns request from ${rinfo.address}:${rinfo.port} for ${name} => ${options.dns.ip}`);
|
|
6573
|
+
}
|
|
6574
|
+
send(response);
|
|
6575
|
+
}
|
|
6576
|
+
});
|
|
6577
|
+
resovedInfo.dnsServerInstence.listen({
|
|
6578
|
+
udp: { address: "0.0.0.0", port: 53 },
|
|
6579
|
+
tcp: { address: "0.0.0.0", port: 53 }
|
|
6580
|
+
}).then(() => {
|
|
6581
|
+
debug("DNS server is running.");
|
|
6582
|
+
const dns = new import_dns2.default({
|
|
6583
|
+
port: 53,
|
|
6584
|
+
nameServers: ["127.0.0.1", "8.8.8.8"]
|
|
6585
|
+
});
|
|
6586
|
+
dns.resolveA(options.dns.host).then((addresses) => {
|
|
6587
|
+
var _a4;
|
|
6588
|
+
if (((_a4 = addresses.answers[0]) == null ? void 0 : _a4.address) === options.dns.ip) {
|
|
6589
|
+
startDnsServer(options);
|
|
6590
|
+
console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(`DNS server is started, please modify the DNS of the remote device to ${options.dns.ip}`)}`);
|
|
6591
|
+
} else {
|
|
6592
|
+
debug(addresses.answers[0].address);
|
|
6593
|
+
throw new Error("DNS server started failed");
|
|
6594
|
+
}
|
|
6595
|
+
}).catch((e2) => {
|
|
6596
|
+
throw e2;
|
|
6597
|
+
});
|
|
6598
|
+
}).catch((e2) => {
|
|
6599
|
+
debug(e2);
|
|
6600
|
+
console.log(` ${import_picocolors.default.red("\u279C")} ${import_picocolors.default.bold((e2 == null ? void 0 : e2.message) || e2)}`);
|
|
6601
|
+
});
|
|
6602
|
+
}
|
|
6603
|
+
}
|
|
6528
6604
|
var unpluginFactory = (options) => {
|
|
6529
6605
|
const {
|
|
6530
|
-
chii
|
|
6606
|
+
chii
|
|
6531
6607
|
} = options || {};
|
|
6608
|
+
const enableChii = (chii == null ? void 0 : chii.enable) !== false;
|
|
6532
6609
|
function debug(...args) {
|
|
6533
6610
|
if (options == null ? void 0 : options.debug) {
|
|
6534
6611
|
console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
|
|
@@ -6544,22 +6621,16 @@ var unpluginFactory = (options) => {
|
|
|
6544
6621
|
var _a4, _b, _c;
|
|
6545
6622
|
if ((options == null ? void 0 : options.enable) && enableChii && !resovedInfo.availablePort) {
|
|
6546
6623
|
resovedInfo.availablePort = await (0, import_get_port_please.getRandomPort)();
|
|
6547
|
-
|
|
6548
|
-
(0, import_chii.start)({
|
|
6549
|
-
host: "0.0.0.0",
|
|
6624
|
+
(0, import_z_chii.start)({
|
|
6550
6625
|
port: resovedInfo.availablePort
|
|
6551
6626
|
});
|
|
6627
|
+
debug(`chii server port: ${resovedInfo.availablePort}`);
|
|
6552
6628
|
}
|
|
6553
6629
|
if (options == null ? void 0 : options.enable) {
|
|
6554
6630
|
const codes = [
|
|
6555
6631
|
"/* eslint-disable */;",
|
|
6556
6632
|
((_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
|
-
(options == null ? void 0 : options.enable) && enableChii ? `(() => {
|
|
6559
|
-
const script = document.createElement('script');
|
|
6560
|
-
script.src="http://localhost:${resovedInfo.availablePort}/target.js";
|
|
6561
|
-
document.body.appendChild(script);
|
|
6562
|
-
})()` : "",
|
|
6633
|
+
devtools.connect(${((_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host) ? `"${options.vueDevtools.host}"` : void 0}, ${((_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port) ? `${options.vueDevtools.port}` : void 0});` : "",
|
|
6563
6634
|
"/* eslint-enable */",
|
|
6564
6635
|
`${_source};`
|
|
6565
6636
|
];
|
|
@@ -6579,6 +6650,22 @@ var unpluginFactory = (options) => {
|
|
|
6579
6650
|
configResolved(_config) {
|
|
6580
6651
|
config = _config;
|
|
6581
6652
|
},
|
|
6653
|
+
transformIndexHtml(html) {
|
|
6654
|
+
if (enableChii) {
|
|
6655
|
+
return html.replace(
|
|
6656
|
+
"</body>",
|
|
6657
|
+
`</body>
|
|
6658
|
+
<script>
|
|
6659
|
+
(() => {
|
|
6660
|
+
const script = document.createElement('script');
|
|
6661
|
+
script.src="./__chii_proxy/target.js";
|
|
6662
|
+
document.body.appendChild(script);
|
|
6663
|
+
})()
|
|
6664
|
+
</script>
|
|
6665
|
+
`
|
|
6666
|
+
);
|
|
6667
|
+
}
|
|
6668
|
+
},
|
|
6582
6669
|
async configureServer(server) {
|
|
6583
6670
|
var _a4, _b;
|
|
6584
6671
|
if (!(options == null ? void 0 : options.enable)) {
|
|
@@ -6614,7 +6701,7 @@ var unpluginFactory = (options) => {
|
|
|
6614
6701
|
server.middlewares.use((req, res, next) => {
|
|
6615
6702
|
const cookies = import_cookie.default.parse(req.headers.cookie || "");
|
|
6616
6703
|
for (const [name, value] of Object.entries(cookies)) {
|
|
6617
|
-
if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
6704
|
+
if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
6618
6705
|
const serializedCookie = import_cookie.default.serialize(name, value, {
|
|
6619
6706
|
httpOnly: false
|
|
6620
6707
|
});
|
|
@@ -6625,6 +6712,51 @@ var unpluginFactory = (options) => {
|
|
|
6625
6712
|
});
|
|
6626
6713
|
}
|
|
6627
6714
|
if (enableChii) {
|
|
6715
|
+
let createProxyMiddleware2 = function() {
|
|
6716
|
+
let proxy = null;
|
|
6717
|
+
const handleUpgrade = (req, socket, head) => {
|
|
6718
|
+
var _a5;
|
|
6719
|
+
if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
|
|
6720
|
+
debug("WS upgrade:", req.url);
|
|
6721
|
+
req.url = req.url.replace("/__chii_proxy", "");
|
|
6722
|
+
proxy.ws(req, socket, head);
|
|
6723
|
+
}
|
|
6724
|
+
};
|
|
6725
|
+
return (resolvedInfo) => {
|
|
6726
|
+
return (req, res, next) => {
|
|
6727
|
+
var _a5;
|
|
6728
|
+
if (!proxy && resolvedInfo.availablePort) {
|
|
6729
|
+
proxy = import_http_proxy.default.createProxyServer({
|
|
6730
|
+
target: `http://localhost:${resolvedInfo.availablePort}`,
|
|
6731
|
+
ws: true
|
|
6732
|
+
// changeOrigin: true, // Consider if you need this
|
|
6733
|
+
});
|
|
6734
|
+
proxy.on("error", (err, req2, res2) => {
|
|
6735
|
+
console.error("Proxy error:", err);
|
|
6736
|
+
if (res2 instanceof import_node_http3.ServerResponse) {
|
|
6737
|
+
if (!res2.headersSent) {
|
|
6738
|
+
res2.writeHead(500, { "Content-Type": "text/plain" });
|
|
6739
|
+
}
|
|
6740
|
+
res2.end(`Proxy error: ${err.message}`);
|
|
6741
|
+
} else if (res2 instanceof import_node_net2.Socket) {
|
|
6742
|
+
res2.destroy();
|
|
6743
|
+
}
|
|
6744
|
+
});
|
|
6745
|
+
if (req.socket.server) {
|
|
6746
|
+
req.socket.server.on("upgrade", handleUpgrade);
|
|
6747
|
+
}
|
|
6748
|
+
}
|
|
6749
|
+
if (proxy && ((_a5 = req.url) == null ? void 0 : _a5.startsWith("/__chii_proxy"))) {
|
|
6750
|
+
debug(req.url);
|
|
6751
|
+
req.url = req.url.replace("/__chii_proxy", "");
|
|
6752
|
+
proxy.web(req, res);
|
|
6753
|
+
} else {
|
|
6754
|
+
next();
|
|
6755
|
+
}
|
|
6756
|
+
};
|
|
6757
|
+
};
|
|
6758
|
+
};
|
|
6759
|
+
var createProxyMiddleware = createProxyMiddleware2;
|
|
6628
6760
|
server.middlewares.use("/__chrome_devtools", async (_req, res) => {
|
|
6629
6761
|
try {
|
|
6630
6762
|
const raw = await fetch(`http://localhost:${resovedInfo.availablePort}/targets`);
|
|
@@ -6633,6 +6765,9 @@ var unpluginFactory = (options) => {
|
|
|
6633
6765
|
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`;
|
|
6634
6766
|
res.writeHead(302, { Location: devToolsUrl });
|
|
6635
6767
|
res.end();
|
|
6768
|
+
} else {
|
|
6769
|
+
res.writeHead(404);
|
|
6770
|
+
res.end();
|
|
6636
6771
|
}
|
|
6637
6772
|
} catch (error) {
|
|
6638
6773
|
debug(`${error}`);
|
|
@@ -6640,6 +6775,8 @@ var unpluginFactory = (options) => {
|
|
|
6640
6775
|
res.end();
|
|
6641
6776
|
}
|
|
6642
6777
|
});
|
|
6778
|
+
const proxyMiddleware = createProxyMiddleware2();
|
|
6779
|
+
server.middlewares.use(proxyMiddleware(resovedInfo));
|
|
6643
6780
|
}
|
|
6644
6781
|
server.middlewares.use("/open-dingtalk", (req, res) => {
|
|
6645
6782
|
var _a5;
|
|
@@ -6647,20 +6784,10 @@ var unpluginFactory = (options) => {
|
|
|
6647
6784
|
res.writeHead(302, {
|
|
6648
6785
|
Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
|
|
6649
6786
|
});
|
|
6650
|
-
|
|
6651
|
-
resovedInfo.devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
|
|
6652
|
-
console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
|
|
6653
|
-
resovedInfo.devtoolsInstance.on("exit", () => {
|
|
6654
|
-
resovedInfo.devtoolsInstance = void 0;
|
|
6655
|
-
});
|
|
6656
|
-
import_node_process.default.on("exit", () => {
|
|
6657
|
-
if (resovedInfo.devtoolsInstance) {
|
|
6658
|
-
resovedInfo.devtoolsInstance.kill();
|
|
6659
|
-
}
|
|
6660
|
-
});
|
|
6661
|
-
}
|
|
6787
|
+
startVueDevtools((_a5 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a5.enable);
|
|
6662
6788
|
res.end();
|
|
6663
6789
|
});
|
|
6790
|
+
startDnsServer(options);
|
|
6664
6791
|
}
|
|
6665
6792
|
},
|
|
6666
6793
|
webpack(compiler) {
|
|
@@ -6691,6 +6818,7 @@ var unpluginFactory = (options) => {
|
|
|
6691
6818
|
if (options == null ? void 0 : options.corpId) {
|
|
6692
6819
|
resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
|
|
6693
6820
|
}
|
|
6821
|
+
startDnsServer(options);
|
|
6694
6822
|
},
|
|
6695
6823
|
async rspack(compiler) {
|
|
6696
6824
|
var _a4, _b, _c, _d2, _e;
|
|
@@ -6719,6 +6847,7 @@ var unpluginFactory = (options) => {
|
|
|
6719
6847
|
"Click to open chrome devtools"
|
|
6720
6848
|
)}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
|
|
6721
6849
|
}
|
|
6850
|
+
startDnsServer(options);
|
|
6722
6851
|
}
|
|
6723
6852
|
};
|
|
6724
6853
|
return unpluginDing;
|
|
@@ -6732,14 +6861,15 @@ var rspack_default = (options) => {
|
|
|
6732
6861
|
}
|
|
6733
6862
|
}
|
|
6734
6863
|
const {
|
|
6735
|
-
chii
|
|
6864
|
+
chii
|
|
6736
6865
|
} = options || {};
|
|
6866
|
+
const enableChii = (chii == null ? void 0 : chii.enable) !== false;
|
|
6737
6867
|
const injectSetupMiddlewares = (middlewares, _devServer) => {
|
|
6738
6868
|
if (options.debugCookies && options.debugCookies.length > 0) {
|
|
6739
6869
|
middlewares.unshift((req, res, next) => {
|
|
6740
6870
|
const cookies = import_cookie2.default.parse(req.headers.cookie || "");
|
|
6741
6871
|
for (const [name, value] of Object.entries(cookies)) {
|
|
6742
|
-
if (options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
6872
|
+
if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
|
|
6743
6873
|
const serializedCookie = import_cookie2.default.serialize(name, value, {
|
|
6744
6874
|
httpOnly: false
|
|
6745
6875
|
});
|
|
@@ -6762,6 +6892,9 @@ var rspack_default = (options) => {
|
|
|
6762
6892
|
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`;
|
|
6763
6893
|
res.writeHead(302, { Location: devToolsUrl });
|
|
6764
6894
|
res.end();
|
|
6895
|
+
} else {
|
|
6896
|
+
res.writeHead(404);
|
|
6897
|
+
res.end();
|
|
6765
6898
|
}
|
|
6766
6899
|
} catch (error) {
|
|
6767
6900
|
debug(`${error}`);
|
|
@@ -6780,18 +6913,7 @@ var rspack_default = (options) => {
|
|
|
6780
6913
|
res.writeHead(302, {
|
|
6781
6914
|
Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
|
|
6782
6915
|
});
|
|
6783
|
-
|
|
6784
|
-
resovedInfo.devtoolsInstance = (0, import_node_child_process2.exec)("npx vue-devtools");
|
|
6785
|
-
console.log(` ${import_picocolors2.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
|
|
6786
|
-
resovedInfo.devtoolsInstance.on("exit", () => {
|
|
6787
|
-
resovedInfo.devtoolsInstance = void 0;
|
|
6788
|
-
});
|
|
6789
|
-
import_node_process2.default.on("exit", () => {
|
|
6790
|
-
if (resovedInfo.devtoolsInstance) {
|
|
6791
|
-
resovedInfo.devtoolsInstance.kill();
|
|
6792
|
-
}
|
|
6793
|
-
});
|
|
6794
|
-
}
|
|
6916
|
+
startVueDevtools((_a4 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a4.enable);
|
|
6795
6917
|
res.end();
|
|
6796
6918
|
});
|
|
6797
6919
|
return middlewares;
|
package/dist/rspack.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import * as _unplugin from 'unplugin';
|
|
2
1
|
import { Options, RspackSetupMiddlewares } from './types.cjs';
|
|
3
2
|
import 'webpack-dev-server';
|
|
4
3
|
import 'node:http';
|
|
5
4
|
import 'vite-plugin-vconsole';
|
|
6
5
|
|
|
7
|
-
declare const _default: (options: Options) => readonly [RspackSetupMiddlewares,
|
|
6
|
+
declare const _default: (options: Options) => readonly [RspackSetupMiddlewares, _rspack_core_dist_config_types.RspackPluginInstance];
|
|
8
7
|
|
|
9
8
|
export { _default as default };
|