diff --git a/build/index.js b/build/index.js index 80138d1..d157e64 100644 --- a/build/index.js +++ b/build/index.js @@ -1,5 +1,6 @@ import * as esbuild from "esbuild"; import copyFilePlugin from 'esbuild-plugin-copy-file'; +import { spawn } from "node:child_process"; import fs from 'fs'; const shimContent = new Buffer.from(await fs.readFileSync('./build/shim.js')); @@ -28,23 +29,37 @@ async function applyPatches(target) { async function bundle(target) { await esbuild.build({ - entryPoints: [`lib/${target}.js`], + entryPoints: [`lib/${target}.ts`], sourcemap: true, bundle: true, + minifyWhitespace: true, + minifySyntax: true, format: "esm", platform: 'node', outfile: `dist/${target}/index.js`, plugins: [ copyFilePlugin({ after: Object.fromEntries( - ["index_bg.wasm", "index_bg.wasm.d.ts", "index.d.ts"].map( + ["index_bg.wasm", "index_bg.wasm.d.ts"].map( (f) => [ `dist/${target}/${f}`, `compiled/${target}/${f}`, ] ) - ), + ) }), ], }); + + spawn("npx", [ + "dts-bundle-generator", + "-o", + `dist/${target}/types.d.ts`, + `lib/${target}.ts`, + "--no-check", + "--export-referenced-types", + "false", + ], { + stdio: "inherit", + }); } diff --git a/lib/surrealql.d.ts b/lib/surrealql.d.ts deleted file mode 100644 index f7ca83e..0000000 --- a/lib/surrealql.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import * as SurrealQL from "../compiled/surrealql"; -import { Value } from "../compiled/surrealql"; - -export { Value, SurrealQL, SurrealQL as default }; \ No newline at end of file diff --git a/lib/surrealql.js b/lib/surrealql.ts similarity index 100% rename from lib/surrealql.js rename to lib/surrealql.ts diff --git a/package.json b/package.json index 255a4b7..af02259 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ ], "exports": { ".": { - "types": "./dist/surrealql/index.d.ts", + "types": "./dist/surrealql/types.d.ts", "default": "./dist/surrealql/index.js" } }, @@ -28,6 +28,7 @@ "build-literal": "node build/index.js" }, "devDependencies": { + "dts-bundle-generator": "^9.5.1", "esbuild": "^0.17.19", "esbuild-plugin-copy-file": "^0.0.2" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 654b22b..3380521 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: devDependencies: + dts-bundle-generator: + specifier: ^9.5.1 + version: 9.5.1 esbuild: specifier: ^0.17.19 version: 0.17.19 @@ -149,6 +152,33 @@ packages: cpu: [x64] os: [win32] + ansi-regex@5.0.1: + resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} + engines: {node: '>=8'} + + ansi-styles@4.3.0: + resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} + engines: {node: '>=8'} + + cliui@8.0.1: + resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} + engines: {node: '>=12'} + + color-convert@2.0.1: + resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} + engines: {node: '>=7.0.0'} + + color-name@1.1.4: + resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + + dts-bundle-generator@9.5.1: + resolution: {integrity: sha512-DxpJOb2FNnEyOzMkG11sxO2dmxPjthoVWxfKqWYJ/bI/rT1rvTMktF5EKjAYrRZu6Z6t3NhOUZ0sZ5ZXevOfbA==} + engines: {node: '>=14.0.0'} + hasBin: true + + emoji-regex@8.0.0: + resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + esbuild-plugin-copy-file@0.0.2: resolution: {integrity: sha512-pr9CTC68YKClMAusuEy3YlB8EbQIdKWsyCVrEEbskCxKvJ7ZfhFEMesteoJl4daBtcY92gfFt0MsZOwfzZKVmw==} @@ -157,6 +187,51 @@ packages: engines: {node: '>=12'} hasBin: true + escalade@3.1.2: + resolution: {integrity: sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==} + engines: {node: '>=6'} + + get-caller-file@2.0.5: + resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} + engines: {node: 6.* || 8.* || >= 10.*} + + is-fullwidth-code-point@3.0.0: + resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} + engines: {node: '>=8'} + + require-directory@2.1.1: + resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} + engines: {node: '>=0.10.0'} + + string-width@4.2.3: + resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} + engines: {node: '>=8'} + + strip-ansi@6.0.1: + resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} + engines: {node: '>=8'} + + typescript@5.5.4: + resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==} + engines: {node: '>=14.17'} + hasBin: true + + wrap-ansi@7.0.0: + resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} + engines: {node: '>=10'} + + y18n@5.0.8: + resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} + engines: {node: '>=10'} + + yargs-parser@21.1.1: + resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} + engines: {node: '>=12'} + + yargs@17.7.2: + resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==} + engines: {node: '>=12'} + snapshots: '@esbuild/android-arm64@0.17.19': @@ -225,6 +300,31 @@ snapshots: '@esbuild/win32-x64@0.17.19': optional: true + ansi-regex@5.0.1: {} + + ansi-styles@4.3.0: + dependencies: + color-convert: 2.0.1 + + cliui@8.0.1: + dependencies: + string-width: 4.2.3 + strip-ansi: 6.0.1 + wrap-ansi: 7.0.0 + + color-convert@2.0.1: + dependencies: + color-name: 1.1.4 + + color-name@1.1.4: {} + + dts-bundle-generator@9.5.1: + dependencies: + typescript: 5.5.4 + yargs: 17.7.2 + + emoji-regex@8.0.0: {} + esbuild-plugin-copy-file@0.0.2: {} esbuild@0.17.19: @@ -251,3 +351,43 @@ snapshots: '@esbuild/win32-arm64': 0.17.19 '@esbuild/win32-ia32': 0.17.19 '@esbuild/win32-x64': 0.17.19 + + escalade@3.1.2: {} + + get-caller-file@2.0.5: {} + + is-fullwidth-code-point@3.0.0: {} + + require-directory@2.1.1: {} + + string-width@4.2.3: + dependencies: + emoji-regex: 8.0.0 + is-fullwidth-code-point: 3.0.0 + strip-ansi: 6.0.1 + + strip-ansi@6.0.1: + dependencies: + ansi-regex: 5.0.1 + + typescript@5.5.4: {} + + wrap-ansi@7.0.0: + dependencies: + ansi-styles: 4.3.0 + string-width: 4.2.3 + strip-ansi: 6.0.1 + + y18n@5.0.8: {} + + yargs-parser@21.1.1: {} + + yargs@17.7.2: + dependencies: + cliui: 8.0.1 + escalade: 3.1.2 + get-caller-file: 2.0.5 + require-directory: 2.1.1 + string-width: 4.2.3 + y18n: 5.0.8 + yargs-parser: 21.1.1 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..2ffc438 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "esnext", + "moduleResolution": "node", + "noImplicitAny": false, + "removeComments": true, + "preserveConstEnums": true, + "sourceMap": true, + "forceConsistentCasingInFileNames": true, + "declaration": true, + "noEmit": true + }, + "exclude": ["node_modules"] +}