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