@ts-for-gir/lib 4.0.0-beta.31 → 4.0.0-beta.32

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 (2) hide show
  1. package/package.json +4 -4
  2. package/src/constants.ts +15 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-for-gir/lib",
3
- "version": "4.0.0-beta.31",
3
+ "version": "4.0.0-beta.32",
4
4
  "description": "Typescript .d.ts generator from GIR for gjs",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -48,9 +48,9 @@
48
48
  "typescript": "^5.9.2"
49
49
  },
50
50
  "dependencies": {
51
- "@gi.ts/parser": "^4.0.0-beta.31",
52
- "@ts-for-gir/reporter": "^4.0.0-beta.31",
53
- "@ts-for-gir/templates": "^4.0.0-beta.31",
51
+ "@gi.ts/parser": "^4.0.0-beta.32",
52
+ "@ts-for-gir/reporter": "^4.0.0-beta.32",
53
+ "@ts-for-gir/templates": "^4.0.0-beta.32",
54
54
  "colorette": "^2.0.20",
55
55
  "ejs": "^3.1.10",
56
56
  "glob": "^11.0.3",
package/src/constants.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { createRequire } from "node:module";
2
- import { dirname, resolve } from "node:path";
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
3
4
  import type { LibraryVersion } from "./library-version.ts";
4
5
 
5
- const require = createRequire(import.meta.url);
6
-
7
6
  export const COMMENT_REG_EXP = /\/\*.*\*\//g;
8
7
  export const PARAM_REG_EXP = /[0-9a-zA-Z_]*:/g;
9
8
  export const OPT_PARAM_REG_EXP = /[0-9a-zA-Z_]*\?:/g;
@@ -23,20 +22,22 @@ interface Package {
23
22
 
24
23
  /**
25
24
  * Resolves the current package's package.json path
25
+ * Uses import.meta.url for ES Module compatibility
26
26
  * Works both in workspace and after publishing
27
27
  */
28
28
  function resolvePackageJson(): string {
29
29
  try {
30
- // Try to resolve the current package's package.json
31
- return require.resolve("@ts-for-gir/lib/package.json");
32
- } catch {
33
- // Fallback: try to resolve from current module location
34
- try {
35
- const currentModule = require.resolve("@ts-for-gir/lib");
36
- return resolve(dirname(currentModule), "..", "package.json");
37
- } catch {
38
- throw new Error("Unable to resolve package.json path");
39
- }
30
+ // Get the directory of the current module
31
+ const currentModulePath = fileURLToPath(import.meta.url);
32
+ const currentDir = dirname(currentModulePath);
33
+
34
+ // Go up to the package root (src/ -> package root)
35
+ const packageRoot = join(currentDir, "..");
36
+ const packageJsonPath = join(packageRoot, "package.json");
37
+
38
+ return packageJsonPath;
39
+ } catch (error) {
40
+ throw new Error(`Unable to resolve package.json path: ${error instanceof Error ? error.message : "Unknown error"}`);
40
41
  }
41
42
  }
42
43
 
@@ -47,8 +48,6 @@ function resolvePackageJson(): string {
47
48
  function readPackageSync(): Package {
48
49
  try {
49
50
  const packagePath = resolvePackageJson();
50
- // Use dynamic import to avoid top-level await in constants
51
- const { readFileSync } = require("node:fs");
52
51
  const content = readFileSync(packagePath, "utf-8");
53
52
  return JSON.parse(content) as Package;
54
53
  } catch (error) {