From f505b7ccf3b7978c5bdf1a4c68208a20475d3cfb Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 25 Jan 2022 17:00:28 +0100 Subject: [PATCH] fix(resolve): ensure absolute id exists and resolved --- src/resolve.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/resolve.ts b/src/resolve.ts index 41e5da4..ba8d878 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -1,4 +1,4 @@ -import { realpathSync } from 'fs' +import { existsSync, realpathSync } from 'fs' import { pathToFileURL } from 'url' import { isAbsolute } from 'pathe' import { moduleResolve } from 'import-meta-resolve' @@ -38,9 +38,11 @@ function _resolve (id: string, opts: ResolveOptions = {}): string { return 'node:' + id } - // Skip absolute - if (isAbsolute(id)) { - return id + // Skip resolve for absolute paths + if (isAbsolute(id) && existsSync(id)) { + // Resolve realPath and normalize slash + const realPath = realpathSync(fileURLToPath(id)) + return pathToFileURL(realPath).toString() } // Condition set