UNPKG

5.79 kBMarkdownView Raw
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
7# interpret
8
9[![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]
10
11A dictionary of file extensions and associated module loaders.
12
13## What is it
14This 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.
15
16## API
17
18### extensions
19Map file types to modules which provide a [require.extensions] loader.
20
21```js
22{
23 '.babel.js': [
24 {
25 module: '@babel/register',
26 register: function(hook) {
27 // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
28 // which only captures the final extension (.babel.js -> .js)
29 hook({ extensions: '.js' });
30 },
31 },
32 {
33 module: 'babel-register',
34 register: function(hook) {
35 hook({ extensions: '.js' });
36 },
37 },
38 {
39 module: 'babel-core/register',
40 register: function(hook) {
41 hook({ extensions: '.js' });
42 },
43 },
44 {
45 module: 'babel/register',
46 register: function(hook) {
47 hook({ extensions: '.js' });
48 },
49 },
50 ],
51 '.babel.ts': [
52 {
53 module: '@babel/register',
54 register: function(hook) {
55 hook({ extensions: '.ts' });
56 },
57 },
58 ],
59 '.buble.js': 'buble/register',
60 '.cirru': 'cirru-script/lib/register',
61 '.cjsx': 'node-cjsx/register',
62 '.co': 'coco',
63 '.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
64 '.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
65 '.csv': 'require-csv',
66 '.eg': 'earlgrey/register',
67 '.esm.js': {
68 module: 'esm',
69 register: function(hook) {
70 // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
71 // which only captures the final extension (.babel.js -> .js)
72 var esmLoader = hook(module);
73 require.extensions['.js'] = esmLoader('module')._extensions['.js'];
74 },
75 },
76 '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
77 '.iced.md': 'iced-coffee-script/register',
78 '.ini': 'require-ini',
79 '.js': null,
80 '.json': null,
81 '.json5': 'json5/lib/require',
82 '.jsx': [
83 {
84 module: '@babel/register',
85 register: function(hook) {
86 hook({ extensions: '.jsx' });
87 },
88 },
89 {
90 module: 'babel-register',
91 register: function(hook) {
92 hook({ extensions: '.jsx' });
93 },
94 },
95 {
96 module: 'babel-core/register',
97 register: function(hook) {
98 hook({ extensions: '.jsx' });
99 },
100 },
101 {
102 module: 'babel/register',
103 register: function(hook) {
104 hook({ extensions: '.jsx' });
105 },
106 },
107 {
108 module: 'node-jsx',
109 register: function(hook) {
110 hook.install({ extension: '.jsx', harmony: true });
111 },
112 },
113 ],
114 '.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
115 '.liticed': 'iced-coffee-script/register',
116 '.ls': ['livescript', 'LiveScript'],
117 '.mjs': '/absolute/path/to/interpret/mjs-stub.js',
118 '.node': null,
119 '.toml': {
120 module: 'toml-require',
121 register: function(hook) {
122 hook.install();
123 },
124 },
125 '.ts': [
126 'ts-node/register',
127 'typescript-node/register',
128 'typescript-register',
129 'typescript-require',
130 'sucrase/register/ts',
131 {
132 module: '@babel/register',
133 register: function(hook) {
134 hook({ extensions: '.ts' });
135 },
136 },
137 ],
138 '.tsx': [
139 'ts-node/register',
140 'typescript-node/register',
141 'sucrase/register',
142 {
143 module: '@babel/register',
144 register: function(hook) {
145 hook({ extensions: '.tsx' });
146 },
147 },
148 ],
149 '.wisp': 'wisp/engine/node',
150 '.xml': 'require-xml',
151 '.yaml': 'require-yaml',
152 '.yml': 'require-yaml',
153}
154```
155
156### jsVariants
157Same as above, but only include the extensions which are javascript variants.
158
159## How to use it
160
161Consumers 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:
162
1631. If the value is null, do nothing.
164
1652. If the value is a string, try to require it.
166
1673. 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.
168
1694. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
170
171[require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions
172
173[downloads-image]: http://img.shields.io/npm/dm/interpret.svg
174[npm-url]: https://www.npmjs.com/package/interpret
175[npm-image]: http://img.shields.io/npm/v/interpret.svg
176
177[travis-url]: https://travis-ci.org/gulpjs/interpret
178[travis-image]: http://img.shields.io/travis/gulpjs/interpret.svg?label=travis-ci
179
180[appveyor-url]: https://ci.appveyor.com/project/gulpjs/interpret
181[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/interpret.svg?label=appveyor
182
183[coveralls-url]: https://coveralls.io/r/gulpjs/interpret
184[coveralls-image]: http://img.shields.io/coveralls/gulpjs/interpret/master.svg
185
186[gitter-url]: https://gitter.im/gulpjs/gulp
187[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg