longmo-unplugin-info 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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +508 -0
  3. package/client.d.ts +106 -0
  4. package/dist/astro.cjs +25 -0
  5. package/dist/astro.d.cts +11 -0
  6. package/dist/astro.d.mts +11 -0
  7. package/dist/astro.d.ts +11 -0
  8. package/dist/astro.mjs +23 -0
  9. package/dist/esbuild.cjs +16 -0
  10. package/dist/esbuild.d.cts +7 -0
  11. package/dist/esbuild.d.mts +7 -0
  12. package/dist/esbuild.d.ts +7 -0
  13. package/dist/esbuild.mjs +14 -0
  14. package/dist/index.cjs +16 -0
  15. package/dist/index.d.cts +7 -0
  16. package/dist/index.d.mts +7 -0
  17. package/dist/index.d.ts +7 -0
  18. package/dist/index.mjs +10 -0
  19. package/dist/nuxt.cjs +43 -0
  20. package/dist/nuxt.d.cts +16 -0
  21. package/dist/nuxt.d.mts +16 -0
  22. package/dist/nuxt.d.ts +16 -0
  23. package/dist/nuxt.mjs +41 -0
  24. package/dist/rollup.cjs +16 -0
  25. package/dist/rollup.d.cts +7 -0
  26. package/dist/rollup.d.mts +7 -0
  27. package/dist/rollup.d.ts +7 -0
  28. package/dist/rollup.mjs +14 -0
  29. package/dist/rspack.cjs +16 -0
  30. package/dist/rspack.d.cts +7 -0
  31. package/dist/rspack.d.mts +7 -0
  32. package/dist/rspack.d.ts +7 -0
  33. package/dist/rspack.mjs +14 -0
  34. package/dist/shared/longmo-unplugin-info.B4uHFilH.mjs +609 -0
  35. package/dist/shared/longmo-unplugin-info.D5mpeSYM.cjs +619 -0
  36. package/dist/shared/longmo-unplugin-info.zS6I--Tu.d.cts +69 -0
  37. package/dist/shared/longmo-unplugin-info.zS6I--Tu.d.mts +69 -0
  38. package/dist/shared/longmo-unplugin-info.zS6I--Tu.d.ts +69 -0
  39. package/dist/vite.cjs +16 -0
  40. package/dist/vite.d.cts +7 -0
  41. package/dist/vite.d.mts +7 -0
  42. package/dist/vite.d.ts +7 -0
  43. package/dist/vite.mjs +14 -0
  44. package/dist/webpack.cjs +16 -0
  45. package/dist/webpack.d.cts +7 -0
  46. package/dist/webpack.d.mts +7 -0
  47. package/dist/webpack.d.ts +7 -0
  48. package/dist/webpack.mjs +14 -0
  49. package/package.json +168 -0
