index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. var path = require('path');
  2. var mjsStub = path.join(__dirname, 'mjs-stub');
  3. var extensions = {
  4. '.babel.js': [
  5. {
  6. module: '@babel/register',
  7. register: function(hook) {
  8. // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
  9. // which only captures the final extension (.babel.js -> .js)
  10. hook({ extensions: '.js' });
  11. },
  12. },
  13. {
  14. module: 'babel-register',
  15. register: function(hook) {
  16. hook({ extensions: '.js' });
  17. },
  18. },
  19. {
  20. module: 'babel-core/register',
  21. register: function(hook) {
  22. hook({ extensions: '.js' });
  23. },
  24. },
  25. {
  26. module: 'babel/register',
  27. register: function(hook) {
  28. hook({ extensions: '.js' });
  29. },
  30. },
  31. ],
  32. '.babel.ts': [
  33. {
  34. module: '@babel/register',
  35. register: function(hook) {
  36. hook({ extensions: '.ts' });
  37. },
  38. },
  39. ],
  40. '.buble.js': 'buble/register',
  41. '.cirru': 'cirru-script/lib/register',
  42. '.cjsx': 'node-cjsx/register',
  43. '.co': 'coco',
  44. '.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  45. '.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  46. '.csv': 'require-csv',
  47. '.eg': 'earlgrey/register',
  48. '.esm.js': {
  49. module: 'esm',
  50. register: function(hook) {
  51. // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
  52. // which only captures the final extension (.babel.js -> .js)
  53. var esmLoader = hook(module);
  54. require.extensions['.js'] = esmLoader('module')._extensions['.js'];
  55. },
  56. },
  57. '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
  58. '.iced.md': 'iced-coffee-script/register',
  59. '.ini': 'require-ini',
  60. '.js': null,
  61. '.json': null,
  62. '.json5': 'json5/lib/require',
  63. '.jsx': [
  64. {
  65. module: '@babel/register',
  66. register: function(hook) {
  67. hook({ extensions: '.jsx' });
  68. },
  69. },
  70. {
  71. module: 'babel-register',
  72. register: function(hook) {
  73. hook({ extensions: '.jsx' });
  74. },
  75. },
  76. {
  77. module: 'babel-core/register',
  78. register: function(hook) {
  79. hook({ extensions: '.jsx' });
  80. },
  81. },
  82. {
  83. module: 'babel/register',
  84. register: function(hook) {
  85. hook({ extensions: '.jsx' });
  86. },
  87. },
  88. {
  89. module: 'node-jsx',
  90. register: function(hook) {
  91. hook.install({ extension: '.jsx', harmony: true });
  92. },
  93. },
  94. ],
  95. '.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  96. '.liticed': 'iced-coffee-script/register',
  97. '.ls': ['livescript', 'LiveScript'],
  98. '.mjs': mjsStub,
  99. '.node': null,
  100. '.toml': {
  101. module: 'toml-require',
  102. register: function(hook) {
  103. hook.install();
  104. },
  105. },
  106. '.ts': [
  107. 'ts-node/register',
  108. 'typescript-node/register',
  109. 'typescript-register',
  110. 'typescript-require',
  111. 'sucrase/register/ts',
  112. {
  113. module: '@babel/register',
  114. register: function(hook) {
  115. hook({ extensions: '.ts' });
  116. },
  117. },
  118. ],
  119. '.tsx': [
  120. 'ts-node/register',
  121. 'typescript-node/register',
  122. 'sucrase/register',
  123. {
  124. module: '@babel/register',
  125. register: function(hook) {
  126. hook({ extensions: '.tsx' });
  127. },
  128. },
  129. ],
  130. '.wisp': 'wisp/engine/node',
  131. '.xml': 'require-xml',
  132. '.yaml': 'require-yaml',
  133. '.yml': 'require-yaml',
  134. };
  135. var jsVariantExtensions = [
  136. '.js',
  137. '.babel.js',
  138. '.babel.ts',
  139. '.buble.js',
  140. '.cirru',
  141. '.cjsx',
  142. '.co',
  143. '.coffee',
  144. '.coffee.md',
  145. '.eg',
  146. '.esm.js',
  147. '.iced',
  148. '.iced.md',
  149. '.jsx',
  150. '.litcoffee',
  151. '.liticed',
  152. '.ls',
  153. '.mjs',
  154. '.ts',
  155. '.tsx',
  156. '.wisp',
  157. ];
  158. module.exports = {
  159. extensions: extensions,
  160. jsVariants: jsVariantExtensions.reduce(function(result, ext) {
  161. result[ext] = extensions[ext];
  162. return result;
  163. }, {}),
  164. };