feat(config): add .cjs file extension config support (#26075)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
Jamie Haywood 2023-12-01 13:07:10 +00:00 committed by GitHub
parent 181c52f1d7
commit 178cc71838
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 0 deletions

View file

@ -24,6 +24,9 @@ If you need an alternate location or name, set it in the environment variable `R
For example `RENOVATE_CONFIG_FILE=myconfig.js` or `RENOVATE_CONFIG_FILE=myconfig.json` and not `RENOVATE_CONFIG_FILE=myconfig`. For example `RENOVATE_CONFIG_FILE=myconfig.js` or `RENOVATE_CONFIG_FILE=myconfig.json` and not `RENOVATE_CONFIG_FILE=myconfig`.
If none is provided, or the file type is invalid, Renovate will fail. If none is provided, or the file type is invalid, Renovate will fail.
If you are in an ESM repo (`"type": "module"` in `package.json`) then you must use a `.cjs` extension and set `RENOVATE_CONFIG_FILE`.
For example `RENOVATE_CONFIG_FILE=myconfig.cjs`.
Using a configuration file gives you very granular configuration options. Using a configuration file gives you very granular configuration options.
For instance, you can override most settings at the global (file), repository, or package level. For instance, you can override most settings at the global (file), repository, or package level.
e.g. apply one set of labels for `backend/package.json` and a different set of labels for `frontend/package.json` in the same repository. e.g. apply one set of labels for `backend/package.json` and a different set of labels for `frontend/package.json` in the same repository.

View file

@ -0,0 +1,3 @@
module.exports = {
token: 'abcdefg',
};

View file

@ -24,6 +24,7 @@ describe('workers/global/config/parse/file', () => {
describe('.getConfig()', () => { describe('.getConfig()', () => {
it.each([ it.each([
['custom js config file', 'config.js'], ['custom js config file', 'config.js'],
['custom js config file', 'config.cjs'],
['custom js config file exporting a Promise', 'config-promise.js'], ['custom js config file exporting a Promise', 'config-promise.js'],
['custom js config file exporting a function', 'config-function.js'], ['custom js config file exporting a function', 'config-function.js'],
// The next two are different syntactic ways of expressing the same thing // The next two are different syntactic ways of expressing the same thing

View file

@ -25,6 +25,7 @@ export async function getParsedContent(file: string): Promise<RenovateConfig> {
await readSystemFile(file, 'utf8'), await readSystemFile(file, 'utf8'),
file, file,
) as RenovateConfig; ) as RenovateConfig;
case '.cjs':
case '.js': { case '.js': {
const tmpConfig = await import(file); const tmpConfig = await import(file);
let config = tmpConfig.default let config = tmpConfig.default