vite-plugin-qrcode 0.0.1 → 0.1.1
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 +42 -0
- package/dist/index.cjs +20 -27
- package/dist/index.d.ts +16 -2
- package/dist/index.js +7 -8
- package/package.json +11 -7
- package/dist/index.cjs.map +0 -7
- package/dist/index.js.map +0 -7
- package/src/index.ts +0 -108
- package/tests/index.ts +0 -9
- package/tsconfig.json +0 -17
- package/tsup.config.js +0 -8
package/README.md
CHANGED
|
@@ -24,6 +24,48 @@ export default defineConfig({
|
|
|
24
24
|
```bash
|
|
25
25
|
# start vite with host to show qrcode
|
|
26
26
|
vite --host
|
|
27
|
+
|
|
28
|
+
vite v2.6.1 dev server running at:
|
|
29
|
+
|
|
30
|
+
> Local: http://localhost:3000/
|
|
31
|
+
> Network: http://192.168.2.169:3000/
|
|
32
|
+
|
|
33
|
+
ready in 186ms.
|
|
34
|
+
|
|
35
|
+
Visit page on mobile:
|
|
36
|
+
http://192.168.2.169:3000/
|
|
37
|
+
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
|
|
38
|
+
█ ▄▄▄▄▄ ██▄▄ ▀▄██▄█ ▄▄▄▄▄ █
|
|
39
|
+
█ █ █ █▀▄ █▀ ▀ █ █ █ █
|
|
40
|
+
█ █▄▄▄█ █▄▀ █▄▀ ███ █▄▄▄█ █
|
|
41
|
+
█▄▄▄▄▄▄▄█▄▀▄█ █▄▀▄█▄▄▄▄▄▄▄█
|
|
42
|
+
█ ▄██▀ ▄ █▄ █▄ █ ▀██ ▀▀██
|
|
43
|
+
██▄▀▀█▀▄▄█▄▀ ▄█▀ ▀█▄▄▀ █▄ █
|
|
44
|
+
█ ▀ ▄▄ ▄██▄ █ ▀ ▀▄▄▄████▀▄█
|
|
45
|
+
█ █▀▄█ ▄ ▀█▄▀▄▀▄█▄▀▄▀▄ █
|
|
46
|
+
█▄█████▄█▀█▄ ▄▀▀ ▄▄▄ █ ███
|
|
47
|
+
█ ▄▄▄▄▄ █ ██▄ █ █ █▄█ ▄██▄█
|
|
48
|
+
█ █ █ ██▀ ▀▀▄█▄▄▄ ▄ ▄▀▀█
|
|
49
|
+
█ █▄▄▄█ █▀█▄█ ██▀▀▄▀▀▀█▄█ █
|
|
50
|
+
█▄▄▄▄▄▄▄█▄██▄██▄▄▄█▄██▄██▄█
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Options
|
|
55
|
+
|
|
56
|
+
### filter
|
|
57
|
+
|
|
58
|
+
A function that allows you to select addresses to show QR-Codes for in case you have multiple interfaces
|
|
59
|
+
|
|
60
|
+
Example:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
// vite.config.js
|
|
64
|
+
import { qrcode } from 'vite-plugin-qrcode';
|
|
65
|
+
|
|
66
|
+
export default defineConfig({
|
|
67
|
+
plugins: [qrcode({ filter: (ip) => ip === '192.168.1.1' })]
|
|
68
|
+
});
|
|
27
69
|
```
|
|
28
70
|
|
|
29
71
|
## License
|
package/dist/index.cjs
CHANGED
|
@@ -4,36 +4,30 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
7
|
var __export = (target, all) => {
|
|
9
|
-
__markAsModule(target);
|
|
10
8
|
for (var name in all)
|
|
11
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
10
|
};
|
|
13
|
-
var
|
|
14
|
-
if (
|
|
15
|
-
for (let key of __getOwnPropNames(
|
|
16
|
-
if (!__hasOwnProp.call(
|
|
17
|
-
__defProp(
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
16
|
}
|
|
19
|
-
return
|
|
20
|
-
};
|
|
21
|
-
var __toModule = (module2) => {
|
|
22
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
17
|
+
return to;
|
|
23
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
21
|
|
|
25
22
|
// src/index.ts
|
|
26
|
-
|
|
23
|
+
var src_exports = {};
|
|
24
|
+
__export(src_exports, {
|
|
27
25
|
qrcode: () => qrcode
|
|
28
26
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
// src/index.ts
|
|
34
|
-
var import_os = __toModule(require("os"));
|
|
35
|
-
var import_qrcode_terminal = __toModule(require("qrcode-terminal"));
|
|
36
|
-
function qrcode() {
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var import_os = __toESM(require("os"), 1);
|
|
29
|
+
var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
|
|
30
|
+
function qrcode(options = {}) {
|
|
37
31
|
return {
|
|
38
32
|
name: "vite-plugin-qrcode",
|
|
39
33
|
apply: "serve",
|
|
@@ -44,7 +38,7 @@ function qrcode() {
|
|
|
44
38
|
const isRestart = arguments[1] === true;
|
|
45
39
|
if (!isRestart) {
|
|
46
40
|
(_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
|
|
47
|
-
setTimeout(() => logQrcode(server), 0);
|
|
41
|
+
setTimeout(() => logQrcode(server, options), 0);
|
|
48
42
|
});
|
|
49
43
|
}
|
|
50
44
|
return _listen.apply(this, arguments);
|
|
@@ -52,8 +46,8 @@ function qrcode() {
|
|
|
52
46
|
}
|
|
53
47
|
};
|
|
54
48
|
}
|
|
55
|
-
function logQrcode(server) {
|
|
56
|
-
const networkUrls = getNetworkUrls(server);
|
|
49
|
+
function logQrcode(server, options) {
|
|
50
|
+
const networkUrls = getNetworkUrls(server, options);
|
|
57
51
|
if (networkUrls.length === 0)
|
|
58
52
|
return;
|
|
59
53
|
const info = server.config.logger.info;
|
|
@@ -66,9 +60,9 @@ function logQrcode(server) {
|
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
62
|
function cyan(str) {
|
|
69
|
-
return
|
|
63
|
+
return `\x1B[36m${str}\x1B[0m`;
|
|
70
64
|
}
|
|
71
|
-
function getNetworkUrls(server) {
|
|
65
|
+
function getNetworkUrls(server, options) {
|
|
72
66
|
var _a;
|
|
73
67
|
const address = (_a = server.httpServer) == null ? void 0 : _a.address();
|
|
74
68
|
if (!isAddressInfo(address))
|
|
@@ -79,7 +73,7 @@ function getNetworkUrls(server) {
|
|
|
79
73
|
const protocol = server.config.server.https ? "https" : "http";
|
|
80
74
|
const port = address.port;
|
|
81
75
|
const base = server.config.base;
|
|
82
|
-
return Object.values(import_os.default.networkInterfaces()).flatMap((nInterface) => nInterface != null ? nInterface : []).filter((detail) => detail && detail.address && detail.family === "IPv4" && !detail.address.includes("127.0.0.1")).map((detail) => `${protocol}://${detail.address}:${port}${base}`);
|
|
76
|
+
return Object.values(import_os.default.networkInterfaces()).flatMap((nInterface) => nInterface != null ? nInterface : []).filter((detail) => detail && detail.address && (detail.family === "IPv4" || detail.family === 4) && !detail.address.includes("127.0.0.1") && (!options.filter || options.filter(detail.address))).map((detail) => `${protocol}://${detail.address}:${port}${base}`);
|
|
83
77
|
}
|
|
84
78
|
function isAddressInfo(v) {
|
|
85
79
|
return v.address;
|
|
@@ -100,4 +94,3 @@ function resolveHostname(optionsHost) {
|
|
|
100
94
|
0 && (module.exports = {
|
|
101
95
|
qrcode
|
|
102
96
|
});
|
|
103
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
-
declare function qrcode(): Plugin;
|
|
3
|
+
declare function qrcode(options?: PluginOptions): Plugin;
|
|
4
|
+
interface PluginOptions {
|
|
5
|
+
/**
|
|
6
|
+
* filter list of shown QR codes. Useful if you have multiple interfaces and only need one
|
|
7
|
+
*
|
|
8
|
+
* examples:
|
|
9
|
+
* ip => ip.startsWith('192.')
|
|
10
|
+
* ip => !ip.startsWith('172.)
|
|
11
|
+
* ip => ip === '192.168.1.70'
|
|
12
|
+
*
|
|
13
|
+
* @param ip {string} ip address
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
filter?: (ip: string) => boolean;
|
|
17
|
+
}
|
|
4
18
|
|
|
5
|
-
export { qrcode };
|
|
19
|
+
export { PluginOptions, qrcode };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import os from "os";
|
|
3
3
|
import qr from "qrcode-terminal";
|
|
4
|
-
function qrcode() {
|
|
4
|
+
function qrcode(options = {}) {
|
|
5
5
|
return {
|
|
6
6
|
name: "vite-plugin-qrcode",
|
|
7
7
|
apply: "serve",
|
|
@@ -12,7 +12,7 @@ function qrcode() {
|
|
|
12
12
|
const isRestart = arguments[1] === true;
|
|
13
13
|
if (!isRestart) {
|
|
14
14
|
(_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
|
|
15
|
-
setTimeout(() => logQrcode(server), 0);
|
|
15
|
+
setTimeout(() => logQrcode(server, options), 0);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
return _listen.apply(this, arguments);
|
|
@@ -20,8 +20,8 @@ function qrcode() {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
function logQrcode(server) {
|
|
24
|
-
const networkUrls = getNetworkUrls(server);
|
|
23
|
+
function logQrcode(server, options) {
|
|
24
|
+
const networkUrls = getNetworkUrls(server, options);
|
|
25
25
|
if (networkUrls.length === 0)
|
|
26
26
|
return;
|
|
27
27
|
const info = server.config.logger.info;
|
|
@@ -34,9 +34,9 @@ function logQrcode(server) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
function cyan(str) {
|
|
37
|
-
return
|
|
37
|
+
return `\x1B[36m${str}\x1B[0m`;
|
|
38
38
|
}
|
|
39
|
-
function getNetworkUrls(server) {
|
|
39
|
+
function getNetworkUrls(server, options) {
|
|
40
40
|
var _a;
|
|
41
41
|
const address = (_a = server.httpServer) == null ? void 0 : _a.address();
|
|
42
42
|
if (!isAddressInfo(address))
|
|
@@ -47,7 +47,7 @@ function getNetworkUrls(server) {
|
|
|
47
47
|
const protocol = server.config.server.https ? "https" : "http";
|
|
48
48
|
const port = address.port;
|
|
49
49
|
const base = server.config.base;
|
|
50
|
-
return Object.values(os.networkInterfaces()).flatMap((nInterface) => nInterface != null ? nInterface : []).filter((detail) => detail && detail.address && detail.family === "IPv4" && !detail.address.includes("127.0.0.1")).map((detail) => `${protocol}://${detail.address}:${port}${base}`);
|
|
50
|
+
return Object.values(os.networkInterfaces()).flatMap((nInterface) => nInterface != null ? nInterface : []).filter((detail) => detail && detail.address && (detail.family === "IPv4" || detail.family === 4) && !detail.address.includes("127.0.0.1") && (!options.filter || options.filter(detail.address))).map((detail) => `${protocol}://${detail.address}:${port}${base}`);
|
|
51
51
|
}
|
|
52
52
|
function isAddressInfo(v) {
|
|
53
53
|
return v.address;
|
|
@@ -67,4 +67,3 @@ function resolveHostname(optionsHost) {
|
|
|
67
67
|
export {
|
|
68
68
|
qrcode
|
|
69
69
|
};
|
|
70
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-qrcode",
|
|
3
3
|
"description": "Show QR code on server start",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "bluwy",
|
|
7
7
|
"type": "module",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
},
|
|
16
16
|
"./package.json": "./package.json"
|
|
17
17
|
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
18
21
|
"engines": {
|
|
19
22
|
"node": "^12.20 || ^14.13.1 || >= 16"
|
|
20
23
|
},
|
|
@@ -41,13 +44,14 @@
|
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|
|
43
46
|
"@types/qrcode-terminal": "^0.12.0",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"vite": "^2.6
|
|
47
|
+
"rollup": "^2.71.1",
|
|
48
|
+
"uvu": "^0.5.3",
|
|
49
|
+
"vite": "^2.9.6"
|
|
47
50
|
},
|
|
48
51
|
"scripts": {
|
|
49
|
-
"dev": "tsup-node --watch src",
|
|
52
|
+
"dev": "tsup-node --sourcemap --watch src",
|
|
50
53
|
"build": "tsup-node --dts",
|
|
51
|
-
"test": "
|
|
52
|
-
}
|
|
54
|
+
"test": "tsm node_modules/uvu/bin.js tests"
|
|
55
|
+
},
|
|
56
|
+
"readme": "# vite-plugin-qrcode\n\nShow QR code on server start.\n\n## Installation\n\n```bash\nnpm install --save-dev vite-plugin-qrcode\n```\n\n## Usage\n\n```js\n// vite.config.js\nimport { qrcode } from 'vite-plugin-qrcode';\n\nexport default defineConfig({\n\tplugins: [\n\t\tqrcode() // only applies in dev mode\n\t]\n});\n```\n\n```bash\n# start vite with host to show qrcode\nvite --host\n\n vite v2.6.1 dev server running at:\n\n > Local: http://localhost:3000/\n > Network: http://192.168.2.169:3000/\n\n ready in 186ms.\n\n Visit page on mobile:\n http://192.168.2.169:3000/\n ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄\n █ ▄▄▄▄▄ ██▄▄ ▀▄██▄█ ▄▄▄▄▄ █\n █ █ █ █▀▄ █▀ ▀ █ █ █ █\n █ █▄▄▄█ █▄▀ █▄▀ ███ █▄▄▄█ █\n █▄▄▄▄▄▄▄█▄▀▄█ █▄▀▄█▄▄▄▄▄▄▄█\n █ ▄██▀ ▄ █▄ █▄ █ ▀██ ▀▀██\n ██▄▀▀█▀▄▄█▄▀ ▄█▀ ▀█▄▄▀ █▄ █\n █ ▀ ▄▄ ▄██▄ █ ▀ ▀▄▄▄████▀▄█\n █ █▀▄█ ▄ ▀█▄▀▄▀▄█▄▀▄▀▄ █\n █▄█████▄█▀█▄ ▄▀▀ ▄▄▄ █ ███\n █ ▄▄▄▄▄ █ ██▄ █ █ █▄█ ▄██▄█\n █ █ █ ██▀ ▀▀▄█▄▄▄ ▄ ▄▀▀█\n █ █▄▄▄█ █▀█▄█ ██▀▀▄▀▀▀█▄█ █\n █▄▄▄▄▄▄▄█▄██▄██▄▄▄█▄██▄██▄█\n\n```\n\n## Options\n\n### filter\n\nA function that allows you to select addresses to show QR-Codes for in case you have multiple interfaces\n\nExample:\n\n```js\n// vite.config.js\nimport { qrcode } from 'vite-plugin-qrcode';\n\nexport default defineConfig({\n\tplugins: [qrcode({ filter: (ip) => ip === '192.168.1.1' })]\n});\n```\n\n## License\n\n[MIT](./LICENSE)\n"
|
|
53
57
|
}
|
package/dist/index.cjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../../../node_modules/.pnpm/tsup@5.2.1_typescript@4.4.3/node_modules/tsup/assets/cjs_shims.js"],
|
|
4
|
-
"sourcesContent": ["import os from 'os';\nimport { AddressInfo } from 'net';\nimport type { Plugin, ViteDevServer } from 'vite';\nimport qr from 'qrcode-terminal';\n\nexport function qrcode(): Plugin {\n\treturn {\n\t\tname: 'vite-plugin-qrcode',\n\t\tapply: 'serve',\n\t\tconfigureServer(server) {\n\t\t\tconst _listen = server.listen;\n\t\t\tserver.listen = function () {\n\t\t\t\t// eslint-disable-next-line prefer-rest-params\n\t\t\t\tconst isRestart = arguments[1] === true;\n\t\t\t\tif (!isRestart) {\n\t\t\t\t\tserver.httpServer?.on('listening', () => {\n\t\t\t\t\t\tsetTimeout(() => logQrcode(server), 0);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\t// @ts-ignore\n\t\t\t\t// eslint-disable-next-line prefer-rest-params\n\t\t\t\treturn _listen.apply(this, arguments);\n\t\t\t};\n\t\t}\n\t};\n}\n\nfunction logQrcode(server: ViteDevServer) {\n\tconst networkUrls = getNetworkUrls(server);\n\n\tif (networkUrls.length === 0) return;\n\n\tconst info = server.config.logger.info;\n\n\tinfo(' Visit page on mobile:');\n\n\tfor (const url of networkUrls) {\n\t\tqr.generate(url, { small: true }, (result) => {\n\t\t\tinfo(` ${cyan(url)}\\n ${result.replace(/\\n/g, '\\n ')}`);\n\t\t});\n\t}\n}\n\nfunction cyan(str: string): string {\n\treturn `\\x1b[36m${str}\\x1b[0m`;\n}\n\n// Referenced from https://github.com/vitejs/vite/blob/77447496704e61cdb68b5788d8d79f19a2d895f1/packages/vite/src/node/logger.ts#L143\nfunction getNetworkUrls(server: ViteDevServer): string[] {\n\tconst address = server.httpServer?.address();\n\n\tif (!isAddressInfo(address)) return [];\n\n\tconst hostname = resolveHostname(server.config.server.host);\n\n\tif (hostname.host === '127.0.0.1') return [];\n\n\tconst protocol = server.config.server.https ? 'https' : 'http';\n\tconst port = address.port;\n\tconst base = server.config.base;\n\n\treturn Object.values(os.networkInterfaces())\n\t\t.flatMap((nInterface) => nInterface ?? [])\n\t\t.filter(\n\t\t\t(detail) =>\n\t\t\t\tdetail &&\n\t\t\t\tdetail.address &&\n\t\t\t\tdetail.family === 'IPv4' &&\n\t\t\t\t!detail.address.includes('127.0.0.1')\n\t\t)\n\t\t.map((detail) => `${protocol}://${detail.address}:${port}${base}`);\n}\n\nfunction isAddressInfo(v: any): v is AddressInfo {\n\treturn v.address;\n}\n\n// Copied from https://github.com/vitejs/vite/blob/77447496704e61cdb68b5788d8d79f19a2d895f1/packages/vite/src/node/utils.ts#L531\nfunction resolveHostname(optionsHost: string | boolean | undefined): Hostname {\n\tlet host: string | undefined;\n\tif (optionsHost === undefined || optionsHost === false || optionsHost === 'localhost') {\n\t\t// Use a secure default\n\t\thost = '127.0.0.1';\n\t} else if (optionsHost === true) {\n\t\t// If passed --host in the CLI without arguments\n\t\thost = undefined; // undefined typically means 0.0.0.0 or :: (listen on all IPs)\n\t} else {\n\t\thost = optionsHost;\n\t}\n\n\t// Set host name to localhost when possible, unless the user explicitly asked for '127.0.0.1'\n\tconst name =\n\t\t(optionsHost !== '127.0.0.1' && host === '127.0.0.1') ||\n\t\thost === '0.0.0.0' ||\n\t\thost === '::' ||\n\t\thost === undefined\n\t\t\t? 'localhost'\n\t\t\t: host;\n\n\treturn { host, name };\n}\n\ninterface Hostname {\n\t// undefined sets the default behaviour of server.listen\n\thost: string | undefined;\n\t// resolve to localhost when possible\n\tname: string;\n}\n", "export const importMetaUrlShim =\n typeof document === 'undefined'\n ? new (require('u' + 'rl').URL)('file:' + __filename).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;;;ACAO,IAAM,oBACX,OAAO,aAAa,cAChB,IAAK,SAAQ,QAAY,IAAK,UAAU,YAAY,OACnD,SAAS,iBAAiB,SAAS,cAAc,OAClD,IAAI,IAAI,WAAW,SAAS,SAAS;;;ADJ3C,gBAAe;AAGf,6BAAe;AAER,kBAA0B;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E,MAAI;AACJ,MAAI,gBAAgB,UAAa,gBAAgB,SAAS,gBAAgB,aAAa;AAEtF,WAAO;AAAA,aACG,gBAAgB,MAAM;AAEhC,WAAO;AAAA,SACD;AACN,WAAO;AAAA;AAIR,QAAM,OACJ,gBAAgB,eAAe,SAAS,eACzC,SAAS,aACT,SAAS,QACT,SAAS,SACN,cACA;AAEJ,SAAO,EAAE,MAAM;AAAA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/index.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import os from 'os';\nimport { AddressInfo } from 'net';\nimport type { Plugin, ViteDevServer } from 'vite';\nimport qr from 'qrcode-terminal';\n\nexport function qrcode(): Plugin {\n\treturn {\n\t\tname: 'vite-plugin-qrcode',\n\t\tapply: 'serve',\n\t\tconfigureServer(server) {\n\t\t\tconst _listen = server.listen;\n\t\t\tserver.listen = function () {\n\t\t\t\t// eslint-disable-next-line prefer-rest-params\n\t\t\t\tconst isRestart = arguments[1] === true;\n\t\t\t\tif (!isRestart) {\n\t\t\t\t\tserver.httpServer?.on('listening', () => {\n\t\t\t\t\t\tsetTimeout(() => logQrcode(server), 0);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\t// @ts-ignore\n\t\t\t\t// eslint-disable-next-line prefer-rest-params\n\t\t\t\treturn _listen.apply(this, arguments);\n\t\t\t};\n\t\t}\n\t};\n}\n\nfunction logQrcode(server: ViteDevServer) {\n\tconst networkUrls = getNetworkUrls(server);\n\n\tif (networkUrls.length === 0) return;\n\n\tconst info = server.config.logger.info;\n\n\tinfo(' Visit page on mobile:');\n\n\tfor (const url of networkUrls) {\n\t\tqr.generate(url, { small: true }, (result) => {\n\t\t\tinfo(` ${cyan(url)}\\n ${result.replace(/\\n/g, '\\n ')}`);\n\t\t});\n\t}\n}\n\nfunction cyan(str: string): string {\n\treturn `\\x1b[36m${str}\\x1b[0m`;\n}\n\n// Referenced from https://github.com/vitejs/vite/blob/77447496704e61cdb68b5788d8d79f19a2d895f1/packages/vite/src/node/logger.ts#L143\nfunction getNetworkUrls(server: ViteDevServer): string[] {\n\tconst address = server.httpServer?.address();\n\n\tif (!isAddressInfo(address)) return [];\n\n\tconst hostname = resolveHostname(server.config.server.host);\n\n\tif (hostname.host === '127.0.0.1') return [];\n\n\tconst protocol = server.config.server.https ? 'https' : 'http';\n\tconst port = address.port;\n\tconst base = server.config.base;\n\n\treturn Object.values(os.networkInterfaces())\n\t\t.flatMap((nInterface) => nInterface ?? [])\n\t\t.filter(\n\t\t\t(detail) =>\n\t\t\t\tdetail &&\n\t\t\t\tdetail.address &&\n\t\t\t\tdetail.family === 'IPv4' &&\n\t\t\t\t!detail.address.includes('127.0.0.1')\n\t\t)\n\t\t.map((detail) => `${protocol}://${detail.address}:${port}${base}`);\n}\n\nfunction isAddressInfo(v: any): v is AddressInfo {\n\treturn v.address;\n}\n\n// Copied from https://github.com/vitejs/vite/blob/77447496704e61cdb68b5788d8d79f19a2d895f1/packages/vite/src/node/utils.ts#L531\nfunction resolveHostname(optionsHost: string | boolean | undefined): Hostname {\n\tlet host: string | undefined;\n\tif (optionsHost === undefined || optionsHost === false || optionsHost === 'localhost') {\n\t\t// Use a secure default\n\t\thost = '127.0.0.1';\n\t} else if (optionsHost === true) {\n\t\t// If passed --host in the CLI without arguments\n\t\thost = undefined; // undefined typically means 0.0.0.0 or :: (listen on all IPs)\n\t} else {\n\t\thost = optionsHost;\n\t}\n\n\t// Set host name to localhost when possible, unless the user explicitly asked for '127.0.0.1'\n\tconst name =\n\t\t(optionsHost !== '127.0.0.1' && host === '127.0.0.1') ||\n\t\thost === '0.0.0.0' ||\n\t\thost === '::' ||\n\t\thost === undefined\n\t\t\t? 'localhost'\n\t\t\t: host;\n\n\treturn { host, name };\n}\n\ninterface Hostname {\n\t// undefined sets the default behaviour of server.listen\n\thost: string | undef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AAO;AAAA;AAG7D,uBAAuB,GAA0B;AAChD,SAAO,EAAE;AAAA;AAIV,yBAAyB,aAAqD;AAC7E,MAAI;AACJ,MAAI,gBAAgB,UAAa,gBAAgB,SAAS,gBAAgB,aAAa;AAEtF,WAAO;AAAA,aACG,gBAAgB,MAAM;AAEhC,WAAO;AAAA,SACD;AACN,WAAO;AAAA;AAIR,QAAM,OACJ,gBAAgB,eAAe,SAAS,eACzC,SAAS,aACT,SAAS,QACT,SAAS,SACN,cACA;AAEJ,SAAO,EAAE,MAAM;AAAA;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import os from 'os';
|
|
2
|
-
import { AddressInfo } from 'net';
|
|
3
|
-
import type { Plugin, ViteDevServer } from 'vite';
|
|
4
|
-
import qr from 'qrcode-terminal';
|
|
5
|
-
|
|
6
|
-
export function qrcode(): Plugin {
|
|
7
|
-
return {
|
|
8
|
-
name: 'vite-plugin-qrcode',
|
|
9
|
-
apply: 'serve',
|
|
10
|
-
configureServer(server) {
|
|
11
|
-
const _listen = server.listen;
|
|
12
|
-
server.listen = function () {
|
|
13
|
-
// eslint-disable-next-line prefer-rest-params
|
|
14
|
-
const isRestart = arguments[1] === true;
|
|
15
|
-
if (!isRestart) {
|
|
16
|
-
server.httpServer?.on('listening', () => {
|
|
17
|
-
setTimeout(() => logQrcode(server), 0);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
// eslint-disable-next-line prefer-rest-params
|
|
22
|
-
return _listen.apply(this, arguments);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function logQrcode(server: ViteDevServer) {
|
|
29
|
-
const networkUrls = getNetworkUrls(server);
|
|
30
|
-
|
|
31
|
-
if (networkUrls.length === 0) return;
|
|
32
|
-
|
|
33
|
-
const info = server.config.logger.info;
|
|
34
|
-
|
|
35
|
-
info(' Visit page on mobile:');
|
|
36
|
-
|
|
37
|
-
for (const url of networkUrls) {
|
|
38
|
-
qr.generate(url, { small: true }, (result) => {
|
|
39
|
-
info(` ${cyan(url)}\n ${result.replace(/\n/g, '\n ')}`);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function cyan(str: string): string {
|
|
45
|
-
return `\x1b[36m${str}\x1b[0m`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Referenced from https://github.com/vitejs/vite/blob/77447496704e61cdb68b5788d8d79f19a2d895f1/packages/vite/src/node/logger.ts#L143
|
|
49
|
-
function getNetworkUrls(server: ViteDevServer): string[] {
|
|
50
|
-
const address = server.httpServer?.address();
|
|
51
|
-
|
|
52
|
-
if (!isAddressInfo(address)) return [];
|
|
53
|
-
|
|
54
|
-
const hostname = resolveHostname(server.config.server.host);
|
|
55
|
-
|
|
56
|
-
if (hostname.host === '127.0.0.1') return [];
|
|
57
|
-
|
|
58
|
-
const protocol = server.config.server.https ? 'https' : 'http';
|
|
59
|
-
const port = address.port;
|
|
60
|
-
const base = server.config.base;
|
|
61
|
-
|
|
62
|
-
return Object.values(os.networkInterfaces())
|
|
63
|
-
.flatMap((nInterface) => nInterface ?? [])
|
|
64
|
-
.filter(
|
|
65
|
-
(detail) =>
|
|
66
|
-
detail &&
|
|
67
|
-
detail.address &&
|
|
68
|
-
detail.family === 'IPv4' &&
|
|
69
|
-
!detail.address.includes('127.0.0.1')
|
|
70
|
-
)
|
|
71
|
-
.map((detail) => `${protocol}://${detail.address}:${port}${base}`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function isAddressInfo(v: any): v is AddressInfo {
|
|
75
|
-
return v.address;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Copied from https://github.com/vitejs/vite/blob/77447496704e61cdb68b5788d8d79f19a2d895f1/packages/vite/src/node/utils.ts#L531
|
|
79
|
-
function resolveHostname(optionsHost: string | boolean | undefined): Hostname {
|
|
80
|
-
let host: string | undefined;
|
|
81
|
-
if (optionsHost === undefined || optionsHost === false || optionsHost === 'localhost') {
|
|
82
|
-
// Use a secure default
|
|
83
|
-
host = '127.0.0.1';
|
|
84
|
-
} else if (optionsHost === true) {
|
|
85
|
-
// If passed --host in the CLI without arguments
|
|
86
|
-
host = undefined; // undefined typically means 0.0.0.0 or :: (listen on all IPs)
|
|
87
|
-
} else {
|
|
88
|
-
host = optionsHost;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Set host name to localhost when possible, unless the user explicitly asked for '127.0.0.1'
|
|
92
|
-
const name =
|
|
93
|
-
(optionsHost !== '127.0.0.1' && host === '127.0.0.1') ||
|
|
94
|
-
host === '0.0.0.0' ||
|
|
95
|
-
host === '::' ||
|
|
96
|
-
host === undefined
|
|
97
|
-
? 'localhost'
|
|
98
|
-
: host;
|
|
99
|
-
|
|
100
|
-
return { host, name };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
interface Hostname {
|
|
104
|
-
// undefined sets the default behaviour of server.listen
|
|
105
|
-
host: string | undefined;
|
|
106
|
-
// resolve to localhost when possible
|
|
107
|
-
name: string;
|
|
108
|
-
}
|
package/tests/index.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": ["src"],
|
|
3
|
-
"exclude": ["**/*.spec.ts"],
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"target": "ES2019",
|
|
7
|
-
"module": "ES2020",
|
|
8
|
-
"moduleResolution": "node",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"sourceMap": true,
|
|
12
|
-
"noUnusedLocals": true,
|
|
13
|
-
"esModuleInterop": true,
|
|
14
|
-
"baseUrl": ".",
|
|
15
|
-
"resolveJsonModule": true
|
|
16
|
-
}
|
|
17
|
-
}
|