Commit Graph

314 Commits

Author SHA1 Message Date
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
Jack Franklin
940a5701ec
chore: exclude api.ts from dependency graph (#6052)
`api.ts` is a list of all our modules which is used to install a helper
and by DocLint. It's not that useful for our dep graph because it
literally requires the majority of modules so it just clutters up the diagram.
2020-06-19 13:44:49 +01:00
Jack Franklin
759b28080a
chore: upgrade to Mocha v8 (#5997)
* chore: upgrade to Mocha v8

Mocha v8 has some nice improvements and also unlocks the potential
to have parallel test runs which may speed up CI.
2020-06-18 16:26:30 +01:00
Jack Franklin
f6af7b8df0
chore: fix dependency chart generation (#6039)
`--max-depth` stopped the chart including our own modules. What we want
instead is the `do-not-follow` option to make it go to infinite depth in
our code but stop at the top level of a node module.
2020-06-18 14:31:05 +01:00
Jack Franklin
64c9c709c3
chore: add dependency chart generation as script (#6034) 2020-06-17 15:29:39 +02:00
Mathias Bynens
56742ebe8c
chore: bump version to v4.0.0-post (#6024) 2020-06-16 08:52:56 +02:00
Jack Franklin
2ffe710177
chore: mark version 4.0.0 (#6018) 2020-06-15 14:48:37 +01:00
Jack Franklin
b659969a38
chore: migrate away from Node's EventEmitter (#5979) 2020-06-15 11:52:19 +01:00
Tim van der Lippe
c701ea194a
chore: fix npm test command (#6010)
The `test` command referenced the task `npm run coverage`, which was renamed to `unit-with-coverage` in #5779.
2020-06-15 07:54:58 +02:00
Jack Franklin
91eb74519c
chore: ensure new-docs are up to date (#5994)
* chore: ensure new-docs are up to date

This adds a Travis check that if we re-generate the docs we get the
exact output (by checking if the Git tree is dirty).

We do the dirty check by using `git status --porcelain`, seeing how many
lines that outputs, and using that as the exit code (taking only the
first 255 lines to avoid invalid exit codes). `--porcelain` makes the
output be empty if the repo is not dirty in anyway which translates into
an exit code of 0.

We can't use `git diff-index --quiet HEAD` as it exits with 0 if there are
untracked files in the repo but we want that to cause a failure.
2020-06-11 09:48:37 +01:00
Jack Franklin
83c29d942b
chore: clean lib when running tsc (#5982)
I've had misleading type errors due to left over builds or tests
behaving oddly. We should just strip the entire folder out before
building again so there's no left over artefacts that could cause
issues.

The `|| true` in the command is so if `rm` errors because the folder
doesn't exist, it doesn't exit with an error code.
2020-06-09 12:10:19 +01:00
Jack Franklin
00324204ff
chore: Introduce API Extractor and start generating documentation (#5967) 2020-06-04 11:47:13 +01:00
Jack Franklin
58d1eab794
chore: mark version v3.3.0-post (#5960) 2020-06-02 15:20:20 +02:00
Jack Franklin
e84e579c3c
chore: mark version v3.3.0 (#5959) 2020-06-02 09:53:53 +01:00
Jack Franklin
309d8115c3
chore: Revert Mitt due to breaking changes (#5952)
Replacing the Node EventEmitter with Mitt caused more problems than
anticipated for end users due to the API differences and the amount of
people who relied on the EventEmitter API. In hindsight this clearly
should have been explored more and then released as a breaking v4.

This commit rolls us back to the built in Node EventEmitter library
which we can release to get everyone back on stable builds. We can then
consider our approach to migrating to Mitt and when we do do that we can
release it as a breaking change and properly document the migration
strategy and approach.
2020-06-02 09:32:02 +01:00
Jack Franklin
cfd72acc57
chore: bump version to v3.2.0-post (#5938) 2020-05-29 11:27:54 +02:00
Jack Franklin
88b5265be1
chore: mark version v3.2.0 (#5937) 2020-05-29 10:22:13 +01:00
Jack Franklin
1d4d25a0f3
Use Mitt as the Event Emitter (#5907)
* chore: migrate to Mitt as the EventEmitter

This commit moves us to using Mitt [1] for the event emitter in
Puppeteer. This removes our dependency to Node's EventEmitter which is
part of a larger stream of work to enable a Puppeteer-web version that
doesn't depend on Node.

There are no large breaking changes as we support the main methods that
EventEmitter had, but it also provides some methods that Puppeteer
didn't use. Technically end users could depend on this but it's
unlikely.

[1]: https://github.com/developit/mitt
2020-05-29 09:59:26 +01:00
Jack Franklin
9737059400
chore: remove doclint generate_types code (#5932)
This script generated an `index.d.ts` file but that file was never
commited to git nor included in Puppeteer when we ship. As of right now
people who want TS types can install from the DefinitelyTyped repo and
we are working on shipping types from Puppeteer itself.

Therefore this script is not adding any value and can be removed.
2020-05-28 15:55:14 +01:00
Alex Rudenko
e6c22dae05
chore: bump version to v3.1.0-post (#5884)
Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
2020-05-18 14:16:25 +02:00
Alex Rudenko
8ba36752e7
chore: mark version v3.1.0 (#5883)
* chore: mark version v3.1.0

Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
2020-05-18 13:47:03 +02:00
Alex Rudenko
e8232890a4
feat(chromium): roll Chromium to r756035 (#5879)
This corresponds to Chromium 83.0.4103.0.

This roll includes:

- Enable SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure https://crrev.com/c/2122809
2020-05-18 11:06:42 +02:00
Jack Franklin
9368edbac9
chore: upgrade TypeScript to 3.9 (#5860)
Sticking to a specific version of TS rather than a ^ version so we know
everyone is on the exact same version. Think that's preferable for such
an important dependency.
2020-05-13 10:50:51 +01:00
Jack Franklin
b38bb4334f
Warn when given unsupported product name. (#5845)
* Warn when given unsupported product name.

Fixes #5844.

This change means when a user launches Puppeteer with a product name
that is not supported (which at the time of this commit means it's not
`firefox` or `chrome) we will warn them about it.

Decided on just a warning vs an error because the current behaviour is
that we fallback to launching Chrome and I don't think this warrants a
breaking change.
2020-05-12 10:30:24 +01:00
Jack Franklin
6099272612
chore: add @types/proxy-from-env (#5831) 2020-05-07 17:26:26 +01:00
Jack Franklin
510354054f
chore: add command to run eslint with --fix flag (#5829) 2020-05-07 15:54:33 +02:00
Jack Franklin
4fdb1e3cab
chore: add Prettier (#5825) 2020-05-07 12:54:55 +02:00
Jack Franklin
ae576aff61
chore: mark v3.0.4-post (#5824) 2020-05-07 12:04:22 +02:00
Jack Franklin
c214d20d54
chore: mark version v3.0.4 (#5823) 2020-05-07 11:52:59 +02:00
Mathias Bynens
17bb660dd5
chore: remove unused mime-types dependency (#5819) 2020-05-07 11:28:46 +02:00
Jack Franklin
51154824d8
chore: bump version to 3.0.3-post (#5814) 2020-05-06 17:27:31 +02:00
Jack Franklin
dd5bdf1616
chore: mark version v3.0.3 (#5813) 2020-05-06 15:57:04 +01:00
Jack Franklin
ae7483d5cf
chore: remove src/externs.d.ts (#5811)
* chore: remove src/externs.d.ts

It defined global types that we don't want to use, and instead we move
to using interfaces that we import and reference just like with any
other interface.

This means other than Protocol (which I think is fine to leave as is),
there are no other magic global types and you have to import any types
or interfaces that you want.
2020-05-06 14:23:07 +01:00
Jack Franklin
5518bac291
chore: update how we track coverage during unit tests (#5779)
* chore: update how we track coverage during unit tests

The old method of tracking coverage was causing issues. If a test failed
on CI, that test's failure would be lost because the test failing would
in turn cause the coverage to fail, but the `process.exit(1)` in the
coverage code caused Mocha to not output anything useful.

Instead the coverage checker now:

* tracks the coverage in memory in a Map (this hasn't changed)
* after all tests, writes that to disk in test/coverage.json (which is
gitignored)
* we then run a single Mocha test that asserts every method was called.

This means if the test run fails, the build will fail and give the error
about that test run, and that output won't be lost when the coverage
then fails too.

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-30 13:00:41 +01:00
Jack Franklin
1ccfbcb684
chore: enforce naming of errors in catch blocks (#5763) 2020-04-28 15:16:28 +02:00
Jack Franklin
3bf9bd199d
chore: enforce src/protocol.d.ts is in sync (#5762)
* chore: enforce src/protocol.d.ts is in sync

On CI we run `npm run compare-protocol-d-ts` which checks that the file
on disk is up to date with the protocol we fetch from the browser.


Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-28 13:58:42 +01:00
Jack Franklin
8ddf4f3114
chore: bump version to 3.0.2-post (#5759) 2020-04-28 11:10:39 +01:00
Jack Franklin
646f42e98c
chore: mark version v3.0.2 (#5752) 2020-04-28 10:23:19 +01:00
Jack Franklin
3ed2f6b0ac
chore: remove puppeteer-web (#5750)
We don't support it and v3 shipped without including puppeteer-web in the browser. People are welcome to manually use Browserify to try to get Puppeteer running in a browser but it ultimately isn't our primary focus right now.

Getting puppeteer-core able to run in a browser is something we'll be looking at in the future so we'll revisit this soon.
2020-04-27 11:25:21 +02:00
Mathieu 'p01' Henri
0731049f86
chore: update pngjs to 5.0.0 and jpeg-js to 0.3.7 (#5676) 2020-04-23 11:38:00 +02:00
Jack Franklin
9d297f0827
chore: Bump version to 3.0.1-post (#5717) 2020-04-22 16:07:57 +01:00
Jack Franklin
feec588f95
chore: add test for npm package installing correctly (#5714)
* chore: add test for npm package installing correctly

This command packs up the module and installs it again to check we're
correctly bundling everything we need to allow users to do a fresh
install.

* install realpath
2020-04-22 15:33:36 +01:00
Jack Franklin
1615c9c9d5
chore: add install.js to files for publishing (#5712) 2020-04-22 12:16:51 +01:00
Jack Franklin
6029fdd618
chore: mark version v3.0.1 (#5709) 2020-04-22 11:10:04 +01:00