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