UNPKG

7.12 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## interpret for enterprise
17
18Available as part of the Tidelift Subscription
19
20The maintainers of interpret and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-interpret?utm_source=npm-interpret&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
21
22## API
23
24### extensions
25Map file types to modules which provide a [require.extensions] loader.
26
27```js
28{
29 '.babel.js': [
30 {
31 module: '@babel/register',
32 register: function(hook) {
33 hook({
34 extensions: '.js',
35 rootMode: 'upward-optional',
36 ignore: [ignoreNonBabelAndNodeModules],
37 });
38 },
39 },
40 {
41 module: 'babel-register',
42 register: function(hook) {
43 hook({
44 extensions: '.js',
45 ignore: ignoreNonBabelAndNodeModules,
46 });
47 },
48 },
49 {
50 module: 'babel-core/register',
51 register: function(hook) {
52 hook({
53 extensions: '.js',
54 ignore: ignoreNonBabelAndNodeModules,
55 });
56 },
57 },
58 {
59 module: 'babel/register',
60 register: function(hook) {
61 hook({
62 extensions: '.js',
63 ignore: ignoreNonBabelAndNodeModules,
64 });
65 },
66 },
67 ],
68 '.babel.ts': [
69 {
70 module: '@babel/register',
71 register: function(hook) {
72 hook({
73 extensions: '.ts',
74 rootMode: 'upward-optional',
75 ignore: [ignoreNonBabelAndNodeModules],
76 });
77 },
78 },
79 ],
80 '.buble.js': 'buble/register',
81 '.cirru': 'cirru-script/lib/register',
82 '.cjsx': 'node-cjsx/register',
83 '.co': 'coco',
84 '.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
85 '.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
86 '.csv': 'require-csv',
87 '.eg': 'earlgrey/register',
88 '.esm.js': {
89 module: 'esm',
90 register: function(hook) {
91 // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
92 // which only captures the final extension (.babel.js -> .js)
93 var esmLoader = hook(module);
94 require.extensions['.js'] = esmLoader('module')._extensions['.js'];
95 },
96 },
97 '.iced': ['iced-coffee-script/register', 'iced-coffee-script'],
98 '.iced.md': 'iced-coffee-script/register',
99 '.ini': 'require-ini',
100 '.js': null,
101 '.json': null,
102 '.json5': ['json5/lib/register', 'json5/lib/require'],
103 '.jsx': [
104 {
105 module: '@babel/register',
106 register: function(hook) {
107 hook({
108 extensions: '.jsx',
109 rootMode: 'upward-optional',
110 ignore: [ignoreNonBabelAndNodeModules],
111 });
112 },
113 },
114 {
115 module: 'babel-register',
116 register: function(hook) {
117 hook({
118 extensions: '.jsx',
119 ignore: ignoreNonBabelAndNodeModules,
120 });
121 },
122 },
123 {
124 module: 'babel-core/register',
125 register: function(hook) {
126 hook({
127 extensions: '.jsx',
128 ignore: ignoreNonBabelAndNodeModules,
129 });
130 },
131 },
132 {
133 module: 'babel/register',
134 register: function(hook) {
135 hook({
136 extensions: '.jsx',
137 ignore: ignoreNonBabelAndNodeModules,
138 });
139 },
140 },
141 {
142 module: 'node-jsx',
143 register: function(hook) {
144 hook.install({ extension: '.jsx', harmony: true });
145 },
146 },
147 ],
148 '.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'],
149 '.liticed': 'iced-coffee-script/register',
150 '.ls': ['livescript', 'LiveScript'],
151 '.mjs': '/absolute/path/to/interpret/mjs-stub.js',
152 '.node': null,
153 '.toml': {
154 module: 'toml-require',
155 register: function(hook) {
156 hook.install();
157 },
158 },
159 '.ts': [
160 'ts-node/register',
161 'typescript-node/register',
162 'typescript-register',
163 'typescript-require',
164 'sucrase/register/ts',
165 {
166 module: '@babel/register',
167 register: function(hook) {
168 hook({
169 extensions: '.ts',
170 rootMode: 'upward-optional',
171 ignore: [ignoreNonBabelAndNodeModules],
172 });
173 },
174 },
175 ],
176 '.tsx': [
177 'ts-node/register',
178 'typescript-node/register',
179 'sucrase/register',
180 {
181 module: '@babel/register',
182 register: function(hook) {
183 hook({
184 extensions: '.tsx',
185 rootMode: 'upward-optional',
186 ignore: [ignoreNonBabelAndNodeModules],
187 });
188 },
189 },
190 ],
191 '.wisp': 'wisp/engine/node',
192 '.xml': 'require-xml',
193 '.yaml': 'require-yaml',
194 '.yml': 'require-yaml',
195}
196```
197
198### jsVariants
199Same as above, but only include the extensions which are javascript variants.
200
201## How to use it
202
203Consumers 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:
204
2051. If the value is null, do nothing.
206
2072. If the value is a string, try to require it.
208
2093. 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.
210
2114. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
212
213[require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions
214
215[downloads-image]: http://img.shields.io/npm/dm/interpret.svg
216[npm-url]: https://www.npmjs.com/package/interpret
217[npm-image]: http://img.shields.io/npm/v/interpret.svg
218
219[travis-url]: https://travis-ci.org/gulpjs/interpret
220[travis-image]: http://img.shields.io/travis/gulpjs/interpret.svg?label=travis-ci
221
222[appveyor-url]: https://ci.appveyor.com/project/gulpjs/interpret
223[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/interpret.svg?label=appveyor
224
225[coveralls-url]: https://coveralls.io/r/gulpjs/interpret
226[coveralls-image]: http://img.shields.io/coveralls/gulpjs/interpret/master.svg
227
228[gitter-url]: https://gitter.im/gulpjs/gulp
229[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg