unplugin-version-checker 1.0.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.
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index.cjs');
4
+ require('unplugin');
5
+
6
+ const esbuild = index.esbuild;
7
+
8
+ module.exports = esbuild;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export { _default as default };
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
@@ -0,0 +1,6 @@
1
+ import unplugin from './index.mjs';
2
+ import 'unplugin';
3
+
4
+ const esbuild = unplugin.esbuild;
5
+
6
+ export { esbuild as default };
package/dist/index.cjs ADDED
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ const unplugin$1 = require('unplugin');
4
+
5
+ const unplugin = unplugin$1.createUnplugin((options = {}) => {
6
+ const {
7
+ metaFileName = "meta.json",
8
+ generateOnBuild = true,
9
+ devMock = true,
10
+ injectComponent = false
11
+ // 由于跨构建工具自动注入组件复杂,建议用户手动注册组件
12
+ } = options;
13
+ return {
14
+ name: "unplugin-version-checker",
15
+ enforce: "post",
16
+ writeBundle() {
17
+ if (!generateOnBuild) return;
18
+ const versionInfo = {
19
+ buildTime: (/* @__PURE__ */ new Date()).toISOString(),
20
+ version: process.env.BUILD_ID || process.env.npm_package_version,
21
+ commitHash: process.env.COMMIT_SHORT || process.env.GIT_COMMIT_SHORT
22
+ };
23
+ this.emitFile({
24
+ type: "asset",
25
+ fileName: metaFileName,
26
+ source: JSON.stringify(versionInfo, null, 2)
27
+ });
28
+ },
29
+ configureServer(server) {
30
+ if (!devMock) return;
31
+ server.middlewares.use((req, res, next) => {
32
+ if (req.url === `/${metaFileName}`) {
33
+ res.setHeader("Content-Type", "application/json");
34
+ res.end(JSON.stringify({
35
+ buildTime: (/* @__PURE__ */ new Date()).toISOString(),
36
+ version: "dev",
37
+ commitHash: "dev"
38
+ }));
39
+ return;
40
+ }
41
+ next();
42
+ });
43
+ }
44
+ };
45
+ });
46
+
47
+ module.exports = unplugin;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export { _default as default };
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
package/dist/index.mjs ADDED
@@ -0,0 +1,45 @@
1
+ import { createUnplugin } from 'unplugin';
2
+
3
+ const unplugin = createUnplugin((options = {}) => {
4
+ const {
5
+ metaFileName = "meta.json",
6
+ generateOnBuild = true,
7
+ devMock = true,
8
+ injectComponent = false
9
+ // 由于跨构建工具自动注入组件复杂,建议用户手动注册组件
10
+ } = options;
11
+ return {
12
+ name: "unplugin-version-checker",
13
+ enforce: "post",
14
+ writeBundle() {
15
+ if (!generateOnBuild) return;
16
+ const versionInfo = {
17
+ buildTime: (/* @__PURE__ */ new Date()).toISOString(),
18
+ version: process.env.BUILD_ID || process.env.npm_package_version,
19
+ commitHash: process.env.COMMIT_SHORT || process.env.GIT_COMMIT_SHORT
20
+ };
21
+ this.emitFile({
22
+ type: "asset",
23
+ fileName: metaFileName,
24
+ source: JSON.stringify(versionInfo, null, 2)
25
+ });
26
+ },
27
+ configureServer(server) {
28
+ if (!devMock) return;
29
+ server.middlewares.use((req, res, next) => {
30
+ if (req.url === `/${metaFileName}`) {
31
+ res.setHeader("Content-Type", "application/json");
32
+ res.end(JSON.stringify({
33
+ buildTime: (/* @__PURE__ */ new Date()).toISOString(),
34
+ version: "dev",
35
+ commitHash: "dev"
36
+ }));
37
+ return;
38
+ }
39
+ next();
40
+ });
41
+ }
42
+ };
43
+ });
44
+
45
+ export { unplugin as default };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index.cjs');
4
+ require('unplugin');
5
+
6
+ const rollup = index.rollup;
7
+
8
+ module.exports = rollup;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export { _default as default };
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
@@ -0,0 +1,6 @@
1
+ import unplugin from './index.mjs';
2
+ import 'unplugin';
3
+
4
+ const rollup = unplugin.rollup;
5
+
6
+ export { rollup as default };
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ const vue = require('vue');
4
+
5
+ const VersionChecker = vue.defineComponent({
6
+ name: "VersionChecker",
7
+ props: {
8
+ metaFileName: { type: String, default: "meta.json" },
9
+ storageKey: { type: String, default: "app-version" },
10
+ interval: { type: Number, default: 6e4 }
11
+ },
12
+ setup(props) {
13
+ const show = vue.ref(false);
14
+ let timer;
15
+ const check = async () => {
16
+ try {
17
+ const url = `/${props.metaFileName}?t=${Date.now()}`;
18
+ const res = await fetch(url);
19
+ const { buildTime: latest } = await res.json();
20
+ const local = localStorage.getItem(props.storageKey);
21
+ if (local && local !== latest) show.value = true;
22
+ localStorage.setItem(props.storageKey, latest);
23
+ } catch {
24
+ }
25
+ };
26
+ vue.onMounted(() => {
27
+ check();
28
+ timer = setInterval(check, props.interval);
29
+ });
30
+ vue.onUnmounted(() => clearInterval(timer));
31
+ return { show, refresh: () => location.reload(true), dismiss: () => show.value = false };
32
+ },
33
+ render() {
34
+ if (!this.show) return null;
35
+ return vue.h("div", { class: "version-update-notification" }, [
36
+ vue.h("span", { class: "message" }, "\u{1F4C4} \u5185\u5BB9\u5DF2\u66F4\u65B0\uFF0C\u8BF7\u5237\u65B0\u9875\u9762"),
37
+ vue.h("div", { class: "actions" }, [
38
+ vue.h("button", { class: "refresh", onClick: this.refresh }, "\u5237\u65B0"),
39
+ vue.h("button", { class: "dismiss", onClick: this.dismiss }, "\u5FFD\u7565")
40
+ ])
41
+ ]);
42
+ }
43
+ });
44
+
45
+ exports.VersionChecker = VersionChecker;
@@ -0,0 +1,3 @@
1
+ declare const VersionChecker: any;
2
+
3
+ export { VersionChecker };
@@ -0,0 +1,3 @@
1
+ declare const VersionChecker: any;
2
+
3
+ export { VersionChecker };
@@ -0,0 +1,3 @@
1
+ declare const VersionChecker: any;
2
+
3
+ export { VersionChecker };
@@ -0,0 +1,43 @@
1
+ import { defineComponent, h, ref, onMounted, onUnmounted } from 'vue';
2
+
3
+ const VersionChecker = defineComponent({
4
+ name: "VersionChecker",
5
+ props: {
6
+ metaFileName: { type: String, default: "meta.json" },
7
+ storageKey: { type: String, default: "app-version" },
8
+ interval: { type: Number, default: 6e4 }
9
+ },
10
+ setup(props) {
11
+ const show = ref(false);
12
+ let timer;
13
+ const check = async () => {
14
+ try {
15
+ const url = `/${props.metaFileName}?t=${Date.now()}`;
16
+ const res = await fetch(url);
17
+ const { buildTime: latest } = await res.json();
18
+ const local = localStorage.getItem(props.storageKey);
19
+ if (local && local !== latest) show.value = true;
20
+ localStorage.setItem(props.storageKey, latest);
21
+ } catch {
22
+ }
23
+ };
24
+ onMounted(() => {
25
+ check();
26
+ timer = setInterval(check, props.interval);
27
+ });
28
+ onUnmounted(() => clearInterval(timer));
29
+ return { show, refresh: () => location.reload(true), dismiss: () => show.value = false };
30
+ },
31
+ render() {
32
+ if (!this.show) return null;
33
+ return h("div", { class: "version-update-notification" }, [
34
+ h("span", { class: "message" }, "\u{1F4C4} \u5185\u5BB9\u5DF2\u66F4\u65B0\uFF0C\u8BF7\u5237\u65B0\u9875\u9762"),
35
+ h("div", { class: "actions" }, [
36
+ h("button", { class: "refresh", onClick: this.refresh }, "\u5237\u65B0"),
37
+ h("button", { class: "dismiss", onClick: this.dismiss }, "\u5FFD\u7565")
38
+ ])
39
+ ]);
40
+ }
41
+ });
42
+
43
+ export { VersionChecker };
package/dist/vite.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index.cjs');
4
+ require('unplugin');
5
+
6
+ const vite = index.vite;
7
+
8
+ module.exports = vite;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export { _default as default };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
package/dist/vite.mjs ADDED
@@ -0,0 +1,6 @@
1
+ import unplugin from './index.mjs';
2
+ import 'unplugin';
3
+
4
+ const vite = unplugin.vite;
5
+
6
+ export { vite as default };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ const index = require('./index.cjs');
4
+ require('unplugin');
5
+
6
+ const webpack = index.webpack;
7
+
8
+ module.exports = webpack;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export { _default as default };
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+
3
+ export = _default;
@@ -0,0 +1,6 @@
1
+ import unplugin from './index.mjs';
2
+ import 'unplugin';
3
+
4
+ const webpack = unplugin.webpack;
5
+
6
+ export { webpack as default };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "unplugin-version-checker",
3
+ "version": "1.0.0",
4
+ "description": "Universal build plugin + Vue component for app version checking",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "src",
9
+ "runtime.js"
10
+ ],
11
+ "main": "dist/index.js",
12
+ "module": "dist/index.js",
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs"
17
+ },
18
+ "./vite": {
19
+ "import": "./dist/vite.js",
20
+ "require": "./dist/vite.cjs"
21
+ },
22
+ "./webpack": {
23
+ "import": "./dist/webpack.js",
24
+ "require": "./dist/webpack.cjs"
25
+ },
26
+ "./rollup": {
27
+ "import": "./dist/rollup.js",
28
+ "require": "./dist/rollup.cjs"
29
+ },
30
+ "./runtime": {
31
+ "import": "./dist/runtime.js",
32
+ "require": "./dist/runtime.cjs"
33
+ }
34
+ },
35
+ "peerDependencies": {
36
+ "vue": "^3.2.0"
37
+ },
38
+ "devDependencies": {
39
+ "esbuild": "^0.20.0",
40
+ "rollup": "^4.0.0",
41
+ "unbuild": "^3.6.1",
42
+ "unplugin": "^1.16.1",
43
+ "vite": "^5.0.0",
44
+ "vue": "^3.5.28",
45
+ "webpack": "^5.0.0"
46
+ },
47
+ "scripts": {
48
+ "build": "unbuild",
49
+ "prepublishOnly": "npm run build"
50
+ }
51
+ }
package/src/esbuild.ts ADDED
@@ -0,0 +1,2 @@
1
+ import unplugin from './index'
2
+ export default unplugin.esbuild
package/src/index.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { createUnplugin } from 'unplugin'
2
+ import type { Options } from './types'
3
+
4
+ export default createUnplugin<Options | undefined>((options = {}) => {
5
+ const {
6
+ metaFileName = 'meta.json',
7
+ generateOnBuild = true,
8
+ devMock = true,
9
+ injectComponent = false, // 由于跨构建工具自动注入组件复杂,建议用户手动注册组件
10
+ } = options
11
+
12
+ return {
13
+ name: 'unplugin-version-checker',
14
+ enforce: 'post',
15
+
16
+ writeBundle() {
17
+ if (!generateOnBuild) return
18
+ const versionInfo = {
19
+ buildTime: new Date().toISOString(),
20
+ version: process.env.BUILD_ID || process.env.npm_package_version,
21
+ commitHash: process.env.COMMIT_SHORT || process.env.GIT_COMMIT_SHORT,
22
+ }
23
+ this.emitFile({
24
+ type: 'asset',
25
+ fileName: metaFileName,
26
+ source: JSON.stringify(versionInfo, null, 2),
27
+ })
28
+ },
29
+
30
+ configureServer(server) {
31
+ if (!devMock) return
32
+ server.middlewares.use((req, res, next) => {
33
+ if (req.url === `/${metaFileName}`) {
34
+ res.setHeader('Content-Type', 'application/json')
35
+ res.end(JSON.stringify({
36
+ buildTime: new Date().toISOString(),
37
+ version: 'dev',
38
+ commitHash: 'dev',
39
+ }))
40
+ return
41
+ }
42
+ next()
43
+ })
44
+ }
45
+ }
46
+ })
package/src/rollup.ts ADDED
@@ -0,0 +1,2 @@
1
+ import unplugin from './index'
2
+ export default unplugin.rollup
package/src/runtime.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { defineComponent, ref, onMounted, onUnmounted, h } from 'vue'
2
+
3
+ export const VersionChecker = defineComponent({
4
+ name: 'VersionChecker',
5
+ props: {
6
+ metaFileName: { type: String, default: 'meta.json' },
7
+ storageKey: { type: String, default: 'app-version' },
8
+ interval: { type: Number, default: 60000 },
9
+ },
10
+ setup(props) {
11
+ const show = ref(false)
12
+ let timer: ReturnType<typeof setInterval>
13
+
14
+ const check = async () => {
15
+ try {
16
+ const url = `/${props.metaFileName}?t=${Date.now()}`
17
+ const res = await fetch(url)
18
+ const { buildTime: latest } = await res.json()
19
+ const local = localStorage.getItem(props.storageKey)
20
+ if (local && local !== latest) show.value = true
21
+ localStorage.setItem(props.storageKey, latest)
22
+ } catch {}
23
+ }
24
+
25
+ onMounted(() => {
26
+ check()
27
+ timer = setInterval(check, props.interval)
28
+ })
29
+ onUnmounted(() => clearInterval(timer))
30
+
31
+ return { show, refresh: () => location.reload(true), dismiss: () => show.value = false }
32
+ },
33
+ render() {
34
+ if (!this.show) return null
35
+ return h('div', { class: 'version-update-notification' }, [
36
+ h('span', { class: 'message' }, '📄 内容已更新,请刷新页面'),
37
+ h('div', { class: 'actions' }, [
38
+ h('button', { class: 'refresh', onClick: this.refresh }, '刷新'),
39
+ h('button', { class: 'dismiss', onClick: this.dismiss }, '忽略')
40
+ ])
41
+ ])
42
+ }
43
+ })
package/src/types.ts ADDED
@@ -0,0 +1,6 @@
1
+ export interface Options {
2
+ metaFileName?: string
3
+ generateOnBuild?: boolean
4
+ devMock?: boolean
5
+ injectComponent?: boolean
6
+ }
package/src/vite.ts ADDED
@@ -0,0 +1,2 @@
1
+ import unplugin from './index'
2
+ export default unplugin.vite
package/src/webpack.ts ADDED
@@ -0,0 +1,2 @@
1
+ import unplugin from './index'
2
+ export default unplugin.webpack