unplugin-version-injector 1.1.1-alpha.5 → 1.1.2-beta.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 +66 -110
- package/README.zh-CN.md +66 -109
- package/dist/rollup.d.mts +11 -0
- package/dist/rollup.d.ts +11 -0
- package/dist/rollup.js +72 -0
- package/dist/rollup.mjs +65 -0
- package/dist/vite.d.mts +5 -0
- package/dist/vite.d.ts +5 -0
- package/dist/vite.js +64 -0
- package/dist/vite.mjs +57 -0
- package/dist/webpack.d.mts +5 -4
- package/dist/webpack.d.ts +5 -4
- package/dist/webpack.js +54 -119
- package/dist/webpack.mjs +44 -90
- package/package.json +30 -25
- package/dist/core.d.mts +0 -6
- package/dist/core.d.ts +0 -6
- package/dist/core.js +0 -140
- package/dist/core.mjs +0 -112
- package/dist/types-DEOBLqEx.d.mts +0 -9
- package/dist/types-DEOBLqEx.d.ts +0 -9
package/dist/core.js
DELETED
@@ -1,140 +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/core.ts
|
31
|
-
var core_exports = {};
|
32
|
-
__export(core_exports, {
|
33
|
-
default: () => core_default,
|
34
|
-
versionInjectorPlugin: () => versionInjectorPlugin
|
35
|
-
});
|
36
|
-
module.exports = __toCommonJS(core_exports);
|
37
|
-
var import_unplugin = require("unplugin");
|
38
|
-
|
39
|
-
// src/utils.ts
|
40
|
-
var import_node_fs = __toESM(require("fs"));
|
41
|
-
var import_node_path = __toESM(require("path"));
|
42
|
-
var import_node_url = require("url");
|
43
|
-
var import_meta = {};
|
44
|
-
function getCurrentDir() {
|
45
|
-
try {
|
46
|
-
return import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
47
|
-
} catch (e) {
|
48
|
-
return process.cwd();
|
49
|
-
}
|
50
|
-
}
|
51
|
-
function getPackageVersion() {
|
52
|
-
var _a;
|
53
|
-
try {
|
54
|
-
let dir = getCurrentDir();
|
55
|
-
while (dir !== import_node_path.default.parse(dir).root) {
|
56
|
-
const pkgPath = import_node_path.default.join(dir, "package.json");
|
57
|
-
if (import_node_fs.default.existsSync(pkgPath)) {
|
58
|
-
const content = import_node_fs.default.readFileSync(pkgPath, "utf-8");
|
59
|
-
const pkg = JSON.parse(content);
|
60
|
-
return (_a = pkg.version) != null ? _a : "0.0.0";
|
61
|
-
}
|
62
|
-
dir = import_node_path.default.dirname(dir);
|
63
|
-
}
|
64
|
-
console.warn("[VersionInjector] package.json not found");
|
65
|
-
return "0.0.0";
|
66
|
-
} catch (err) {
|
67
|
-
console.warn("[VersionInjector] Failed to read package.json:", err);
|
68
|
-
return "0.0.0";
|
69
|
-
}
|
70
|
-
}
|
71
|
-
function defaultFormatDate(date) {
|
72
|
-
return date.toISOString();
|
73
|
-
}
|
74
|
-
|
75
|
-
// src/core.ts
|
76
|
-
var dayjs;
|
77
|
-
var versionInjectorPlugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
78
|
-
const {
|
79
|
-
version = getPackageVersion(),
|
80
|
-
formatDate,
|
81
|
-
dateFormat,
|
82
|
-
injectToHead = true,
|
83
|
-
injectToBody = true
|
84
|
-
} = options;
|
85
|
-
let resolvedFormatDate = defaultFormatDate;
|
86
|
-
if (typeof formatDate === "function") {
|
87
|
-
resolvedFormatDate = formatDate;
|
88
|
-
} else if (typeof dateFormat === "string") {
|
89
|
-
try {
|
90
|
-
dayjs = require("dayjs");
|
91
|
-
resolvedFormatDate = (d) => dayjs(d).format(dateFormat);
|
92
|
-
} catch (err) {
|
93
|
-
console.warn("[unplugin-version-injector] To use `dateFormat`, please install `dayjs` manually.");
|
94
|
-
}
|
95
|
-
}
|
96
|
-
if (!injectToHead && !injectToBody) {
|
97
|
-
return { name: "unplugin-version-injector" };
|
98
|
-
}
|
99
|
-
const buildTime = resolvedFormatDate(/* @__PURE__ */ new Date());
|
100
|
-
const metaTag = `<meta name="version" content="${version}">
|
101
|
-
`;
|
102
|
-
const logScript = `
|
103
|
-
<script>
|
104
|
-
console.log("%c Version: ${version} ", "background: #222; color: #00ff00; font-size: 12px; padding: 4px; border-radius: 4px;");
|
105
|
-
console.log("%c Build Time: ${buildTime} ", "background: #222; color: #ffcc00; font-size: 12px; padding: 4px; border-radius: 4px;");
|
106
|
-
</script>`;
|
107
|
-
function processHtml(html) {
|
108
|
-
if (injectToHead && !html.includes('<meta name="version"')) {
|
109
|
-
html = html.replace(/<head>/, `<head>
|
110
|
-
${metaTag}`);
|
111
|
-
}
|
112
|
-
if (injectToBody && !html.includes('<script>console.log("%c Version:')) {
|
113
|
-
html = html.replace("</body>", ` ${logScript}
|
114
|
-
</body>`);
|
115
|
-
}
|
116
|
-
return html;
|
117
|
-
}
|
118
|
-
return {
|
119
|
-
name: "unplugin-version-injector",
|
120
|
-
vite: {
|
121
|
-
transformIndexHtml(html) {
|
122
|
-
return processHtml(html);
|
123
|
-
}
|
124
|
-
},
|
125
|
-
rollup: {
|
126
|
-
generateBundle(_, bundle) {
|
127
|
-
for (const file of Object.values(bundle)) {
|
128
|
-
if (file.type === "asset" && file.fileName.endsWith(".html")) {
|
129
|
-
file.source = processHtml(file.source);
|
130
|
-
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
}
|
134
|
-
};
|
135
|
-
});
|
136
|
-
var core_default = versionInjectorPlugin;
|
137
|
-
// Annotate the CommonJS export names for ESM import in node:
|
138
|
-
0 && (module.exports = {
|
139
|
-
versionInjectorPlugin
|
140
|
-
});
|
package/dist/core.mjs
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
3
|
-
}) : x)(function(x) {
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
6
|
-
});
|
7
|
-
|
8
|
-
// src/core.ts
|
9
|
-
import { createUnplugin } from "unplugin";
|
10
|
-
|
11
|
-
// src/utils.ts
|
12
|
-
import fs from "node:fs";
|
13
|
-
import path from "node:path";
|
14
|
-
import { fileURLToPath } from "node:url";
|
15
|
-
var import_meta = {};
|
16
|
-
function getCurrentDir() {
|
17
|
-
try {
|
18
|
-
return path.dirname(fileURLToPath(import_meta.url));
|
19
|
-
} catch (e) {
|
20
|
-
return process.cwd();
|
21
|
-
}
|
22
|
-
}
|
23
|
-
function getPackageVersion() {
|
24
|
-
var _a;
|
25
|
-
try {
|
26
|
-
let dir = getCurrentDir();
|
27
|
-
while (dir !== path.parse(dir).root) {
|
28
|
-
const pkgPath = path.join(dir, "package.json");
|
29
|
-
if (fs.existsSync(pkgPath)) {
|
30
|
-
const content = fs.readFileSync(pkgPath, "utf-8");
|
31
|
-
const pkg = JSON.parse(content);
|
32
|
-
return (_a = pkg.version) != null ? _a : "0.0.0";
|
33
|
-
}
|
34
|
-
dir = path.dirname(dir);
|
35
|
-
}
|
36
|
-
console.warn("[VersionInjector] package.json not found");
|
37
|
-
return "0.0.0";
|
38
|
-
} catch (err) {
|
39
|
-
console.warn("[VersionInjector] Failed to read package.json:", err);
|
40
|
-
return "0.0.0";
|
41
|
-
}
|
42
|
-
}
|
43
|
-
function defaultFormatDate(date) {
|
44
|
-
return date.toISOString();
|
45
|
-
}
|
46
|
-
|
47
|
-
// src/core.ts
|
48
|
-
var dayjs;
|
49
|
-
var versionInjectorPlugin = createUnplugin((options = {}) => {
|
50
|
-
const {
|
51
|
-
version = getPackageVersion(),
|
52
|
-
formatDate,
|
53
|
-
dateFormat,
|
54
|
-
injectToHead = true,
|
55
|
-
injectToBody = true
|
56
|
-
} = options;
|
57
|
-
let resolvedFormatDate = defaultFormatDate;
|
58
|
-
if (typeof formatDate === "function") {
|
59
|
-
resolvedFormatDate = formatDate;
|
60
|
-
} else if (typeof dateFormat === "string") {
|
61
|
-
try {
|
62
|
-
dayjs = __require("dayjs");
|
63
|
-
resolvedFormatDate = (d) => dayjs(d).format(dateFormat);
|
64
|
-
} catch (err) {
|
65
|
-
console.warn("[unplugin-version-injector] To use `dateFormat`, please install `dayjs` manually.");
|
66
|
-
}
|
67
|
-
}
|
68
|
-
if (!injectToHead && !injectToBody) {
|
69
|
-
return { name: "unplugin-version-injector" };
|
70
|
-
}
|
71
|
-
const buildTime = resolvedFormatDate(/* @__PURE__ */ new Date());
|
72
|
-
const metaTag = `<meta name="version" content="${version}">
|
73
|
-
`;
|
74
|
-
const logScript = `
|
75
|
-
<script>
|
76
|
-
console.log("%c Version: ${version} ", "background: #222; color: #00ff00; font-size: 12px; padding: 4px; border-radius: 4px;");
|
77
|
-
console.log("%c Build Time: ${buildTime} ", "background: #222; color: #ffcc00; font-size: 12px; padding: 4px; border-radius: 4px;");
|
78
|
-
</script>`;
|
79
|
-
function processHtml(html) {
|
80
|
-
if (injectToHead && !html.includes('<meta name="version"')) {
|
81
|
-
html = html.replace(/<head>/, `<head>
|
82
|
-
${metaTag}`);
|
83
|
-
}
|
84
|
-
if (injectToBody && !html.includes('<script>console.log("%c Version:')) {
|
85
|
-
html = html.replace("</body>", ` ${logScript}
|
86
|
-
</body>`);
|
87
|
-
}
|
88
|
-
return html;
|
89
|
-
}
|
90
|
-
return {
|
91
|
-
name: "unplugin-version-injector",
|
92
|
-
vite: {
|
93
|
-
transformIndexHtml(html) {
|
94
|
-
return processHtml(html);
|
95
|
-
}
|
96
|
-
},
|
97
|
-
rollup: {
|
98
|
-
generateBundle(_, bundle) {
|
99
|
-
for (const file of Object.values(bundle)) {
|
100
|
-
if (file.type === "asset" && file.fileName.endsWith(".html")) {
|
101
|
-
file.source = processHtml(file.source);
|
102
|
-
}
|
103
|
-
}
|
104
|
-
}
|
105
|
-
}
|
106
|
-
};
|
107
|
-
});
|
108
|
-
var core_default = versionInjectorPlugin;
|
109
|
-
export {
|
110
|
-
core_default as default,
|
111
|
-
versionInjectorPlugin
|
112
|
-
};
|