Skip to content

Commit 3c940a2

Browse files
committed
build: Fix bug with resolving paths in Bun build plugins
1 parent f21edc4 commit 3c940a2

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

scripts/build.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export const InlineWasmBunPlugin: BunPlugin = {
4343
// Hook into the "resolve" phase to intercept .wasm imports
4444
builder.onResolve({ filter: /\.wasm$/ }, async (args) => {
4545
// Resolve the .wasm file path relative to the directory of the importing file
46-
const resolvedPath = path.resolve(
47-
path.dirname(args.importer),
46+
const resolvedPath = Bun.resolveSync(
4847
args.path,
48+
path.dirname(args.importer),
4949
);
5050
return { path: resolvedPath, namespace: "wasm" };
5151
});
@@ -74,9 +74,9 @@ export const InlineSqlBunPlugin: BunPlugin = {
7474
// Hook into the "resolve" phase to intercept .sql imports
7575
builder.onResolve({ filter: /\.sql$/ }, async (args) => {
7676
// Resolve the .sql file path relative to the directory of the importing file
77-
const resolvedPath = path.resolve(
78-
path.dirname(args.importer),
77+
const resolvedPath = Bun.resolveSync(
7978
args.path,
79+
path.dirname(args.importer),
8080
);
8181
return { path: resolvedPath, namespace: "sql" };
8282
});
@@ -144,6 +144,8 @@ export interface BuildConfig {
144144
sourcemap: boolean;
145145
}
146146

147+
const defaultBunPlugins = [InlineSqlBunPlugin];
148+
147149
export function build(config: BuildConfig) {
148150
const createOutputFolder = ResultAsync.fromPromise(
149151
$`mkdir -p ${config.outputFolder}`,
@@ -184,8 +186,8 @@ export function build(config: BuildConfig) {
184186
target: "browser",
185187
format: config.format,
186188
plugins: config.useWasm
187-
? [InlineWasmBunPlugin, InlineSqlBunPlugin]
188-
: [InlineSqlBunPlugin],
189+
? [InlineWasmBunPlugin, ...defaultBunPlugins]
190+
: defaultBunPlugins,
189191
drop: config.drop,
190192
sourcemap: config.sourcemap ? "inline" : "none",
191193
external: [

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
// Path alias
3131
"baseUrl": ".",
3232
"paths": {
33-
"@/*": ["src/*"]
33+
"@/*": ["src/*"],
34+
"!/*": ["node_modules/*"]
3435
}
3536
},
3637
"exclude": ["node_modules", "dist", "lib-dist", "scripts"]

0 commit comments

Comments
 (0)