Permalink
Cannot retrieve contributors at this time
46 lines (37 sloc)
1.08 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/ava/lib/extensions.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function resolveExtensions(configuredExtensions, providers = []) { | |
// Combine all extensions possible for testing. Remove duplicate extensions. | |
const duplicates = new Set(); | |
const seen = new Set(); | |
const normalize = extensions => Array.isArray(extensions) ? extensions : Object.keys(extensions); | |
const combine = extensions => { | |
for (const ext of normalize(extensions)) { | |
if (seen.has(ext)) { | |
duplicates.add(ext); | |
} else { | |
seen.add(ext); | |
} | |
} | |
}; | |
if (configuredExtensions !== undefined) { | |
combine(configuredExtensions); | |
} | |
for (const {main} of providers) { | |
combine(main.extensions); | |
} | |
if (duplicates.size > 0) { | |
throw new Error(`Unexpected duplicate extensions in options: ’${[...duplicates].join('’, ’')}’.`); | |
} | |
// Unless the default was used by providers, as long as the extensions aren't explicitly set, set the default. | |
if (configuredExtensions === undefined) { | |
if (!seen.has('cjs')) { | |
seen.add('cjs'); | |
} | |
if (!seen.has('mjs')) { | |
seen.add('mjs'); | |
} | |
if (!seen.has('js')) { | |
seen.add('js'); | |
} | |
} | |
return [...seen]; | |
} |