From 778bd735e29882f18f42f8994547532106cab5a6 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 21 Feb 2024 14:51:03 +0100 Subject: [PATCH] fix(resolver): strictly check input --- src/resolve.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/resolve.ts b/src/resolve.ts index b6b7be8..b7a419a 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -37,7 +37,15 @@ function _tryModuleResolve( } } -function _resolve(id: string, options: ResolveOptions = {}): string { +function _resolve(id: string | URL, options: ResolveOptions = {}): string { + if (typeof id !== "string") { + if (id instanceof URL) { + id = fileURLToPath(id); + } else { + throw new TypeError("input must be a `string` or `URL`"); + } + } + // Skip if already has a protocol if (/(node|data|http|https):/.test(id)) { return id; @@ -49,7 +57,7 @@ function _resolve(id: string, options: ResolveOptions = {}): string { } // Enable fast path for file urls - if (id.startsWith("file:")) { + if (id.startsWith("file://")) { id = fileURLToPath(id); }