@ts-for-gir/lib 4.0.0-beta.41 → 4.0.0-beta.42

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 +5 -5
  2. package/src/constants.ts +12 -46
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-for-gir/lib",
3
- "version": "4.0.0-beta.41",
3
+ "version": "4.0.0-beta.42",
4
4
  "description": "Typescript .d.ts generator from GIR for gjs",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -41,7 +41,7 @@
41
41
  "type definitions"
42
42
  ],
43
43
  "devDependencies": {
44
- "@ts-for-gir/tsconfig": "^4.0.0-beta.41",
44
+ "@ts-for-gir/tsconfig": "^4.0.0-beta.42",
45
45
  "@types/ejs": "^3.1.5",
46
46
  "@types/lodash": "^4.17.24",
47
47
  "@types/node": "^24.12.0",
@@ -49,9 +49,9 @@
49
49
  "typescript": "^5.9.3"
50
50
  },
51
51
  "dependencies": {
52
- "@gi.ts/parser": "^4.0.0-beta.41",
53
- "@ts-for-gir/reporter": "^4.0.0-beta.41",
54
- "@ts-for-gir/templates": "^4.0.0-beta.41",
52
+ "@gi.ts/parser": "^4.0.0-beta.42",
53
+ "@ts-for-gir/reporter": "^4.0.0-beta.42",
54
+ "@ts-for-gir/templates": "^4.0.0-beta.42",
55
55
  "colorette": "^2.0.20",
56
56
  "ejs": "^5.0.1",
57
57
  "glob": "^13.0.6",
package/src/constants.ts CHANGED
@@ -8,61 +8,27 @@ export const PARAM_REG_EXP = /[0-9a-zA-Z_]*:/g;
8
8
  export const OPT_PARAM_REG_EXP = /[0-9a-zA-Z_]*\?:/g;
9
9
  export const NEW_LINE_REG_EXP = /[\n\r]+/g;
10
10
 
11
- /**
12
- * Package information interface for package.json
13
- */
14
- interface Package {
15
- name: string;
16
- version: string;
17
- description: string;
18
- license: string;
19
- homepage: string;
20
- author: string;
21
- }
11
+ declare const __TS_FOR_GIR_VERSION__: string;
22
12
 
23
13
  /**
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
14
+ * Reads the package version, using the build-time injected value when bundled
15
+ * or falling back to reading package.json in development mode.
27
16
  */
28
- function resolvePackageJson(): string {
29
- try {
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"}`);
17
+ function getPackageVersion(): string {
18
+ if (typeof __TS_FOR_GIR_VERSION__ !== "undefined") {
19
+ return __TS_FOR_GIR_VERSION__;
41
20
  }
21
+ const currentModulePath = fileURLToPath(import.meta.url);
22
+ const currentDir = dirname(currentModulePath);
23
+ const packageJsonPath = join(currentDir, "..", "package.json");
24
+ const content = readFileSync(packageJsonPath, "utf-8");
25
+ return (JSON.parse(content) as { version: string }).version;
42
26
  }
43
27
 
44
- /**
45
- * Reads and parses the current package's package.json file synchronously
46
- * Contains version and metadata for this specific package
47
- */
48
- function readPackageSync(): Package {
49
- try {
50
- const packagePath = resolvePackageJson();
51
- const content = readFileSync(packagePath, "utf-8");
52
- return JSON.parse(content) as Package;
53
- } catch (error) {
54
- const message = error instanceof Error ? error.message : "Unknown error";
55
- throw new Error(`Failed to read package.json: ${message}`);
56
- }
57
- }
58
-
59
- // Read package information once at module load
60
- export const PACKAGE = readPackageSync();
61
-
62
28
  export const APP_NAME = "ts-for-gir";
63
29
  export const APP_USAGE = "TypeScript type definition generator for GObject introspection GIR files";
64
30
  export const APP_SOURCE = "https://github.com/gjsify/ts-for-gir";
65
- export const APP_VERSION = PACKAGE.version;
31
+ export const APP_VERSION = getPackageVersion();
66
32
 
67
33
  export const PACKAGE_DESC = (packageName: string, libraryVersion?: LibraryVersion) => {
68
34
  if (libraryVersion) {