unplugin-version-injector 1.1.2-beta.0 → 1.1.2-beta.1

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/rollup.js CHANGED
@@ -2,28 +2,41 @@
2
2
 
3
3
  var fs = require('fs');
4
4
  var path = require('path');
5
+ var url = require('url');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
8
 
8
9
  var fs__default = /*#__PURE__*/_interopDefault(fs);
9
10
  var path__default = /*#__PURE__*/_interopDefault(path);
10
11
 
11
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
12
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
13
- }) : x)(function(x) {
14
- if (typeof require !== "undefined") return require.apply(this, arguments);
15
- throw Error('Dynamic require of "' + x + '" is not supported');
16
- });
12
+ // src/shared/utils.ts
13
+ var import_meta = {};
17
14
  function getPackageVersion() {
18
15
  try {
19
- const packageJsonPath = path__default.default.resolve(process.cwd(), "package.json");
20
- if (fs__default.default.existsSync(packageJsonPath)) {
21
- return __require(packageJsonPath).version;
16
+ let currentDir;
17
+ const isESM = typeof __dirname === "undefined";
18
+ if (isESM) {
19
+ const metaUrl = import_meta.url || "";
20
+ currentDir = path__default.default.dirname(url.fileURLToPath(metaUrl));
21
+ } else {
22
+ currentDir = __dirname;
22
23
  }
23
- } catch (error) {
24
- console.warn("[VersionInjector] Failed to read package.json:", error);
24
+ let dir = currentDir;
25
+ while (dir !== path__default.default.parse(dir).root) {
26
+ const pkgPath = path__default.default.join(dir, "package.json");
27
+ if (fs__default.default.existsSync(pkgPath)) {
28
+ const content = fs__default.default.readFileSync(pkgPath, "utf-8");
29
+ const pkg = JSON.parse(content);
30
+ return pkg.version || "0.0.0";
31
+ }
32
+ dir = path__default.default.dirname(dir);
33
+ }
34
+ console.warn("[VersionInjector] package.json not found");
35
+ return "0.0.0";
36
+ } catch (err) {
37
+ console.warn("[VersionInjector] Failed to read package.json:", err);
38
+ return "0.0.0";
25
39
  }
26
- return "0.0.0";
27
40
  }
28
41
  function defaultFormatDate(date) {
29
42
  return date.toISOString();
package/dist/rollup.mjs CHANGED
@@ -1,22 +1,35 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { fileURLToPath } from 'node:url';
3
4
 
4
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
- }) : x)(function(x) {
7
- if (typeof require !== "undefined") return require.apply(this, arguments);
8
- throw Error('Dynamic require of "' + x + '" is not supported');
9
- });
5
+ // src/shared/utils.ts
6
+ var import_meta = {};
10
7
  function getPackageVersion() {
11
8
  try {
12
- const packageJsonPath = path.resolve(process.cwd(), "package.json");
13
- if (fs.existsSync(packageJsonPath)) {
14
- return __require(packageJsonPath).version;
9
+ let currentDir;
10
+ const isESM = typeof __dirname === "undefined";
11
+ if (isESM) {
12
+ const metaUrl = import_meta.url || "";
13
+ currentDir = path.dirname(fileURLToPath(metaUrl));
14
+ } else {
15
+ currentDir = __dirname;
15
16
  }
16
- } catch (error) {
17
- console.warn("[VersionInjector] Failed to read package.json:", error);
17
+ let dir = currentDir;
18
+ while (dir !== path.parse(dir).root) {
19
+ const pkgPath = path.join(dir, "package.json");
20
+ if (fs.existsSync(pkgPath)) {
21
+ const content = fs.readFileSync(pkgPath, "utf-8");
22
+ const pkg = JSON.parse(content);
23
+ return pkg.version || "0.0.0";
24
+ }
25
+ dir = path.dirname(dir);
26
+ }
27
+ console.warn("[VersionInjector] package.json not found");
28
+ return "0.0.0";
29
+ } catch (err) {
30
+ console.warn("[VersionInjector] Failed to read package.json:", err);
31
+ return "0.0.0";
18
32
  }
19
- return "0.0.0";
20
33
  }
21
34
  function defaultFormatDate(date) {
22
35
  return date.toISOString();
package/dist/vite.js CHANGED
@@ -2,28 +2,41 @@
2
2
 
3
3
  var fs = require('fs');
4
4
  var path = require('path');
5
+ var url = require('url');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
8
 
8
9
  var fs__default = /*#__PURE__*/_interopDefault(fs);
9
10
  var path__default = /*#__PURE__*/_interopDefault(path);
10
11
 
11
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
12
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
13
- }) : x)(function(x) {
14
- if (typeof require !== "undefined") return require.apply(this, arguments);
15
- throw Error('Dynamic require of "' + x + '" is not supported');
16
- });
12
+ // src/shared/utils.ts
13
+ var import_meta = {};
17
14
  function getPackageVersion() {
18
15
  try {
19
- const packageJsonPath = path__default.default.resolve(process.cwd(), "package.json");
20
- if (fs__default.default.existsSync(packageJsonPath)) {
21
- return __require(packageJsonPath).version;
16
+ let currentDir;
17
+ const isESM = typeof __dirname === "undefined";
18
+ if (isESM) {
19
+ const metaUrl = import_meta.url || "";
20
+ currentDir = path__default.default.dirname(url.fileURLToPath(metaUrl));
21
+ } else {
22
+ currentDir = __dirname;
22
23
  }
23
- } catch (error) {
24
- console.warn("[VersionInjector] Failed to read package.json:", error);
24
+ let dir = currentDir;
25
+ while (dir !== path__default.default.parse(dir).root) {
26
+ const pkgPath = path__default.default.join(dir, "package.json");
27
+ if (fs__default.default.existsSync(pkgPath)) {
28
+ const content = fs__default.default.readFileSync(pkgPath, "utf-8");
29
+ const pkg = JSON.parse(content);
30
+ return pkg.version || "0.0.0";
31
+ }
32
+ dir = path__default.default.dirname(dir);
33
+ }
34
+ console.warn("[VersionInjector] package.json not found");
35
+ return "0.0.0";
36
+ } catch (err) {
37
+ console.warn("[VersionInjector] Failed to read package.json:", err);
38
+ return "0.0.0";
25
39
  }
26
- return "0.0.0";
27
40
  }
28
41
  function defaultFormatDate(date) {
29
42
  return date.toISOString();
package/dist/vite.mjs CHANGED
@@ -1,22 +1,35 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { fileURLToPath } from 'node:url';
3
4
 
4
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
- }) : x)(function(x) {
7
- if (typeof require !== "undefined") return require.apply(this, arguments);
8
- throw Error('Dynamic require of "' + x + '" is not supported');
9
- });
5
+ // src/shared/utils.ts
6
+ var import_meta = {};
10
7
  function getPackageVersion() {
11
8
  try {
12
- const packageJsonPath = path.resolve(process.cwd(), "package.json");
13
- if (fs.existsSync(packageJsonPath)) {
14
- return __require(packageJsonPath).version;
9
+ let currentDir;
10
+ const isESM = typeof __dirname === "undefined";
11
+ if (isESM) {
12
+ const metaUrl = import_meta.url || "";
13
+ currentDir = path.dirname(fileURLToPath(metaUrl));
14
+ } else {
15
+ currentDir = __dirname;
15
16
  }
16
- } catch (error) {
17
- console.warn("[VersionInjector] Failed to read package.json:", error);
17
+ let dir = currentDir;
18
+ while (dir !== path.parse(dir).root) {
19
+ const pkgPath = path.join(dir, "package.json");
20
+ if (fs.existsSync(pkgPath)) {
21
+ const content = fs.readFileSync(pkgPath, "utf-8");
22
+ const pkg = JSON.parse(content);
23
+ return pkg.version || "0.0.0";
24
+ }
25
+ dir = path.dirname(dir);
26
+ }
27
+ console.warn("[VersionInjector] package.json not found");
28
+ return "0.0.0";
29
+ } catch (err) {
30
+ console.warn("[VersionInjector] Failed to read package.json:", err);
31
+ return "0.0.0";
18
32
  }
19
- return "0.0.0";
20
33
  }
21
34
  function defaultFormatDate(date) {
22
35
  return date.toISOString();
package/dist/webpack.js CHANGED
@@ -2,28 +2,41 @@
2
2
 
3
3
  var fs = require('fs');
4
4
  var path = require('path');
5
+ var url = require('url');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
8
 
8
9
  var fs__default = /*#__PURE__*/_interopDefault(fs);
9
10
  var path__default = /*#__PURE__*/_interopDefault(path);
10
11
 
11
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
12
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
13
- }) : x)(function(x) {
14
- if (typeof require !== "undefined") return require.apply(this, arguments);
15
- throw Error('Dynamic require of "' + x + '" is not supported');
16
- });
12
+ // src/shared/utils.ts
13
+ var import_meta = {};
17
14
  function getPackageVersion() {
18
15
  try {
19
- const packageJsonPath = path__default.default.resolve(process.cwd(), "package.json");
20
- if (fs__default.default.existsSync(packageJsonPath)) {
21
- return __require(packageJsonPath).version;
16
+ let currentDir;
17
+ const isESM = typeof __dirname === "undefined";
18
+ if (isESM) {
19
+ const metaUrl = import_meta.url || "";
20
+ currentDir = path__default.default.dirname(url.fileURLToPath(metaUrl));
21
+ } else {
22
+ currentDir = __dirname;
22
23
  }
23
- } catch (error) {
24
- console.warn("[VersionInjector] Failed to read package.json:", error);
24
+ let dir = currentDir;
25
+ while (dir !== path__default.default.parse(dir).root) {
26
+ const pkgPath = path__default.default.join(dir, "package.json");
27
+ if (fs__default.default.existsSync(pkgPath)) {
28
+ const content = fs__default.default.readFileSync(pkgPath, "utf-8");
29
+ const pkg = JSON.parse(content);
30
+ return pkg.version || "0.0.0";
31
+ }
32
+ dir = path__default.default.dirname(dir);
33
+ }
34
+ console.warn("[VersionInjector] package.json not found");
35
+ return "0.0.0";
36
+ } catch (err) {
37
+ console.warn("[VersionInjector] Failed to read package.json:", err);
38
+ return "0.0.0";
25
39
  }
26
- return "0.0.0";
27
40
  }
28
41
  function defaultFormatDate(date) {
29
42
  return date.toISOString();
package/dist/webpack.mjs CHANGED
@@ -1,22 +1,35 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { fileURLToPath } from 'node:url';
3
4
 
4
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
- }) : x)(function(x) {
7
- if (typeof require !== "undefined") return require.apply(this, arguments);
8
- throw Error('Dynamic require of "' + x + '" is not supported');
9
- });
5
+ // src/shared/utils.ts
6
+ var import_meta = {};
10
7
  function getPackageVersion() {
11
8
  try {
12
- const packageJsonPath = path.resolve(process.cwd(), "package.json");
13
- if (fs.existsSync(packageJsonPath)) {
14
- return __require(packageJsonPath).version;
9
+ let currentDir;
10
+ const isESM = typeof __dirname === "undefined";
11
+ if (isESM) {
12
+ const metaUrl = import_meta.url || "";
13
+ currentDir = path.dirname(fileURLToPath(metaUrl));
14
+ } else {
15
+ currentDir = __dirname;
15
16
  }
16
- } catch (error) {
17
- console.warn("[VersionInjector] Failed to read package.json:", error);
17
+ let dir = currentDir;
18
+ while (dir !== path.parse(dir).root) {
19
+ const pkgPath = path.join(dir, "package.json");
20
+ if (fs.existsSync(pkgPath)) {
21
+ const content = fs.readFileSync(pkgPath, "utf-8");
22
+ const pkg = JSON.parse(content);
23
+ return pkg.version || "0.0.0";
24
+ }
25
+ dir = path.dirname(dir);
26
+ }
27
+ console.warn("[VersionInjector] package.json not found");
28
+ return "0.0.0";
29
+ } catch (err) {
30
+ console.warn("[VersionInjector] Failed to read package.json:", err);
31
+ return "0.0.0";
18
32
  }
19
- return "0.0.0";
20
33
  }
21
34
  function defaultFormatDate(date) {
22
35
  return date.toISOString();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-version-injector",
3
- "version": "1.1.2-beta.0",
3
+ "version": "1.1.2-beta.1",
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)",