From 5d6aec38968012e78d2c0cda285e74b0f5f31ec3 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 18 Dec 2024 19:33:11 +0100 Subject: [PATCH] fix(defineEnv): fallback support for `unenv-nightly` (#378) --- src/env.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/env.ts b/src/env.ts index 915a7a88..a674ae81 100644 --- a/src/env.ts +++ b/src/env.ts @@ -44,7 +44,20 @@ export function defineEnv(opts: CreateEnvOptions = {}): { const resolveOpts: ResolveOptions = { url: resolvePaths, }; - const _resolve = (id: string) => resolvePathSync(id, resolveOpts); + + const _tryResolve = (id: string) => { + try { + return resolvePathSync(id, resolveOpts); + } catch {} + }; + + const _resolve = (id: string) => { + let resolved = _tryResolve(id); + if (!resolved && id.startsWith("unenv/")) { + resolved = _tryResolve(id.replace("unenv/", "unenv-nightly/")); + } + return resolved || id; + }; // Resolve aliases for (const alias in resolvedEnv.alias) {