@ts-for-gir/lib 4.0.0-rc.7 → 4.0.0-rc.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-for-gir/lib",
3
- "version": "4.0.0-rc.7",
3
+ "version": "4.0.0-rc.8",
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-rc.7",
44
+ "@ts-for-gir/tsconfig": "^4.0.0-rc.8",
45
45
  "@types/ejs": "^3.1.5",
46
46
  "@types/lodash": "^4.17.24",
47
47
  "@types/node": "^25.6.0",
@@ -49,9 +49,9 @@
49
49
  "typescript": "^6.0.3"
50
50
  },
51
51
  "dependencies": {
52
- "@gi.ts/parser": "^4.0.0-rc.7",
53
- "@ts-for-gir/reporter": "^4.0.0-rc.7",
54
- "@ts-for-gir/templates": "^4.0.0-rc.7",
52
+ "@gi.ts/parser": "^4.0.0-rc.8",
53
+ "@ts-for-gir/reporter": "^4.0.0-rc.8",
54
+ "@ts-for-gir/templates": "^4.0.0-rc.8",
55
55
  "colorette": "^2.0.20",
56
56
  "ejs": "^5.0.2",
57
57
  "glob": "^13.0.6",
package/src/constants.ts CHANGED
@@ -18,11 +18,18 @@ function getPackageVersion(): string {
18
18
  if (typeof __TS_FOR_GIR_VERSION__ !== "undefined") {
19
19
  return __TS_FOR_GIR_VERSION__;
20
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;
21
+ // Dev mode reads the sibling package.json relative to this source file.
22
+ // Wrapped in try/catch so a bundle missing the __TS_FOR_GIR_VERSION__ define
23
+ // degrades to a fallback string instead of throwing at module load.
24
+ try {
25
+ const currentModulePath = fileURLToPath(import.meta.url);
26
+ const currentDir = dirname(currentModulePath);
27
+ const packageJsonPath = join(currentDir, "..", "package.json");
28
+ const content = readFileSync(packageJsonPath, "utf-8");
29
+ return (JSON.parse(content) as { version: string }).version;
30
+ } catch {
31
+ return "0.0.0-unknown";
32
+ }
26
33
  }
27
34
 
28
35
  export const APP_NAME = "ts-for-gir";
@@ -37,7 +37,9 @@ export function addTSDocCommentLines(lines: string[], indentCount = 0): string[]
37
37
  }
38
38
 
39
39
  /**
40
- * Adds an info comment, is used for debugging the generated types
40
+ * Adds an info comment, is used for debugging the generated types.
41
+ * One blank line before the comment, one after — readers see a single
42
+ * blank-line separator on each side without a double-blank gap.
41
43
  */
42
44
  export function addInfoComment(comment?: string, indentCount = 0): string[] {
43
45
  const def: string[] = [];
@@ -45,7 +47,6 @@ export function addInfoComment(comment?: string, indentCount = 0): string[] {
45
47
  if (comment) {
46
48
  def.push("");
47
49
  def.push(`${indent}// ${comment}`);
48
- def.push("");
49
50
  }
50
51
  return def;
51
52
  }
@@ -58,7 +59,8 @@ export function mergeDescs(descs: string[], comment?: string, indentCount = 1):
58
59
  const indent = generateIndent(indentCount);
59
60
 
60
61
  for (const desc of descs) {
61
- def.push(`${indent}${desc}`);
62
+ // Empty separator strings stay empty; only real content gets indented.
63
+ def.push(desc.length === 0 ? desc : `${indent}${desc}`);
62
64
  }
63
65
 
64
66
  if (def.length > 0) {
package/src/utils/path.ts CHANGED
@@ -1,7 +1,15 @@
1
1
  import { dirname, resolve } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
3
 
4
- // Get __filename on ESM
5
- const __filename = fileURLToPath(import.meta.url);
6
- // Get __dirname on ESM, resolve to the root directory of this package
7
- export const __dirname = resolve(dirname(__filename), "../.."); // TODO: Bundled this must be '..' but unbundled it must be '../..'
4
+ // Resolves to the root directory of this package in dev mode.
5
+ // Wrapped in try/catch so a bundled consumer that lacks `import.meta.url`
6
+ // support degrades to "" instead of crashing at module load.
7
+ function resolvePackageDir(): string {
8
+ try {
9
+ return resolve(dirname(fileURLToPath(import.meta.url)), "../..");
10
+ } catch {
11
+ return "";
12
+ }
13
+ }
14
+
15
+ export const __dirname = resolvePackageDir();