Skip to content

Commit

Permalink
feat(config): add .cjs file extension config support (#26075)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
jamiehaywood and viceice committed Dec 1, 2023
1 parent 181c52f commit 178cc71
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/development/configuration.md
Expand Up @@ -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`.
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.
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
@@ -0,0 +1,3 @@
module.exports = {
token: 'abcdefg',
};
1 change: 1 addition & 0 deletions lib/workers/global/config/parse/file.spec.ts
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
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

0 comments on commit 178cc71

Please sign in to comment.