Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@elysiajs/openapi": "^1.4.1",
"@types/bun": "^1.2.12",
"@types/bun": "^1.3.0",
"@types/cookie": "^1.0.0",
"@types/fast-decode-uri-component": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^8.30.1",
Expand Down Expand Up @@ -246,7 +246,7 @@

"@tybys/wasm-util": ["@tybys/[email protected]", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg=="],

"@types/bun": ["@types/bun@1.2.23", "", { "dependencies": { "bun-types": "1.2.23" } }, "sha512-le8ueOY5b6VKYf19xT3McVbXqLqmxzPXHsQT/q9JHgikJ2X22wyTW3g3ohz2ZMnp7dod6aduIiq8A14Xyimm0A=="],
"@types/bun": ["@types/bun@1.3.0", "", { "dependencies": { "bun-types": "1.3.0" } }, "sha512-+lAGCYjXjip2qY375xX/scJeVRmZ5cY0wyHYyCYxNcdEXrQ4AOe3gACgd4iQ8ksOslJtW4VNxBJ8llUwc3a6AA=="],

"@types/cookie": ["@types/[email protected]", "", { "dependencies": { "cookie": "*" } }, "sha512-mGFXbkDQJ6kAXByHS7QAggRXgols0mAdP4MuXgloGY1tXokvzaFFM4SMqWvf7AH0oafI7zlFJwoGWzmhDqTZ9w=="],

Expand Down Expand Up @@ -304,7 +304,7 @@

"builtin-modules": ["[email protected]", "", {}, "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw=="],

"bun-types": ["bun-types@1.2.23", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-R9f0hKAZXgFU3mlrA0YpE/fiDvwV0FT9rORApt2aQVWSuJDzZOyB5QLc0N/4HF57CS8IXJ6+L5E4W1bW6NS2Aw=="],
"bun-types": ["bun-types@1.3.0", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-u8X0thhx+yJ0KmkxuEo9HAtdfgCBaM/aI9K90VQcQioAmkVp3SG3FkwWGibUFz3WdXAdcsqOcbU40lK7tbHdkQ=="],

"bundle-require": ["[email protected]", "", { "dependencies": { "load-tsconfig": "^0.2.3" }, "peerDependencies": { "esbuild": ">=0.18" } }, "sha512-3WrrOuZiyaaZPWiEt4G3+IffISVC9HYlWueJEBWED4ZH4aIAC2PnkdnuRrR94M+w6yGWn4AglWtJtBI8YqvgoA=="],

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
},
"devDependencies": {
"@elysiajs/openapi": "^1.4.1",
"@types/bun": "^1.2.12",
"@types/bun": "^1.3.0",
"@types/cookie": "^1.0.0",
"@types/fast-decode-uri-component": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^8.30.1",
Expand Down
6 changes: 3 additions & 3 deletions src/universal/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Serve as BunServe, Server as BunServer } from 'bun'
import { Serve as BunServe, type Server as BunServer } from 'bun'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Avoid runtime import of "bun" in universal types by using type-only module import.

Importing Serve as a value can survive emit in some setups (e.g., verbatimModuleSyntax) and accidentally pull "bun" at runtime in non-Bun targets. Prefer a pure type import for safety.

Apply:

-import { Serve as BunServe, type Server as BunServer } from 'bun'
+import type * as BunTypes from 'bun'

And update aliases:

-export type Serve = IsAny<BunServe.Options<unknown>> extends false ? BunServe.Options<unknown> : ServeOptions
-export type Server = IsAny<BunServer<unknown>> extends false ? BunServer<unknown> : ServerOptions
+export type Serve = IsAny<BunTypes.Serve.Options<unknown>> extends false ? BunTypes.Serve.Options<unknown> : ServeOptions
+export type Server = IsAny<BunTypes.Server<unknown>> extends false ? BunTypes.Server<unknown> : ServerOptions

Also applies to: 125-126


🏁 Script executed:

#!/bin/bash
# Verify we don't emit runtime imports of "bun" in built artifacts
# (run after your normal build)
rg -nP 'from\s+[\'"]bun[\'"]' -g 'dist/**/universal/*.js' -S || echo "OK: no runtime bun imports found in dist/universal"

Length of output: 68



---

🏁 Script executed:

```shell
#!/bin/bash
# Examine the source file to understand current import structure
echo "=== Examining src/universal/server.ts ===" 
head -20 src/universal/server.ts

echo ""
echo "=== Checking lines around 125-126 ===" 
sed -n '120,130p' src/universal/server.ts

Length of output: 944


🏁 Script executed:

#!/bin/bash
# Check if dist/universal exists and search for bun imports using alternative escaping
if [ -d dist/universal ]; then
  echo "=== Checking for bun imports in dist/universal ==="
  rg -n 'from.*bun' dist/universal/ --type js 2>/dev/null || echo "No matches found or directory structure differs"
else
  echo "dist/universal not found - build artifacts may not exist"
  find . -name "*.js" -path "*/dist/*" -type f 2>/dev/null | head -5 || echo "No dist files found"
fi

Length of output: 1140


🏁 Script executed:

#!/bin/bash
# Verify the overall structure and search for any bun-related imports in the source
echo "=== Source file import section ===" 
rg -n 'import.*bun' src/universal/ --type ts 2>/dev/null || echo "No matches found"

Length of output: 246


🏁 Script executed:

#!/bin/bash
# Check all usages of BunServe and BunServer in the file
echo "=== All usages of BunServe ===" 
rg -n 'BunServe' src/universal/server.ts

echo ""
echo "=== All usages of BunServer ===" 
rg -n 'BunServer' src/universal/server.ts

Length of output: 517


Fix value import of "Serve" to prevent runtime "bun" imports in universal code.

The Serve import on line 1 is imported as a value but only used in type positions (lines 125–126). With compiler options like verbatimModuleSyntax, this will emit a runtime import of "bun" in the compiled output, breaking compatibility in non-Bun environments.

Apply:

-import { Serve as BunServe, type Server as BunServer } from 'bun'
+import type * as BunTypes from 'bun'

Then update lines 125–126:

-export type Serve = IsAny<BunServe.Options<unknown>> extends false ? BunServe.Options<unknown> : ServeOptions
-export type Server = IsAny<BunServer<unknown>> extends false ? BunServer<unknown> : ServerOptions
+export type Serve = IsAny<BunTypes.Serve.Options<unknown>> extends false ? BunTypes.Serve.Options<unknown> : ServeOptions
+export type Server = IsAny<BunTypes.Server<unknown>> extends false ? BunTypes.Server<unknown> : ServerOptions

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/universal/server.ts around line 1 and lines 125–126, the import currently
brings Serve as a runtime value which causes a runtime import of "bun"; change
the import to a type-only import (import type { Serve as BunServe, Server as
BunServer } from 'bun') and update the usages at lines 125–126 to be type
annotations only (remove any runtime references to BunServe/BunServer so they
are used purely as types).

import type { IsAny, MaybePromise } from '../types'

export interface ErrorLike extends Error {
Expand Down Expand Up @@ -122,8 +122,8 @@ export interface ServeOptions extends GenericServeOptions {
>
}

export type Serve = IsAny<BunServe> extends false ? BunServe : ServeOptions
export type Server = IsAny<BunServer> extends false ? BunServer : ServerOptions
export type Serve = IsAny<BunServe.Options<unknown>> extends false ? BunServe.Options<unknown> : ServeOptions
export type Server = IsAny<BunServer<unknown>> extends false ? BunServer<unknown> : ServerOptions

export type ServerWebSocketSendStatus = number

Expand Down