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

revert: esm modules #7996

Merged
merged 2 commits into from
Feb 10, 2022
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ yarn.lock
test/coverage.json
temp/
new-docs/
puppeteer*.tgz
puppeteer.tgz
docs-api-json/
docs-dist/
website/docs
16 changes: 0 additions & 16 deletions compat/README.md

This file was deleted.

19 changes: 0 additions & 19 deletions compat/cjs/compat.ts

This file was deleted.

11 changes: 0 additions & 11 deletions compat/cjs/tsconfig.json

This file was deleted.

22 changes: 0 additions & 22 deletions compat/esm/compat.ts

This file was deleted.

9 changes: 0 additions & 9 deletions compat/esm/tsconfig.json

This file was deleted.

19 changes: 2 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@
"name": "puppeteer",
"version": "13.3.0-post",
"description": "A high-level API to control headless Chrome over the DevTools Protocol",
"type": "commonjs",
"main": "./cjs-entry.js",
"exports": {
".": {
"import": "./lib/esm/puppeteer/node.js",
"require": "./cjs-entry.js"
},
"./*": {
"import": "./*",
"require": "./*"
}
},
"types": "lib/types.d.ts",
"repository": "github:puppeteer/puppeteer",
"engines": {
Expand All @@ -40,18 +29,15 @@
"lint": "npm run eslint && npm run build && npm run doc && npm run markdownlint",
"doc": "node utils/doclint/cli.js",
"clean-lib": "rimraf lib",
"build": "npm run tsc && npm run generate-d-ts && npm run generate-pkg-json",
"tsc": "npm run clean-lib && tsc --version && (npm run tsc-cjs & npm run tsc-esm) && (npm run tsc-compat-cjs & npm run tsc-compat-esm)",
"build": "npm run tsc && npm run generate-d-ts",
"tsc": "npm run clean-lib && tsc --version && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc -b src/tsconfig.cjs.json",
"tsc-esm": "tsc -b src/tsconfig.esm.json",
"tsc-compat-cjs": "tsc -b compat/cjs/tsconfig.json",
"tsc-compat-esm": "tsc -b compat/esm/tsconfig.json",
"apply-next-version": "node utils/apply_next_version.js",
"test-install": "scripts/test-install.sh",
"clean-docs": "rimraf website/docs && rimraf docs-api-json",
"generate-d-ts": "npm run clean-docs && api-extractor run --local --verbose",
"generate-docs": "npm run generate-d-ts && api-documenter markdown -i docs-api-json -o website/docs && node utils/remove-tag.js",
"generate-pkg-json": "echo '{\"type\": \"module\"}' > lib/esm/package.json",
"ensure-correct-devtools-protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package",
"ensure-pinned-deps": "ts-node -s scripts/ensure-pinned-deps",
"test-types-file": "ts-node -s scripts/test-ts-definition-files.ts",
Expand All @@ -64,7 +50,6 @@
"lib/**/*.d.ts.map",
"lib/**/*.js",
"lib/**/*.js.map",
"lib/**/package.json",
"install.js",
"typescript-if-required.js",
"cjs-entry.js",
Expand Down
31 changes: 0 additions & 31 deletions scripts/test-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,6 @@ cd $TMPDIR
# 3. Requiring Puppeteer from Node works.
npm install --loglevel silent "${tarball}"
node --eval="require('puppeteer')"
node --eval="
require('puppeteer/lib/cjs/puppeteer/revisions.js');
"
ls $TMPDIR/node_modules/puppeteer/.local-chromium/

# Testing ES module features
TMPDIR="$(mktemp -d)"
cd $TMPDIR
echo '{"type":"module"}' >>$TMPDIR/package.json
npm install --loglevel silent "${tarball}"
node --input-type="module" --eval="import puppeteer from 'puppeteer'"
node --input-type="module" --eval="
import 'puppeteer/lib/esm/puppeteer/revisions.js';
"
node --input-type="module" --eval="
import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://example.com');
await page.screenshot({ path: 'example.png' });
await browser.close();
})();
"
ls $TMPDIR/node_modules/puppeteer/.local-chromium/

