Skip to content

Commit

Permalink
default to esm when running in deno
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwhit committed Oct 16, 2024
1 parent 458e6c8 commit 26c13a2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/playwright/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string | undefined>();
Expand Down

0 comments on commit 26c13a2

Please sign in to comment.