Commit Graph

457 Commits

Author SHA1 Message Date
Jan Scheffler
f863f4bfe0
feat(chromium): roll to Chromium 92.0.4512.0 (r884014) (#7288) 2021-05-26 16:44:29 +00:00
Jack Franklin
4796382f01
chore: enforce pinned dependencies (#7238)
* chore: enforce pinned dependencies

Because we don't check our `package-lock.json` in, we can end up with
different versions installed locally vs CI, or even two devs having
different versions. Let's pin and enforce we pin every version to
avoid this.
2021-05-14 12:02:36 +01:00
Jack Franklin
3204f2780f
chore: fix eslint warnings around type defs (#7230)
This PR updates some code to remove constant ESLint warnings. It also
upgrades those warnings to errors - so that they have to be resolved
as part of the PR, rather than landing as a warning and causing noise.

Fixes #7229.
2021-05-12 17:43:05 +01:00
Jack Franklin
523aa0aafa
chore: upgrade and pin prettier dependencies (#7232)
We're seeing odd failures with Prettier on some CI branches; my hunch is that they are installing different versions of the package and therefore getting formatting conflicts. This PR updates them all and pins them to specific versions - something we should probably consider generally, or remove our `package-lock.json` from the gitignore.
2021-05-12 16:48:30 +02:00
Mathias Bynens
d9ace6c664
chore: disable markdownlint for api.md (#7228)
api.md is autogenerated anyhow, and this avoids the recent CI failures.

Issue: #7227
2021-05-12 14:47:27 +02:00
Jan Scheffler
476e9259fe
chore: bump version to v9.1.1-post (#7206) 2021-05-05 09:57:19 +00:00
Jan Scheffler
d615dd3d2c
chore(release): mark v9.1.1 (#7205) 2021-05-05 10:38:53 +02:00
Jan Scheffler
8816645c71
chore: bump version to v9.1.0-post (#7202) 2021-05-03 12:40:47 +00:00
Jan Scheffler
1d473bc79f
chore(release): mark v9.1.0 (#7201) 2021-05-03 14:08:44 +02:00
Jan Scheffler
ad6b736039
fix: change rm -rf to rimraf (#7168)
Currently, `npm clean-lib` fails on windows with `cmd` because it does not now about `rm`.
This change uses the already installed `rimraf` to do the job instead.
2021-04-27 10:32:15 +02:00
Maksim Sadym
0fa0a34802
chore: bump version to v9.0.0-post (#7112) 2021-04-21 11:43:49 +00:00
Maksim Sadym
5872e7178a
chore(release): mark v9.0.0 (#7111) 2021-04-21 11:18:09 +00:00
Maksim Sadym
715e7a8d62
feat(chromium): roll to Chromium 91.0.4469.0 (r869685) (#7110)
* Roll to Chromium 91.0.4469.0 (r869685).
* Update CONTRIBUTING.md.
2021-04-21 10:43:08 +00:00
David Barton
c62b02f177
chore: automate prettier in docs (#7014)
Issue: #7012
Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2021-03-23 10:02:34 +01:00
Henrik Skupin
669f04a7a6
chore: enable unit tests for Firefox on Windows (#6895)
Co-authored-by: Jan Scheffler <janscheffler@chromium.org>
2021-03-05 09:00:56 +00:00
Alex Rudenko
0c26301bee
chore: bump version to v8.0.0-post (#6929) 2021-02-26 08:51:52 +00:00
Alex Rudenko
0b5969dea9
chore(release): mark v8.0.0 (#6928) 2021-02-26 08:32:27 +00:00
Alex Rudenko
0c688bd75e
feat(chromium): roll Chromium to r856583 (#6927)
* feat(chromium): roll Chromium to r856583

This corresponds to Chromium 90.0.4427.0

This roll includes:
- Add sourceScheme, sourcePort, and sameParty to DevTools backend (https://crbug.com/1170548, https://crbug.com/1142606)
2021-02-26 09:12:43 +01:00
Jack Franklin
8adf5b467d
chore: upgrade TypeScript to 4.1.5 (#6889)
We were blocked on doing this because API Extractor didn't support it,
but now it does, so we can bump TS and the API tooling in one go. None
of the breaking changes in TS4 cause us any issues.
2021-02-16 10:43:32 +00:00
Jack Franklin
29c059427e
chore: bump to 7.1.0-post (#6880) 2021-02-12 11:19:06 +00:00
Jack Franklin
a681aac7e3
chore(release): mark v7.1.0 (#6879) 2021-02-12 10:51:43 +00:00
Jack Franklin
0889b7eb66
chore: upgrade @web/test-runner and increase timeout (#6870)
We've seen the odd timeout on the bots; increasing this in the hope that
it helps stop the flakes.
2021-02-11 12:38:22 +01:00
Jack Franklin
6a0eb7841f
fix: wider compat TS types and CI checks to ensure correct type defs (#6855)
* fix: wider compat TS types and CI checks to ensure correct type defs

This PR improves our TS types further to make sure they are usable in a
TS environment where ES Modules are the target output. Our use of
`export =` is problematic this environment as TypeScript does not allow
`export =` to be used and it errors.

The fix for the type issues to avoid `export =` is to instead define the
functions that you gain access to when you import Puppeteer as top level
functions in our `types.d.ts` file. We can do this by declaring them
explicitly in `src/node.ts`. These are then rolled into `lib/types.d.ts`
at build time. The downside to this is that we have to keep those
declarations in sync with the Puppeteer API; should we add a new method
to the `Puppeteer` class, we must add it to the `nodes.ts` declarations.
However, this could easily be automated by a small script that walks the
AST and generates these. I will do that in a follow-up PR, but I
consider this low risk given how rarely the very top level API of
Puppeteer changes. The nice thing about this approach is we no longer
need our script that hacks on changes to `lib/types.d.ts`.

To avoid yet more releases to fix issues in one particular TS
environment, this PR also includes a suite of example setups that we
test on each CI run. Each sample folder contains `good.ts`, which should
have no TS errors, and `bad.ts`, which should have some errors. The test
first packs Puppeteer into a tar, and then installs it from that tar
into each project. This should replicate how the published package
behaves when it is installed. We then check that we get no errors on
`good.ts`, and the expected errors on `bad.ts`.

We have a variety of test projects that cover both TS and JS source
code, and CJS and ESM imports and outputs.
2021-02-10 12:04:36 +00:00
Jack Franklin
e16741dee2
chore: mark version 7.0.4-post (#6851) 2021-02-09 14:10:28 +00:00
Jack Franklin
db2b4898e1
chore(release): mark v7.0.4 (#6850) 2021-02-09 13:24:44 +01:00
Jack Franklin
fd857474cc
chore: fix doclint violations (#6849) 2021-02-09 11:52:35 +00:00
Jack Franklin
f718b14b64
fix: make publish bot run full build, not just tsc (#6848)
`npm run tsc` is not enough to do a full build now we also include the
`types.d.ts` file, so we need to run `build.`
2021-02-09 11:34:21 +00:00
Jack Franklin
de904db51d
chore: bump version to 7.0.3-post (#6846) 2021-02-09 09:56:17 +01:00
Jack Franklin
27eaf607ce
chore(release): mark v7.0.3 (#6845) 2021-02-09 09:49:44 +01:00
Jack Franklin
a1d4d7f854
chore: bump version to 7.0.2-post (#6843)
Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2021-02-09 09:44:52 +01:00
Jack Franklin
e34f317b37
fix: include lib/types.d.ts in files list (#6844)
Else it's missed when npm publish happens. Didn't pick this up in my testing because a previous PR that changed this hadn't landed at the time of testing so the bug was missed.
2021-02-09 09:44:23 +01:00
Jack Franklin
ff50c86332
chore(release): mark v7.0.2 (#6842) 2021-02-09 08:17:15 +00:00
Jack Franklin
f1b46ab5fa
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
Jack Franklin
6fec36d8ba
chore: don’t ship tsbuildinfo files in npm package (#6809)
This PR updates our `files` list to be more specific; rather than include everything from `lib`, we include just `.js`, `.d.ts`, and their equivalent sourcemaps. This prevents noisy meta-files like `.tsbuildinfo` sneaking into the package, which are no use to anyone.
2021-02-08 16:21:41 +00:00
Arjen Korevaar
3b13012d1f
chore: update proxy-from-env (#6660) 2021-02-05 09:20:40 +01:00
Jack Franklin
c936b18651
chore: bump version to 7.0.1-post (#6814) 2021-02-04 10:32:11 +00:00
Jack Franklin
eb0d604bf3
chore(release): mark v7.0.1 (#6812) 2021-02-04 10:07:37 +00:00
Jack Franklin
a7e3c2e09e
fix(typescript): ship .d.ts file in npm package (#6811)
In all my excitement about shipping types, we forgot to export the
actual `d.ts` file that makes it all happen... :(

I didn't pick this up locally because I was testing with `npm link`,
which does a symbolic link and therefore doesn't mirror the list of
files that make it into the published package.

To test this change, I made the change and ran `npm pack` to generate a
tar. I then created a new empty directory and did `npm init -y` followed
by `npm install path/to/puppeteer-7.tgz`.

I then initialised TypeScript, and wrote this:

```js
import puppeteer from 'puppeteer';

async function run() {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.goto('https://foo.com')
}
run();
```

As I typed I got autocompletions and if I were to make an error, I'd get
a TypeScript error.

There is follow up work to be done because this unfortunately does not
work if you use `require` rather than ES Modules. @AviVahl suggested a
change in https://github.com/puppeteer/puppeteer/issues/6807 but I
cannot get it to work, so I'd like to do more investigation here. In the
mean time, whatever the contents of `cjs-entry.d.ts`, we should
definitely be exporting it as part of the module, so this PR is still
good to land.
2021-02-04 09:45:46 +00:00
Jan Scheffler
9abd459b2a
chore: bump version to v7.0.0-post (#6808) 2021-02-03 15:54:54 +00:00
Jan Scheffler
edd8bcc619
chore(release): mark v7.0.0 (#6804) 2021-02-03 16:33:32 +01:00
Maksim Sadym
890d5c2e57
feat(chromium): roll Chromium to r848005 (#6801)
This corresponds to Chromium 90.0.4403.0
This roll includes:
- Cut screenshot by ViewPort size, not position (crrev.com/c/2643792)

BREAKING CHANGE:
- `page.screenshot` cuts screenshot content by the ViewPort size, not ViewPort position.
2021-02-02 17:24:10 +01:00
Jan Scheffler
20526b57b8
chore: bump version to v6.0.0-post (#6802) 2021-02-02 11:22:53 +00:00
Jan Scheffler
ef4767080a
chore(release): mark v6.0.0 (#6800) 2021-02-02 12:00:09 +01:00
Maksim Sadym
8f9fbdbae6 feat(chromium): roll Chromium to r843427 (#6797)
This corresponds to Chromium 89.0.4389.0.

This roll includes:

- Add `SameParty` attribute to cookies
  https://crrev.com/c/2598846
- Anchor `target=_blank` implies `rel=noopener`
  https://crrev.com/c/1630010
- Don’t expect ignored elements in the AXTree
  https://crrev.com/c/2505362

BREAKING CHANGE: The built-in `aria/` selector query handler doesn’t return ignored elements anymore.

Issue: #6758
2021-02-02 08:40:56 +01:00
Mathias Bynens
53ce52e3b6
chore: automate release commits (#6628)
Issue: #6482
2020-11-30 10:29:38 +01:00
Peter Marshall
46e74ff3f5
test: use sourcemaps in unit tests (#6485)
Introduce the source-map-support package and require it for mocha running unit tests.

Turn on the sourceMap option for tsconfig.base.json so that the sourceMappingURL= line is emitted in the generated files.

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-11-26 14:51:17 +01:00
Dr
3bf5a55289
fix: update to https-proxy-agent@^5.0.0 to fix ERR_INVALID_PROTOCOL (#6555)
With `nodejs@15.0.1`, install puppeteer with `https_proxy` set causes an error like:

```
> puppeteer@5.4.1 install node_modules/puppeteer
> node install.js

ERROR: Failed to set up Chromium r809590! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
    at new NodeError (node:internal/errors:258:15)
    at new ClientRequest (node:_http_client:155:11)
    at Object.request (node:https:313:10)
    at httpRequest (node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:488:17)
    at downloadFile (node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:357:21)
    at BrowserFetcher.download (node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:239:19)
    at async downloadBrowser (node_modules/puppeteer/lib/cjs/puppeteer/node/install.js:48:5) {
  code: 'ERR_INVALID_PROTOCOL'
}
```

The related issue is at https://github.com/TooTallNate/node-agent-base/pull/47, from package `agent-base` under `https-proxy-agent`

And the version bump is for `Refactor to TypeScript` is here: https://github.com/TooTallNate/node-https-proxy-agent/compare/4.0.0...5.0.0
2020-11-26 12:42:18 +01:00
Mathias Bynens
470124fb2b
chore: automate version bumps (#6627)
Issue: #6482
2020-11-26 11:38:24 +01:00
Mathias Bynens
0473a2ae32
chore: bump version to v5.5.0-post (#6605) 2020-11-17 11:46:21 +01:00
Mathias Bynens
18143b3573
chore(release): mark v5.5.0 (#6604) 2020-11-16 14:38:50 +01:00
Yash Ladha
8690a77a2b
chore: remove redundant npm script for dependency-graph (#6583)
Remove the redundant rule for dependency graph as the `src/index.ts` is not required. This was introduced in 64c9c709, but the filestructure has changed from since then and it doesn't work as `src/index.ts` is replaced with `src/node.ts` and `src/web.ts` as per the use case.
2020-11-04 17:08:07 +01:00
Mathias Bynens
a0d8a27856
chore: automate versioning + changelog (#6556)
As long as we follow Conventional Commits for our commit messages (which is now enforced since #6483), we can automate the maintenance of this new changelog, which enables us to later automate the release process altogether.

This patch also eliminates the versioning decision-making process by automating it based on our commit messages.

Issue: #6482
2020-10-29 10:53:51 +01:00
Joel Einbinder
b549256952 feat(chromium): roll Chromium to r818858 (#6526)
This corresponds to Chromium 88.0.4298.0.

This roll includes:

- DevTools: Wait for a frame before sending touch and wheel events
  https://chromium-review.googlesource.com/c/chromium/src/+/2437695
2020-10-27 18:15:52 +01:00
Jack Franklin
d3d7cb92eb
chore: mark v5.4.1-post (#6553) 2020-10-27 16:07:36 +00:00
Jack Franklin
562c9c2723
chore: mark version 5.4.1 (#6552) 2020-10-27 15:05:43 +00:00
Johan Bay
d787865066
chore: bump version to v5.4.0-post (#6544) 2020-10-26 08:27:40 +01:00
Johan Bay
729cdfe98a
chore: mark version v5.4.0 (#6542) 2020-10-23 16:28:38 +02:00
Mathias Bynens
8e9970df67
chore: automate publishing on new Git tags (#6536)
Issues: #6482
2020-10-23 14:40:14 +02:00
Jack Franklin
e6b8c77d94
chore: fix travis config (#6537) 2020-10-22 15:37:28 +02:00
Jack Franklin
c2c2bb7e55
chore(agnostification): common/helper.ts (#6515)
* chore(agnostification): common/helper.ts

The `readProtocolStream` method uses `fs` only if you want to write to a
file. So we gate at the start of the function and ensure that if we got
given a path we are not in a Node environment.
2020-10-19 09:57:15 +01:00
Jack Franklin
637a1f7409
chore: gitignore new-docs (#6511)
They are generating a lot of noise in PRs. This commit removes them from git, but updates CI to generate them - to ensure there are no errors when generating the new documentation.

Further commits will:

1. Introduce linting to enforce methods are documented.
2. Generate previews of the new docs via GitHub actions or similar.
2020-10-14 11:44:40 +01:00
Jack Franklin
f04bec5a15
chore: update eslint & eslint plugins (#6487)
Updates ESLint, the TypeScript ESLint plugins, and updates code where
the rules have changed.
2020-10-12 10:30:35 +01:00
Jack Franklin
4846b8723c
chore(agnostification): split up launcher class (#6484)
The `Launcher` class was serving two purposes:

1. Launch browsers
2. Connect to browsers

Number 1) only needs to be done in Node land, but 2) is agnostic; in a
browser version of Puppeteer we'll need the ability to connect over a
websocket to send commands back and forth.

As part of the agnostification work we needed to split the `Launcher` up
so that the connection part can be made agnostic. Additionally, I
removed dependencies on `https`, `http` and `URL` from Node, instead
leaning on fetch (via `node-fetch` if in Node land) and the browser
`URL` API (which was added to Node in Node 10).
2020-10-12 10:08:57 +01:00
Jack Franklin
e94a1e87dc
chore: bump misc dependencies (#6488)
This commit updates some miscellaneous dependencies to their latest
versions (with no other changes required) and also removes the `browser`
section, which was used by Browserify for the now long gone
Puppeteer-Web package that we used to publish.
2020-10-08 16:02:37 +01:00
Mathias Bynens
936ccdca2c
chore: enforce Conventional Commits through commitlint (#6483)
This patch sets up commitlint to enforce the Conventional Commits format. This check runs with the other lint checks as part of npm run lint, and a Git commit hook is set up via Husky for automated local checks.

Issue: #6482
2020-10-08 12:04:15 +02:00
Johan Bay
49f25e2412
feat(chromium) roll Chromium to r809590 (#6458)
This corresponds to Chromium 87.0.4272.0
This roll includes:
- Reland "idle-detection: Implement requestPermission() method"
  (crrev.com/c/2417779)
2020-10-01 08:24:47 +02:00
Jack Franklin
caa9a1cafa
chore(agnostic): Remove use of util.promisify (#6446)
In `src/common` we now use `fs.promises.X` which we can dynamically
`import`. In a browser environment this code will never run because it's
gated on `isNode` (in a future PR we will add tree-shaking to the bundle
step such that this code is eliminated). By using `import`, we ensure
TypeScript still can track types and give good type information.

In `src/node` we continue to use `util.promisify` but that's not a
concern as that code explicitly is never run in the browser.
2020-09-28 10:35:35 +01:00
Jack Franklin
322cc96e7b
chore: remove npm run test-types call (#6447)
It was an old script that doesn't exist any more.
2020-09-25 12:44:34 +02:00
Maksim Sadym
1396c9d4cd
chore: bump version to v5.3.1-post (#6440) 2020-09-23 11:28:08 +02:00
Maksim Sadym
11ab402846
fix: add mime dependency back to fix build (#6441)
* Added back dependency `"mime": "^2.0.3",` to fix build;
* Previous builds passed because of the node package caching.
2020-09-23 09:56:40 +02:00
Maksim Sadym
c7d32cb92f
chore: mark version v5.3.1 (#6439) 2020-09-22 12:49:28 +02:00
Mathias Bynens
bb1c5215a8
chore: remove mime dependency (#6415)
Bug: #5026, #6125
2020-09-14 13:39:33 +02:00
Maksim Sadym
03e41da465
chore: bump version to v5.3.0-post (#6413) 2020-09-14 10:17:05 +02:00
Maksim Sadym
030fcaa075
chore: mark version v5.3.0 (#6412) 2020-09-11 10:43:09 +02:00
Maksim Sadym
4ce600a6f4
chore: Remove target debug-unit and add unit-debug (#6411)
* debug-unit is confusing
* unit-debug runs all tests in debug mode
2020-09-11 10:10:25 +02:00
Maksim Sadym
62ac167339
feat(chromium): roll Chromium to r800071 (#6407)
* roll Chromium to version 86, r800071
* roll Chrome DevTools protocol version to 0.0.799653
* fix HTTPRequest.continue after
  * CDP: accept post data in the binary form in Fetch.continueRequest.
    https://chromium-review.googlesource.com/c/chromium/src/+/2315239
* update new-docs
2020-09-09 21:23:46 +02:00
Jack Franklin
21552f8fe7
feat: page.waitForTimeout (#6268) 2020-07-28 10:37:49 +02:00
Lars den Bakker
15d1906e7c
feat: add web test runner (#6200) 2020-07-22 13:14:35 +02:00
Johan Bay
e3933ddd82
chore: mark 5.2.1-post (#6257) 2020-07-21 16:24:07 +01:00
Johan Bay
4ee4649de6
chore: mark v5.2.1 (#6254) 2020-07-21 14:53:02 +02:00
Johan Bay
e89e264a16
feat(chromium): roll Chromium to r782078 (#6250)
This corresponds to Chromium 85.0.4182.0.

This roll includes: 
- Enable SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure
   https://crrev.com/c/2231445
- [FlexNG] Enable FlexNG by default
   https://crrev.com/c/2216595

Closes #6151.
2020-07-20 17:17:06 +02:00
Jack Franklin
042c4a23d7
chore: mark 5.2.0-post (#6240) 2020-07-17 14:48:14 +02:00
Jack Franklin
028f144256
chore: mark v5.2.0 (#6238) 2020-07-17 13:44:29 +02:00
Jack Franklin
f1a6b8d66d
chore: vendor Mitt & update project structure (#6209)
* chore: vendor Mitt into src/common/third-party

As discussed in #6203 we need to vendor our common dependencies in so
that when we ship an ESM build all imports point to file paths and do
not rely on Node resolution (e.g. a browser does not understand `import
mitt from 'mitt'`).
2020-07-14 16:57:29 +01:00
Jack Franklin
ffec2475d0
chore: enforce file extensions on imports (#6202)
* chore: enforce file extensions on imports

To make our output agnostic it should include file extensions in the
output, as per the ESM spec. It's a bit odd for Node packages but makes
it easier to publish a browser build.
2020-07-13 10:22:26 +01:00
Changhao Han
8d6e0d8a79
chore: mark version to v5.1.0-post (#6208) 2020-07-13 10:43:46 +02:00
Changhao Han
8fa18aef99
chore: mark version v5.1.0 (#6206)
Co-authored-by: Changhao Han <changhaohan@chromium.org>
2020-07-13 10:25:14 +02:00
Changhao Han
790c277f0e
feat(chromium): roll Chromium to r768783 (#6201)
* feat(chromium): roll Chromium to r768783

* fix: update unit test for crrev:2135046

* chore: update devtools-protocol revision

Co-authored-by: Changhao Han <changhaohan@chromium.org>
2020-07-10 15:32:44 +02:00
Jack Franklin
31309b0e20
chore: use devtools-protocol package (#6172)
* chore: Use devtools-protocol package

Rather than maintain our own protocol we can instead use the devtools-protocol package and pin it to the version of Chromium that Puppeteer is shipping with.

The only changes are naming changes between the bespoke protocol that Puppeteer created and the devtools-protocol one.
2020-07-10 11:51:52 +01:00
Jack Franklin
f666be3f5f
chore: remove src/api.ts (#6191)
Now the async hooks helper is gone api.ts was only used by the coverage
tools and by doclint.

DocLint is nearing the end of its lifespan with the TSDoc work, so I
focused on how best to define a list of modules for the coverage
tooling. They define an object of classes, and the path to that module.
They need the full path because we also check if the module exports any
events that need to be emitted - the coverage tool asserts that the
emitting of those events is also tested.

It's not _great_ that DocLint relies on a constant defined in the
coverage utils, but it should only be this way for a short period of
time and no one is actively working on DocLint (bar the effort to remove
it) so I don't think this is worth worrying about.

This change also broke the DocLint tests; based on the fact that DocLint is on its way out it doesn't feel worth fixing the tests, so this commit also removes them.
2020-07-10 10:07:28 +01:00
Jack Franklin
928924ed36
chore: mark v5.0.0-post (#6144) 2020-07-02 16:13:04 +01:00
Jack Franklin
6d06adea10
chore: mark v5.0.0 (#6143) 2020-07-02 14:32:43 +01:00
Jack Franklin
221d172843
chore: add typecheck command (#6140)
If you want to run TypeScript only to verify that it's typechecking correctly, this command is quicker as it doesn't output CJS and ESM to disk. Useful for checking during development.
2020-07-02 13:04:55 +02:00
Jack Franklin
1f5e333f00
chore: Don't store revisions in package.json (#6109)
* chore: Don't store revisions in `package.json`

It's quite messy to have to require the `package.json` file in multiple
places purely to find out what revision of a given browser we want to
use. We can also achieve better type safety by placing it in an actual
source file.

This commit makes that change and also tidies up our reliance on
`package.json` within the source code generally; we now only use it to
find the location of the Puppeteer root such that we know where to
install downloaded browsers to.

To avoid using `package.json` to parse the name of the module, we also
now explicitly have an entry point for the Puppeteer module and the
Puppeter Core module. This will make it easier in the future to ship
less code as part of core (e.g. core never needs to download a browser,
so why ship that code?). Core can also then not have any revisions based
info contained in it.

The test install script has also been updated to ensure that
puppeteer-core can be installed correctly too.

Finally, the `install` script has been moved to TypeScript for nicer
typechecking and safety. The functionality of it has not changed.
2020-06-29 16:13:24 +01:00
Jack Franklin
1c0009d2c0
chore(agnostic): ship CJS and ESM builds (#6095)
* chore(agnostic): ship CJS and ESM builds

For our work to enable Puppeteer in other environments (e.g. a browser)
we need to ship an ESM build. This commit changes our config to ship to
`lib/cjs` and `lib/esm` accordingly. The majority of our code stays the
same, with one small fix for the CJS build to ensure that we ship a
version that lets you `require('puppeteer')` rather than have to
`require('puppeteer').default`. We do this with the `cjs-entry.js` which
is what the `main` field in our `package.json` points to.

We also swap to `read-pkg-up` to find the `package.json` file. This is
because the folder structure of `lib/` does not match `src/` now we ship
to `cjs` and `esm`, so you cannot rely on exact paths. This module works
up from the file to find the nearest `package.json` so it will always
find Puppeteer's `package.json`.

Note that we *do not* point any users to the ESM build. We happen to
ship those files so people who know about them can get at them but it's
not expected (nor will we actively support) that people will rely on
them. The CommonJS build is considered our main build.

We may make breaking changes to the structure of the ESM build which we
will do without requiring new major versions. For example the ESM build
currently ships all files that the CJS build does, but given we are
working on the ESM build being able to run in the browser this may
change over time.

Long term once the Node versions catch up we can ditch CJS and ship
exclusively ESM but we are not there yet.
2020-06-25 14:24:46 +01:00
Jack Franklin
70a900e93b
chore: fix ESLint violation and lessen rule strictness (#6081) 2020-06-23 12:55:42 +01:00
Jack Franklin
28797dee41
chore: migrate tests to TypeScript (#6075)
This CL migrates all the tests to TypeScript. The main benefits of this is that we start consuming our TypeScript definitions and therefore find errors in them. The act of migrating found some bugs in our definitions and now we can be sure to avoid them going forwards.

You'll notice the addition of some `TODO`s in the code; I didn't want this CL to get any bigger than it already is but I intend to follow those up once this lands. It's mostly figuring out how to extend the `expect` types with our `toBeGolden` helpers and some other slight confusions with types that the tests exposed.

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-06-23 07:18:46 +02:00
Jack Franklin
ace31d6f58
chore: pin TSDoc related dependencies (#6063)
Without the API-* dependencies pinned different versions may be
installed on local machines vs CI. One of the checks we do is to check
that the checked in docs matches what is generated on CI. Therefore we
need to ensure devs locally run the exact version that CI runs such that
they generate the same output. So in this case we pin to a particular
version of the dependencies.
2020-06-22 09:16:51 +01:00
Jack Franklin
7a4170fe6e
chore: remove top level errors and DeviceDescriptors (#6043)
As far as I can tell these became irrelevant as of v1.15 which added
`puppeteer.errors` and `puppeteer.devices [1]. This is a breaking change
but one that's easily mitigated. We've said that we don't consider
changes to our folder/file structure a breaking change, but we can't
really do that if we have these two top level files that we've
documented.

[1]: e3abb0aa32 (diff-522b24108d7446af4c59873472a90444)
2020-06-19 15:15:13 +02:00
Jack Franklin
5ff698ec98
chore: move index.js into src and TS-ify (#6049)
It was causing some infra issues when trying to migrate tests to
TypeScript (that's WIP in another branch that I'll have up soon). It's
unusual to have the entire src in TS except for the main file, which
then reaches into the compiled `lib` directory for the files it needs.

Much better is to move the entry point into TypeScript itself and update
the `main` entry in our `package.json` to point to the compiled output.

This also has the advantange of hooking up all the TS type defs that we
are shipping and will make that process easier too, along with making it
easier to port our tests to TypeScript.
2020-06-19 15:14:54 +02:00