Skip to content

Commit 6a4195f

Browse files
authored
fix(require): allow requiring internals (#3153)
1 parent 3162c06 commit 6a4195f

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

packages/build_package.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,15 @@ if (!package) {
124124
homepage: pwInternalJSON.homepage,
125125
main: 'index.js',
126126
exports: {
127-
import: './index.mjs',
128-
require: './index.js',
127+
// Root import: we have a wrapper ES Module to support the following syntax.
128+
// const { chromium } = require('playwright');
129+
// import { chromium } from 'playwright';
130+
'.': {
131+
import: './index.mjs',
132+
require: './index.js',
133+
},
134+
// Anything else can be required/imported by providing a relative path.
135+
'./': './',
129136
},
130137
scripts: {
131138
install: 'node install.js',

packages/installation-tests/esm-playwright-chromium.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616

1717
import { chromium, selectors, devices, errors } from 'playwright-chromium';
1818
import playwright from 'playwright-chromium';
19+
import errorsFile from 'playwright-chromium/lib/errors.js';
1920

2021
if (playwright.chromium !== chromium)
2122
process.exit(1);
2223

24+
if (playwright.errors !== errors)
25+
process.exit(1);
26+
if (errors.TimeoutError !== errorsFile.TimeoutError)
27+
process.exit(1);
28+
2329
(async () => {
2430
for (const browserType of [chromium]) {
2531
const browser = await browserType.launch();

packages/installation-tests/esm-playwright-firefox.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616

1717
import { firefox, selectors, devices, errors } from 'playwright-firefox';
1818
import playwright from 'playwright-firefox';
19+
import errorsFile from 'playwright-firefox/lib/errors.js';
1920

2021
if (playwright.firefox !== firefox)
2122
process.exit(1);
2223

24+
if (playwright.errors !== errors)
25+
process.exit(1);
26+
if (errors.TimeoutError !== errorsFile.TimeoutError)
27+
process.exit(1);
28+
2329
(async () => {
2430
for (const browserType of [firefox]) {
2531
const browser = await browserType.launch();

packages/installation-tests/esm-playwright-webkit.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616

1717
import { webkit, selectors, devices, errors } from 'playwright-webkit';
1818
import playwright from 'playwright-webkit';
19+
import errorsFile from 'playwright-webkit/lib/errors.js';
1920

2021
if (playwright.webkit !== webkit)
2122
process.exit(1);
2223

24+
if (playwright.errors !== errors)
25+
process.exit(1);
26+
if (errors.TimeoutError !== errorsFile.TimeoutError)
27+
process.exit(1);
28+
2329
(async () => {
2430
for (const browserType of [webkit]) {
2531
const browser = await browserType.launch();

packages/installation-tests/esm-playwright.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright';
1818
import playwright from 'playwright';
19+
import errorsFile from 'playwright/lib/errors.js';
1920

2021
if (playwright.chromium !== chromium)
2122
process.exit(1);
@@ -24,6 +25,11 @@ if (playwright.firefox !== firefox)
2425
if (playwright.webkit !== webkit)
2526
process.exit(1);
2627

28+
if (playwright.errors !== errors)
29+
process.exit(1);
30+
if (errors.TimeoutError !== errorsFile.TimeoutError)
31+
process.exit(1);
32+
2733
(async () => {
2834
for (const browserType of [chromium, firefox, webkit]) {
2935
const browser = await browserType.launch();

packages/installation-tests/sanity.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const browsers = process.argv.slice(3);
1919

2020
const playwright = require(requireName);
2121

22+
// Requiring internals should work.
23+
const errors = require(requireName + '/lib/errors');
24+
const installer = require(requireName + '/lib/install/installer');
25+
2226
(async () => {
2327
for (const browserType of browsers) {
2428
const browser = await playwright[browserType].launch();

0 commit comments

Comments
 (0)