vite-plugin-version-info 1.0.0 → 1.1.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 +7 -0
- package/dist/index.cjs +10 -11
- package/dist/index.d.ts +7 -1
- package/dist/index.mjs +10 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,6 +56,13 @@ export default defineConfig({
|
|
|
56
56
|
});
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
If using typescript, define the exposed constants in a separate `src/globals.d.ts` file:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
declare const __APP_VERSION__: string;
|
|
63
|
+
declare const __COMMIT_DATE__: string;
|
|
64
|
+
```
|
|
65
|
+
|
|
59
66
|
Then use the global constants injected by the plugin anywhere in your app:
|
|
60
67
|
|
|
61
68
|
```ts
|
package/dist/index.cjs
CHANGED
|
@@ -59,21 +59,20 @@ function getCurrentBranchName() {
|
|
|
59
59
|
function getCommitHash(short) {
|
|
60
60
|
return runCommand(`git rev-parse${short ? " --short" : ""} HEAD`);
|
|
61
61
|
}
|
|
62
|
-
function getVersionString({
|
|
63
|
-
commitHashLength,
|
|
64
|
-
noLicenseSuffix,
|
|
65
|
-
pattern
|
|
66
|
-
}) {
|
|
62
|
+
function getVersionString({ commitHashLength, noLicenseSuffix, pattern }, { commitHash, gitBranch }) {
|
|
67
63
|
const { version, license } = readPackageJson();
|
|
68
|
-
const currentBranch = getCurrentBranchName();
|
|
64
|
+
const currentBranch = gitBranch ?? getCurrentBranchName();
|
|
69
65
|
const licenseSuffix = license ? "" : noLicenseSuffix;
|
|
70
|
-
const
|
|
66
|
+
const slicedCommitHash = sliceCommitHash(
|
|
67
|
+
commitHash ?? getCommitHash(commitHashLength < 8),
|
|
68
|
+
commitHashLength
|
|
69
|
+
);
|
|
71
70
|
const branchSuffix = getBranchSuffix();
|
|
72
71
|
const context = {
|
|
73
72
|
version,
|
|
74
73
|
noLicenseSuffix: licenseSuffix,
|
|
75
74
|
currentBranch,
|
|
76
|
-
commitHash,
|
|
75
|
+
commitHash: slicedCommitHash,
|
|
77
76
|
branchSuffix
|
|
78
77
|
};
|
|
79
78
|
return formatVersionString(pattern, context);
|
|
@@ -99,7 +98,7 @@ function plugin({
|
|
|
99
98
|
} = {}) {
|
|
100
99
|
return {
|
|
101
100
|
name: "vite-plugin-version-info",
|
|
102
|
-
config() {
|
|
101
|
+
config(pluginParameters) {
|
|
103
102
|
return {
|
|
104
103
|
define: {
|
|
105
104
|
__APP_VERSION__: JSON.stringify(
|
|
@@ -107,10 +106,10 @@ function plugin({
|
|
|
107
106
|
commitHashLength: commitHashLength ?? 8,
|
|
108
107
|
noLicenseSuffix: noLicenseSuffix ?? "-nonfree",
|
|
109
108
|
pattern: pattern ?? "{version}{noLicenseSuffix} {currentBranch}-{commitHash}{branchSuffix}"
|
|
110
|
-
})
|
|
109
|
+
}, pluginParameters)
|
|
111
110
|
),
|
|
112
111
|
__COMMIT_DATE__: JSON.stringify(
|
|
113
|
-
getCommitDate({
|
|
112
|
+
pluginParameters.commitDate ?? getCommitDate({
|
|
114
113
|
locale: locale ?? "en-US",
|
|
115
114
|
intlOptions: intlOptions ?? {
|
|
116
115
|
dateStyle: "long"
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ type VersionStringOptions = {
|
|
|
33
33
|
*/
|
|
34
34
|
type VersionInfoPluginOptions = CommitDateOptions & VersionStringOptions;
|
|
35
35
|
|
|
36
|
+
type VersionInfoParameters = {
|
|
37
|
+
commitHash?: string;
|
|
38
|
+
gitBranch?: string;
|
|
39
|
+
commitDate?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
36
42
|
/**
|
|
37
43
|
* Vite plugin that injects Git version info and commit metadata into your frontend app.
|
|
38
44
|
*
|
|
@@ -49,7 +55,7 @@ type VersionInfoPluginOptions = CommitDateOptions & VersionStringOptions;
|
|
|
49
55
|
*/
|
|
50
56
|
declare function plugin({ locale, commitHashLength, intlOptions, noLicenseSuffix, pattern, }?: VersionInfoPluginOptions): {
|
|
51
57
|
name: string;
|
|
52
|
-
config(): {
|
|
58
|
+
config(pluginParameters: VersionInfoParameters): {
|
|
53
59
|
define: {
|
|
54
60
|
__APP_VERSION__: string;
|
|
55
61
|
__COMMIT_DATE__: string;
|
package/dist/index.mjs
CHANGED
|
@@ -35,21 +35,20 @@ function getCurrentBranchName() {
|
|
|
35
35
|
function getCommitHash(short) {
|
|
36
36
|
return runCommand(`git rev-parse${short ? " --short" : ""} HEAD`);
|
|
37
37
|
}
|
|
38
|
-
function getVersionString({
|
|
39
|
-
commitHashLength,
|
|
40
|
-
noLicenseSuffix,
|
|
41
|
-
pattern
|
|
42
|
-
}) {
|
|
38
|
+
function getVersionString({ commitHashLength, noLicenseSuffix, pattern }, { commitHash, gitBranch }) {
|
|
43
39
|
const { version, license } = readPackageJson();
|
|
44
|
-
const currentBranch = getCurrentBranchName();
|
|
40
|
+
const currentBranch = gitBranch ?? getCurrentBranchName();
|
|
45
41
|
const licenseSuffix = license ? "" : noLicenseSuffix;
|
|
46
|
-
const
|
|
42
|
+
const slicedCommitHash = sliceCommitHash(
|
|
43
|
+
commitHash ?? getCommitHash(commitHashLength < 8),
|
|
44
|
+
commitHashLength
|
|
45
|
+
);
|
|
47
46
|
const branchSuffix = getBranchSuffix();
|
|
48
47
|
const context = {
|
|
49
48
|
version,
|
|
50
49
|
noLicenseSuffix: licenseSuffix,
|
|
51
50
|
currentBranch,
|
|
52
|
-
commitHash,
|
|
51
|
+
commitHash: slicedCommitHash,
|
|
53
52
|
branchSuffix
|
|
54
53
|
};
|
|
55
54
|
return formatVersionString(pattern, context);
|
|
@@ -75,7 +74,7 @@ function plugin({
|
|
|
75
74
|
} = {}) {
|
|
76
75
|
return {
|
|
77
76
|
name: "vite-plugin-version-info",
|
|
78
|
-
config() {
|
|
77
|
+
config(pluginParameters) {
|
|
79
78
|
return {
|
|
80
79
|
define: {
|
|
81
80
|
__APP_VERSION__: JSON.stringify(
|
|
@@ -83,10 +82,10 @@ function plugin({
|
|
|
83
82
|
commitHashLength: commitHashLength ?? 8,
|
|
84
83
|
noLicenseSuffix: noLicenseSuffix ?? "-nonfree",
|
|
85
84
|
pattern: pattern ?? "{version}{noLicenseSuffix} {currentBranch}-{commitHash}{branchSuffix}"
|
|
86
|
-
})
|
|
85
|
+
}, pluginParameters)
|
|
87
86
|
),
|
|
88
87
|
__COMMIT_DATE__: JSON.stringify(
|
|
89
|
-
getCommitDate({
|
|
88
|
+
pluginParameters.commitDate ?? getCommitDate({
|
|
90
89
|
locale: locale ?? "en-US",
|
|
91
90
|
intlOptions: intlOptions ?? {
|
|
92
91
|
dateStyle: "long"
|
package/package.json
CHANGED