# Again for Firefox
Expand All @@ -64,9 +39,3 @@ cd $TMPDIR
npm install --loglevel silent "${tarball}"
node --eval="require('puppeteer-core')"

# Testing ES module features
TMPDIR="$(mktemp -d)"
cd $TMPDIR
echo '{"type":"module"}' >>$TMPDIR/package.json
npm install --loglevel silent "${tarball}"
node --input-type="module" --eval="import puppeteer from 'puppeteer-core'"
4 changes: 1 addition & 3 deletions src/common/Debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ import { isNode } from '../environment.js';
export const debug = (prefix: string): ((...args: unknown[]) => void) => {
if (isNode) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
return async (...logArgs: unknown[]) => {
(await import('debug')).default(prefix)(logArgs);
};
return require('debug')(prefix);
}

return (...logArgs: unknown[]): void => {
Expand Down
19 changes: 0 additions & 19 deletions src/compat.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/initialize-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import { PuppeteerNode } from './node/Puppeteer.js';
import { PUPPETEER_REVISIONS } from './revisions.js';
import { sync } from 'pkg-dir';
import { Product } from './common/Product.js';
import { puppeteerDirname } from './compat.js';

export const initializePuppeteerNode = (packageName: string): PuppeteerNode => {
const puppeteerRootDirectory = sync(puppeteerDirname);
const puppeteerRootDirectory = sync(__dirname);

let preferredRevision = PUPPETEER_REVISIONS.chromium;
const isPuppeteerCore = packageName === 'puppeteer-core';
Expand Down
6 changes: 4 additions & 2 deletions src/node/BrowserFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import createHttpsProxyAgent, {
} from 'https-proxy-agent';
import { getProxyForUrl } from 'proxy-from-env';
import { assert } from '../common/assert.js';
import tar from 'tar-fs';
import bzip from 'unbzip2-stream';

const debugFetcher = debug('puppeteer:fetcher');

Expand Down Expand Up @@ -501,6 +499,10 @@ function install(archivePath: string, folderPath: string): Promise<unknown> {
* @internal
*/
function extractTar(tarPath: string, folderPath: string): Promise<unknown> {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const tar = require('tar-fs');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const bzip = require('unbzip2-stream');
return new Promise((fulfill, reject) => {
const tarStream = tar.extract(folderPath);
tarStream.on('error', reject);
Expand Down
14 changes: 3 additions & 11 deletions src/node/NodeWebSocketTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,18 @@
*/
import { ConnectionTransport } from '../common/ConnectionTransport.js';
import NodeWebSocket from 'ws';
import { readFileSync } from 'fs';
import { join } from 'path';
import { puppeteerDirname } from '../compat.js';

// We parse rather than import for ES module compatibility.
const version = JSON.parse(
readFileSync(join(puppeteerDirname, 'package.json'), {
encoding: 'utf8',
})
).version;

export class NodeWebSocketTransport implements ConnectionTransport {
static create(url: string): Promise<NodeWebSocketTransport> {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../../../package.json');
return new Promise((resolve, reject) => {
const ws = new NodeWebSocket(url, [], {
followRedirects: true,
perMessageDeflate: false,
maxPayload: 256 * 1024 * 1024, // 256Mb
headers: {
'User-Agent': `Puppeteer ${version}`,
'User-Agent': `Puppeteer ${pkg.version}`,
},
});

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
*/
"module": "esnext"
},
"include": ["src"],
"include": ["src"]
}
5 changes: 1 addition & 4 deletions utils/prepare_puppeteer_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ const path = require('path');
const packagePath = path.join(__dirname, '..', 'package.json');
const json = require(packagePath);

delete json.scripts.install;

json.name = 'puppeteer-core';
delete json.scripts.install;
json.main = './cjs-entry-core.js';
json.exports['.'].imports = './lib/esm/puppeteer/node-puppeteer-core.js';
json.exports['.'].require = './cjs-entry-core.js';
fs.writeFileSync(packagePath, JSON.stringify(json, null, ' '));