diff --git a/packages/build_package.js b/packages/build_package.js index be20aa6d5b..9c9359fcdb 100755 --- a/packages/build_package.js +++ b/packages/build_package.js @@ -124,8 +124,15 @@ if (!package) { homepage: pwInternalJSON.homepage, main: 'index.js', exports: { - import: './index.mjs', - require: './index.js', + // Root import: we have a wrapper ES Module to support the following syntax. + // const { chromium } = require('playwright'); + // import { chromium } from 'playwright'; + '.': { + import: './index.mjs', + require: './index.js', + }, + // Anything else can be required/imported by providing a relative path. + './': './', }, scripts: { install: 'node install.js', diff --git a/packages/installation-tests/esm-playwright-chromium.mjs b/packages/installation-tests/esm-playwright-chromium.mjs index a14c843ba5..0e2f6fd4e3 100644 --- a/packages/installation-tests/esm-playwright-chromium.mjs +++ b/packages/installation-tests/esm-playwright-chromium.mjs @@ -16,10 +16,16 @@ import { chromium, selectors, devices, errors } from 'playwright-chromium'; import playwright from 'playwright-chromium'; +import errorsFile from 'playwright-chromium/lib/errors.js'; if (playwright.chromium !== chromium) process.exit(1); +if (playwright.errors !== errors) + process.exit(1); +if (errors.TimeoutError !== errorsFile.TimeoutError) + process.exit(1); + (async () => { for (const browserType of [chromium]) { const browser = await browserType.launch(); diff --git a/packages/installation-tests/esm-playwright-firefox.mjs b/packages/installation-tests/esm-playwright-firefox.mjs index 102c65b4ad..d3854688f9 100644 --- a/packages/installation-tests/esm-playwright-firefox.mjs +++ b/packages/installation-tests/esm-playwright-firefox.mjs @@ -16,10 +16,16 @@ import { firefox, selectors, devices, errors } from 'playwright-firefox'; import playwright from 'playwright-firefox'; +import errorsFile from 'playwright-firefox/lib/errors.js'; if (playwright.firefox !== firefox) process.exit(1); +if (playwright.errors !== errors) + process.exit(1); +if (errors.TimeoutError !== errorsFile.TimeoutError) + process.exit(1); + (async () => { for (const browserType of [firefox]) { const browser = await browserType.launch(); diff --git a/packages/installation-tests/esm-playwright-webkit.mjs b/packages/installation-tests/esm-playwright-webkit.mjs index 2706589070..dba784d3c6 100644 --- a/packages/installation-tests/esm-playwright-webkit.mjs +++ b/packages/installation-tests/esm-playwright-webkit.mjs @@ -16,10 +16,16 @@ import { webkit, selectors, devices, errors } from 'playwright-webkit'; import playwright from 'playwright-webkit'; +import errorsFile from 'playwright-webkit/lib/errors.js'; if (playwright.webkit !== webkit) process.exit(1); +if (playwright.errors !== errors) + process.exit(1); +if (errors.TimeoutError !== errorsFile.TimeoutError) + process.exit(1); + (async () => { for (const browserType of [webkit]) { const browser = await browserType.launch(); diff --git a/packages/installation-tests/esm-playwright.mjs b/packages/installation-tests/esm-playwright.mjs index 526792b648..18be425d2f 100644 --- a/packages/installation-tests/esm-playwright.mjs +++ b/packages/installation-tests/esm-playwright.mjs @@ -16,6 +16,7 @@ import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright'; import playwright from 'playwright'; +import errorsFile from 'playwright/lib/errors.js'; if (playwright.chromium !== chromium) process.exit(1); @@ -24,6 +25,11 @@ if (playwright.firefox !== firefox) if (playwright.webkit !== webkit) process.exit(1); +if (playwright.errors !== errors) + process.exit(1); +if (errors.TimeoutError !== errorsFile.TimeoutError) + process.exit(1); + (async () => { for (const browserType of [chromium, firefox, webkit]) { const browser = await browserType.launch(); diff --git a/packages/installation-tests/sanity.js b/packages/installation-tests/sanity.js index b37278f41f..4ff42fbadc 100644 --- a/packages/installation-tests/sanity.js +++ b/packages/installation-tests/sanity.js @@ -19,6 +19,10 @@ const browsers = process.argv.slice(3); const playwright = require(requireName); +// Requiring internals should work. +const errors = require(requireName + '/lib/errors'); +const installer = require(requireName + '/lib/install/installer'); + (async () => { for (const browserType of browsers) { const browser = await playwright[browserType].launch();