vite-plugin-qrcode 0.2.4 → 0.4.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 CHANGED
@@ -15,9 +15,9 @@ npm install --save-dev vite-plugin-qrcode
15
15
  import { qrcode } from 'vite-plugin-qrcode';
16
16
 
17
17
  export default defineConfig({
18
- plugins: [
19
- qrcode() // only applies in dev mode
20
- ]
18
+ plugins: [
19
+ qrcode() // only applies in dev mode
20
+ ]
21
21
  });
22
22
  ```
23
23
 
@@ -41,7 +41,7 @@ Example:
41
41
  import { qrcode } from 'vite-plugin-qrcode';
42
42
 
43
43
  export default defineConfig({
44
- plugins: [qrcode({ filter: (url) => url === 'http://192.168.1.1:4173' })]
44
+ plugins: [qrcode({ filter: (url) => url === 'http://192.168.1.1:4173' })]
45
45
  });
46
46
  ```
47
47
 
package/package.json CHANGED
@@ -1,26 +1,22 @@
1
1
  {
2
2
  "name": "vite-plugin-qrcode",
3
3
  "description": "Show QR code on server start",
4
- "version": "0.2.4",
4
+ "version": "0.4.0",
5
5
  "license": "MIT",
6
6
  "author": "bluwy",
7
7
  "type": "module",
8
- "main": "dist/index.cjs",
9
- "module": "dist/index.js",
10
- "types": "dist/index.d.ts",
8
+ "types": "types/index.d.ts",
11
9
  "exports": {
12
10
  ".": {
13
- "import": "./dist/index.js",
14
- "require": "./dist/index.cjs"
11
+ "types": "./types/index.d.ts",
12
+ "default": "./src/index.js"
15
13
  },
16
14
  "./package.json": "./package.json"
17
15
  },
18
16
  "files": [
19
- "dist"
17
+ "src",
18
+ "types"
20
19
  ],
21
- "engines": {
22
- "node": "^14.13.1 || ^16.0.0 || >=18"
23
- },
24
20
  "repository": {
25
21
  "type": "git",
26
22
  "url": "git+https://github.com/svitejs/vite-plugin-qrcode.git",
@@ -37,19 +33,19 @@
37
33
  },
38
34
  "homepage": "https://github.com/svitejs/vite-plugin-qrcode#readme",
39
35
  "dependencies": {
40
- "qrcode-terminal": "^0.12.0"
36
+ "uqr": "^0.1.2"
41
37
  },
42
38
  "peerDependencies": {
43
- "vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0"
39
+ "vite": ">=3"
44
40
  },
45
41
  "devDependencies": {
46
- "@types/qrcode-terminal": "^0.12.2",
47
- "uvu": "^0.5.6",
48
- "vite": "^6.0.0"
42
+ "vite": "^8.0.2",
43
+ "vitest": "^4.1.1"
49
44
  },
50
45
  "scripts": {
51
- "dev": "tsup-node --sourcemap --watch src",
52
- "build": "tsup-node --dts",
53
- "test": "tsm node_modules/uvu/bin.js tests"
46
+ "check:publint": "publint --strict",
47
+ "check:types": "tsc --noEmit",
48
+ "generate:types": "dts-buddy -m \"vite-plugin-qrcode:src/public.d.ts\"",
49
+ "test": "vitest"
54
50
  }
55
51
  }
