1 | module.exports = (configuredExtensions, providers = []) => {
|
2 |
|
3 | const duplicates = new Set();
|
4 | const seen = new Set();
|
5 |
|
6 | const normalize = extensions => Array.isArray(extensions) ? extensions : Object.keys(extensions);
|
7 |
|
8 | const combine = extensions => {
|
9 | for (const ext of normalize(extensions)) {
|
10 | if (seen.has(ext)) {
|
11 | duplicates.add(ext);
|
12 | } else {
|
13 | seen.add(ext);
|
14 | }
|
15 | }
|
16 | };
|
17 |
|
18 | if (configuredExtensions !== undefined) {
|
19 | combine(configuredExtensions);
|
20 | }
|
21 |
|
22 | for (const {main} of providers) {
|
23 | combine(main.extensions);
|
24 | }
|
25 |
|
26 | if (duplicates.size > 0) {
|
27 | throw new Error(`Unexpected duplicate extensions in options: ’${[...duplicates].join('’, ’')}’.`);
|
28 | }
|
29 |
|
30 |
|
31 | if (configuredExtensions === undefined) {
|
32 | if (!seen.has('cjs')) {
|
33 | seen.add('cjs');
|
34 | }
|
35 |
|
36 | if (!seen.has('mjs')) {
|
37 | seen.add('mjs');
|
38 | }
|
39 |
|
40 | if (!seen.has('js')) {
|
41 | seen.add('js');
|
42 | }
|
43 | }
|
44 |
|
45 | return [...seen];
|
46 | };
|