@ts-for-gir/lib 4.0.0-beta.30 → 4.0.0-beta.31
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/package.json +4 -4
- package/src/constants.ts +19 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-for-gir/lib",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.31",
|
|
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.
|
|
52
|
-
"@ts-for-gir/reporter": "^4.0.0-beta.
|
|
53
|
-
"@ts-for-gir/templates": "^4.0.0-beta.
|
|
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",
|
|
54
54
|
"colorette": "^2.0.20",
|
|
55
55
|
"ejs": "^3.1.10",
|
|
56
56
|
"glob": "^11.0.3",
|
package/src/constants.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { dirname,
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
3
|
import type { LibraryVersion } from "./library-version.ts";
|
|
4
4
|
|
|
5
5
|
const require = createRequire(import.meta.url);
|
|
@@ -10,9 +10,9 @@ export const OPT_PARAM_REG_EXP = /[0-9a-zA-Z_]*\?:/g;
|
|
|
10
10
|
export const NEW_LINE_REG_EXP = /[\n\r]+/g;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Package information interface for
|
|
13
|
+
* Package information interface for package.json
|
|
14
14
|
*/
|
|
15
|
-
interface
|
|
15
|
+
interface Package {
|
|
16
16
|
name: string;
|
|
17
17
|
version: string;
|
|
18
18
|
description: string;
|
|
@@ -22,44 +22,43 @@ interface WorkspacePackage {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Resolves the
|
|
26
|
-
*
|
|
25
|
+
* Resolves the current package's package.json path
|
|
26
|
+
* Works both in workspace and after publishing
|
|
27
27
|
*/
|
|
28
|
-
function
|
|
28
|
+
function resolvePackageJson(): string {
|
|
29
29
|
try {
|
|
30
|
-
// Try to resolve
|
|
31
|
-
|
|
32
|
-
return require.resolve("../../../package.json");
|
|
30
|
+
// Try to resolve the current package's package.json
|
|
31
|
+
return require.resolve("@ts-for-gir/lib/package.json");
|
|
33
32
|
} catch {
|
|
34
|
-
// Fallback: try to resolve from current
|
|
33
|
+
// Fallback: try to resolve from current module location
|
|
35
34
|
try {
|
|
36
|
-
const
|
|
37
|
-
return
|
|
35
|
+
const currentModule = require.resolve("@ts-for-gir/lib");
|
|
36
|
+
return resolve(dirname(currentModule), "..", "package.json");
|
|
38
37
|
} catch {
|
|
39
|
-
throw new Error("Unable to resolve
|
|
38
|
+
throw new Error("Unable to resolve package.json path");
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
|
-
* Reads and parses the
|
|
46
|
-
* Contains version and metadata
|
|
44
|
+
* Reads and parses the current package's package.json file synchronously
|
|
45
|
+
* Contains version and metadata for this specific package
|
|
47
46
|
*/
|
|
48
|
-
function
|
|
47
|
+
function readPackageSync(): Package {
|
|
49
48
|
try {
|
|
50
|
-
const packagePath =
|
|
49
|
+
const packagePath = resolvePackageJson();
|
|
51
50
|
// Use dynamic import to avoid top-level await in constants
|
|
52
51
|
const { readFileSync } = require("node:fs");
|
|
53
52
|
const content = readFileSync(packagePath, "utf-8");
|
|
54
|
-
return JSON.parse(content) as
|
|
53
|
+
return JSON.parse(content) as Package;
|
|
55
54
|
} catch (error) {
|
|
56
55
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
57
|
-
throw new Error(`Failed to read
|
|
56
|
+
throw new Error(`Failed to read package.json: ${message}`);
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
// Read package information once at module load
|
|
62
|
-
export const PACKAGE =
|
|
61
|
+
export const PACKAGE = readPackageSync();
|
|
63
62
|
|
|
64
63
|
export const APP_NAME = "ts-for-gir";
|
|
65
64
|
export const APP_USAGE = "TypeScript type definition generator for GObject introspection GIR files";
|