unplugin-version-injector 1.1.1-alpha.0 → 1.1.1-alpha.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.
package/dist/core.js CHANGED
@@ -37,18 +37,30 @@ module.exports = __toCommonJS(core_exports);
37
37
  var import_unplugin = require("unplugin");
38
38
 
39
39
  // src/utils.ts
40
- var import_fs = __toESM(require("fs"));
41
- var import_path = __toESM(require("path"));
40
+ var import_node_fs = __toESM(require("fs"));
41
+ var import_node_path = __toESM(require("path"));
42
+ var import_node_url = require("url");
43
+ var import_meta = {};
42
44
  function getPackageVersion() {
43
45
  try {
44
- const packageJsonPath = import_path.default.resolve(process.cwd(), "package.json");
45
- if (import_fs.default.existsSync(packageJsonPath)) {
46
- return require(packageJsonPath).version;
46
+ const __filename = (0, import_node_url.fileURLToPath)(import_meta.url);
47
+ const __dirname = import_node_path.default.dirname(__filename);
48
+ let dir = __dirname;
49
+ while (dir !== import_node_path.default.parse(dir).root) {
50
+ const pkgPath = import_node_path.default.join(dir, "package.json");
51
+ if (import_node_fs.default.existsSync(pkgPath)) {
52
+ const content = import_node_fs.default.readFileSync(pkgPath, "utf-8");
53
+ const pkg = JSON.parse(content);
54
+ return pkg.version || "0.0.0";
55
+ }
56
+ dir = import_node_path.default.dirname(dir);
47
57
  }
48
- } catch (error) {
49
- console.warn("[VersionInjector] Failed to read package.json:", error);
58
+ console.warn("[VersionInjector] package.json not found");
59
+ return "0.0.0";
60
+ } catch (err) {
61
+ console.warn("[VersionInjector] Failed to read package.json:", err);
62
+ return "0.0.0";
50
63
  }
51
- return "0.0.0";
52
64
  }
53
65
  function defaultFormatDate(date) {
54
66
  return date.toISOString();
package/dist/core.mjs CHANGED
@@ -9,18 +9,30 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
9
9
  import { createUnplugin } from "unplugin";
10
10
 
11
11
  // src/utils.ts
12
- import fs from "fs";
13
- import path from "path";
12
+ import fs from "node:fs";
13
+ import path from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ var import_meta = {};
14
16
  function getPackageVersion() {
15
17
  try {
16
- const packageJsonPath = path.resolve(process.cwd(), "package.json");
17
- if (fs.existsSync(packageJsonPath)) {
18
- return __require(packageJsonPath).version;
18
+ const __filename = fileURLToPath(import_meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+ let dir = __dirname;
21
+ while (dir !== path.parse(dir).root) {
22
+ const pkgPath = path.join(dir, "package.json");
23
+ if (fs.existsSync(pkgPath)) {
24
+ const content = fs.readFileSync(pkgPath, "utf-8");
25
+ const pkg = JSON.parse(content);
26
+ return pkg.version || "0.0.0";
27
+ }
28
+ dir = path.dirname(dir);
19
29
  }
20
- } catch (error) {
21
- console.warn("[VersionInjector] Failed to read package.json:", error);
30
+ console.warn("[VersionInjector] package.json not found");
31
+ return "0.0.0";
32
+ } catch (err) {
33
+ console.warn("[VersionInjector] Failed to read package.json:", err);
34
+ return "0.0.0";
22
35
  }
23
- return "0.0.0";
24
36
  }
25
37
  function defaultFormatDate(date) {
26
38
  return date.toISOString();
package/dist/webpack.js CHANGED
@@ -38,18 +38,30 @@ module.exports = __toCommonJS(webpack_exports);
38
38
  var import_unplugin = require("unplugin");
39
39
 
40
40
  // src/utils.ts
41
- var import_fs = __toESM(require("fs"));
42
- var import_path = __toESM(require("path"));
41
+ var import_node_fs = __toESM(require("fs"));
42
+ var import_node_path = __toESM(require("path"));
43
+ var import_node_url = require("url");
44
+ var import_meta = {};
43
45
  function getPackageVersion() {
44
46
  try {
45
- const packageJsonPath = import_path.default.resolve(process.cwd(), "package.json");
46
- if (import_fs.default.existsSync(packageJsonPath)) {
47
- return require(packageJsonPath).version;
47
+ const __filename = (0, import_node_url.fileURLToPath)(import_meta.url);
48
+ const __dirname = import_node_path.default.dirname(__filename);
49
+ let dir = __dirname;
50
+ while (dir !== import_node_path.default.parse(dir).root) {
51
+ const pkgPath = import_node_path.default.join(dir, "package.json");
52
+ if (import_node_fs.default.existsSync(pkgPath)) {
53
+ const content = import_node_fs.default.readFileSync(pkgPath, "utf-8");
54
+ const pkg = JSON.parse(content);
55
+ return pkg.version || "0.0.0";
56
+ }
57
+ dir = import_node_path.default.dirname(dir);
48
58
  }
49
- } catch (error) {
50
- console.warn("[VersionInjector] Failed to read package.json:", error);
59
+ console.warn("[VersionInjector] package.json not found");
60
+ return "0.0.0";
61
+ } catch (err) {
62
+ console.warn("[VersionInjector] Failed to read package.json:", err);
63
+ return "0.0.0";
51
64
  }
52
- return "0.0.0";
53
65
  }
54
66
  function defaultFormatDate(date) {
55
67
  return date.toISOString();
package/dist/webpack.mjs CHANGED
@@ -9,18 +9,30 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
9
9
  import { createUnplugin } from "unplugin";
10
10
 
11
11
  // src/utils.ts
12
- import fs from "fs";
13
- import path from "path";
12
+ import fs from "node:fs";
13
+ import path from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ var import_meta = {};
14
16
  function getPackageVersion() {
15
17
  try {
16
- const packageJsonPath = path.resolve(process.cwd(), "package.json");
17
- if (fs.existsSync(packageJsonPath)) {
18
- return __require(packageJsonPath).version;
18
+ const __filename = fileURLToPath(import_meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+ let dir = __dirname;
21
+ while (dir !== path.parse(dir).root) {
22
+ const pkgPath = path.join(dir, "package.json");
23
+ if (fs.existsSync(pkgPath)) {
24
+ const content = fs.readFileSync(pkgPath, "utf-8");
25
+ const pkg = JSON.parse(content);
26
+ return pkg.version || "0.0.0";
27
+ }
28
+ dir = path.dirname(dir);
19
29
  }
20
- } catch (error) {
21
- console.warn("[VersionInjector] Failed to read package.json:", error);
30
+ console.warn("[VersionInjector] package.json not found");
31
+ return "0.0.0";
32
+ } catch (err) {
33
+ console.warn("[VersionInjector] Failed to read package.json:", err);
34
+ return "0.0.0";
22
35
  }
23
- return "0.0.0";
24
36
  }
25
37
  function defaultFormatDate(date) {
26
38
  return date.toISOString();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-version-injector",
3
- "version": "1.1.1-alpha.0",
3
+ "version": "1.1.1-alpha.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)",