diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d0d2325..2f9a4a9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,26 +11,24 @@ on: branches: - "*" jobs: - examples: + ci: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: - node-version: [20.x] + node-version: [22.x] architecture: - x64 steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v3 with: submodules: true - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - # - name: Workaround for bad mirror - # run: sudo gem install apt-spy2; sudo apt-spy2 check; sudo apt-spy2 fix --commit; - name: Update package repository run: sudo apt-get update; # sudo apt-get upgrade - name: Install dependencies @@ -40,36 +38,11 @@ jobs: - run: gjs --version - run: yarn install - run: yarn build - - run: yarn build:examples - - run: yarn validate:examples - - run: yarn test:examples:cli-apps - - gjs-types-all: - - runs-on: ubuntu-22.04 - - strategy: - matrix: - node-version: [20.x] - architecture: - - x64 - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - submodules: true - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - name: Update package repository - run: sudo apt-get update; # sudo apt-get upgrade - - name: Install dependencies - run: sudo apt-get --yes install gjs libappindicator3-dev libgda-5.0-dev libgirepository1.0-dev libgtk-3-dev libgtk-4-dev libgtksourceview-3.0-dev libnotify-dev libsoup2.4-dev libsoup-3.0-dev libwebkit2gtk-4.0-dev libadwaita-1-dev gnome-shell-common libmutter-10-dev libgcr-3-dev libgnome-desktop-3-dev build-essential gobject-introspection libgirepository1.0-dev libcairo2-dev - - run: yarn install - - run: yarn build - run: yarn build:types:packages - name: Show diff run: (cd ./types && git diff | cat) - run: yarn validate:types:packages - - run: yarn test:tests \ No newline at end of file + - run: yarn test:tests + - run: yarn build:examples + - run: yarn validate:examples + - run: yarn test:examples:cli-apps \ No newline at end of file diff --git a/examples/gio-2-cat/main.ts b/examples/gio-2-cat/main.ts index 86e181e6..c291a912 100644 --- a/examples/gio-2-cat/main.ts +++ b/examples/gio-2-cat/main.ts @@ -11,33 +11,37 @@ * the label should show a translation of 'Print help' */ -import '@girs/gjs'; -import '@girs/gjs/dom'; -import GLib from '@girs/glib-2.0'; -import Gio from '@girs/gio-2.0'; +import '@girs/gjs' +import '@girs/gjs/dom' +import GLib from '@girs/glib-2.0' +import Gio from '@girs/gio-2.0' -const loop = GLib.MainLoop.new(null, false); +const loop = GLib.MainLoop.new(null, false) const textDecoder = new TextDecoder() function cat(filename: string) { - const file = Gio.file_new_for_path(filename); + const file = Gio.file_new_for_path(filename) + file.load_contents_async(null, (obj, res) => { - let contents: Uint8Array; + let contents: Uint8Array try { - contents = obj!.load_contents_finish(res)![1]; + contents = obj!.load_contents_finish(res)![1] } catch (e) { - logError(e); - loop.quit(); - return; + logError(e) + loop.quit() + return } - print(textDecoder.decode(contents)); - loop.quit(); - }); + print(textDecoder.decode(contents)) + loop.quit() + }) + + // Tests instanceof, see https://github.com/gjsify/ts-for-gir/issues/195 + if (!(file instanceof Gio.File)) { + throw new Error('file is not an instance of Gio.File') + } - loop.run(); + loop.run() } -if (ARGV.length !== 1) - printerr('Usage: gio-cat.js filename'); -else - cat(ARGV[0]); +if (ARGV.length !== 1) printerr('Usage: gio-cat.js filename') +else cat(ARGV[0]) diff --git a/packages/generator-typescript/src/module-generator.ts b/packages/generator-typescript/src/module-generator.ts index 8f24e347..d77a20b4 100644 --- a/packages/generator-typescript/src/module-generator.ts +++ b/packages/generator-typescript/src/module-generator.ts @@ -217,7 +217,11 @@ export class ModuleGenerator extends FormatGenerator { ] } generateInterfaceDeclaration(node: IntrospectedInterface): string[] { - return [`\n\nexport const ${node.name}: ${node.name}Namespace;\n`] + return [ + `\n\nexport const ${node.name}: ${node.name}Namespace & { + new (): ${node.name} // This allows \`obj instanceof ${node.name}\` + }\n`, + ] } generateError(node: IntrospectedError): string[] { const { namespace } = this diff --git a/packages/generator-typescript/templates/tsconfig.json b/packages/generator-typescript/templates/tsconfig.json index 0744895f..6ec1194a 100644 --- a/packages/generator-typescript/templates/tsconfig.json +++ b/packages/generator-typescript/templates/tsconfig.json @@ -24,7 +24,9 @@ _%> "removeComments": false, "inlineSourceMap": false, "inlineSources": false, - "newLine": "LF" + "newLine": "LF", + // Show diagnostics + "diagnostics": true }, "include": <%- JSON.stringify(includes) %> }