Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace try-import with globalThis.process #18

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 1 addition & 4 deletions packages/vike-node/src/runtime/handler-web-and-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type Handler<PlatformRequest> = (params: {
}) => Response | undefined | Promise<Response | undefined>

export function createHandler<PlatformRequest>(options: VikeOptions<PlatformRequest> = {}): Handler<PlatformRequest> {
let nodeLike: boolean | undefined = undefined
let nodeHandler: Handler<PlatformRequest> | undefined = undefined
let webHandler: Handler<PlatformRequest> | undefined = undefined

Expand All @@ -16,9 +15,7 @@ export function createHandler<PlatformRequest>(options: VikeOptions<PlatformRequ
return undefined
}

nodeLike ??= await isNodeLike()

if (nodeLike) {
if (isNodeLike()) {
if (!nodeHandler) {
const { connectToWeb } = await import('./adapters/connectToWeb.js')
const { createHandler } = await import('./handler-node-only.js')
Expand Down
3 changes: 0 additions & 3 deletions packages/vike-node/src/utils/import_.ts

This file was deleted.

11 changes: 2 additions & 9 deletions packages/vike-node/src/utils/isNodeLike.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import { import_ } from './import_.js'

export async function isNodeLike() {
try {
await import_('node:http')
return true
} catch {
return false
}
export function isNodeLike() {
return globalThis.process !== undefined
}