mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
f1a6b8d66d
* 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'`). |
||
---|---|---|
.. | ||
mitt | ||
README.md | ||
tsconfig.cjs.json | ||
tsconfig.esm.json |
Vendoring third party dependencies
Because we are working towards an agnostic Puppeteer that can run in any environment (see #6125) we cannot import common dependencies in a way that relies on Node's resolution to find them. For example, import mitt from 'mitt'
works fine in Node, but in an ESM build running in the browser, the browser has no idea where to find 'mitt'
.
Therefore we put all common dependencies into this directory, vendor
. This means there are extra criteria for these dependencies; ideally they will not depend on any other modules. If they do, we should consider an alternative way of managing our dependencies.
The process for updating a vendored dependency is:
npm install {DEP NAME HERE}
cp -r node_modules/DEP vendor/DEP
- Update
eslintrc.js
to forbid importing DEP directly (see theMitt
rule already defined in there). - Use the new DEP, and run
npm run tsc
to check everything compiles successfully. - If the dep ships as compiled JS, you may need to disable TypeScript checking the file. Add an entry to the
excludes
property of the TSConfig files invendor
. (again, see the entry that's already there for Mitt as an example). Don't forget to update both the ESM and CJS config files.