From 458e6c81fe772d810813849f011a7332ebce6f5c Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 15 Oct 2024 17:27:40 -0700 Subject: [PATCH 1/3] Use native ts/esm support in deno --- packages/playwright/src/common/configLoader.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playwright/src/common/configLoader.ts b/packages/playwright/src/common/configLoader.ts index 5ed1c68ea7c21..1d914167b43af 100644 --- a/packages/playwright/src/common/configLoader.ts +++ b/packages/playwright/src/common/configLoader.ts @@ -347,8 +347,8 @@ export async function loadEmptyConfigForMergeReports() { } export function restartWithExperimentalTsEsm(configFile: string | undefined, force: boolean = false): boolean { - // Opt-out switch. - if (process.env.PW_DISABLE_TS_ESM) + // Opt-out switch. Default to disabled if running in Deno, which supports TS and ESM natively. + if (process.env.PW_DISABLE_TS_ESM || typeof process.versions.deno === 'string') return false; // There are two esm loader APIs: From 26c13a28bf6b487a1adfbabee4da13f350f1ca65 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 15 Oct 2024 17:27:49 -0700 Subject: [PATCH 2/3] 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 460b3de07e746..0df177d1e0177 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(); From 49d941c00e2e0a356660632d75b260efc5ae9dd7 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker Date: Tue, 15 Oct 2024 17:41:26 -0700 Subject: [PATCH 3/3] Retain comment --- packages/playwright/src/util.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/playwright/src/util.ts b/packages/playwright/src/util.ts index 0df177d1e0177..0ef9e6baf7864 100644 --- a/packages/playwright/src/util.ts +++ b/packages/playwright/src/util.ts @@ -293,6 +293,7 @@ function folderIsModule(folder: string): boolean { const isDeno = typeof process.versions.deno === 'string'; if (!packageJsonPath) return isDeno; + // Rely on `require` internal caching logic. const type = require(packageJsonPath).type; if (type === 'module') return true;