fix(require): allow requiring internals (#3153)

This commit is contained in:
Dmitry Gozman 2020-07-24 14:21:25 -07:00 committed by GitHub
parent 3162c06f49
commit 6a4195fd1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 2 deletions

View File

@ -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',

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();