Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
Dec 1, 2023
2 changes: 2 additions & 0 deletions docs/development/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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`.
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`.
rarkins marked this conversation as resolved.
Show resolved Hide resolved

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.
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.
Expand Down
3 changes: 3 additions & 0 deletions lib/workers/global/config/parse/__fixtures__/config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
token: 'abcdefg',
};
1 change: 1 addition & 0 deletions lib/workers/global/config/parse/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('workers/global/config/parse/file', () => {
describe('.getConfig()', () => {
it.each([
['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 function', 'config-function.js'],
// The next two are different syntactic ways of expressing the same thing
Expand Down
1 change: 1 addition & 0 deletions lib/workers/global/config/parse/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export async function getParsedContent(file: string): Promise<RenovateConfig> {
await readSystemFile(file, 'utf8'),
file,
) as RenovateConfig;
case '.cjs':
case '.js': {
const tmpConfig = await import(file);
let config = tmpConfig.default
Expand Down