From cf5641a9345124e7254afd0d299bdcb9ea94971d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Fri, 26 Jan 2024 07:10:47 +0200 Subject: [PATCH] fix(vitest): support older NodeJS with async `import.meta.resolve` (#5045) --- packages/vitest/src/runtime/external-executor.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/vitest/src/runtime/external-executor.ts b/packages/vitest/src/runtime/external-executor.ts index 7bb526005ae2..5093ab6c8a1f 100644 --- a/packages/vitest/src/runtime/external-executor.ts +++ b/packages/vitest/src/runtime/external-executor.ts @@ -71,7 +71,11 @@ export class ExternalModulesExecutor { } public resolveModule = async (specifier: string, referencer: string) => { - const identifier = this.resolve(specifier, referencer) + let identifier = this.resolve(specifier, referencer) as string | Promise + + if (identifier instanceof Promise) + identifier = await identifier + return await this.createModule(identifier) } @@ -81,6 +85,8 @@ export class ExternalModulesExecutor { if (id) return id } + + // import.meta.resolve can be asynchronous in older +18 Node versions return nativeResolve(specifier, parent) }