diff --git a/bin/pa11y-ci.js b/bin/pa11y-ci.js index 6a08dbb..24dd8a8 100755 --- a/bin/pa11y-ci.js +++ b/bin/pa11y-ci.js @@ -126,6 +126,9 @@ function loadConfig(configPath) { if (!config) { config = loadLocalConfigWithJs(configPath); } + if (!config) { + config = loadLocalConfigWithCjs(configPath); + } if (!config) { config = loadLocalConfigWithJson(configPath); } @@ -153,8 +156,8 @@ function resolveConfigPath(configPath) { if (!path.isAbsolute(configPath)) { configPath = path.join(process.cwd(), configPath); } - if (/\.js(on)?$/.test(configPath)) { - configPath = configPath.replace(/\.js(on)?$/, ''); + if (/\.(c?js|json)$/.test(configPath)) { + configPath = configPath.replace(/\.(c?js|json)$/, ''); } return configPath; } @@ -182,6 +185,17 @@ function loadLocalConfigWithJs(configPath) { } } +// Load the config file but adding a .cjs extension +function loadLocalConfigWithCjs(configPath) { + try { + return require(`${configPath}.cjs`); + } catch (error) { + if (error.code !== 'MODULE_NOT_FOUND') { + throw error; + } + } +} + // Load the config file but adding a .json extension function loadLocalConfigWithJson(configPath) { try {