2017-05-11 07:06:41 +00:00
|
|
|
{
|
|
|
|
"name": "puppeteer",
|
2022-07-21 14:25:48 +00:00
|
|
|
"version": "15.5.0",
|
2017-08-16 05:30:56 +00:00
|
|
|
"description": "A high-level API to control headless Chrome over the DevTools Protocol",
|
2022-03-09 12:42:33 +00:00
|
|
|
"keywords": [
|
|
|
|
"puppeteer",
|
|
|
|
"chrome",
|
|
|
|
"headless",
|
|
|
|
"automation"
|
|
|
|
],
|
2022-05-09 11:17:24 +00:00
|
|
|
"type": "commonjs",
|
2022-06-09 17:00:50 +00:00
|
|
|
"main": "./lib/cjs/puppeteer/puppeteer.js",
|
2022-05-09 11:17:24 +00:00
|
|
|
"exports": {
|
|
|
|
".": {
|
2022-05-31 14:34:32 +00:00
|
|
|
"types": "./lib/types.d.ts",
|
2022-06-09 17:00:50 +00:00
|
|
|
"import": "./lib/esm/puppeteer/puppeteer.js",
|
|
|
|
"require": "./lib/cjs/puppeteer/puppeteer.js"
|
2022-05-09 11:17:24 +00:00
|
|
|
},
|
|
|
|
"./*": {
|
|
|
|
"import": "./*",
|
|
|
|
"require": "./*"
|
|
|
|
}
|
|
|
|
},
|
fix: much better TypeScript definitions (#6837)
This PR aims to vastly improve our TS types and how we ship them.
Our previous attempt at shipping TypeScript was unfortunately flawed for
many reasons when compared to the @types/puppeteer package:
* It only worked if you needed the default export. If you wanted to
import a type that Puppeteer uses, you'd have to do `import type X
from 'puppeteer/lib/...'`. This is not something we want to encourage
because that means our internal file structure becomes almost public
API.
* It gave absolutely no help to CommonJS users in JS files because it
would warn people they needed to do `const pptr =
require('puppeteer').default, which is not correct.
* I found a bug in the `evaluate` types which mean't you couldn't
override the types to provide more info, and TS would insist the types
were all `unknown`.
The goal of this PR is to support:
1. In a `ts` file, `import puppeteer from 'puppeteer'`
1. In a `ts` file, `import type {ElementHandle} from 'puppeteer'`
1. In a `ts` file, referencing a type as `puppeteer.ElementHandle`
1. In a `ts` file, you can get good type inference when running
`foo.evaluate(x => x.clientHeight)`.
1. In a `js` file using CJS, you can do `const puppeteer =
require('puppeteer')` and get good type help from VSCode.
To test this I created a new empty repository with two test files in,
one `.ts` file with this in:
https://gist.github.com/jackfranklin/22ba2f390f97c7312cd70025a2096fc8,
and a `js` file with this in:
https://gist.github.com/jackfranklin/06bed136fdb22419cb7a8a9a4d4ef32f.
These files included enough code to check that the types were behaving
as I expected.
The fix for our types was to make use of API Extractor, which we already
use for our docs, to "rollup" all the disparate type files that TS
generates into one large `types.d.ts` which contains all the various
types that we define, such as:
```ts
export declare class ElementHandle {...}
export type EvaluateFn ...
```
If we then update our `package.json` `types` field to point to that file
in `lib/types.d.ts`, this then allows a developer to write:
```
import type {ElementHandle} from 'puppeteer'
```
And get the correct type definitions. However, what the `types.d.ts`
file doesn't do out of the box is declare the default export, so
importing Puppeteer's default export to call a method such as `launch`
on it will get you an error.
That's where the `script/add-default-export-to-types.ts` comes in. It
appends the following to the auto-generated `types.d.ts` file:
```ts
declare const puppeteer: PuppeteerNode;
export = puppeteer;
```
This tells TypeScript what the default export is, and by using the
`export =` syntax, we make sure TS understands both in a TS ESM
environment and in a JS CJS environment.
Now the `build` step, which is run by GitHub Actions when we release,
will generate the `.d.ts` file and then extend it with the default
export code.
To ensure that I was generating a valid package, I created a new
repository locally with the two code samples linked in Gists above. I
then ran:
```
npm init -y
npm install --save-dev typescript
npx tsc --init
```
Which gives me a base to test from. In Puppeteer, I ran `npm pack`,
which packs the module into a tar that's almost identical to what would
be published, so I can be confident that the .d.ts files in there are
what would be published.
I then installed it:
```
npm install --save-dev ../../puppeteer/puppeteer-7.0.1-post.tgz
```
And then reloaded VSCode in my dummy project. By deliberately making
typos and hovering over the code, I could confirm that all the goals
listed above were met, and this seems like a vast improvement on our
types.
2021-02-09 08:00:42 +00:00
|
|
|
"types": "lib/types.d.ts",
|
2019-11-26 12:12:25 +00:00
|
|
|
"repository": "github:puppeteer/puppeteer",
|
2017-06-19 22:01:14 +00:00
|
|
|
"engines": {
|
2022-05-03 06:59:40 +00:00
|
|
|
"node": ">=14.1.0"
|
2017-06-19 22:01:14 +00:00
|
|
|
},
|
2017-05-11 07:06:41 +00:00
|
|
|
"scripts": {
|
2022-07-21 18:50:46 +00:00
|
|
|
"test": "c8 --check-coverage --lines 93 run-s test:chrome test:chrome:* test:firefox",
|
2022-07-06 07:05:37 +00:00
|
|
|
"test:types": "tsd",
|
2022-07-01 13:03:12 +00:00
|
|
|
"test:install": "scripts/test-install.sh",
|
|
|
|
"test:firefox": "cross-env PUPPETEER_PRODUCT=firefox MOZ_WEBRENDER=0 mocha",
|
|
|
|
"test:chrome": "mocha",
|
|
|
|
"test:chrome:headless": "cross-env HEADLESS=chrome mocha",
|
|
|
|
"test:chrome:headful": "cross-env HEADLESS=false mocha",
|
2021-02-09 11:34:21 +00:00
|
|
|
"prepublishOnly": "npm run build",
|
2022-07-01 13:03:12 +00:00
|
|
|
"prepare": "node typescript-if-required.js && husky install",
|
|
|
|
"lint": "run-s lint:prettier lint:eslint",
|
2022-06-10 09:55:53 +00:00
|
|
|
"lint:prettier": "prettier --check .",
|
|
|
|
"lint:eslint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .)",
|
2017-06-19 21:43:05 +00:00
|
|
|
"install": "node install.js",
|
2022-07-01 14:00:03 +00:00
|
|
|
"generate:types": "node utils/export_all.js && api-extractor run --local --verbose && eslint --ext ts --no-ignore --no-eslintrc -c .eslintrc.types.cjs --fix lib/types.d.ts",
|
2022-07-05 13:41:43 +00:00
|
|
|
"generate:markdown": "ts-node -O '{\"module\":\"commonjs\"}' utils/generate_docs.ts && prettier --ignore-path none --write docs",
|
2022-07-01 13:03:12 +00:00
|
|
|
"generate:esm-package-json": "echo '{\"type\": \"module\"}' > lib/esm/package.json",
|
|
|
|
"format": "run-s format:*",
|
|
|
|
"format:prettier": "prettier --write .",
|
2022-07-01 14:00:03 +00:00
|
|
|
"format:eslint": "eslint --ext js --ext ts --fix .",
|
2022-07-01 13:03:12 +00:00
|
|
|
"docs": "run-s build generate:markdown",
|
2022-07-01 14:29:21 +00:00
|
|
|
"debug": "npm run build && mocha --inspect-brk",
|
2022-06-10 09:55:53 +00:00
|
|
|
"commitlint": "commitlint --from=HEAD~1",
|
2022-07-07 13:04:28 +00:00
|
|
|
"clean": "rimraf lib && rimraf test/build",
|
2022-07-01 13:03:12 +00:00
|
|
|
"check": "run-p check:*",
|
|
|
|
"check:protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package",
|
|
|
|
"check:pinned-deps": "ts-node -s scripts/ensure-pinned-deps",
|
|
|
|
"build": "run-s build:tsc generate:types generate:esm-package-json",
|
|
|
|
"build:tsc": "tsc --version && run-p build:tsc:*",
|
2022-06-10 09:55:53 +00:00
|
|
|
"build:tsc:esm": "tsc -b src/tsconfig.esm.json",
|
2022-07-01 13:03:12 +00:00
|
|
|
"build:tsc:cjs": "tsc -b src/tsconfig.cjs.json",
|
2022-07-01 14:29:21 +00:00
|
|
|
"build:tsc:test": "tsc -b test"
|
2017-05-11 07:06:41 +00:00
|
|
|
},
|
2020-04-17 09:32:25 +00:00
|
|
|
"files": [
|
2022-06-09 17:00:50 +00:00
|
|
|
"lib",
|
2020-04-22 14:33:36 +00:00
|
|
|
"install.js",
|
2022-07-13 13:16:39 +00:00
|
|
|
"typescript-if-required.js",
|
|
|
|
"!**/*.tsbuildinfo"
|
2020-04-17 09:32:25 +00:00
|
|
|
],
|
2017-05-11 07:06:41 +00:00
|
|
|
"author": "The Chromium Authors",
|
2017-08-31 18:16:28 +00:00
|
|
|
"license": "Apache-2.0",
|
2017-05-11 07:06:41 +00:00
|
|
|
"dependencies": {
|
2022-02-09 14:49:25 +00:00
|
|
|
"cross-fetch": "3.1.5",
|
2022-03-18 08:14:09 +00:00
|
|
|
"debug": "4.3.4",
|
2022-07-21 13:16:47 +00:00
|
|
|
"devtools-protocol": "0.0.1019158",
|
2021-05-14 11:02:36 +00:00
|
|
|
"extract-zip": "2.0.1",
|
2022-04-21 05:33:59 +00:00
|
|
|
"https-proxy-agent": "5.0.1",
|
2021-05-14 11:02:36 +00:00
|
|
|
"pkg-dir": "4.2.0",
|
2021-10-07 12:22:33 +00:00
|
|
|
"progress": "2.0.3",
|
2021-05-14 11:02:36 +00:00
|
|
|
"proxy-from-env": "1.1.0",
|
|
|
|
"rimraf": "3.0.2",
|
2021-10-14 15:08:03 +00:00
|
|
|
"tar-fs": "2.1.1",
|
2021-10-08 12:20:02 +00:00
|
|
|
"unbzip2-stream": "1.4.3",
|
2022-07-27 05:42:18 +00:00
|
|
|
"ws": "8.8.1"
|
2017-05-11 07:06:41 +00:00
|
|
|
},
|
2017-05-12 23:36:37 +00:00
|
|
|
"devDependencies": {
|
2022-05-31 17:04:30 +00:00
|
|
|
"@commitlint/cli": "17.0.1",
|
2022-06-02 11:59:23 +00:00
|
|
|
"@commitlint/config-conventional": "17.0.2",
|
2022-07-01 11:52:39 +00:00
|
|
|
"@microsoft/api-documenter": "7.18.0",
|
2022-05-31 17:04:30 +00:00
|
|
|
"@microsoft/api-extractor": "7.24.2",
|
2022-07-01 11:52:39 +00:00
|
|
|
"@microsoft/api-extractor-model": "7.21.0",
|
2021-10-11 07:50:28 +00:00
|
|
|
"@types/debug": "4.1.7",
|
2022-06-15 10:09:22 +00:00
|
|
|
"@types/diff": "5.0.2",
|
2021-05-14 11:02:36 +00:00
|
|
|
"@types/mime": "2.0.3",
|
2022-04-22 08:33:58 +00:00
|
|
|
"@types/mocha": "9.1.1",
|
2022-06-02 11:58:59 +00:00
|
|
|
"@types/node": "17.0.38",
|
2022-06-15 10:09:22 +00:00
|
|
|
"@types/pixelmatch": "5.2.4",
|
|
|
|
"@types/pngjs": "6.0.1",
|
2022-01-28 09:38:36 +00:00
|
|
|
"@types/progress": "2.0.5",
|
2021-05-14 11:02:36 +00:00
|
|
|
"@types/proxy-from-env": "1.0.1",
|
2021-10-07 14:40:23 +00:00
|
|
|
"@types/rimraf": "3.0.2",
|
2022-07-01 11:52:39 +00:00
|
|
|
"@types/semver": "7.3.10",
|
2022-02-09 14:49:25 +00:00
|
|
|
"@types/sinon": "10.0.11",
|
2021-10-11 08:48:26 +00:00
|
|
|
"@types/tar-fs": "2.0.1",
|
2022-05-31 14:34:16 +00:00
|
|
|
"@types/unbzip2-stream": "1.4.0",
|
2022-03-15 06:29:42 +00:00
|
|
|
"@types/ws": "8.5.3",
|
2022-05-31 17:04:30 +00:00
|
|
|
"@typescript-eslint/eslint-plugin": "5.27.0",
|
|
|
|
"@typescript-eslint/parser": "5.27.0",
|
2022-06-10 16:49:14 +00:00
|
|
|
"c8": "7.11.3",
|
2022-02-09 14:49:25 +00:00
|
|
|
"commonmark": "0.30.0",
|
2021-05-14 11:02:36 +00:00
|
|
|
"cross-env": "7.0.3",
|
2022-06-15 10:09:22 +00:00
|
|
|
"diff": "5.1.0",
|
2022-05-31 17:04:30 +00:00
|
|
|
"eslint": "8.16.0",
|
2022-03-03 13:20:23 +00:00
|
|
|
"eslint-config-prettier": "8.5.0",
|
2022-06-15 10:05:25 +00:00
|
|
|
"eslint-formatter-codeframe": "7.32.1",
|
2022-04-06 14:28:43 +00:00
|
|
|
"eslint-plugin-import": "2.26.0",
|
2022-05-31 17:04:30 +00:00
|
|
|
"eslint-plugin-mocha": "10.0.5",
|
2021-10-08 15:44:22 +00:00
|
|
|
"eslint-plugin-prettier": "4.0.0",
|
2022-06-01 09:11:09 +00:00
|
|
|
"eslint-plugin-tsdoc": "0.2.16",
|
2022-07-01 14:00:03 +00:00
|
|
|
"eslint-plugin-unused-imports": "2.0.0",
|
2021-10-18 13:22:59 +00:00
|
|
|
"esprima": "4.0.1",
|
2021-05-14 11:02:36 +00:00
|
|
|
"expect": "25.2.7",
|
2022-06-22 13:25:44 +00:00
|
|
|
"gts": "3.1.0",
|
2022-05-31 17:04:30 +00:00
|
|
|
"husky": "8.0.1",
|
2022-06-22 13:25:44 +00:00
|
|
|
"jpeg-js": "0.4.4",
|
2022-02-09 14:49:25 +00:00
|
|
|
"mime": "3.0.0",
|
2022-03-22 09:12:53 +00:00
|
|
|
"minimist": "1.2.6",
|
2022-05-03 09:42:19 +00:00
|
|
|
"mocha": "10.0.0",
|
2021-05-14 11:02:36 +00:00
|
|
|
"ncp": "2.0.0",
|
2022-07-01 13:03:12 +00:00
|
|
|
"npm-run-all": "4.1.5",
|
2022-04-28 05:53:20 +00:00
|
|
|
"pixelmatch": "5.3.0",
|
2021-10-18 12:45:03 +00:00
|
|
|
"pngjs": "6.0.0",
|
2022-04-04 09:13:02 +00:00
|
|
|
"prettier": "2.6.2",
|
2022-07-01 11:52:39 +00:00
|
|
|
"semver": "7.3.7",
|
2022-05-20 06:33:15 +00:00
|
|
|
"sinon": "14.0.0",
|
2022-02-09 14:49:25 +00:00
|
|
|
"source-map-support": "0.5.21",
|
2021-05-14 11:02:36 +00:00
|
|
|
"text-diff": "1.0.1",
|
2022-06-27 08:57:31 +00:00
|
|
|
"tsd": "0.21.0",
|
2022-05-31 17:04:30 +00:00
|
|
|
"typescript": "4.7.2"
|
2017-05-11 07:06:41 +00:00
|
|
|
}
|
|
|
|
}
|