Skip to content

Commit

Permalink
fix(typescript): ship .d.ts file in npm package (#6811)
Browse files Browse the repository at this point in the history
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 #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.
  • Loading branch information
jackfranklin committed Feb 4, 2021
1 parent 9abd459 commit a7e3c2e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -41,7 +41,8 @@
"install.js",
"typescript-if-required.js",
"cjs-entry.js",
"cjs-entry-core.js"
"cjs-entry-core.js",
"cjs-entry.d.ts"
],
"author": "The Chromium Authors",
"license": "Apache-2.0",
Expand Down

0 comments on commit a7e3c2e

Please sign in to comment.