unplugin-build-meta 1.0.5 → 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.
Files changed (64) hide show
  1. package/dist/astro.cjs +25 -17
  2. package/dist/astro.d.cts +4 -5
  3. package/dist/{astro.d.ts → astro.d.mts} +5 -5
  4. package/dist/astro.mjs +25 -18
  5. package/dist/esbuild.cjs +20 -9
  6. package/dist/esbuild.d.cts +5 -6
  7. package/dist/{esbuild.d.ts → esbuild.d.mts} +7 -6
  8. package/dist/esbuild.mjs +19 -9
  9. package/dist/farm.cjs +20 -9
  10. package/dist/farm.d.cts +3 -4
  11. package/dist/{farm.d.ts → farm.d.mts} +5 -4
  12. package/dist/farm.mjs +19 -9
  13. package/dist/{index.d.ts → index-Crle-EHN.d.cts} +5 -4
  14. package/dist/index-DEDKZAET.d.mts +14 -0
  15. package/dist/index.cjs +4 -8
  16. package/dist/index.d.cts +3 -13
  17. package/dist/index.d.mts +3 -0
  18. package/dist/index.mjs +3 -9
  19. package/dist/module-D-A3G8xU.mjs +14 -0
  20. package/dist/module-DT5DVEPk.cjs +20 -0
  21. package/dist/module.cjs +3 -5
  22. package/dist/module.d.cts +4 -4
  23. package/dist/{module.d.ts → module.d.mts} +4 -4
  24. package/dist/module.mjs +3 -6
  25. package/dist/nuxt.cjs +35 -29
  26. package/dist/nuxt.d.cts +4 -5
  27. package/dist/{nuxt.d.ts → nuxt.d.mts} +6 -5
  28. package/dist/nuxt.mjs +33 -28
  29. package/dist/rolldown.cjs +20 -9
  30. package/dist/rolldown.d.cts +5 -6
  31. package/dist/{rolldown.d.ts → rolldown.d.mts} +7 -6
  32. package/dist/rolldown.mjs +19 -9
  33. package/dist/rollup.cjs +20 -9
  34. package/dist/rollup.d.cts +5 -6
  35. package/dist/{rollup.d.ts → rollup.d.mts} +7 -6
  36. package/dist/rollup.mjs +19 -9
  37. package/dist/rspack.cjs +25 -9
  38. package/dist/rspack.d.cts +5 -5
  39. package/dist/{rspack.d.ts → rspack.d.mts} +7 -5
  40. package/dist/rspack.mjs +24 -9
  41. package/dist/src-BZ8mQVle.cjs +208 -0
  42. package/dist/src-D338eO6B.mjs +150 -0
  43. package/dist/types--sVtB8IG.d.mts +25 -0
  44. package/dist/types-Be8ZD_mp.d.cts +25 -0
  45. package/dist/vite.cjs +20 -6
  46. package/dist/vite.d.cts +5 -6
  47. package/dist/{vite.d.ts → vite.d.mts} +7 -6
  48. package/dist/vite.mjs +21 -8
  49. package/dist/webpack.cjs +18 -6
  50. package/dist/webpack.d.cts +5 -6
  51. package/dist/webpack.d.mts +19 -0
  52. package/dist/webpack.mjs +19 -8
  53. package/package.json +55 -110
  54. package/dist/chunk-7ZTBKMAA.mjs +0 -11
  55. package/dist/chunk-GU2UU6BD.mjs +0 -11
  56. package/dist/chunk-IO4OWFHV.cjs +0 -170
  57. package/dist/chunk-NT6BOYSQ.cjs +0 -11
  58. package/dist/chunk-OAZ3YOGG.mjs +0 -170
  59. package/dist/chunk-RJEZ2A3A.mjs +0 -8
  60. package/dist/chunk-SSXJV7C2.cjs +0 -8
  61. package/dist/chunk-TQTDIF6M.cjs +0 -11
  62. package/dist/types-C-6IiPYY.d.cts +0 -24
  63. package/dist/types-C-6IiPYY.d.ts +0 -24
  64. package/dist/webpack.d.ts +0 -18