package/src/index.js ADDED
@@ -0,0 +1,68 @@
1
+ import { renderUnicodeCompact } from 'uqr';
2
+
3
+ /**
4
+ *
5
+ * @param {Partial<import('./public.d.ts').PluginOptions>} [options]
6
+ * @returns {import('vite').Plugin} vite-plugin-qrcode
7
+ */
8
+ export function qrcode(options = {}) {
9
+ /** @type {import('vite').Plugin} */
10
+ const plugin = {
11
+ name: 'vite-plugin-qrcode',
12
+ apply: 'serve',
13
+ configureServer(server) {
14
+ const _listen = server.listen;
15
+ server.listen = function () {
16
+ const isRestart = arguments[1] === true;
17
+ if (!isRestart) {
18
+ server.httpServer?.on('listening', () => {
19
+ setTimeout(() => logQrcode(server, options), 0);
20
+ });
21
+ }
22
+ // @ts-expect-error arguments
23
+ return _listen.apply(this, arguments);
24
+ };
25
+ },
26
+ configurePreviewServer(server) {
27
+ server.httpServer?.on('listening', () => {
28
+ setTimeout(() => logQrcode(server, options), 0);
29
+ });
30
+ }
31
+ };
32
+ return plugin;
33
+ }
34
+
35
+ /**
36
+ *
37
+ * @param {import('vite').ViteDevServer | import('vite').PreviewServer } server
38
+ * @param {import('./public.d.ts').PluginOptions} options
39
+ */
40
+ function logQrcode(server, options) {
41
+ let networkUrls = server.resolvedUrls?.network;
42
+
43
+ if (!networkUrls) return;
44
+
45
+ if (options.filter) {
46
+ networkUrls = networkUrls.filter(options.filter);
47
+ }
48
+
49
+ if (networkUrls.length === 0) return;
50
+
51
+ const info = server.config.logger.info;
52
+
53
+ info('\n Visit page on mobile:');
54
+
55
+ for (const url of networkUrls) {
56
+ const qr = renderUnicodeCompact(url);
57
+ info(` ${cyan(url)}\n ${qr.replace(/\n/g, '\n ')}`);
58
+ }
59
+ }
60
+
61
+ /**
62
+ *
63
+ * @param {string} str
64
+ * @returns {string}
65
+ */
66
+ function cyan(str) {
67
+ return `\x1b[36m${str}\x1b[0m`;
68
+ }
@@ -0,0 +1,15 @@
1
+ export interface PluginOptions {
2
+ /**
3
+ * filter list of shown QR codes. Useful if you have multiple interfaces and only need one
4
+ *
5
+ * examples:
6
+ * url => url.startsWith('http://192.')
7
+ * url => !url.startsWith('http://172.)
8
+ * url => url === 'http://192.168.1.70:4173'
9
+ *
10
+ * @param url {string} ip address
11
+ * @returns {boolean}
12
+ */
13
+
14
+ filter?: (url: string) => boolean;
15
+ }
@@ -0,0 +1,20 @@
1
+ declare module 'vite-plugin-qrcode' {
2
+ export interface PluginOptions {
3
+ /**
4
+ * filter list of shown QR codes. Useful if you have multiple interfaces and only need one
5
+ *
6
+ * examples:
7
+ * url => url.startsWith('http://192.')
8
+ * url => !url.startsWith('http://172.)
9
+ * url => url === 'http://192.168.1.70:4173'
10
+ *
11
+ * @param url ip address
12
+ * */
13
+
14
+ filter?: (url: string) => boolean;
15
+ }
16
+
17
+ export {};
18
+ }
19
+
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,15 @@
1
+ {
2
+ "version": 3,
3
+ "file": "index.d.ts",
4
+ "names": [
5
+ "PluginOptions"
6
+ ],
7
+ "sources": [
8
+ "../src/public.d.ts"
9
+ ],
10
+ "sourcesContent": [
11
+ null
12
+ ],
13
+ "mappings": ";kBAAiBA,aAAaA",
14
+ "ignoreList": []
15
+ }
package/dist/index.cjs DELETED
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- qrcode: () => qrcode
34
- });
35
- module.exports = __toCommonJS(src_exports);
36
- var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
37
- function qrcode(options = {}) {
38
- return {
39
- name: "vite-plugin-qrcode",
40
- apply: "serve",
41
- configureServer(server) {
42
- const _listen = server.listen;
43
- server.listen = function() {
44
- var _a;
45
- const isRestart = arguments[1] === true;
46
- if (!isRestart) {
47
- (_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
48
- setTimeout(() => logQrcode(server, options), 0);
49
- });
50
- }
51
- return _listen.apply(this, arguments);
52
- };
53
- },
54
- configurePreviewServer(server) {
55
- var _a;
56
- if ("resolvedUrls" in server) {
57
- (_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
58
- setTimeout(() => logQrcode(server, options), 0);
59
- });
60
- }
61
- }
62
- };
63
- }
64
- function logQrcode(server, options) {
65
- var _a;
66
- let networkUrls = (_a = server.resolvedUrls) == null ? void 0 : _a.network;
67
- if (!networkUrls)
68
- return;
69
- if (options.filter) {
70
- networkUrls = networkUrls.filter(options.filter);
71
- }
72
- if (networkUrls.length === 0)
73
- return;
74
- const info = server.config.logger.info;
75
- info("\n Visit page on mobile:");
76
- for (const url of networkUrls) {
77
- import_qrcode_terminal.default.generate(url, { small: true }, (result) => {
78
- info(` ${cyan(url)}
79
- ${result.replace(/\n/g, "\n ")}`);
80
- });
81
- }
82
- }
83
- function cyan(str) {
84
- return `\x1B[36m${str}\x1B[0m`;
85
- }
86
- // Annotate the CommonJS export names for ESM import in node:
87
- 0 && (module.exports = {
88
- qrcode
89
- });
package/dist/index.d.cts DELETED
@@ -1,19 +0,0 @@
1
- import { Plugin } from 'vite';
2
-
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
- * url => url.startsWith('http://192.')
10
- * url => !url.startsWith('http://172.)
11
- * url => url === 'http://192.168.1.70:4173'
12
- *
13
- * @param url {string} ip address
14
- * @returns {boolean}
15
- */
16
- filter?: (url: string) => boolean;
17
- }
18
-
19
- export { type PluginOptions, qrcode };
package/dist/index.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import { Plugin } from 'vite';
2
-
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
- * url => url.startsWith('http://192.')
10
- * url => !url.startsWith('http://172.)
11
- * url => url === 'http://192.168.1.70:4173'
12
- *
13
- * @param url {string} ip address
14
- * @returns {boolean}
15
- */
16
- filter?: (url: string) => boolean;
17
- }
18
-
19
- export { type PluginOptions, qrcode };
package/dist/index.js DELETED
@@ -1,54 +0,0 @@
1
- // src/index.ts
2
- import qr from "qrcode-terminal";
3
- function qrcode(options = {}) {
4
- return {
5
- name: "vite-plugin-qrcode",
6
- apply: "serve",
7
- configureServer(server) {
8
- const _listen = server.listen;
9
- server.listen = function() {
10
- var _a;
11
- const isRestart = arguments[1] === true;
12
- if (!isRestart) {
13
- (_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
14
- setTimeout(() => logQrcode(server, options), 0);
15
- });
16
- }
17
- return _listen.apply(this, arguments);
18
- };
19
- },
20
- configurePreviewServer(server) {
21
- var _a;
22
- if ("resolvedUrls" in server) {
23
- (_a = server.httpServer) == null ? void 0 : _a.on("listening", () => {
24
- setTimeout(() => logQrcode(server, options), 0);
25
- });
26
- }
27
- }
28
- };
29
- }
30
- function logQrcode(server, options) {
31
- var _a;
32
- let networkUrls = (_a = server.resolvedUrls) == null ? void 0 : _a.network;
33
- if (!networkUrls)
34
- return;
35
- if (options.filter) {
36
- networkUrls = networkUrls.filter(options.filter);
37
- }
38
- if (networkUrls.length === 0)
39
- return;
40
- const info = server.config.logger.info;
41
- info("\n Visit page on mobile:");
42
- for (const url of networkUrls) {
43
- qr.generate(url, { small: true }, (result) => {
44
- info(` ${cyan(url)}
45
- ${result.replace(/\n/g, "\n ")}`);
46
- });
47
- }
48
- }
49
- function cyan(str) {
50
- return `\x1B[36m${str}\x1B[0m`;
51
- }
52
- export {
53
- qrcode
54
- };