From 5eac0a1e301fddfe890dd32c435eea43670858d5 Mon Sep 17 00:00:00 2001 From: Thomas Beverley Date: Thu, 14 Nov 2024 09:47:40 +0000 Subject: [PATCH] Add types for the dom apis --- README.md | 14 + config.json | 3 + examples/package-lock.json | 8 +- package-lock.json | 371 +++++++++++++++++++- package.json | 4 + src/extension/tsconfig.json | 4 +- src/extension/types-rollup.config.js | 15 + src/extension/webpack.config.cjs | 76 +++- src/shared/API/AI.ts | 2 +- src/shared/API/Untrusted/UntrustedParser.ts | 2 +- 10 files changed, 489 insertions(+), 10 deletions(-) create mode 100644 src/extension/types-rollup.config.js diff --git a/README.md b/README.md index 60f535c..2a5a741 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,20 @@ if (window.aibrow) { } ``` +#### Typescript types + +Types for `window.aibrow` can be added to your project by using the `npm install --save-dev @aibrow/dom-types` package. Then to expose them, place the following either in your `global.d.ts` or the entry point to your code + +```ts +import type AI from "@aibrow/dom-types" + +declare global { + interface Window { + readonly aibrow: typeof AI; + } +} +``` + ### Extension Install the library using `npm install @aibrow/extension` diff --git a/config.json b/config.json index fe02ea1..cefdd77 100644 --- a/config.json +++ b/config.json @@ -21,6 +21,9 @@ "extensionLibrary": { "name": "@aibrow/extension" }, + "typesLibrary": { + "name": "@aibrow/dom-types" + }, "defaultModels": { "text": "smollm2-1-7b-instruct-q4-k-m", diff --git a/examples/package-lock.json b/examples/package-lock.json index f953106..fbed469 100644 --- a/examples/package-lock.json +++ b/examples/package-lock.json @@ -43,7 +43,13 @@ }, "../out/extlib": { "name": "@aibrow/extension", - "version": "1.0.59", + "version": "1.1.4", + "license": "MPL-2.0" + }, + "../out/typeslib": { + "name": "@aibrow/dom-types", + "version": "1.1.4", + "extraneous": true, "license": "MPL-2.0" }, "node_modules/@aibrow/extension": { diff --git a/package-lock.json b/package-lock.json index a508d28..e44c7c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "yargs": "^17.7.2" }, "devDependencies": { + "@aibrow/dom-types": "file:./out/typeslib", "@babel/core": "^7.26.0", "@babel/eslint-parser": "^7.25.9", "@babel/preset-env": "^7.26.0", @@ -58,6 +59,9 @@ "mini-css-extract-plugin": "^2.9.2", "node-loader": "^2.0.0", "patch-package": "^8.0.0", + "rollup": "^4.26.0", + "rollup-plugin-dts": "^6.1.1", + "rollup-plugin-typescript-paths": "^1.5.0", "style-loader": "^4.0.0", "terser-webpack-plugin": "^5.3.10", "ts-loader": "^9.5.1", @@ -69,6 +73,10 @@ "node": ">=20.17.0" } }, + "node_modules/@aibrow/dom-types": { + "resolved": "out/typeslib", + "link": true + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -1904,10 +1912,11 @@ } }, "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", - "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", - "dev": true + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", + "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", + "dev": true, + "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.25", @@ -2662,6 +2671,258 @@ "node": ">= 10" } }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.26.0.tgz", + "integrity": "sha512-gJNwtPDGEaOEgejbaseY6xMFu+CPltsc8/T+diUTTbOQLqD+bnrJq9ulH6WD69TqwqWmrfRAtUv30cCFZlbGTQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.26.0.tgz", + "integrity": "sha512-YJa5Gy8mEZgz5JquFruhJODMq3lTHWLm1fOy+HIANquLzfIOzE9RA5ie3JjCdVb9r46qfAQY/l947V0zfGJ0OQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.26.0.tgz", + "integrity": "sha512-ErTASs8YKbqTBoPLp/kA1B1Um5YSom8QAc4rKhg7b9tyyVqDBlQxy7Bf2wW7yIlPGPg2UODDQcbkTlruPzDosw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.26.0.tgz", + "integrity": "sha512-wbgkYDHcdWW+NqP2mnf2NOuEbOLzDblalrOWcPyY6+BRbVhliavon15UploG7PpBRQ2bZJnbmh8o3yLoBvDIHA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.26.0.tgz", + "integrity": "sha512-Y9vpjfp9CDkAG4q/uwuhZk96LP11fBz/bYdyg9oaHYhtGZp7NrbkQrj/66DYMMP2Yo/QPAsVHkV891KyO52fhg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.26.0.tgz", + "integrity": "sha512-A/jvfCZ55EYPsqeaAt/yDAG4q5tt1ZboWMHEvKAH9Zl92DWvMIbnZe/f/eOXze65aJaaKbL+YeM0Hz4kLQvdwg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.26.0.tgz", + "integrity": "sha512-paHF1bMXKDuizaMODm2bBTjRiHxESWiIyIdMugKeLnjuS1TCS54MF5+Y5Dx8Ui/1RBPVRE09i5OUlaLnv8OGnA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.26.0.tgz", + "integrity": "sha512-cwxiHZU1GAs+TMxvgPfUDtVZjdBdTsQwVnNlzRXC5QzIJ6nhfB4I1ahKoe9yPmoaA/Vhf7m9dB1chGPpDRdGXg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.26.0.tgz", + "integrity": "sha512-4daeEUQutGRCW/9zEo8JtdAgtJ1q2g5oHaoQaZbMSKaIWKDQwQ3Yx0/3jJNmpzrsScIPtx/V+1AfibLisb3AMQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.26.0.tgz", + "integrity": "sha512-eGkX7zzkNxvvS05ROzJ/cO/AKqNvR/7t1jA3VZDi2vRniLKwAWxUr85fH3NsvtxU5vnUUKFHKh8flIBdlo2b3Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.26.0.tgz", + "integrity": "sha512-Odp/lgHbW/mAqw/pU21goo5ruWsytP7/HCC/liOt0zcGG0llYWKrd10k9Fj0pdj3prQ63N5yQLCLiE7HTX+MYw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.26.0.tgz", + "integrity": "sha512-MBR2ZhCTzUgVD0OJdTzNeF4+zsVogIR1U/FsyuFerwcqjZGvg2nYe24SAHp8O5sN8ZkRVbHwlYeHqcSQ8tcYew==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.26.0.tgz", + "integrity": "sha512-YYcg8MkbN17fMbRMZuxwmxWqsmQufh3ZJFxFGoHjrE7bv0X+T6l3glcdzd7IKLiwhT+PZOJCblpnNlz1/C3kGQ==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.26.0.tgz", + "integrity": "sha512-ZuwpfjCwjPkAOxpjAEjabg6LRSfL7cAJb6gSQGZYjGhadlzKKywDkCUnJ+KEfrNY1jH5EEoSIKLCb572jSiglA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.26.0.tgz", + "integrity": "sha512-+HJD2lFS86qkeF8kNu0kALtifMpPCZU80HvwztIKnYwym3KnA1os6nsX4BGSTLtS2QVAGG1P3guRgsYyMA0Yhg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.26.0.tgz", + "integrity": "sha512-WUQzVFWPSw2uJzX4j6YEbMAiLbs0BUysgysh8s817doAYhR5ybqTI1wtKARQKo6cGop3pHnrUJPFCsXdoFaimQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.26.0.tgz", + "integrity": "sha512-D4CxkazFKBfN1akAIY6ieyOqzoOoBV1OICxgUblWxff/pSjCA2khXlASUx7mK6W1oP4McqhgcCsu6QaLj3WMWg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.26.0.tgz", + "integrity": "sha512-2x8MO1rm4PGEP0xWbubJW5RtbNLk3puzAMaLQd3B3JHVw4KcHlmXcO+Wewx9zCoo7EUFiMlu/aZbCJ7VjMzAag==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@rtsao/scc": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@rtsao/scc/-/scc-1.1.0.tgz", @@ -5806,6 +6067,21 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -7298,6 +7574,16 @@ "yallist": "^3.0.2" } }, + "node_modules/magic-string": { + "version": "0.30.12", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.12.tgz", + "integrity": "sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0" + } + }, "node_modules/memory-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/memory-stream/-/memory-stream-1.0.0.tgz", @@ -8923,6 +9209,77 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rollup": { + "version": "4.26.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.26.0.tgz", + "integrity": "sha512-ilcl12hnWonG8f+NxU6BlgysVA0gvY2l8N0R84S1HcINbW20bvwuCngJkkInV6LXhwRpucsW5k1ovDwEdBVrNg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "1.0.6" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.26.0", + "@rollup/rollup-android-arm64": "4.26.0", + "@rollup/rollup-darwin-arm64": "4.26.0", + "@rollup/rollup-darwin-x64": "4.26.0", + "@rollup/rollup-freebsd-arm64": "4.26.0", + "@rollup/rollup-freebsd-x64": "4.26.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.26.0", + "@rollup/rollup-linux-arm-musleabihf": "4.26.0", + "@rollup/rollup-linux-arm64-gnu": "4.26.0", + "@rollup/rollup-linux-arm64-musl": "4.26.0", + "@rollup/rollup-linux-powerpc64le-gnu": "4.26.0", + "@rollup/rollup-linux-riscv64-gnu": "4.26.0", + "@rollup/rollup-linux-s390x-gnu": "4.26.0", + "@rollup/rollup-linux-x64-gnu": "4.26.0", + "@rollup/rollup-linux-x64-musl": "4.26.0", + "@rollup/rollup-win32-arm64-msvc": "4.26.0", + "@rollup/rollup-win32-ia32-msvc": "4.26.0", + "@rollup/rollup-win32-x64-msvc": "4.26.0", + "fsevents": "~2.3.2" + } + }, + "node_modules/rollup-plugin-dts": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-6.1.1.tgz", + "integrity": "sha512-aSHRcJ6KG2IHIioYlvAOcEq6U99sVtqDDKVhnwt70rW6tsz3tv5OSjEiWcgzfsHdLyGXZ/3b/7b/+Za3Y6r1XA==", + "dev": true, + "license": "LGPL-3.0-only", + "dependencies": { + "magic-string": "^0.30.10" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/Swatinem" + }, + "optionalDependencies": { + "@babel/code-frame": "^7.24.2" + }, + "peerDependencies": { + "rollup": "^3.29.4 || ^4", + "typescript": "^4.5 || ^5.0" + } + }, + "node_modules/rollup-plugin-typescript-paths": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-typescript-paths/-/rollup-plugin-typescript-paths-1.5.0.tgz", + "integrity": "sha512-zly2aiGNjYJNq5YUi6eyGrQnCYUQ8b5czOtHZIGriwG9U3Ba2F9hlSklafXCdsNulK/IlNmE0Kzj0h+fVV32pA==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "typescript": ">=3.4" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -10384,6 +10741,12 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "out/typeslib": { + "name": "@aibrow/dom-types", + "version": "1.1.4", + "dev": true, + "license": "MPL-2.0" } } } diff --git a/package.json b/package.json index 9bd6036..0894352 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@types/yargs": "^17.0.33", "@typescript-eslint/eslint-plugin": "^8.14.0", "@typescript-eslint/parser": "^8.14.0", + "@aibrow/dom-types": "file:./out/typeslib", "babel-loader": "^9.2.1", "case-sensitive-paths-webpack-plugin": "^2.4.0", "circular-dependency-plugin": "^5.2.2", @@ -52,6 +53,9 @@ "mini-css-extract-plugin": "^2.9.2", "node-loader": "^2.0.0", "patch-package": "^8.0.0", + "rollup": "^4.26.0", + "rollup-plugin-dts": "^6.1.1", + "rollup-plugin-typescript-paths": "^1.5.0", "style-loader": "^4.0.0", "terser-webpack-plugin": "^5.3.10", "ts-loader": "^9.5.1", diff --git a/src/extension/tsconfig.json b/src/extension/tsconfig.json index 42e7797..cdd26f3 100644 --- a/src/extension/tsconfig.json +++ b/src/extension/tsconfig.json @@ -7,9 +7,9 @@ "resolveJsonModule": true, "moduleResolution": "node", "paths": { - "#R/*": ["./*"], "#Shared/*": ["../shared/*"] - } + }, + "types": ["@aibrow/dom-types"] }, "include": [ "./*/*.ts" diff --git a/src/extension/types-rollup.config.js b/src/extension/types-rollup.config.js new file mode 100644 index 0000000..ca39641 --- /dev/null +++ b/src/extension/types-rollup.config.js @@ -0,0 +1,15 @@ +import path from 'path' +import dts from 'rollup-plugin-dts' +import { typescriptPaths } from 'rollup-plugin-typescript-paths' + +export default [{ + plugins: [ + typescriptPaths({ + tsConfigPath: path.join(import.meta.dirname, 'tsconfig.json'), + absolute: false, + preserveExtensions: true, + transform: (p) => path.resolve('/', p) + }), + dts() + ] +}] diff --git a/src/extension/webpack.config.cjs b/src/extension/webpack.config.cjs index 697719c..ab6f2c4 100644 --- a/src/extension/webpack.config.cjs +++ b/src/extension/webpack.config.cjs @@ -1,4 +1,5 @@ const path = require('path') +const fs = require('fs-extra') const CopyWebpackPlugin = require('copy-webpack-plugin') const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin') const CircularDependencyPlugin = require('circular-dependency-plugin') @@ -8,6 +9,7 @@ const { pathsToWebpackAlias } = require('../../build/tsconfig_util.cjs') const webpack = require('webpack') const MiniCssExtractPlugin = require('mini-css-extract-plugin') const HtmlWebpackPlugin = require('html-webpack-plugin') +const childProcess = require('child_process') module.exports = function ({ outDir, nodeModulesDir, pkg, config }, { mode }) { const srcDir = __dirname @@ -150,5 +152,77 @@ module.exports = function ({ outDir, nodeModulesDir, pkg, config }, { mode }) { ] } } - }) + }).concat([{ + name: 'typeslib', + mode: 'development', + entry: {}, + output: { + filename: '[name].js', + path: path.join(outDir, 'typeslib') + }, + plugins: [{ + apply: (compiler) => { + compiler.hooks.done.tapAsync('BuildDonePlugin', async (compilation, callback) => { + try { + const typesOutPath = path.join(outDir, 'typeslib', 'index.d.ts') + + // Build the definitions + await new Promise((resolve, reject) => { + const child = childProcess.spawn('npx', [ + 'rollup', + '--config', './types-rollup.config.js', + '--input', path.join(srcDir, 'contentscript-main/index.ts'), + '--format es', + '--file', typesOutPath + ], { + shell: true, stdio: 'inherit', detatched: true, cwd: __dirname + }) + child.on('close', (code) => { + if (code === 0) { + resolve() + } else { + reject(new Error(`Failed to run rollup with exit code ${code}`)) + } + }) + child.on('error', (err) => { + reject(new Error(`Rollup failed to generate types ${err}`)) + }) + }) + + // Update the export + await fs.appendFile(typesOutPath, '\ndeclare global { interface Window { readonly aibrow: AI; } }\n') + + // Write the accompanying files + await fs.writeJSON(path.join(outDir, 'typeslib', 'package.json'), { + name: config.typesLibrary.name, + main: '', + types: 'index.d.ts', + ...['version', 'author', 'license', 'description', 'repository'].reduce((acc, k) => { + acc[k] = pkg[k] + return acc + }, {}) + }, { spaces: 2 }) + await fs.writeJSON(path.join(outDir, 'typeslib', 'tsconfig.json'), { + compilerOptions: { + module: 'node16', + lib: ['es6'], + noImplicitAny: true, + noImplicitThis: true, + strictFunctionTypes: true, + strictNullChecks: true, + types: [], + noEmit: true, + forceConsistentCasingInFileNames: true + }, + files: ['index.d.ts'] + }, { spaces: 2 }) + + callback() + } catch (ex) { + callback(ex) + } + }) + } + }] + }]) } diff --git a/src/shared/API/AI.ts b/src/shared/API/AI.ts index caa95ba..9d0c058 100644 --- a/src/shared/API/AI.ts +++ b/src/shared/API/AI.ts @@ -2,7 +2,7 @@ // MARK: Enums /* **************************************************************************/ -import { AIModelManifestConfigRange } from '#Shared/AIModelManifest' +import { AIModelManifestConfigRange } from '../AIModelManifest' export enum AICapabilityAvailability { Readily = 'readily', diff --git a/src/shared/API/Untrusted/UntrustedParser.ts b/src/shared/API/Untrusted/UntrustedParser.ts index 11bbeed..32d147a 100644 --- a/src/shared/API/Untrusted/UntrustedParser.ts +++ b/src/shared/API/Untrusted/UntrustedParser.ts @@ -3,7 +3,7 @@ import { AILanguageModelInitialPromptRole, AILanguageModelPrompt, AILanguageModelPromptRole -} from '#Shared/API/AILanguageModel/AILanguageModelTypes' +} from '../AILanguageModel/AILanguageModelTypes' /* **************************************************************************/ // MARK: Base types