From 26c13a28bf6b487a1adfbabee4da13f350f1ca65 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 15 Oct 2024 17:27:49 -0700 Subject: [PATCH] default to esm when running in deno --- packages/playwright/src/util.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/playwright/src/util.ts b/packages/playwright/src/util.ts index 460b3de07e..0df177d1e0 100644 --- a/packages/playwright/src/util.ts +++ b/packages/playwright/src/util.ts @@ -289,10 +289,16 @@ export function fileIsModule(file: string): boolean { function folderIsModule(folder: string): boolean { const packageJsonPath = getPackageJsonPath(folder); + // deno is ESM unless package.json specifies otherwise + const isDeno = typeof process.versions.deno === 'string'; if (!packageJsonPath) + return isDeno; + const type = require(packageJsonPath).type; + if (type === 'module') + return true; + if (type === 'commonjs') return false; - // Rely on `require` internal caching logic. - return require(packageJsonPath).type === 'module'; + return isDeno; } const packageJsonMainFieldCache = new Map();