unplugin-version-injector 1.1.1 → 1.1.2

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.
@@ -0,0 +1,5 @@
1
+ export interface VersionInjectorOptions {
2
+ version?: string;
3
+ log?: boolean;
4
+ formatDate?: (date: Date) => string;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ /** 获取 package.json 版本 */
2
+ export declare function getPackageVersion(): string;
3
+ /** 默认格式化 build time */
4
+ export declare function defaultFormatDate(date: Date): string;
@@ -0,0 +1,19 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ /** 获取 package.json 版本 */
4
+ export function getPackageVersion() {
5
+ try {
6
+ const packageJsonPath = path.resolve(process.cwd(), 'package.json');
7
+ if (fs.existsSync(packageJsonPath)) {
8
+ return require(packageJsonPath).version;
9
+ }
10
+ }
11
+ catch (error) {
12
+ console.warn('[VersionInjector] Failed to read package.json:', error);
13
+ }
14
+ return '0.0.0';
15
+ }
16
+ /** 默认格式化 build time */
17
+ export function defaultFormatDate(date) {
18
+ return date.toISOString();
19
+ }
package/package.json CHANGED
@@ -1,53 +1,41 @@
1
1
  {
2
2
  "name": "unplugin-version-injector",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "author": "Nian Yi <nianyi778@gmail.com>",
5
5
  "license": "MIT",
6
6
  "description": "A universal plugin to inject version and build time into HTML (supports Webpack, Vite, Rollup)",
7
7
  "repository": {
8
- "type": "git",
9
- "url": "https://github.com/nianyi778/unplugin-version-injector.git"
8
+ "type": "git",
9
+ "url": "https://github.com/nianyi778/unplugin-version-injector.git"
10
10
  },
11
- "keywords": [
12
- "unplugin",
13
- "version",
14
- "injector",
15
- "webpack",
16
- "vite",
17
- "rollup"
18
- ],
19
- "main": "./dist/index.cjs",
20
- "module": "./dist/index.mjs",
21
- "types": "./dist/index.d.ts",
11
+ "keywords": ["unplugin", "version", "injector", "webpack", "vite", "rollup"],
12
+ "main": "./dist/cjs/index.js",
13
+ "module": "./dist/esm/index.js",
22
14
  "exports": {
23
- ".": {
24
- "import": "./dist/index.mjs",
25
- "require": "./dist/index.cjs"
26
- }
15
+ "require": "./dist/cjs/index.js",
16
+ "import": "./dist/esm/index.js",
17
+ "default": "./dist/esm/index.js"
27
18
  },
19
+ "types": "./dist/index.d.ts",
28
20
  "scripts": {
29
- "clean": "rm -rf dist",
30
- "build": "tsup",
31
- "dev": "tsup --watch",
32
- "prepublishOnly": "npm run clean && npm run build"
21
+ "clean": "rm -rf dist",
22
+ "build:esm": "tsc --module ESNext --outDir dist/esm",
23
+ "build:cjs": "tsc --module CommonJS --outDir dist/cjs",
24
+ "build": "npm run clean && npm run build:esm && npm run build:cjs",
25
+ "prepublishOnly": "npm run build"
33
26
  },
34
27
  "dependencies": {
35
- "unplugin": "^1.0.0"
28
+ "unplugin": "^1.0.0"
36
29
  },
37
30
  "devDependencies": {
38
- "rollup": "^3",
39
- "tsup": "^8.4.0",
40
- "typescript": "^4.9.5",
41
- "vite": "^4",
42
- "webpack": "^5"
31
+ "typescript": "^4.9.5",
32
+ "webpack": "^5",
33
+ "vite": "^4",
34
+ "rollup": "^3"
43
35
  },
44
36
  "publishConfig": {
45
- "access": "public"
37
+ "access": "public"
46
38
  },
47
- "files": [
48
- "dist",
49
- "README.md",
50
- "README.zh-CN.md"
51
- ],
39
+ "files": ["dist","README.md","README.zh-CN.md"],
52
40
  "packageManager": "pnpm@10.5.2+sha512.da9dc28cd3ff40d0592188235ab25d3202add8a207afbedc682220e4a0029ffbff4562102b9e6e46b4e3f9e8bd53e6d05de48544b0c57d4b0179e22c76d1199b"
53
- }
41
+ }
package/dist/index.d.mts DELETED
@@ -1,20 +0,0 @@
1
- import * as _rollup from 'rollup';
2
- import * as _webpack from 'webpack';
3
- import * as _vite from 'vite';
4
- import * as unplugin from 'unplugin';
5
-
6
- interface VersionInjectorOptions {
7
- version?: string;
8
- formatDate?: (date: Date) => string;
9
- dateFormat?: string;
10
- injectToHead?: boolean;
11
- injectToBody?: boolean;
12
- }
13
-
14
- declare const VersionInjectorPlugin: unplugin.UnpluginInstance<VersionInjectorOptions | undefined, boolean>;
15
-
16
- declare const vite: (options?: VersionInjectorOptions | undefined) => _vite.Plugin | _vite.Plugin[];
17
- declare const webpack: (options?: VersionInjectorOptions | undefined) => _webpack.WebpackPluginInstance;
18
- declare const rollup: (options?: VersionInjectorOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
19
-
20
- export { VersionInjectorPlugin as default, rollup, vite, webpack };
package/dist/index.d.ts DELETED
@@ -1,20 +0,0 @@
1
- import * as _rollup from 'rollup';
2
- import * as _webpack from 'webpack';
3
- import * as _vite from 'vite';
4
- import * as unplugin from 'unplugin';
5
-
6
- interface VersionInjectorOptions {
7
- version?: string;
8
- formatDate?: (date: Date) => string;
9
- dateFormat?: string;
10
- injectToHead?: boolean;
11
- injectToBody?: boolean;
12
- }
13
-
14
- declare const VersionInjectorPlugin: unplugin.UnpluginInstance<VersionInjectorOptions | undefined, boolean>;
15
-
16
- declare const vite: (options?: VersionInjectorOptions | undefined) => _vite.Plugin | _vite.Plugin[];
17
- declare const webpack: (options?: VersionInjectorOptions | undefined) => _webpack.WebpackPluginInstance;
18
- declare const rollup: (options?: VersionInjectorOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
19
-
20
- export { VersionInjectorPlugin as default, rollup, vite, webpack };