1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getExtensions = void 0;
|
4 | const util_1 = require("./util");
|
5 | const nodeEquivalents = new Map([
|
6 | ['.ts', '.js'],
|
7 | ['.tsx', '.js'],
|
8 | ['.jsx', '.js'],
|
9 | ['.mts', '.mjs'],
|
10 | ['.cts', '.cjs'],
|
11 | ]);
|
12 | const tsResolverEquivalents = new Map([
|
13 | ['.ts', ['.js']],
|
14 | ['.tsx', ['.js', '.jsx']],
|
15 | ['.mts', ['.mjs']],
|
16 | ['.cts', ['.cjs']],
|
17 | ]);
|
18 |
|
19 | const vanillaNodeExtensions = [
|
20 | '.js',
|
21 | '.json',
|
22 | '.node',
|
23 | '.mjs',
|
24 | '.cjs',
|
25 | ];
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | const nodeDoesNotUnderstand = [
|
33 | '.ts',
|
34 | '.tsx',
|
35 | '.jsx',
|
36 | '.cts',
|
37 | '.mts',
|
38 | ];
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | function getExtensions(config, options, tsVersion) {
|
44 |
|
45 | const tsSupportsMtsCtsExts = (0, util_1.versionGteLt)(tsVersion, '4.5.0');
|
46 | const requiresHigherTypescriptVersion = [];
|
47 | if (!tsSupportsMtsCtsExts)
|
48 | requiresHigherTypescriptVersion.push('.cts', '.cjs', '.mts', '.mjs');
|
49 | const allPossibleExtensionsSortedByPreference = Array.from(new Set([
|
50 | ...(options.preferTsExts ? nodeDoesNotUnderstand : []),
|
51 | ...vanillaNodeExtensions,
|
52 | ...nodeDoesNotUnderstand,
|
53 | ]));
|
54 | const compiledJsUnsorted = ['.ts'];
|
55 | const compiledJsxUnsorted = [];
|
56 | if (config.options.jsx)
|
57 | compiledJsxUnsorted.push('.tsx');
|
58 | if (tsSupportsMtsCtsExts)
|
59 | compiledJsUnsorted.push('.mts', '.cts');
|
60 | if (config.options.allowJs) {
|
61 | compiledJsUnsorted.push('.js');
|
62 | if (config.options.jsx)
|
63 | compiledJsxUnsorted.push('.jsx');
|
64 | if (tsSupportsMtsCtsExts)
|
65 | compiledJsUnsorted.push('.mjs', '.cjs');
|
66 | }
|
67 | const compiledUnsorted = [...compiledJsUnsorted, ...compiledJsxUnsorted];
|
68 | const compiled = allPossibleExtensionsSortedByPreference.filter((ext) => compiledUnsorted.includes(ext));
|
69 | const compiledNodeDoesNotUnderstand = nodeDoesNotUnderstand.filter((ext) => compiled.includes(ext));
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | const r = allPossibleExtensionsSortedByPreference.filter((ext) => [...compiledUnsorted, '.js', '.mjs', '.cjs', '.mts', '.cts'].includes(ext));
|
78 | const replacementsForJs = r.filter((ext) => ['.js', '.jsx', '.ts', '.tsx'].includes(ext));
|
79 | const replacementsForJsx = r.filter((ext) => ['.jsx', '.tsx'].includes(ext));
|
80 | const replacementsForMjs = r.filter((ext) => ['.mjs', '.mts'].includes(ext));
|
81 | const replacementsForCjs = r.filter((ext) => ['.cjs', '.cts'].includes(ext));
|
82 | const replacementsForJsOrMjs = r.filter((ext) => ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.mts'].includes(ext));
|
83 |
|
84 |
|
85 | const experimentalSpecifierResolutionAddsIfOmitted = Array.from(new Set([...replacementsForJsOrMjs, '.json', '.node']));
|
86 |
|
87 | const legacyMainResolveAddsIfOmitted = Array.from(new Set([...replacementsForJs, '.json', '.node']));
|
88 | return {
|
89 |
|
90 | compiled,
|
91 |
|
92 | nodeDoesNotUnderstand,
|
93 |
|
94 | compiledNodeDoesNotUnderstand,
|
95 | |
96 |
|
97 |
|
98 |
|
99 | nodeEquivalents,
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | tsResolverEquivalents,
|
113 | |
114 |
|
115 |
|
116 |
|
117 | requiresHigherTypescriptVersion,
|
118 | |
119 |
|
120 |
|
121 | experimentalSpecifierResolutionAddsIfOmitted,
|
122 | |
123 |
|
124 |
|
125 | legacyMainResolveAddsIfOmitted,
|
126 | replacementsForMjs,
|
127 | replacementsForCjs,
|
128 | replacementsForJsx,
|
129 | replacementsForJs,
|
130 | };
|
131 | }
|
132 | exports.getExtensions = getExtensions;
|
133 |
|
\ | No newline at end of file |