@ts-for-gir/generator-typescript 3.2.3 → 3.2.5

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/generator-typescript",
3
- "version": "3.2.3",
3
+ "version": "3.2.5",
4
4
  "description": "TypeScript type definition generator for ts-for-gir",
5
5
  "module": "lib/index.js",
6
6
  "main": "lib/index.js",
@@ -35,18 +35,18 @@
35
35
  "generator"
36
36
  ],
37
37
  "devDependencies": {
38
- "@types/node": "^20.8.10",
39
- "@typescript-eslint/eslint-plugin": "^6.9.1",
40
- "@typescript-eslint/parser": "^6.9.1",
41
- "eslint": "^8.52.0",
38
+ "@types/node": "^20.9.0",
39
+ "@typescript-eslint/eslint-plugin": "^6.11.0",
40
+ "@typescript-eslint/parser": "^6.11.0",
41
+ "eslint": "^8.53.0",
42
42
  "eslint-config-prettier": "^9.0.0",
43
43
  "eslint-plugin-prettier": "^5.0.1",
44
- "prettier": "^3.0.3",
44
+ "prettier": "^3.1.0",
45
45
  "rimraf": "^5.0.5",
46
46
  "typescript": "^5.2.2"
47
47
  },
48
48
  "dependencies": {
49
- "@ts-for-gir/generator-base": "^3.2.3",
50
- "@ts-for-gir/lib": "^3.2.3"
49
+ "@ts-for-gir/generator-base": "^3.2.5",
50
+ "@ts-for-gir/lib": "^3.2.5"
51
51
  }
52
52
  }
@@ -97,6 +97,19 @@ const <%= pkg.namespace %> = imports.gi.<%= pkg.namespace %>;
97
97
  ```
98
98
  <%_ } _%>
99
99
 
100
+
101
+ ### ESM vs. CommonJS
102
+
103
+ GJS supports two different import syntaxes. The new modern ESM syntax and the old global imports syntax.
104
+
105
+ In TypeScript projects for GJS and GNOME Shell extensions, you have the flexibility to use `ESM` syntax and then decide the import syntax for your bundled file. If your bundler is configured to use `CommonJS`, it will convert to the GJS-specific global imports syntax, like `const moduleName = imports.gi[moduleName]`. This is different from the traditional `require` syntax seen in Node.js. The global imports syntax is chosen because it aligns with the CommonJS format supported by NPM, which is used for the generated type definitions and this package.
106
+
107
+ On the other hand, if you configure your bundler to use ESM, it will retain the ESM import syntax. It's crucial to ensure that your bundler is set up to correctly translate and bundle these imports into either CommonJS or ESM format, depending on your project's requirements.
108
+
109
+ This approach is particularly important due to the `@girs` types, which include both `*.cjs `files, using the GJS global imports syntax, and `*.js` files, which utilize the ESM syntax. By appropriately setting up your bundler, you can control which syntax—CommonJS or ESM—is used in your project. The choice of CommonJS in this context is also due to the similarity between the GJS-specific global imports and CommonJS syntax, allowing for easier management and bundling in these specific types of projects.
110
+
111
+ Since GNOME Shell 45, you should only use ESM, even for GNOME Shell extensions. Before that, extensions had to use the global import syntax, unlike normal GJS applications, where ESM has been available for some time.
112
+
100
113
  ### Bundle
101
114
 
102
115
  Depending on your project configuration, it is recommended to use a bundler like [esbuild](https://esbuild.github.io/). You can find examples using different bundlers [here](https://github.com/gjsify/ts-for-gir/tree/main/examples).
@@ -1,7 +1,7 @@
1
1
  <%#
2
- This EJS template is used for the generated .d.ts files for ambient typescript module support.
3
- See https://www.typescriptlang.org/docs/handbook/modules.html#ambient-modules
4
- %>
2
+ // This EJS template is used for the generated .d.ts files for ambient typescript module support.
3
+ // See https://www.typescriptlang.org/docs/handbook/modules.html#ambient-modules
4
+ _%>
5
5
  <%_ const pkg = dep.get(girModule.namespace, girModule.version) _%>
6
6
  <%_ let moduleImportStr = ""; _%>
7
7
  <%_ if(package){ _%>
@@ -23,7 +23,8 @@ declare module 'gi://<%= name %>?version=<%= version %>' {
23
23
  export default <%- girModule.importNamespace -%>;
24
24
  }
25
25
 
26
- <%_ if(!dep.hasConflict(name, version)){ _%>
26
+ <%# // Generate ambient module declarations Without version number if there are no conflicts or the target is an NPM package _%>
27
+ <%_ if(package || !dep.hasConflict(name, version)){ _%>
27
28
  declare module 'gi://<%= name %>' {
28
29
  <%- moduleImportStr %>;
29
30
  export default <%- girModule.importNamespace -%>;
@@ -1,6 +1,6 @@
1
1
  <%#
2
- This EJS template is used to extend the global GjsGiImports interface with the GIR module, for `imports.gi[namespace] GJS GIR types`
3
- %>
2
+ // This EJS template is used to extend the global GjsGiImports interface with the GIR module, for `imports.gi[namespace] GJS GIR types`
3
+ _%>
4
4
  <%_ if(!package && !dep.isLatestVersion(girModule.namespace, girModule.version)){ _%>
5
5
  <%_ return `// Module import type definition not generated, otherwise this would cause a type conflict, this is because several GIR modules were generated with the same namespace: "${ girModule.namespace }"` _%>
6
6
  <%_ } _%>