Skip to content

Commit

Permalink
feat(puppeteer): export esm modules in package.json
Browse files Browse the repository at this point in the history
Signed-off-by: Randolf Jung <jrandolf@chromium.org>
  • Loading branch information
jrandolf committed Feb 7, 2022
1 parent 6dc0e73 commit 4b43cf9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions package.esm.json
@@ -0,0 +1,3 @@
{
"type": "module"
}
8 changes: 7 additions & 1 deletion package.json
Expand Up @@ -2,7 +2,12 @@
"name": "puppeteer",
"version": "13.2.0",
"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"
},
"types": "lib/types.d.ts",
"repository": "github:puppeteer/puppeteer",
"engines": {
Expand All @@ -29,7 +34,7 @@
"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",
"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",
"tsc-cjs": "tsc -b src/tsconfig.cjs.json",
"tsc-esm": "tsc -b src/tsconfig.esm.json",
Expand All @@ -38,6 +43,7 @@
"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": "cp package.esm.json 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 Down
4 changes: 3 additions & 1 deletion src/common/Debug.ts
Expand Up @@ -55,7 +55,9 @@ 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 require('debug')(prefix);
return async (...logArgs: unknown[]) => {
(await import('debug')).default(prefix)(logArgs);
};
}

return (...logArgs: unknown[]): void => {
Expand Down
2 changes: 1 addition & 1 deletion src/initialize-node.ts
Expand Up @@ -20,7 +20,7 @@ import pkgDir from 'pkg-dir';
import { Product } from './common/Product.js';

export const initializePuppeteerNode = (packageName: string): PuppeteerNode => {
const puppeteerRootDirectory = pkgDir.sync(__dirname);
const puppeteerRootDirectory = pkgDir.sync(process.cwd());

let preferredRevision = PUPPETEER_REVISIONS.chromium;
const isPuppeteerCore = packageName === 'puppeteer-core';
Expand Down

0 comments on commit 4b43cf9

Please sign in to comment.