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

Add support for .cjs extension #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions bin/pa11y-ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ function loadConfig(configPath) {
if (!config) {
config = loadLocalConfigWithJs(configPath);
}
if (!config) {
config = loadLocalConfigWithCjs(configPath);
}
if (!config) {
config = loadLocalConfigWithJson(configPath);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down