You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
5.5 KiB

4 years ago
  1. <p align="center">
  2. <a href="http://gulpjs.com">
  3. <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
  4. </a>
  5. </p>
  6. # interpret
  7. [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]
  8. A dictionary of file extensions and associated module loaders.
  9. ## What is it
  10. This is used by [Liftoff](http://github.com/tkellen/node-liftoff) to automatically require dependencies for configuration files, and by [rechoir](http://github.com/tkellen/node-rechoir) for registering module loaders.
  11. ## API
  12. ### extensions
  13. Map file types to modules which provide a [require.extensions] loader.
  14. ```js
  15. {
  16. '.babel.js': [
  17. {
  18. module: '@babel/register',
  19. register: function(hook) {
  20. // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
  21. // which only captures the final extension (.babel.js -> .js)
  22. hook({ extensions: '.js' });
  23. },
  24. },
  25. {
  26. module: 'babel-register',
  27. register: function(hook) {
  28. hook({ extensions: '.js' });
  29. },
  30. },
  31. {
  32. module: 'babel-core/register',
  33. register: function(hook) {
  34. hook({ extensions: '.js' });
  35. },
  36. },
  37. {
  38. module: 'babel/register',
  39. register: function(hook) {
  40. hook({ extensions: '.js' });
  41. },
  42. },
  43. ],
  44. '.babel.ts': [
  45. {
  46. module: '@babel/register',
  47. register: function(hook) {
  48. hook({ extensions: '.ts' });
  49. },
  50. },
  51. ],
  52. '.buble.js': 'buble/register',
  53. '.cirru': 'cirru-script/lib/register',
  54. '.cjsx': 'node-cjsx/register',
  55. '.co': 'coco',
  56. '.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  57. '.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  58. '.csv': 'require-csv',
  59. '.eg': 'earlgrey/register',
  60. '.esm.js': {
  61. module: 'esm',
  62. register: function(hook) {
  63. // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
  64. // which only captures the final extension (.babel.js -> .js)
  65. var esmLoader = hook(module);
  66. require.extensions['.js'] = esmLoader('module')._extensions['.js'];
  67. },
  68. },
  69. '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
  70. '.iced.md': 'iced-coffee-script/register',
  71. '.ini': 'require-ini',
  72. '.js': null,
  73. '.json': null,
  74. '.json5': 'json5/lib/require',
  75. '.jsx': [
  76. {
  77. module: '@babel/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: 'babel-core/register',
  90. register: function(hook) {
  91. hook({ extensions: '.jsx' });
  92. },
  93. },
  94. {
  95. module: 'babel/register',
  96. register: function(hook) {
  97. hook({ extensions: '.jsx' });
  98. },
  99. },
  100. {
  101. module: 'node-jsx',
  102. register: function(hook) {
  103. hook.install({ extension: '.jsx', harmony: true });
  104. },
  105. },
  106. ],
  107. '.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
  108. '.liticed': 'iced-coffee-script/register',
  109. '.ls': ['livescript', 'LiveScript'],
  110. '.node': null,
  111. '.toml': {
  112. module: 'toml-require',
  113. register: function(hook) {
  114. hook.install();
  115. },
  116. },
  117. '.ts': [
  118. 'ts-node/register',
  119. 'typescript-node/register',
  120. 'typescript-register',
  121. 'typescript-require',
  122. {
  123. module: '@babel/register',
  124. register: function(hook) {
  125. hook({ extensions: '.ts' });
  126. },
  127. },
  128. ],
  129. '.tsx': [
  130. 'ts-node/register',
  131. 'typescript-node/register',
  132. {
  133. module: '@babel/register',
  134. register: function(hook) {
  135. hook({ extensions: '.tsx' });
  136. },
  137. },
  138. ],
  139. '.wisp': 'wisp/engine/node',
  140. '.xml': 'require-xml',
  141. '.yaml': 'require-yaml',
  142. '.yml': 'require-yaml',
  143. }
  144. ```
  145. ### jsVariants
  146. Same as above, but only include the extensions which are javascript variants.
  147. ## How to use it
  148. Consumers should use the exported `extensions` or `jsVariants` object to determine which module should be loaded for a given extension. If a matching extension is found, consumers should do the following:
  149. 1. If the value is null, do nothing.
  150. 2. If the value is a string, try to require it.
  151. 3. If the value is an object, try to require the `module` property. If successful, the `register` property (a function) should be called with the module passed as the first argument.
  152. 4. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
  153. [require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions
  154. [downloads-image]: http://img.shields.io/npm/dm/interpret.svg
  155. [npm-url]: https://www.npmjs.com/package/interpret
  156. [npm-image]: http://img.shields.io/npm/v/interpret.svg
  157. [travis-url]: https://travis-ci.org/gulpjs/interpret
  158. [travis-image]: http://img.shields.io/travis/gulpjs/interpret.svg?label=travis-ci
  159. [appveyor-url]: https://ci.appveyor.com/project/gulpjs/interpret
  160. [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/interpret.svg?label=appveyor
  161. [coveralls-url]: https://coveralls.io/r/gulpjs/interpret
  162. [coveralls-image]: http://img.shields.io/coveralls/gulpjs/interpret/master.svg
  163. [gitter-url]: https://gitter.im/gulpjs/gulp
  164. [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg