Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(loader): support other node versions (#41319)

Dmitry Gozman33458b7ee1d3
diff --git a/packages/playwright/src/transform/esmLoaderSync.ts b/packages/playwright/src/transform/esmLoaderSync.ts
index 18c9c93af8..11d8281ab8 100644
--- a/packages/playwright/src/transform/esmLoaderSync.ts
+++ b/packages/playwright/src/transform/esmLoaderSync.ts
@@ -21,7 +21,7 @@ import { currentFileDepsCollector } from './compilationCache';
import { resolveHook, shouldTransform, transformHook } from './transform';
import { fileIsModule } from '../util';
-export function resolve(specifier: string, context: { parentURL?: string, conditions?: string[] }, nextResolve: Function) {
+export function resolve(specifier: string, context: { parentURL?: string, conditions?: string[] | Set<string> }, nextResolve: Function) {
if (context.parentURL && context.parentURL.startsWith('file://')) {
const filename = url.fileURLToPath(context.parentURL);
const resolved = resolveHook(filename, specifier);
@@ -32,7 +32,7 @@ export function resolve(specifier: string, context: { parentURL?: string, condit
// - the ESM resolver wants a file:// URL and, on Windows, mistakes an absolute path's
// drive letter for a URL scheme ("Received protocol 'c:'").
// The `import` condition is present only for ESM resolution, so use it to pick the form.
- specifier = context.conditions?.includes('import') ? url.pathToFileURL(resolved).toString() : resolved;
+ specifier = new Set(context.conditions).has('import') ? url.pathToFileURL(resolved).toString() : resolved;
}
}
const result = nextResolve(specifier, context);