@@ -1,170 +0,0 @@
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/modules/runtime.ts
107
- var _process = require('process'); var _process2 = _interopRequireDefault(_process);
108
- var runtimeModule = {
109
- name: "runtime",
110
- load: async () => {
111
- const runtime = {
112
- platform: _process2.default.platform,
113
- arch: _process2.default.arch,
114
- versions: _process2.default.versions
115
- };
116
- return [
117
- `export const platform = ${JSON.stringify(runtime.platform)}`,
118
- `export const arch = ${JSON.stringify(runtime.arch)}`,
119
- `export const versions = ${JSON.stringify(runtime.versions, null, 2)}`
120
- ].join("\n");
121
- }
122
- };
123
-
124
- // src/core/index.ts
125
- var PREFIX = "virtual:build-meta/";
126
- var PREFIX_WITH_NULL = `\0${PREFIX}`;
127
- var unpluginFactory = (options = {}) => {
128
- const { git = true, extraModules = [], runtime = true } = options;
129
- const modules = [];
130
- if (git) {
131
- modules.push(git_default);
132
- }
133
- if (runtime) {
134
- modules.push(runtimeModule);
135
- }
136
- modules.push(...extraModules);
137
- return {
138
- name: PLUGIN_NAME,
139
- enforce: "pre",
140
- resolveId(id) {
141
- if (!id.startsWith(PREFIX)) return;
142
- id = id.slice(PREFIX.length);
143
- if (!modules.map((m) => m.name).includes(id)) {
144
- return;
145
- }
146
- return `${PREFIX_WITH_NULL}${id}`;
147
- },
148
- loadInclude(id) {
149
- if (!id.startsWith(PREFIX_WITH_NULL)) return false;
150
- return modules.map((m) => m.name).includes(id.slice(PREFIX_WITH_NULL.length));
151
- },
152
- async load(id) {
153
- if (!id.startsWith(PREFIX_WITH_NULL)) return;
154
- id = id.slice(PREFIX_WITH_NULL.length);
155
- for (const mod of Object.values(modules)) {
156
- if (id === mod.name) {
157
- return mod.load(this, id);
158
- }
159
- }
160
- }
161
- };
162
- };
163
- var unplugin = /* @__PURE__ */ _unplugin.createUnplugin.call(void 0, unpluginFactory);
164
-
165
-
166
-
167
-
168
-
169
-
170
- exports.PLUGIN_NAME = PLUGIN_NAME; exports.NUXT_CONFIG_KEY = NUXT_CONFIG_KEY; exports.unpluginFactory = unpluginFactory; exports.unplugin = unplugin;
@@ -1,11 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkIO4OWFHVcjs = require('./chunk-IO4OWFHV.cjs');
4
-
5
- // src/vite.ts
6
- var _unplugin = require('unplugin');
7
- var vite_default = _unplugin.createVitePlugin.call(void 0, _chunkIO4OWFHVcjs.unpluginFactory);
8
-
9
-
10
-
11
- exports.vite_default = vite_default;
@@ -1,170 +0,0 @@
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/modules/runtime.ts
107
- import process from "process";
108
- var runtimeModule = {
109
- name: "runtime",
110
- load: async () => {
111
- const runtime = {
112
- platform: process.platform,
113
- arch: process.arch,
114
- versions: process.versions
115
- };
116
- return [
117
- `export const platform = ${JSON.stringify(runtime.platform)}`,
118
- `export const arch = ${JSON.stringify(runtime.arch)}`,
119
- `export const versions = ${JSON.stringify(runtime.versions, null, 2)}`
120
- ].join("\n");
121
- }
122
- };
123
-
124
- // src/core/index.ts
125
- var PREFIX = "virtual:build-meta/";
126
- var PREFIX_WITH_NULL = `\0${PREFIX}`;
127
- var unpluginFactory = (options = {}) => {
128
- const { git = true, extraModules = [], runtime = true } = options;
129
- const modules = [];
130
- if (git) {
131
- modules.push(git_default);
132
- }
133
- if (runtime) {
134
- modules.push(runtimeModule);
135
- }
136
- modules.push(...extraModules);
137
- return {
138
- name: PLUGIN_NAME,
139
- enforce: "pre",
140
- resolveId(id) {
141
- if (!id.startsWith(PREFIX)) return;
142
- id = id.slice(PREFIX.length);
143
- if (!modules.map((m) => m.name).includes(id)) {
144
- return;
145
- }
146
- return `${PREFIX_WITH_NULL}${id}`;
147
- },
148
- loadInclude(id) {
149
- if (!id.startsWith(PREFIX_WITH_NULL)) return false;
150
- return modules.map((m) => m.name).includes(id.slice(PREFIX_WITH_NULL.length));
151
- },
152
- async load(id) {
153
- if (!id.startsWith(PREFIX_WITH_NULL)) return;
154
- id = id.slice(PREFIX_WITH_NULL.length);
155
- for (const mod of Object.values(modules)) {
156
- if (id === mod.name) {
157
- return mod.load(this, id);
158
- }
159
- }
160
- }
161
- };
162
- };
163
- var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
164
-
165
- export {
166
- PLUGIN_NAME,
167
- NUXT_CONFIG_KEY,
168
- unpluginFactory,
169
- unplugin
170
- };
@@ -1,8 +0,0 @@
1
- // src/module.ts
2
- function defineBuildMetaModule(module) {
3
- return module;
4
- }
5
-
6
- export {
7
- defineBuildMetaModule
8
- };
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/module.ts
2
- function defineBuildMetaModule(module) {
3
- return module;
4
- }
5
-
6
-
7
-
8
- exports.defineBuildMetaModule = defineBuildMetaModule;
@@ -1,11 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkIO4OWFHVcjs = require('./chunk-IO4OWFHV.cjs');
4
-
5
- // src/webpack.ts
6
- var _unplugin = require('unplugin');
7
- var webpack_default = _unplugin.createWebpackPlugin.call(void 0, _chunkIO4OWFHVcjs.unpluginFactory);
8
-
9
-
10
-
11
- exports.webpack_default = webpack_default;
@@ -1,24 +0,0 @@
1
- import { UnpluginBuildContext, UnpluginContext } from 'unplugin';
2
-
3
- interface BuildMetaModule {
4
- name: string;
5
- load: (ctx: UnpluginBuildContext & UnpluginContext, id: string) => Promise<string>;
6
- }
7
- interface BuildMetaOptions {
8
- /**
9
- * Whether to enable the git module.
10
- * @default true
11
- */
12
- git?: boolean;
13
- /**
14
- * Whether to enable the runtime module.
15
- * @default true
16
- */
17
- runtime?: boolean;
18
- /**
19
- * Additional custom modules to include in the build meta.
20
- */
21
- extraModules?: BuildMetaModule[];
22
- }
23
-
24
- export type { BuildMetaOptions as B, BuildMetaModule as a };
@@ -1,24 +0,0 @@
1
- import { UnpluginBuildContext, UnpluginContext } from 'unplugin';
2
-
3
- interface BuildMetaModule {
4
- name: string;
5
- load: (ctx: UnpluginBuildContext & UnpluginContext, id: string) => Promise<string>;
6
- }
7
- interface BuildMetaOptions {
8
- /**
9
- * Whether to enable the git module.
10
- * @default true
11
- */
12
- git?: boolean;
13
- /**
14
- * Whether to enable the runtime module.
15
- * @default true
16
- */
17
- runtime?: boolean;
18
- /**
19
- * Additional custom modules to include in the build meta.
20
- */
21
- extraModules?: BuildMetaModule[];
22
- }
23
-
24
- export type { BuildMetaOptions as B, BuildMetaModule as a };
package/dist/webpack.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import * as webpack from 'webpack';
2
- import { B as BuildMetaOptions } from './types-C-6IiPYY.js';
3
- import 'unplugin';
4
-
5
- /**
6
- * Webpack plugin
7
- *
8
- * @example
9
- * ```ts
10
- * // webpack.config.js
11
- * module.exports = {
12
- * plugins: [require("unplugin-build-meta/webpack")()],
13
- * }
14
- * ```
15
- */
16
- declare const _default: (options?: BuildMetaOptions | undefined) => webpack.WebpackPluginInstance;
17
-
18
- export { _default as default };