@@ -0,0 +1,619 @@
1
+ 'use strict';
2
+
3
+ const path = require('node:path');
4
+ const process$1 = require('node:process');
5
+ const unplugin = require('unplugin');
6
+ const ci = require('ci-info');
7
+ const simpleGit = require('simple-git');
8
+ const parseGitUrl = require('git-url-parse');
9
+ const node_child_process = require('node:child_process');
10
+ const node_util = require('node:util');
11
+ const fs = require('node:fs');
12
+
13
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
+
15
+ const path__default = /*#__PURE__*/_interopDefaultCompat(path);
16
+ const process__default = /*#__PURE__*/_interopDefaultCompat(process$1);
17
+ const ci__default = /*#__PURE__*/_interopDefaultCompat(ci);
18
+ const parseGitUrl__default = /*#__PURE__*/_interopDefaultCompat(parseGitUrl);
19
+ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
20
+
21
+ class BuildInfoModule {
22
+ name;
23
+ root;
24
+ options;
25
+ constructor(name, root, options) {
26
+ this.name = `${options?.prefix ?? "~build"}/${name}`;
27
+ this.root = root;
28
+ this.options = options;
29
+ }
30
+ buildStart(ctx) {
31
+ }
32
+ buildEnd(ctx) {
33
+ }
34
+ }
35
+
36
+ class BuildTimeModule extends BuildInfoModule {
37
+ now;
38
+ constructor(root, options) {
39
+ super("time", root, options);
40
+ }
41
+ buildStart() {
42
+ this.now = this.options.time ? this.options.time : /* @__PURE__ */ new Date();
43
+ }
44
+ load() {
45
+ return `const time = new Date(${this.now.getTime()})
46
+ export default time`;
47
+ }
48
+ }
49
+
50
+ async function getRepoInfo(root, extra = {}) {
51
+ const git = simpleGit.simpleGit(root);
52
+ if (!await git.checkIsRepo()) {
53
+ return void 0;
54
+ }
55
+ const [branch, currentCommit, committer, describe, tags, github, result] = await Promise.all([
56
+ getBranch(git),
57
+ getCommit(git),
58
+ getCommitter(git),
59
+ getDescribe(git),
60
+ getTags(git),
61
+ getGitHubUrl(git),
62
+ Promise.all(
63
+ Object.entries(extra).map(async ([key, fn]) => {
64
+ return [key, await fn(git)];
65
+ })
66
+ )
67
+ ]);
68
+ return {
69
+ ...branch,
70
+ ...currentCommit,
71
+ ...committer,
72
+ ...describe,
73
+ ...tags,
74
+ ...github,
75
+ ...Object.fromEntries(result)
76
+ };
77
+ }
78
+ async function getBranch(git) {
79
+ try {
80
+ const branch = (await git.branch([])).current;
81
+ return { branch };
82
+ } catch (error) {
83
+ return { branch: void 0 };
84
+ }
85
+ }
86
+ async function getCommit(git) {
87
+ try {
88
+ const log = await git.log(["-1"]);
89
+ const sha = log.latest?.hash;
90
+ const commitMessage = log.latest?.message;
91
+ const author = log.latest?.author_name;
92
+ const authorEmail = log.latest?.author_email;
93
+ const authorDate = log.latest?.date;
94
+ return {
95
+ sha,
96
+ abbreviatedSha: sha?.slice(0, 10),
97
+ commitMessage,
98
+ author,
99
+ authorEmail,
100
+ authorDate
101
+ };
102
+ } catch (error) {
103
+ return {
104
+ sha: void 0,
105
+ abbreviatedSha: void 0,
106
+ commitMessage: void 0,
107
+ author: void 0,
108
+ authorEmail: void 0,
109
+ authorDate: void 0
110
+ };
111
+ }
112
+ }
113
+ function removeLineBreak(str) {
114
+ return str.replace(/[\s\r\n]+$/, "");
115
+ }
116
+ async function getCommitter(git) {
117
+ try {
118
+ const [committer, committerEmail, committerDate] = await Promise.all([
119
+ git.show(["-s", "--format=%cn"]),
120
+ git.show(["-s", "--format=%ce"]),
121
+ git.show(["-s", "--format=%cd"])
122
+ ]);
123
+ return {
124
+ committer: removeLineBreak(committer),
125
+ committerEmail: removeLineBreak(committerEmail),
126
+ committerDate: removeLineBreak(committerDate)
127
+ };
128
+ } catch (error) {
129
+ return {
130
+ committer: void 0,
131
+ committerEmail: void 0,
132
+ committerDate: void 0
133
+ };
134
+ }
135
+ }
136
+ async function getTags(git) {
137
+ try {
138
+ const hash = await git.revparse(["HEAD"]);
139
+ const tags = await git.tags(["--points-at", hash]);
140
+ const all = await git.tags();
141
+ return { tag: tags.all[tags.all.length - 1], tags: tags.all, lastTag: all.latest };
142
+ } catch (error) {
143
+ return { tags: void 0, lastTag: void 0 };
144
+ }
145
+ }
146
+ async function getDescribe(git) {
147
+ try {
148
+ const output = await git.raw(["describe", "--always"]);
149
+ return {
150
+ describe: removeLineBreak(output)
151
+ };
152
+ } catch (error) {
153
+ return {
154
+ describe: void 0
155
+ };
156
+ }
157
+ }
158
+ async function getGitHubUrl(git) {
159
+ const remotes = await git.getRemotes(true);
160
+ const origin = remotes.find((remote) => remote.name === "origin");
161
+ const url = origin?.refs.fetch;
162
+ if (url) {
163
+ const parsed = parseGitUrl__default(url);
164
+ if (parsed.resource === "github.com" && parsed.full_name) {
165
+ return { github: `https://github.com/${parsed.full_name}` };
166
+ }
167
+ }
168
+ return { github: void 0 };
169
+ }
170
+
171
+ class BuildGitModule extends BuildInfoModule {
172
+ constructor(root, options) {
173
+ super("git", root, options);
174
+ }
175
+ async load(ctx, id) {
176
+ const { root, options } = this;
177
+ const info = await getRepoInfo(root, options?.git);
178
+ if (info && options?.github) {
179
+ info.github = options.github;
180
+ }
181
+ if (!info) {
182
+ ctx.warn("This may not be a git repo");
183
+ }
184
+ const keys = [
185
+ .../* @__PURE__ */ new Set([
186
+ "github",
187
+ "sha",
188
+ "abbreviatedSha",
189
+ "branch",
190
+ "tag",
191
+ "tags",
192
+ "lastTag",
193
+ "describe",
194
+ "author",
195
+ "authorEmail",
196
+ "authorDate",
197
+ "committer",
198
+ "committerEmail",
199
+ "committerDate",
200
+ "commitMessage",
201
+ ...Object.keys(options?.git ?? {})
202
+ ])
203
+ ];
204
+ const gen = (key) => {
205
+ return `export const ${key} = ${info ? JSON.stringify(info[key]) : "null"}`;
206
+ };
207
+ return [
208
+ // Support legacy ~build/info module
209
+ id.endsWith("info") ? `export const CI = ${ci__default.isCI ? `"${ci__default.name}"` : "null"}` : ``,
210
+ ...keys.map((key) => gen(key))
211
+ ].join("\n");
212
+ }
213
+ }
214
+
215
+ const execAsync = node_util.promisify(node_child_process.exec);
216
+ async function getSvnInfo(root, extra = {}) {
217
+ try {
218
+ const svnDir = await execSync("svn info --show-item wc-root", root);
219
+ if (!svnDir) {
220
+ return void 0;
221
+ }
222
+ const [info, lastCommit, log, extraResult] = await Promise.all([
223
+ getSvnBasicInfo(root),
224
+ getLastCommit(root),
225
+ getCommitLog(root),
226
+ Promise.all(
227
+ Object.entries(extra).map(async ([key, fn]) => {
228
+ return [key, await fn(null)];
229
+ })
230
+ )
231
+ ]);
232
+ return {
233
+ ...info,
234
+ ...lastCommit,
235
+ ...log,
236
+ ...Object.fromEntries(extraResult)
237
+ };
238
+ } catch (error) {
239
+ return void 0;
240
+ }
241
+ }
242
+ async function getSvnBasicInfo(root) {
243
+ try {
244
+ const output = await execSync("svn info", root);
245
+ const lines = output.split("\n");
246
+ const info = {};
247
+ for (const line of lines) {
248
+ const match = line.match(/^([^:]+):\s*(.+)$/);
249
+ if (match) {
250
+ const key = toCamelCase(match[1].trim());
251
+ info[key] = match[2].trim();
252
+ }
253
+ }
254
+ return {
255
+ url: info["URL"],
256
+ repositoryRoot: info["Repository Root"],
257
+ repositoryUuid: info["Repository UUID"],
258
+ revision: info["Revision"],
259
+ nodeKind: info["Node Kind"],
260
+ lastChangedRev: info["Last Changed Rev"],
261
+ lastChangedDate: info["Last Changed Date"],
262
+ lastChangedAuthor: info["Last Changed Author"]
263
+ };
264
+ } catch (error) {
265
+ return {
266
+ url: void 0,
267
+ repositoryRoot: void 0,
268
+ repositoryUuid: void 0,
269
+ revision: void 0,
270
+ nodeKind: void 0,
271
+ lastChangedRev: void 0,
272
+ lastChangedDate: void 0,
273
+ lastChangedAuthor: void 0
274
+ };
275
+ }
276
+ }
277
+ async function getLastCommit(root) {
278
+ try {
279
+ const output = await execSync("svn log -l 1 --xml", root);
280
+ const logEntry = parseSvnXmlLog(output);
281
+ return {
282
+ sha: logEntry?.revision,
283
+ abbreviatedSha: logEntry?.revision,
284
+ commitMessage: logEntry?.msg,
285
+ author: logEntry?.author,
286
+ authorDate: logEntry?.date,
287
+ authorEmail: void 0
288
+ // SVN 不包含邮箱信息
289
+ };
290
+ } catch (error) {
291
+ return {
292
+ sha: void 0,
293
+ abbreviatedSha: void 0,
294
+ commitMessage: void 0,
295
+ author: void 0,
296
+ authorDate: void 0,
297
+ authorEmail: void 0
298
+ };
299
+ }
300
+ }
301
+ async function getCommitLog(root) {
302
+ try {
303
+ const output = await execSync("svn log -l 10 --xml", root);
304
+ const logs = parseSvnXmlLogs(output);
305
+ const lastTag = await getBranchOrTag(root);
306
+ return {
307
+ branch: lastTag || void 0,
308
+ tag: lastTag || void 0,
309
+ tags: logs.map((log) => log.revision),
310
+ lastTag: lastTag || void 0,
311
+ describe: `r${logs[0]?.revision || ""}`
312
+ };
313
+ } catch (error) {
314
+ return {
315
+ branch: void 0,
316
+ tag: void 0,
317
+ tags: [],
318
+ lastTag: void 0,
319
+ describe: void 0
320
+ };
321
+ }
322
+ }
323
+ async function getBranchOrTag(root) {
324
+ try {
325
+ const url = await execSync("svn info --show-item url", root);
326
+ if (url.includes("/trunk/")) {
327
+ return "trunk";
328
+ }
329
+ if (url.includes("/branches/")) {
330
+ const match = url.match(/\/branches\/([^\/]+)/);
331
+ return match ? match[1] : void 0;
332
+ }
333
+ if (url.includes("/tags/")) {
334
+ const match = url.match(/\/tags\/([^\/]+)/);
335
+ return match ? match[1] : void 0;
336
+ }
337
+ return void 0;
338
+ } catch (error) {
339
+ return void 0;
340
+ }
341
+ }
342
+ function parseSvnXmlLog(xml) {
343
+ try {
344
+ const entryMatch = xml.match(/<logentry[^>]*revision="(\d+)"[^>]*>/);
345
+ if (!entryMatch) return null;
346
+ const authorMatch = xml.match(/<author>([^<]+)<\/author>/);
347
+ const dateMatch = xml.match(/<date>([^<]+)<\/date>/);
348
+ const msgMatch = xml.match(/<msg>([^<]*)<\/msg>/);
349
+ return {
350
+ revision: entryMatch[1],
351
+ author: authorMatch?.[1] || "",
352
+ date: dateMatch?.[1] || "",
353
+ msg: msgMatch?.[1] || ""
354
+ };
355
+ } catch (error) {
356
+ return null;
357
+ }
358
+ }
359
+ function parseSvnXmlLogs(xml) {
360
+ try {
361
+ const entries = [];
362
+ const regex = /<logentry[^>]*revision="(\d+)"[^>]*>[\s\S]*?<author>([^<]+)<\/author>[\s\S]*?<date>([^<]+)<\/date>[\s\S]*?<msg>([^<]*)<\/msg>[\s\S]*?<\/logentry>/g;
363
+ let match;
364
+ while ((match = regex.exec(xml)) !== null) {
365
+ entries.push({
366
+ revision: match[1],
367
+ author: match[2],
368
+ date: match[3],
369
+ msg: match[4]
370
+ });
371
+ }
372
+ return entries;
373
+ } catch (error) {
374
+ return [];
375
+ }
376
+ }
377
+ function toCamelCase(str) {
378
+ return str.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => {
379
+ return index === 0 ? word.toLowerCase() : word.toUpperCase();
380
+ }).replace(/\s+/g, "");
381
+ }
382
+ function execSync(command, cwd) {
383
+ return execAsync(command, { cwd, encoding: "utf-8" }).then((res) => res.stdout.trim()).catch(() => "");
384
+ }
385
+
386
+ class BuildSvnModule extends BuildInfoModule {
387
+ constructor(root, options) {
388
+ super("svn", root, options);
389
+ }
390
+ async load(ctx, id) {
391
+ const { root, options } = this;
392
+ const info = await getSvnInfo(root, options?.svn);
393
+ if (!info) {
394
+ ctx.warn("This may not be a svn repo");
395
+ }
396
+ const keys = [
397
+ .../* @__PURE__ */ new Set([
398
+ "url",
399
+ "repositoryRoot",
400
+ "repositoryUuid",
401
+ "revision",
402
+ "nodeKind",
403
+ "lastChangedRev",
404
+ "lastChangedDate",
405
+ "lastChangedAuthor",
406
+ "sha",
407
+ "abbreviatedSha",
408
+ "commitMessage",
409
+ "author",
410
+ "authorDate",
411
+ "authorEmail",
412
+ "branch",
413
+ "tag",
414
+ "tags",
415
+ "lastTag",
416
+ "describe",
417
+ ...Object.keys(options?.svn ?? {})
418
+ ])
419
+ ];
420
+ const gen = (key) => {
421
+ return `export const ${key} = ${info ? JSON.stringify(info[key]) : "null"}`;
422
+ };
423
+ return keys.map((key) => gen(key)).join("\n");
424
+ }
425
+ }
426
+
427
+ class LegacyInfoModule extends BuildGitModule {
428
+ constructor(root, options) {
429
+ super(root, options);
430
+ this.name = `${options.prefix ?? "~build"}/info`;
431
+ }
432
+ }
433
+
434
+ class BuildConsoleModule extends BuildInfoModule {
435
+ constructor(root, options) {
436
+ super("console", root, options);
437
+ }
438
+ load() {
439
+ const { environment = ["development", "production"] } = this.options.console ?? {};
440
+ return [
441
+ `import time from '~build/time';`,
442
+ `import { isCI } from '~build/ci';`,
443
+ `import { github } from '~build/git';`,
444
+ `import { name, version } from '~build/package';`,
445
+ ``,
446
+ `export const print = () => {`,
447
+ ` if (!${JSON.stringify(environment)}.includes(process.env.NODE_ENV)) return;`,
448
+ ` if (typeof import.meta?.env?.SSR !== 'undefined' && import.meta.env.SSR) return;`,
449
+ ` console.groupCollapsed('~build/console');`,
450
+ ` console.log('Project:', name);`,
451
+ ` console.log('Build-at:', time ? time.toLocaleString() : 'Unknown');`,
452
+ ` console.log('Environment:', \`${process.env.NODE_ENV}\${isCI ? '(ci)' : ''}\`);`,
453
+ ` console.log('Version:', version);`,
454
+ ` console.log('GitHub:', github);`,
455
+ ` console.groupEnd();`,
456
+ `};`,
457
+ ``,
458
+ `print();`
459
+ ].join("\n");
460
+ }
461
+ }
462
+
463
+ class BuildCIModule extends BuildInfoModule {
464
+ constructor(root, options) {
465
+ super("ci", root, options);
466
+ }
467
+ load() {
468
+ return [
469
+ `export const isCI = ${ci__default.isCI !== null ? ci__default.isCI ? "true" : "false" : "null"}`,
470
+ `export const isPR = ${ci__default.isPR !== null ? ci__default.isPR ? "true" : "false" : "null"}`,
471
+ `export const name = ${ci__default.name !== null ? `\`${ci__default.name}\`` : "null"}`
472
+ ].join("\n");
473
+ }
474
+ }
475
+
476
+ class BuildMetaModule extends BuildInfoModule {
477
+ constructor(root, options) {
478
+ super("meta", root, options);
479
+ }
480
+ async load() {
481
+ const { options } = this;
482
+ const get = () => {
483
+ if (!options?.meta) return {};
484
+ if (typeof options.meta === "function") {
485
+ return options.meta();
486
+ }
487
+ return options.meta;
488
+ };
489
+ const meta = await get();
490
+ const body = Object.entries(meta).map(
491
+ ([key, value]) => `export const ${key} = ${JSON.stringify(value, null, 2)};`
492
+ );
493
+ return body.length > 0 ? body.join("\n") : "export {};";
494
+ }
495
+ }
496
+
497
+ class BuildEnvModule extends BuildInfoModule {
498
+ constructor(root, options) {
499
+ super("env", root, options);
500
+ }
501
+ async load() {
502
+ const { options } = this;
503
+ const get = () => {
504
+ if (!options?.env) return {};
505
+ if (typeof options.env === "function") {
506
+ return options.env();
507
+ }
508
+ return options.env;
509
+ };
510
+ const cloudflare = options.cloudflare === true;
511
+ const meta = await get();
512
+ const body = Object.entries(meta).map(
513
+ ([key, value]) => !cloudflare ? `export const ${key} = (typeof import.meta?.env?.SSR !== 'undefined' && import.meta.env.SSR ? process?.env?.['${key.replace(/'/g, "\\\\")}'] : undefined) ?? ${JSON.stringify(value, null, 2)};` : `export const ${key} = ${JSON.stringify(value, null, 2)};`
514
+ );
515
+ return body.length > 0 ? body.join("\n") : "export {};";
516
+ }
517
+ }
518
+
519
+ class BuildPackageModule extends BuildInfoModule {
520
+ constructor(root, options) {
521
+ super("package", root, options);
522
+ }
523
+ load() {
524
+ const { root, options } = this;
525
+ const pkg = JSON.parse(fs__default.readFileSync(path__default.join(root, "package.json"), "utf-8"));
526
+ const defaults = ["name", "version", "description", "keywords", "license", "author"];
527
+ const keys = new Set(
528
+ Array.isArray(options?.package) ? [...defaults, ...options.package] : typeof options?.package === "object" ? Object.entries(
529
+ Object.fromEntries([
530
+ ...defaults.map((d) => [d, true]),
531
+ ...Object.entries(options.package)
532
+ ])
533
+ ).filter(([k, v]) => !!v).map(([k, v]) => k) : defaults
534
+ );
535
+ const resolved = {
536
+ name: "",
537
+ version: "0.0.0",
538
+ description: "",
539
+ keywords: [],
540
+ license: "",
541
+ author: "",
542
+ ...pkg
543
+ };
544
+ const entries = [...keys].map((key) => [key, resolved[key]]);
545
+ return entries.map(([key, value]) => `export const ${key} = ${JSON.stringify(value, null, 2)};`).join("\n");
546
+ }
547
+ }
548
+
549
+ const UnpluginInfo = /* @__PURE__ */ unplugin.createUnplugin(
550
+ (options = {}, meta) => {
551
+ const root = path__default.resolve(options?.root ?? process__default.cwd());
552
+ const modules = {
553
+ Time: new BuildTimeModule(root, options),
554
+ Git: new BuildGitModule(root, options),
555
+ Svn: new BuildSvnModule(root, options),
556
+ CI: new BuildCIModule(root, options),
557
+ Info: new LegacyInfoModule(root, options),
558
+ Console: new BuildConsoleModule(root, options),
559
+ Meta: new BuildMetaModule(root, options),
560
+ Env: new BuildEnvModule(root, options),
561
+ Package: new BuildPackageModule(root, options)
562
+ };
563
+ return {
564
+ name: "unplugin-info",
565
+ async buildStart() {
566
+ await Promise.all(Object.values(modules).map((mod) => mod.buildStart(this)));
567
+ },
568
+ async buildEnd() {
569
+ await Promise.all(Object.values(modules).map((mod) => mod.buildEnd(this)));
570
+ },
571
+ resolveId(id) {
572
+ if (Object.values(modules).map((m) => m.name).includes(id)) {
573
+ return `\0${id}`;
574
+ }
575
+ },
576
+ loadInclude(id) {
577
+ if (!id.startsWith("\0")) return false;
578
+ id = id.slice(1);
579
+ return Object.values(modules).map((m) => m.name).includes(id);
580
+ },
581
+ async load(id) {
582
+ if (!id.startsWith("\0")) return;
583
+ id = id.slice(1);
584
+ for (const mod of Object.values(modules)) {
585
+ if (id === mod.name) {
586
+ if (id === modules.Info.name) {
587
+ this.warn(
588
+ `${modules.Info.name} is deprecated, please migrate to ${modules.Git.name} and ${modules.CI.name}.`
589
+ );
590
+ }
591
+ if (id === modules.Env.name && meta.framework !== "vite") {
592
+ this.warn(`${modules.Env.name} is only supported in Vite.`);
593
+ return;
594
+ }
595
+ return mod.load(this, id);
596
+ }
597
+ }
598
+ },
599
+ vite: {
600
+ handleHotUpdate({ file, server }) {
601
+ if (file === normalizePath(path__default.resolve(root, "package.json"))) {
602
+ const module = server.moduleGraph.getModuleById("\0" + modules.Package.name);
603
+ if (module) {
604
+ server.moduleGraph.invalidateModule(module);
605
+ server.ws.send({
606
+ type: "full-reload"
607
+ });
608
+ }
609
+ }
610
+ }
611
+ }
612
+ };
613
+ }
614
+ );
615
+ function normalizePath(filename) {
616
+ return filename.split(path__default.win32.sep).join(path__default.posix.sep);
617
+ }
618
+
619
+ exports.UnpluginInfo = UnpluginInfo;
@@ -0,0 +1,69 @@
1
+ import { SimpleGit } from 'simple-git';
2
+
3
+ type Metadata = Record<string | number, any>;
4
+ type Env = Record<string | number, any>;
5
+ type ConsoleField = string;
6
+ interface Options {
7
+ /**
8
+ * Git repo root path
9
+ */
10
+ root?: string;
11
+ /**
12
+ * Github repo url
13
+ */
14
+ github?: string;
15
+ /**
16
+ * Sepcify build time manually
17
+ */
18
+ time?: Date;
19
+ /**
20
+ * Custom the exported fields in ~build/git
21
+ */
22
+ git?: Record<string, (git: SimpleGit) => Promise<any> | any>;
23
+ /**
24
+ * Custom the exported fields in ~build/svn
25
+ */
26
+ svn?: Record<string, (info: any) => Promise<any> | any>;
27
+ /**
28
+ * Filter exported fields of package.json
29
+ */
30
+ package?: string[] | Record<string, boolean | null | undefined>;
31
+ /**
32
+ * Pass some meta data to Vite app
33
+ *
34
+ * Notice: meta data will be serialized to JSON format
35
+ */
36
+ meta?: Metadata | (() => Metadata | Promise<Metadata>);
37
+ /**
38
+ * Pass environment variables to Vite SSR app
39
+ *
40
+ * For each key / value record
41
+ * - In the SSR environment, it will read the environment variable (e.g. process.env.<key>)
42
+ * - In the client environment, it will return the provided default value
43
+ */
44
+ env?: Metadata | (() => Env | Promise<Env>);
45
+ /**
46
+ * Print help build information
47
+ */
48
+ console?: {
49
+ /**
50
+ * Enable build info log under these NODE_ENV
51
+ *
52
+ * @default ['development','production']
53
+ */
54
+ environment?: string[];
55
+ fields?: ConsoleField[] | Record<string, ConsoleField>;
56
+ };
57
+ /**
58
+ * Custom virtual module prefix
59
+ *
60
+ * @default '~build'
61
+ */
62
+ prefix?: string;
63
+ /**
64
+ * Whether it is bundled for cloudflare worker runtime
65
+ */
66
+ cloudflare?: boolean;
67
+ }
68
+
69
+ export type { Options as O };