Skip to content

Commit

Permalink
change: bundle types
Browse files Browse the repository at this point in the history
  • Loading branch information
macjuul committed Aug 28, 2024
1 parent 649d2cb commit 0f4c5ad
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 8 deletions.
21 changes: 18 additions & 3 deletions build/index.js
Original file line number Diff line number Diff line change
@@ -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'));
Expand Down Expand Up @@ -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",
});
}
4 changes: 0 additions & 4 deletions lib/surrealql.d.ts

This file was deleted.

File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"exports": {
".": {
"types": "./dist/surrealql/index.d.ts",
"types": "./dist/surrealql/types.d.ts",
"default": "./dist/surrealql/index.js"
}
},
Expand All @@ -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"
}
Expand Down
140 changes: 140 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit 0f4c5ad

Please sign in to comment.