fix: deprecate configuration via package.json (#12176)

This commit is contained in:
Alex Rudenko 2024-04-02 10:35:18 +02:00 committed by GitHub
parent 308bc8d05a
commit c96c7623bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View File

@ -36,9 +36,6 @@ Puppeteer will look up the file tree for any of the following formats:
- `puppeteer.config.js`, and - `puppeteer.config.js`, and
- `puppeteer.config.cjs` - `puppeteer.config.cjs`
Puppeteer will also read a `puppeteer` key from your application's
`package.json`.
See the [`Configuration`](../api/puppeteer.configuration) interface for possible See the [`Configuration`](../api/puppeteer.configuration) interface for possible
options. options.
@ -49,6 +46,13 @@ After adding a configuration file, you may need to remove and reinstall
::: :::
:::caution
Previous versions of Puppeteer allowed configuration via the `config` key in
`package.json`. This behavior is now deprecated and will be removed in the future.
:::
### Examples ### Examples
#### Changing the default cache directory #### Changing the default cache directory

View File

@ -127,6 +127,17 @@ export const getConfiguration = (): Configuration => {
downloadHost; downloadHost;
} }
if (
Object.keys(process.env).some(key => {
return key.startsWith('npm_package_config_puppeteer_');
}) &&
configuration.logLevel === 'warn'
) {
console.warn(
`Configuring Puppeteer via npm/package.json is deprecated. Use https://pptr.dev/guides/configuration instead.`
);
}
configuration.cacheDirectory = configuration.cacheDirectory =
process.env['PUPPETEER_CACHE_DIR'] ?? process.env['PUPPETEER_CACHE_DIR'] ??
process.env['npm_config_puppeteer_cache_dir'] ?? process.env['npm_config_puppeteer_cache_dir'] ??