puppeteer/tsconfig.json

18 lines
324 B
JSON
Raw Normal View History

{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
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 13:24:46 +00:00
"outDir": "./lib/cjs",
"target": "ESNext",
feat(TypeScript): move DeviceDescriptors to TS (#5595) This commit moves `src/DeviceDescriptors` to be authored in TypeScript. This file was chosen due to its simplicity so that we can focus on getting a mixed JS/TS codebase playing nicely before migrating the more complex files. The file itself was a bit odd: although the array of devices was exported via `module.exports` that was never referenced by any consumers; each device was also exported via `module.exports[name] = device` and that is how it's consumed. The Puppeteer docs suggest using it like so: ```js puppeteer.devices['iPhone 6'] ``` So instead of exporting the array and then setting a bunch of properties on that, we instead define the array and export an object of keys where each key is a device. This is a breaking change (see the footer for details). Rather than export an object I'd much rather export a Map, but that would be a larger breaking change and I'm keen to avoid those for the time being. Note that we have to use special TypeScript specific syntax for the export that enables it to work in a CommonJS codebase [1] but again I'd rather this than move to ESM at this time. TypeScript still outputs CommonJS into `lib/` as you would expect. BREAKING CHANGE: We no longer export an array of devices, so any users relying on doing: ```js puppeter.devices.forEach(...) ``` …will now see a breakage. The fix is to use `Object.{keys/entries/values}` to iterate instead. [1]: https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
2020-04-14 09:55:29 +00:00
"moduleResolution": "node",
"module": "CommonJS",
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
"include": [
"src"
]
}