vite-plugin-qrcode 0.0.1 → 0.0.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/README.md +25 -0
- package/dist/index.cjs +0 -1
- package/dist/index.js +0 -1
- package/package.json +5 -2
- 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,31 @@ 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
|
+
|
|
27
52
|
```
|
|
28
53
|
|
|
29
54
|
## License
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
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.0.
|
|
4
|
+
"version": "0.0.2",
|
|
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
|
},
|
|
@@ -46,7 +49,7 @@
|
|
|
46
49
|
"vite": "^2.6.1"
|
|
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
54
|
"test": "esmo node_modules/uvu/bin.js tests"
|
|
52
55
|
}
|
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;AAChC,SAAO;AAA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AAI,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 | undefined;\n\t// resolve to localh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D,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
|
-
}
|