unplugin-build-meta 0.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/LICENSE +21 -0
- package/README.md +253 -0
- package/dist/astro.cjs +21 -0
- package/dist/astro.d.cts +20 -0
- package/dist/astro.d.ts +20 -0
- package/dist/astro.mjs +21 -0
- package/dist/chunk-2TPIXTEW.cjs +154 -0
- package/dist/chunk-BJB5XFUG.mjs +11 -0
- package/dist/chunk-FH2TLW2E.cjs +11 -0
- package/dist/chunk-MMKRPHVS.mjs +154 -0
- package/dist/chunk-RJEZ2A3A.mjs +8 -0
- package/dist/chunk-SSXJV7C2.cjs +8 -0
- package/dist/chunk-VL4NLRZW.cjs +11 -0
- package/dist/chunk-YRRFFWQG.mjs +11 -0
- package/dist/esbuild.cjs +11 -0
- package/dist/esbuild.d.cts +20 -0
- package/dist/esbuild.d.ts +20 -0
- package/dist/esbuild.mjs +11 -0
- package/dist/farm.cjs +11 -0
- package/dist/farm.d.cts +19 -0
- package/dist/farm.d.ts +19 -0
- package/dist/farm.mjs +11 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.mjs +9 -0
- package/dist/module.cjs +6 -0
- package/dist/module.d.cts +13 -0
- package/dist/module.d.ts +13 -0
- package/dist/module.mjs +6 -0
- package/dist/nuxt.cjs +31 -0
- package/dist/nuxt.d.cts +20 -0
- package/dist/nuxt.d.ts +20 -0
- package/dist/nuxt.mjs +31 -0
- package/dist/rolldown.cjs +11 -0
- package/dist/rolldown.d.cts +20 -0
- package/dist/rolldown.d.ts +20 -0
- package/dist/rolldown.mjs +11 -0
- package/dist/rollup.cjs +11 -0
- package/dist/rollup.d.cts +20 -0
- package/dist/rollup.d.ts +20 -0
- package/dist/rollup.mjs +11 -0
- package/dist/rspack.cjs +11 -0
- package/dist/rspack.d.cts +24 -0
- package/dist/rspack.d.ts +24 -0
- package/dist/rspack.mjs +11 -0
- package/dist/types-dRhtxdLo.d.cts +16 -0
- package/dist/types-dRhtxdLo.d.ts +16 -0
- package/dist/vite.cjs +8 -0
- package/dist/vite.d.cts +20 -0
- package/dist/vite.d.ts +20 -0
- package/dist/vite.mjs +8 -0
- package/dist/webpack.cjs +8 -0
- package/dist/webpack.d.cts +18 -0
- package/dist/webpack.d.ts +18 -0
- package/dist/webpack.mjs +8 -0
- package/package.json +225 -0
- package/types/git.d.ts +19 -0
- package/types/index.d.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-PRESENT Lucas Nørgård
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# unplugin-build-meta
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
|
|
6
|
+
Import build metadata into your JavaScript/TypeScript projects for Vite, Webpack, Rollup, esbuild and more. Powered by [unplugin](https://github.com/unjs/unplugin).
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<br />
|
|
10
|
+
<a href="https://stackblitz.com/github/luxass/unplugin-build-meta/tree/main/examples/vite-vue?file=vite.config.ts"><img src="https://developer.stackblitz.com/img/open_in_stackblitz.svg" /></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -D unplugin-build-meta
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
> [!TIP]
|
|
22
|
+
> You can view all examples [here](./examples).
|
|
23
|
+
|
|
24
|
+
<details>
|
|
25
|
+
<summary>Vite</summary><br/>
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// vite.config.ts
|
|
29
|
+
import buildMeta from "unplugin-build-meta/vite";
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
plugins: [
|
|
33
|
+
buildMeta({ /* options */ }),
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
<br/></details>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary>Rollup</summary><br/>
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// rollup.config.js
|
|
45
|
+
import buildMeta from "unplugin-build-meta/rollup";
|
|
46
|
+
|
|
47
|
+
export default {
|
|
48
|
+
plugins: [
|
|
49
|
+
buildMeta({ /* options */ }),
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
<br/></details>
|
|
55
|
+
|
|
56
|
+
<details>
|
|
57
|
+
<summary>Webpack</summary><br/>
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// webpack.config.js
|
|
61
|
+
module.exports = {
|
|
62
|
+
/* ... */
|
|
63
|
+
plugins: [
|
|
64
|
+
require("unplugin-build-meta/webpack").default({ /* options */ }),
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
<br/></details>
|
|
70
|
+
|
|
71
|
+
<details>
|
|
72
|
+
<summary>Nuxt</summary><br/>
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
// nuxt.config.js
|
|
76
|
+
export default defineNuxtConfig({
|
|
77
|
+
modules: [
|
|
78
|
+
["unplugin-build-meta/nuxt", { /* options */ }]
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
<br/></details>
|
|
84
|
+
|
|
85
|
+
<details>
|
|
86
|
+
<summary>Astro</summary><br/>
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// astro.config.mjs
|
|
90
|
+
import { defineConfig } from "astro/config";
|
|
91
|
+
import buildMeta from "unplugin-build-meta/astro";
|
|
92
|
+
|
|
93
|
+
// https://astro.build/config
|
|
94
|
+
export default defineConfig({
|
|
95
|
+
integrations: [
|
|
96
|
+
buildMeta({
|
|
97
|
+
/* options */
|
|
98
|
+
})
|
|
99
|
+
]
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
<br/></details>
|
|
104
|
+
|
|
105
|
+
<details>
|
|
106
|
+
<summary>esbuild</summary><br/>
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
// esbuild.config.js
|
|
110
|
+
import { build } from "esbuild";
|
|
111
|
+
import buildMeta from "unplugin-build-meta/esbuild";
|
|
112
|
+
|
|
113
|
+
build({
|
|
114
|
+
/* ... */
|
|
115
|
+
plugins: [
|
|
116
|
+
buildMeta({
|
|
117
|
+
/* options */
|
|
118
|
+
}),
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
<br/></details>
|
|
124
|
+
|
|
125
|
+
<details>
|
|
126
|
+
<summary>Farm</summary><br/>
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
// farm.config.ts
|
|
130
|
+
import { defineConfig } from "@farmfe/core";
|
|
131
|
+
import vue from "@vitejs/plugin-vue";
|
|
132
|
+
import buildMeta from "unplugin-build-meta/farm";
|
|
133
|
+
|
|
134
|
+
export default defineConfig({
|
|
135
|
+
vitePlugins: [
|
|
136
|
+
vue(),
|
|
137
|
+
],
|
|
138
|
+
plugins: [
|
|
139
|
+
buildMeta({
|
|
140
|
+
/* options */
|
|
141
|
+
})
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
<br/></details>
|
|
147
|
+
|
|
148
|
+
<details>
|
|
149
|
+
<summary>Rspack</summary><br/>
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
// rspack.config.mjs
|
|
153
|
+
import rspack from "@rspack/core";
|
|
154
|
+
import buildMeta from "unplugin-build-meta/rspack";
|
|
155
|
+
|
|
156
|
+
/** @type {import('@rspack/core').Configuration} */
|
|
157
|
+
export default {
|
|
158
|
+
plugins: [
|
|
159
|
+
new rspack.HtmlRspackPlugin({
|
|
160
|
+
template: "./index.html"
|
|
161
|
+
}),
|
|
162
|
+
buildMeta()
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
<br/></details>
|
|
168
|
+
|
|
169
|
+
<details>
|
|
170
|
+
<summary>Rolldown (Experimental)</summary><br/>
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
// rolldown.config.js
|
|
174
|
+
import { defineConfig } from "rolldown";
|
|
175
|
+
import buildMeta from "unplugin-build-meta/rolldown";
|
|
176
|
+
|
|
177
|
+
export default defineConfig({
|
|
178
|
+
input: "./index.js",
|
|
179
|
+
plugins: [
|
|
180
|
+
buildMeta({
|
|
181
|
+
/* options */
|
|
182
|
+
}),
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
<br/></details>
|
|
188
|
+
|
|
189
|
+
## Configuration
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
buildMeta({
|
|
193
|
+
modules: ["git"] // Configure which modules to include
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Modules
|
|
198
|
+
|
|
199
|
+
### Git Module
|
|
200
|
+
|
|
201
|
+
The git module provides access to repository metadata from your code.
|
|
202
|
+
|
|
203
|
+
Import it in your code:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
// Import all git metadata
|
|
207
|
+
import * as git from "virtual:build-meta/git";
|
|
208
|
+
|
|
209
|
+
// Or import specific values
|
|
210
|
+
import { branch, sha, shortSha } from "virtual:build-meta/git";
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Available properties (all properties are nullable):
|
|
214
|
+
|
|
215
|
+
| Property | Type | Description |
|
|
216
|
+
|----------|------|-------------|
|
|
217
|
+
| `branch` | `string \| null` | Current git branch name |
|
|
218
|
+
| `sha` | `string \| null` | Full git commit hash |
|
|
219
|
+
| `shortSha` | `string \| null` | First 10 characters of the commit hash |
|
|
220
|
+
| `latestCommitMessage` | `string \| null` | Latest commit message |
|
|
221
|
+
| `commitAuthorName` | `string \| null` | Commit author name |
|
|
222
|
+
| `commitAuthorEmail` | `string \| null` | Commit author email |
|
|
223
|
+
| `commitAuthorDate` | `string \| null` | Commit author date |
|
|
224
|
+
| `commitCommitterName` | `string \| null` | Committer name |
|
|
225
|
+
| `commitCommitterEmail` | `string \| null` | Committer email |
|
|
226
|
+
| `commitCommitterDate` | `string \| null` | Committer date |
|
|
227
|
+
| `tag` | `string \| null` | Current tag (if any) |
|
|
228
|
+
| `tags` | `string[] \| null` | All tags pointing at current commit |
|
|
229
|
+
| `lastTag` | `string \| null` | Latest tag in the repository |
|
|
230
|
+
| `repositoryUrl` | `string \| null` | Repository URL (for GitHub repositories) |
|
|
231
|
+
|
|
232
|
+
### TypeScript
|
|
233
|
+
|
|
234
|
+
To get proper type support, make sure to include the type declarations:
|
|
235
|
+
|
|
236
|
+
```json
|
|
237
|
+
{
|
|
238
|
+
"compilerOptions": {
|
|
239
|
+
"types": [
|
|
240
|
+
"unplugin-build-meta/types"
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 📄 License
|
|
247
|
+
|
|
248
|
+
Published under [MIT License](./LICENSE).
|
|
249
|
+
|
|
250
|
+
[npm-version-src]: https://img.shields.io/npm/v/unplugin-build-meta?style=flat&colorA=18181B&colorB=4169E1
|
|
251
|
+
[npm-version-href]: https://npmjs.com/package/unplugin-build-meta
|
|
252
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/unplugin-build-meta?style=flat&colorA=18181B&colorB=4169E1
|
|
253
|
+
[npm-downloads-href]: https://npmjs.com/package/unplugin-build-meta
|
package/dist/astro.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk2TPIXTEWcjs = require('./chunk-2TPIXTEW.cjs');
|
|
5
|
+
require('./chunk-SSXJV7C2.cjs');
|
|
6
|
+
|
|
7
|
+
// src/astro.ts
|
|
8
|
+
function BuildMetaIntegration(options) {
|
|
9
|
+
return {
|
|
10
|
+
name: _chunk2TPIXTEWcjs.PLUGIN_NAME,
|
|
11
|
+
hooks: {
|
|
12
|
+
"astro:config:setup": async (astro) => {
|
|
13
|
+
astro.config.vite.plugins ||= [];
|
|
14
|
+
astro.config.vite.plugins.push(_chunk2TPIXTEWcjs.unplugin.vite(options));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.default = BuildMetaIntegration;
|
package/dist/astro.d.cts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AstroIntegration } from 'astro';
|
|
2
|
+
import { B as BuildMetaOptions } from './types-dRhtxdLo.cjs';
|
|
3
|
+
import 'unplugin';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Astro integration
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // astro.config.mjs
|
|
11
|
+
* import buildMeta from "unplugin-build-meta/astro"
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* integrations: [buildMeta()],
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function BuildMetaIntegration(options: BuildMetaOptions): AstroIntegration;
|
|
19
|
+
|
|
20
|
+
export { BuildMetaIntegration as default };
|
package/dist/astro.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AstroIntegration } from 'astro';
|
|
2
|
+
import { B as BuildMetaOptions } from './types-dRhtxdLo.js';
|
|
3
|
+
import 'unplugin';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Astro integration
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // astro.config.mjs
|
|
11
|
+
* import buildMeta from "unplugin-build-meta/astro"
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* integrations: [buildMeta()],
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function BuildMetaIntegration(options: BuildMetaOptions): AstroIntegration;
|
|
19
|
+
|
|
20
|
+
export { BuildMetaIntegration as default };
|
package/dist/astro.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PLUGIN_NAME,
|
|
3
|
+
unplugin
|
|
4
|
+
} from "./chunk-MMKRPHVS.mjs";
|
|
5
|
+
import "./chunk-RJEZ2A3A.mjs";
|
|
6
|
+
|
|
7
|
+
// src/astro.ts
|
|
8
|
+
function BuildMetaIntegration(options) {
|
|
9
|
+
return {
|
|
10
|
+
name: PLUGIN_NAME,
|
|
11
|
+
hooks: {
|
|
12
|
+
"astro:config:setup": async (astro) => {
|
|
13
|
+
astro.config.vite.plugins ||= [];
|
|
14
|
+
astro.config.vite.plugins.push(unplugin.vite(options));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
BuildMetaIntegration as default
|
|
21
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkSSXJV7C2cjs = require('./chunk-SSXJV7C2.cjs');
|
|
4
|
+
|
|
5
|
+
// src/core/index.ts
|
|
6
|
+
var _unplugin = require('unplugin');
|
|
7
|
+
|
|
8
|
+
// src/core/constants.ts
|
|
9
|
+
var PLUGIN_NAME = "unplugin-build-meta";
|
|
10
|
+
var NUXT_CONFIG_KEY = "buildMeta";
|
|
11
|
+
|
|
12
|
+
// src/core/modules/git.ts
|
|
13
|
+
var _giturlparse = require('git-url-parse'); var _giturlparse2 = _interopRequireDefault(_giturlparse);
|
|
14
|
+
var _simplegit = require('simple-git');
|
|
15
|
+
var git_default = _chunkSSXJV7C2cjs.defineBuildMetaModule.call(void 0, {
|
|
16
|
+
name: "git",
|
|
17
|
+
load: async () => {
|
|
18
|
+
const git = _simplegit.simpleGit.call(void 0, );
|
|
19
|
+
const info = {};
|
|
20
|
+
function generateOutput(data) {
|
|
21
|
+
const keys = [
|
|
22
|
+
"repositoryUrl",
|
|
23
|
+
"sha",
|
|
24
|
+
"shortSha",
|
|
25
|
+
"branch",
|
|
26
|
+
"tag",
|
|
27
|
+
"tags",
|
|
28
|
+
"lastTag",
|
|
29
|
+
"commitAuthorName",
|
|
30
|
+
"commitAuthorEmail",
|
|
31
|
+
"commitAuthorDate",
|
|
32
|
+
"commitCommitterName",
|
|
33
|
+
"commitCommitterEmail",
|
|
34
|
+
"commitCommitterDate",
|
|
35
|
+
"latestCommitMessage"
|
|
36
|
+
];
|
|
37
|
+
return keys.map(
|
|
38
|
+
(key) => `export const ${key} = ${data && data[key] !== void 0 ? JSON.stringify(data[key]) : "null"}`
|
|
39
|
+
).join("\n");
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const isRepo = await git.checkIsRepo();
|
|
43
|
+
if (!isRepo) {
|
|
44
|
+
return generateOutput();
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error("failed to check if directory is a git repository:", error);
|
|
48
|
+
return generateOutput();
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const branchInfo = await git.branch([]);
|
|
52
|
+
info.branch = branchInfo.current;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error("failed to fetch branch information:", error);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const log = await git.log(["-1"]);
|
|
58
|
+
if (log.latest) {
|
|
59
|
+
info.sha = log.latest.hash;
|
|
60
|
+
info.shortSha = _optionalChain([log, 'access', _ => _.latest, 'access', _2 => _2.hash, 'optionalAccess', _3 => _3.slice, 'call', _4 => _4(0, 10)]);
|
|
61
|
+
info.latestCommitMessage = log.latest.message;
|
|
62
|
+
info.commitAuthorName = log.latest.author_name;
|
|
63
|
+
info.commitAuthorEmail = log.latest.author_email;
|
|
64
|
+
info.commitAuthorDate = log.latest.date;
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error("failed to fetch commit information:", error);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const committerInfo = await git.show(["-s", "--format=%cn%n%ce%n%cd"]);
|
|
71
|
+
const committerLines = committerInfo.split("\n").map((line) => line.trim());
|
|
72
|
+
if (committerLines.length >= 3) {
|
|
73
|
+
info.commitCommitterName = committerLines[0];
|
|
74
|
+
info.commitCommitterEmail = committerLines[1];
|
|
75
|
+
info.commitCommitterDate = committerLines[2];
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error("failed to fetch committer information:", error);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const hash = await git.revparse(["HEAD"]);
|
|
82
|
+
const tagsResult = await git.tags(["--points-at", hash]);
|
|
83
|
+
const allTags = await git.tags();
|
|
84
|
+
info.tags = tagsResult.all;
|
|
85
|
+
info.tag = tagsResult.all[tagsResult.all.length - 1];
|
|
86
|
+
info.lastTag = allTags.latest;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error("failed to fetch tags information:", error);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const remotes = await git.getRemotes(true);
|
|
92
|
+
const origin = remotes.find((remote) => remote.name === "origin");
|
|
93
|
+
if (_optionalChain([origin, 'optionalAccess', _5 => _5.refs, 'access', _6 => _6.fetch])) {
|
|
94
|
+
const parsed = _giturlparse2.default.call(void 0, origin.refs.fetch);
|
|
95
|
+
if (parsed.resource === "github.com" && parsed.full_name) {
|
|
96
|
+
info.repositoryUrl = `https://github.com/${parsed.full_name}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error("failed to fetch GitHub URL:", error);
|
|
101
|
+
}
|
|
102
|
+
return generateOutput(info);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// src/core/index.ts
|
|
107
|
+
var PREFIX = "virtual:build-meta/";
|
|
108
|
+
var PREFIX_WITH_NULL = `\0${PREFIX}`;
|
|
109
|
+
var unpluginFactory = (options = {}) => {
|
|
110
|
+
const { modules: _modules = [] } = options;
|
|
111
|
+
const modules = [];
|
|
112
|
+
for (const module of _modules) {
|
|
113
|
+
if (typeof module === "object" && "name" in module) {
|
|
114
|
+
modules.push(module);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (module === "git") {
|
|
118
|
+
modules.push(git_default);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
name: PLUGIN_NAME,
|
|
123
|
+
enforce: "pre",
|
|
124
|
+
resolveId(id) {
|
|
125
|
+
if (!id.startsWith(PREFIX)) return;
|
|
126
|
+
id = id.slice(PREFIX.length);
|
|
127
|
+
if (!modules.map((m) => m.name).includes(id)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
return `${PREFIX_WITH_NULL}${id}`;
|
|
131
|
+
},
|
|
132
|
+
loadInclude(id) {
|
|
133
|
+
if (!id.startsWith(PREFIX_WITH_NULL)) return false;
|
|
134
|
+
return modules.map((m) => m.name).includes(id.slice(PREFIX_WITH_NULL.length));
|
|
135
|
+
},
|
|
136
|
+
async load(id) {
|
|
137
|
+
if (!id.startsWith(PREFIX_WITH_NULL)) return;
|
|
138
|
+
id = id.slice(PREFIX_WITH_NULL.length);
|
|
139
|
+
for (const mod of Object.values(modules)) {
|
|
140
|
+
if (id === mod.name) {
|
|
141
|
+
return mod.load(this, id);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
var unplugin = /* @__PURE__ */ _unplugin.createUnplugin.call(void 0, unpluginFactory);
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
exports.PLUGIN_NAME = PLUGIN_NAME; exports.NUXT_CONFIG_KEY = NUXT_CONFIG_KEY; exports.unpluginFactory = unpluginFactory; exports.unplugin = unplugin;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk2TPIXTEWcjs = require('./chunk-2TPIXTEW.cjs');
|
|
4
|
+
|
|
5
|
+
// src/vite.ts
|
|
6
|
+
var _unplugin = require('unplugin');
|
|
7
|
+
var vite_default = _unplugin.createVitePlugin.call(void 0, _chunk2TPIXTEWcjs.unpluginFactory);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.vite_default = vite_default;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineBuildMetaModule
|
|
3
|
+
} from "./chunk-RJEZ2A3A.mjs";
|
|
4
|
+
|
|
5
|
+
// src/core/index.ts
|
|
6
|
+
import { createUnplugin } from "unplugin";
|
|
7
|
+
|
|
8
|
+
// src/core/constants.ts
|
|
9
|
+
var PLUGIN_NAME = "unplugin-build-meta";
|
|
10
|
+
var NUXT_CONFIG_KEY = "buildMeta";
|
|
11
|
+
|
|
12
|
+
// src/core/modules/git.ts
|
|
13
|
+
import parseGitUrl from "git-url-parse";
|
|
14
|
+
import { simpleGit } from "simple-git";
|
|
15
|
+
var git_default = defineBuildMetaModule({
|
|
16
|
+
name: "git",
|
|
17
|
+
load: async () => {
|
|
18
|
+
const git = simpleGit();
|
|
19
|
+
const info = {};
|
|
20
|
+
function generateOutput(data) {
|
|
21
|
+
const keys = [
|
|
22
|
+
"repositoryUrl",
|
|
23
|
+
"sha",
|
|
24
|
+
"shortSha",
|
|
25
|
+
"branch",
|
|
26
|
+
"tag",
|
|
27
|
+
"tags",
|
|
28
|
+
"lastTag",
|
|
29
|
+
"commitAuthorName",
|
|
30
|
+
"commitAuthorEmail",
|
|
31
|
+
"commitAuthorDate",
|
|
32
|
+
"commitCommitterName",
|
|
33
|
+
"commitCommitterEmail",
|
|
34
|
+
"commitCommitterDate",
|
|
35
|
+
"latestCommitMessage"
|
|
36
|
+
];
|
|
37
|
+
return keys.map(
|
|
38
|
+
(key) => `export const ${key} = ${data && data[key] !== void 0 ? JSON.stringify(data[key]) : "null"}`
|
|
39
|
+
).join("\n");
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const isRepo = await git.checkIsRepo();
|
|
43
|
+
if (!isRepo) {
|
|
44
|
+
return generateOutput();
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error("failed to check if directory is a git repository:", error);
|
|
48
|
+
return generateOutput();
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const branchInfo = await git.branch([]);
|
|
52
|
+
info.branch = branchInfo.current;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error("failed to fetch branch information:", error);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const log = await git.log(["-1"]);
|
|
58
|
+
if (log.latest) {
|
|
59
|
+
info.sha = log.latest.hash;
|
|
60
|
+
info.shortSha = log.latest.hash?.slice(0, 10);
|
|
61
|
+
info.latestCommitMessage = log.latest.message;
|
|
62
|
+
info.commitAuthorName = log.latest.author_name;
|
|
63
|
+
info.commitAuthorEmail = log.latest.author_email;
|
|
64
|
+
info.commitAuthorDate = log.latest.date;
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error("failed to fetch commit information:", error);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const committerInfo = await git.show(["-s", "--format=%cn%n%ce%n%cd"]);
|
|
71
|
+
const committerLines = committerInfo.split("\n").map((line) => line.trim());
|
|
72
|
+
if (committerLines.length >= 3) {
|
|
73
|
+
info.commitCommitterName = committerLines[0];
|
|
74
|
+
info.commitCommitterEmail = committerLines[1];
|
|
75
|
+
info.commitCommitterDate = committerLines[2];
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error("failed to fetch committer information:", error);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const hash = await git.revparse(["HEAD"]);
|
|
82
|
+
const tagsResult = await git.tags(["--points-at", hash]);
|
|
83
|
+
const allTags = await git.tags();
|
|
84
|
+
info.tags = tagsResult.all;
|
|
85
|
+
info.tag = tagsResult.all[tagsResult.all.length - 1];
|
|
86
|
+
info.lastTag = allTags.latest;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error("failed to fetch tags information:", error);
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const remotes = await git.getRemotes(true);
|
|
92
|
+
const origin = remotes.find((remote) => remote.name === "origin");
|
|
93
|
+
if (origin?.refs.fetch) {
|
|
94
|
+
const parsed = parseGitUrl(origin.refs.fetch);
|
|
95
|
+
if (parsed.resource === "github.com" && parsed.full_name) {
|
|
96
|
+
info.repositoryUrl = `https://github.com/${parsed.full_name}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error("failed to fetch GitHub URL:", error);
|
|
101
|
+
}
|
|
102
|
+
return generateOutput(info);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// src/core/index.ts
|
|
107
|
+
var PREFIX = "virtual:build-meta/";
|
|
108
|
+
var PREFIX_WITH_NULL = `\0${PREFIX}`;
|
|
109
|
+
var unpluginFactory = (options = {}) => {
|
|
110
|
+
const { modules: _modules = [] } = options;
|
|
111
|
+
const modules = [];
|
|
112
|
+
for (const module of _modules) {
|
|
113
|
+
if (typeof module === "object" && "name" in module) {
|
|
114
|
+
modules.push(module);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (module === "git") {
|
|
118
|
+
modules.push(git_default);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
name: PLUGIN_NAME,
|
|
123
|
+
enforce: "pre",
|
|
124
|
+
resolveId(id) {
|
|
125
|
+
if (!id.startsWith(PREFIX)) return;
|
|
126
|
+
id = id.slice(PREFIX.length);
|
|
127
|
+
if (!modules.map((m) => m.name).includes(id)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
return `${PREFIX_WITH_NULL}${id}`;
|
|
131
|
+
},
|
|
132
|
+
loadInclude(id) {
|
|
133
|
+
if (!id.startsWith(PREFIX_WITH_NULL)) return false;
|
|
134
|
+
return modules.map((m) => m.name).includes(id.slice(PREFIX_WITH_NULL.length));
|
|
135
|
+
},
|
|
136
|
+
async load(id) {
|
|
137
|
+
if (!id.startsWith(PREFIX_WITH_NULL)) return;
|
|
138
|
+
id = id.slice(PREFIX_WITH_NULL.length);
|
|
139
|
+
for (const mod of Object.values(modules)) {
|
|
140
|
+
if (id === mod.name) {
|
|
141
|
+
return mod.load(this, id);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
148
|
+
|
|
149
|
+
export {
|
|
150
|
+
PLUGIN_NAME,
|
|
151
|
+
NUXT_CONFIG_KEY,
|
|
152
|
+
unpluginFactory,
|
|
153
|
+
unplugin
|
|
154
|
+
};
|