unplugin-version-injector 1.1.1-alpha.1 → 1.1.1-alpha.3

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
@@ -39,24 +39,34 @@ var import_unplugin = require("unplugin");
39
39
  // src/utils.ts
40
40
  var import_node_path = __toESM(require("path"));
41
41
  var import_node_fs = __toESM(require("fs"));
42
- function getCallerDir() {
43
- const _stack = new Error().stack;
44
- if (!_stack) return process.cwd();
45
- const stackLines = _stack.split("\n");
46
- const callerLine = stackLines.find((l) => l.includes(".js") || l.includes(".ts")) || "";
47
- const match = callerLine.match(/\((.*):\d+:\d+\)$/) || callerLine.match(/at (.*):\d+:\d+/);
48
- if (match) return import_node_path.default.dirname(match[1]);
49
- return process.cwd();
42
+ var import_node_url = require("url");
43
+ var import_meta = {};
44
+ function getDirname() {
45
+ try {
46
+ if (typeof import_meta !== "undefined" && import_meta.url) {
47
+ return import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
48
+ }
49
+ } catch (e) {
50
+ }
51
+ return __dirname;
50
52
  }
51
53
  function getPackageVersion() {
54
+ var _a;
52
55
  try {
53
- const baseDir = getCallerDir();
54
- const pkgPath = import_node_path.default.resolve(baseDir, "package.json");
55
- const content = import_node_fs.default.readFileSync(pkgPath, "utf-8");
56
- const pkg = JSON.parse(content);
57
- return pkg.version || "0.0.0";
58
- } catch (e) {
59
- console.warn("[VersionInjector] Failed to read package.json:", e);
56
+ let dir = getDirname();
57
+ while (dir !== import_node_path.default.parse(dir).root) {
58
+ const pkgPath = import_node_path.default.join(dir, "package.json");
59
+ if (import_node_fs.default.existsSync(pkgPath)) {
60
+ const content = import_node_fs.default.readFileSync(pkgPath, "utf-8");
61
+ const pkg = JSON.parse(content);
62
+ return (_a = pkg.version) != null ? _a : "0.0.0";
63
+ }
64
+ dir = import_node_path.default.dirname(dir);
65
+ }
66
+ console.warn("[VersionInjector] package.json not found");
67
+ return "0.0.0";
68
+ } catch (err) {
69
+ console.warn("[VersionInjector] Failed to read package.json:", err);
60
70
  return "0.0.0";
61
71
  }
62
72
  }
package/dist/core.mjs CHANGED
@@ -11,24 +11,34 @@ import { createUnplugin } from "unplugin";
11
11
  // src/utils.ts
12
12
  import path from "node:path";
13
13
  import fs from "node:fs";
14
- function getCallerDir() {
15
- const _stack = new Error().stack;
16
- if (!_stack) return process.cwd();
17
- const stackLines = _stack.split("\n");
18
- const callerLine = stackLines.find((l) => l.includes(".js") || l.includes(".ts")) || "";
19
- const match = callerLine.match(/\((.*):\d+:\d+\)$/) || callerLine.match(/at (.*):\d+:\d+/);
20
- if (match) return path.dirname(match[1]);
21
- return process.cwd();
14
+ import { fileURLToPath } from "node:url";
15
+ var import_meta = {};
16
+ function getDirname() {
17
+ try {
18
+ if (typeof import_meta !== "undefined" && import_meta.url) {
19
+ return path.dirname(fileURLToPath(import_meta.url));
20
+ }
21
+ } catch (e) {
22
+ }
23
+ return __dirname;
22
24
  }
23
25
  function getPackageVersion() {
26
+ var _a;
24
27
  try {
25
- const baseDir = getCallerDir();
26
- const pkgPath = path.resolve(baseDir, "package.json");
27
- const content = fs.readFileSync(pkgPath, "utf-8");
28
- const pkg = JSON.parse(content);
29
- return pkg.version || "0.0.0";
30
- } catch (e) {
31
- console.warn("[VersionInjector] Failed to read package.json:", e);
28
+ let dir = getDirname();
29
+ while (dir !== path.parse(dir).root) {
30
+ const pkgPath = path.join(dir, "package.json");
31
+ if (fs.existsSync(pkgPath)) {
32
+ const content = fs.readFileSync(pkgPath, "utf-8");
33
+ const pkg = JSON.parse(content);
34
+ return (_a = pkg.version) != null ? _a : "0.0.0";
35
+ }
36
+ dir = path.dirname(dir);
37
+ }
38
+ console.warn("[VersionInjector] package.json not found");
39
+ return "0.0.0";
40
+ } catch (err) {
41
+ console.warn("[VersionInjector] Failed to read package.json:", err);
32
42
  return "0.0.0";
33
43
  }
34
44
  }
package/dist/webpack.js CHANGED
@@ -40,24 +40,34 @@ var import_unplugin = require("unplugin");
40
40
  // src/utils.ts
41
41
  var import_node_path = __toESM(require("path"));
42
42
  var import_node_fs = __toESM(require("fs"));
43
- function getCallerDir() {
44
- const _stack = new Error().stack;
45
- if (!_stack) return process.cwd();
46
- const stackLines = _stack.split("\n");
47
- const callerLine = stackLines.find((l) => l.includes(".js") || l.includes(".ts")) || "";
48
- const match = callerLine.match(/\((.*):\d+:\d+\)$/) || callerLine.match(/at (.*):\d+:\d+/);
49
- if (match) return import_node_path.default.dirname(match[1]);
50
- return process.cwd();
43
+ var import_node_url = require("url");
44
+ var import_meta = {};
45
+ function getDirname() {
46
+ try {
47
+ if (typeof import_meta !== "undefined" && import_meta.url) {
48
+ return import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
49
+ }
50
+ } catch (e) {
51
+ }
52
+ return __dirname;
51
53
  }
52
54
  function getPackageVersion() {
55
+ var _a;
53
56
  try {
54
- const baseDir = getCallerDir();
55
- const pkgPath = import_node_path.default.resolve(baseDir, "package.json");
56
- const content = import_node_fs.default.readFileSync(pkgPath, "utf-8");
57
- const pkg = JSON.parse(content);
58
- return pkg.version || "0.0.0";
59
- } catch (e) {
60
- console.warn("[VersionInjector] Failed to read package.json:", e);
57
+ let dir = getDirname();
58
+ while (dir !== import_node_path.default.parse(dir).root) {
59
+ const pkgPath = import_node_path.default.join(dir, "package.json");
60
+ if (import_node_fs.default.existsSync(pkgPath)) {
61
+ const content = import_node_fs.default.readFileSync(pkgPath, "utf-8");
62
+ const pkg = JSON.parse(content);
63
+ return (_a = pkg.version) != null ? _a : "0.0.0";
64
+ }
65
+ dir = import_node_path.default.dirname(dir);
66
+ }
67
+ console.warn("[VersionInjector] package.json not found");
68
+ return "0.0.0";
69
+ } catch (err) {
70
+ console.warn("[VersionInjector] Failed to read package.json:", err);
61
71
  return "0.0.0";
62
72
  }
63
73
  }
package/dist/webpack.mjs CHANGED
@@ -11,24 +11,34 @@ import { createUnplugin } from "unplugin";
11
11
  // src/utils.ts
12
12
  import path from "node:path";
13
13
  import fs from "node:fs";
14
- function getCallerDir() {
15
- const _stack = new Error().stack;
16
- if (!_stack) return process.cwd();
17
- const stackLines = _stack.split("\n");
18
- const callerLine = stackLines.find((l) => l.includes(".js") || l.includes(".ts")) || "";
19
- const match = callerLine.match(/\((.*):\d+:\d+\)$/) || callerLine.match(/at (.*):\d+:\d+/);
20
- if (match) return path.dirname(match[1]);
21
- return process.cwd();
14
+ import { fileURLToPath } from "node:url";
15
+ var import_meta = {};
16
+ function getDirname() {
17
+ try {
18
+ if (typeof import_meta !== "undefined" && import_meta.url) {
19
+ return path.dirname(fileURLToPath(import_meta.url));
20
+ }
21
+ } catch (e) {
22
+ }
23
+ return __dirname;
22
24
  }
23
25
  function getPackageVersion() {
26
+ var _a;
24
27
  try {
25
- const baseDir = getCallerDir();
26
- const pkgPath = path.resolve(baseDir, "package.json");
27
- const content = fs.readFileSync(pkgPath, "utf-8");
28
- const pkg = JSON.parse(content);
29
- return pkg.version || "0.0.0";
30
- } catch (e) {
31
- console.warn("[VersionInjector] Failed to read package.json:", e);
28
+ let dir = getDirname();
29
+ while (dir !== path.parse(dir).root) {
30
+ const pkgPath = path.join(dir, "package.json");
31
+ if (fs.existsSync(pkgPath)) {
32
+ const content = fs.readFileSync(pkgPath, "utf-8");
33
+ const pkg = JSON.parse(content);
34
+ return (_a = pkg.version) != null ? _a : "0.0.0";
35
+ }
36
+ dir = path.dirname(dir);
37
+ }
38
+ console.warn("[VersionInjector] package.json not found");
39
+ return "0.0.0";
40
+ } catch (err) {
41
+ console.warn("[VersionInjector] Failed to read package.json:", err);
32
42
  return "0.0.0";
33
43
  }
34
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-version-injector",
3
- "version": "1.1.1-alpha.1",
3
+ "version": "1.1.1-alpha.3",
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)",