Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve compatibility of using ESM/TS with Deno #33128

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/playwright/src/common/configLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions packages/playwright/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,17 @@ 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 false;
return isDeno;
// Rely on `require` internal caching logic.
return require(packageJsonPath).type === 'module';
const type = require(packageJsonPath).type;
if (type === 'module')
return true;
if (type === 'commonjs')
return false;
return isDeno;
}

const packageJsonMainFieldCache = new Map<string, string | undefined>();
Expand Down