1 | var path = require('path');
|
2 |
|
3 | var endsInBabelJs = /\.babel\.[jt]s(x)$/;
|
4 |
|
5 | var mjsStub = path.join(__dirname, 'mjs-stub');
|
6 |
|
7 | function ignoreNonBabelAndNodeModules(file) {
|
8 | return !endsInBabelJs.test(file) &&
|
9 | path.relative(process.cwd(), file).split(path.sep).indexOf('node_modules') >= 0;
|
10 | }
|
11 |
|
12 | var extensions = {
|
13 | '.babel.js': [
|
14 | {
|
15 | module: '@babel/register',
|
16 | register: function(hook) {
|
17 | hook({
|
18 | extensions: '.js',
|
19 | rootMode: 'upward-optional',
|
20 | ignore: [ignoreNonBabelAndNodeModules],
|
21 | });
|
22 | },
|
23 | },
|
24 | {
|
25 | module: 'babel-register',
|
26 | register: function(hook) {
|
27 | hook({
|
28 | extensions: '.js',
|
29 | ignore: ignoreNonBabelAndNodeModules,
|
30 | });
|
31 | },
|
32 | },
|
33 | {
|
34 | module: 'babel-core/register',
|
35 | register: function(hook) {
|
36 | hook({
|
37 | extensions: '.js',
|
38 | ignore: ignoreNonBabelAndNodeModules,
|
39 | });
|
40 | },
|
41 | },
|
42 | {
|
43 | module: 'babel/register',
|
44 | register: function(hook) {
|
45 | hook({
|
46 | extensions: '.js',
|
47 | ignore: ignoreNonBabelAndNodeModules,
|
48 | });
|
49 | },
|
50 | },
|
51 | ],
|
52 | '.babel.ts': [
|
53 | {
|
54 | module: '@babel/register',
|
55 | register: function(hook) {
|
56 | hook({
|
57 | extensions: '.ts',
|
58 | rootMode: 'upward-optional',
|
59 | ignore: [ignoreNonBabelAndNodeModules],
|
60 | });
|
61 | },
|
62 | },
|
63 | ],
|
64 | '.buble.js': 'buble/register',
|
65 | '.cirru': 'cirru-script/lib/register',
|
66 | '.cjsx': 'node-cjsx/register',
|
67 | '.co': 'coco',
|
68 | '.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
|
69 | '.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
|
70 | '.csv': 'require-csv',
|
71 | '.eg': 'earlgrey/register',
|
72 | '.esm.js': {
|
73 | module: 'esm',
|
74 | register: function(hook) {
|
75 |
|
76 |
|
77 | var esmLoader = hook(module);
|
78 | require.extensions['.js'] = esmLoader('module')._extensions['.js'];
|
79 | },
|
80 | },
|
81 | '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
|
82 | '.iced.md': 'iced-coffee-script/register',
|
83 | '.ini': 'require-ini',
|
84 | '.js': null,
|
85 | '.json': null,
|
86 | '.json5': ['json5/lib/register', 'json5/lib/require'],
|
87 | '.jsx': [
|
88 | {
|
89 | module: '@babel/register',
|
90 | register: function(hook) {
|
91 | hook({
|
92 | extensions: '.jsx',
|
93 | rootMode: 'upward-optional',
|
94 | ignore: [ignoreNonBabelAndNodeModules],
|
95 | });
|
96 | },
|
97 | },
|
98 | {
|
99 | module: 'babel-register',
|
100 | register: function(hook) {
|
101 | hook({
|
102 | extensions: '.jsx',
|
103 | ignore: ignoreNonBabelAndNodeModules,
|
104 | });
|
105 | },
|
106 | },
|
107 | {
|
108 | module: 'babel-core/register',
|
109 | register: function(hook) {
|
110 | hook({
|
111 | extensions: '.jsx',
|
112 | ignore: ignoreNonBabelAndNodeModules,
|
113 | });
|
114 | },
|
115 | },
|
116 | {
|
117 | module: 'babel/register',
|
118 | register: function(hook) {
|
119 | hook({
|
120 | extensions: '.jsx',
|
121 | ignore: ignoreNonBabelAndNodeModules,
|
122 | });
|
123 | },
|
124 | },
|
125 | {
|
126 | module: 'node-jsx',
|
127 | register: function(hook) {
|
128 | hook.install({ extension: '.jsx', harmony: true });
|
129 | },
|
130 | },
|
131 | ],
|
132 | '.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
|
133 | '.liticed': 'iced-coffee-script/register',
|
134 | '.ls': ['livescript', 'LiveScript'],
|
135 | '.mjs': mjsStub,
|
136 | '.node': null,
|
137 | '.toml': {
|
138 | module: 'toml-require',
|
139 | register: function(hook) {
|
140 | hook.install();
|
141 | },
|
142 | },
|
143 | '.ts': [
|
144 | 'ts-node/register',
|
145 | 'typescript-node/register',
|
146 | 'typescript-register',
|
147 | 'typescript-require',
|
148 | 'sucrase/register/ts',
|
149 | {
|
150 | module: '@babel/register',
|
151 | register: function(hook) {
|
152 | hook({
|
153 | extensions: '.ts',
|
154 | rootMode: 'upward-optional',
|
155 | ignore: [ignoreNonBabelAndNodeModules],
|
156 | });
|
157 | },
|
158 | },
|
159 | ],
|
160 | '.tsx': [
|
161 | 'ts-node/register',
|
162 | 'typescript-node/register',
|
163 | 'sucrase/register',
|
164 | {
|
165 | module: '@babel/register',
|
166 | register: function(hook) {
|
167 | hook({
|
168 | extensions: '.tsx',
|
169 | rootMode: 'upward-optional',
|
170 | ignore: [ignoreNonBabelAndNodeModules],
|
171 | });
|
172 | },
|
173 | },
|
174 | ],
|
175 | '.wisp': 'wisp/engine/node',
|
176 | '.xml': 'require-xml',
|
177 | '.yaml': 'require-yaml',
|
178 | '.yml': 'require-yaml',
|
179 | };
|
180 |
|
181 | var jsVariantExtensions = [
|
182 | '.js',
|
183 | '.babel.js',
|
184 | '.babel.ts',
|
185 | '.buble.js',
|
186 | '.cirru',
|
187 | '.cjsx',
|
188 | '.co',
|
189 | '.coffee',
|
190 | '.coffee.md',
|
191 | '.eg',
|
192 | '.esm.js',
|
193 | '.iced',
|
194 | '.iced.md',
|
195 | '.jsx',
|
196 | '.litcoffee',
|
197 | '.liticed',
|
198 | '.ls',
|
199 | '.mjs',
|
200 | '.ts',
|
201 | '.tsx',
|
202 | '.wisp',
|
203 | ];
|
204 |
|
205 | module.exports = {
|
206 | extensions: extensions,
|
207 | jsVariants: jsVariantExtensions.reduce(function(result, ext) {
|
208 | result[ext] = extensions[ext];
|
209 | return result;
|
210 | }, {}),
|
211 | };
|