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] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
|
---|
10 |
|
---|
11 | A dictionary of file extensions and associated module loaders.
|
---|
12 |
|
---|
13 | ## What is it
|
---|
14 |
|
---|
15 | This is used by [Liftoff] to automatically require dependencies for configuration files, and by [rechoir] for registering module loaders.
|
---|
16 |
|
---|
17 | ## How to use it
|
---|
18 |
|
---|
19 | 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:
|
---|
20 |
|
---|
21 | 1. If the value is null, do nothing.
|
---|
22 | 2. If the value is a string, try to require it.
|
---|
23 | 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. **Advanced:** An optional second argument can be provided to replace the default configuration for a hook.
|
---|
24 | 4. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.
|
---|
25 |
|
---|
26 | ## API
|
---|
27 |
|
---|
28 | This module provides two top-level properties: `extensions` and `jsVariants`.
|
---|
29 |
|
---|
30 | **Note:** This module does not depend on any of the loaders it recommends; instead, end-users are expected to install the hooks they want to use for the file types they want to use. See supported extensions and their hooks in the sections below.
|
---|
31 |
|
---|
32 | ### `extensions`
|
---|
33 |
|
---|
34 | A mapping of file extensions to modules which provide a [require.extensions] loader.
|
---|
35 |
|
---|
36 | File extension keys are all in the format of `'.foo'` or `'.foo.bar'` and module loader values are either `null` if the loader should fallthrough to node's loader,
|
---|
37 | or a string representing the module to be required, an object of `{ module: 'foobar', register: function }`, or an array containing those strings and/or objects.
|
---|
38 |
|
---|
39 | A sample of an entry containing multiple hooks would look like:
|
---|
40 |
|
---|
41 | ```js
|
---|
42 | {
|
---|
43 | '.ts': [
|
---|
44 | 'ts-node/register',
|
---|
45 | 'sucrase/register/ts',
|
---|
46 | {
|
---|
47 | module: '@babel/register',
|
---|
48 | register: function(hook) {
|
---|
49 | hook({
|
---|
50 | extensions: '.ts',
|
---|
51 | rootMode: 'upward-optional',
|
---|
52 | ignore: [ignoreNonBabelAndNodeModules],
|
---|
53 | });
|
---|
54 | },
|
---|
55 | },
|
---|
56 | ],
|
---|
57 | }
|
---|
58 | ```
|
---|
59 |
|
---|
60 | **Supported extensions and their hooks**
|
---|
61 |
|
---|
62 | ```yaml file=scripts/extensions.yaml
|
---|
63 | .babel.js:
|
---|
64 | - '@babel/register'
|
---|
65 | .babel.jsx:
|
---|
66 | - '@babel/register'
|
---|
67 | .babel.ts:
|
---|
68 | - '@babel/register'
|
---|
69 | .babel.tsx:
|
---|
70 | - '@babel/register'
|
---|
71 | .cjs:
|
---|
72 | - interpret/cjs-stub
|
---|
73 | .coffee:
|
---|
74 | - coffeescript/register
|
---|
75 | .coffee.md:
|
---|
76 | - coffeescript/register
|
---|
77 | .cts:
|
---|
78 | - ts-node/register
|
---|
79 | .esbuild.js:
|
---|
80 | - esbuild-register/dist/node
|
---|
81 | .esbuild.jsx:
|
---|
82 | - esbuild-register/dist/node
|
---|
83 | .esbuild.ts:
|
---|
84 | - esbuild-register/dist/node
|
---|
85 | .esbuild.tsx:
|
---|
86 | - esbuild-register/dist/node
|
---|
87 | .esm.js:
|
---|
88 | - esm
|
---|
89 | .js:
|
---|
90 | - built-in node.js loader
|
---|
91 | .json:
|
---|
92 | - built-in node.js loader
|
---|
93 | .json5:
|
---|
94 | - json5/lib/register
|
---|
95 | .jsx:
|
---|
96 | - '@babel/register'
|
---|
97 | - sucrase/register/jsx
|
---|
98 | .litcoffee:
|
---|
99 | - coffeescript/register
|
---|
100 | .mdx:
|
---|
101 | - '@mdx-js/register'
|
---|
102 | .mjs:
|
---|
103 | - interpret/mjs-stub
|
---|
104 | .node:
|
---|
105 | - built-in node.js loader
|
---|
106 | .sucrase.js:
|
---|
107 | - sucrase/dist/register
|
---|
108 | .sucrase.jsx:
|
---|
109 | - sucrase/dist/register
|
---|
110 | .sucrase.ts:
|
---|
111 | - sucrase/dist/register
|
---|
112 | .sucrase.tsx:
|
---|
113 | - sucrase/dist/register
|
---|
114 | .swc.js:
|
---|
115 | - '@swc/register'
|
---|
116 | .swc.jsx:
|
---|
117 | - '@swc/register'
|
---|
118 | .swc.ts:
|
---|
119 | - '@swc/register'
|
---|
120 | .swc.tsx:
|
---|
121 | - '@swc/register'
|
---|
122 | .toml:
|
---|
123 | - toml-require
|
---|
124 | .ts:
|
---|
125 | - ts-node/register
|
---|
126 | - sucrase/register/ts
|
---|
127 | - '@babel/register'
|
---|
128 | - esbuild-register/dist/node
|
---|
129 | - '@swc/register'
|
---|
130 | .tsx:
|
---|
131 | - ts-node/register
|
---|
132 | - sucrase/register/tsx
|
---|
133 | - '@babel/register'
|
---|
134 | - esbuild-register/dist/node
|
---|
135 | - '@swc/register'
|
---|
136 | .yaml:
|
---|
137 | - yaml-hook/register
|
---|
138 | .yml:
|
---|
139 | - yaml-hook/register
|
---|
140 | ```
|
---|
141 |
|
---|
142 | ### `jsVariants`
|
---|
143 |
|
---|
144 | The `jsVariants` is the same mapping as above, but only include the extensions which are variants of JavaScript.
|
---|
145 |
|
---|
146 | **Supported extensions and their hooks**
|
---|
147 |
|
---|
148 | ```yaml file=scripts/jsVariants.yaml
|
---|
149 | .babel.js:
|
---|
150 | - '@babel/register'
|
---|
151 | .babel.jsx:
|
---|
152 | - '@babel/register'
|
---|
153 | .babel.ts:
|
---|
154 | - '@babel/register'
|
---|
155 | .babel.tsx:
|
---|
156 | - '@babel/register'
|
---|
157 | .cjs:
|
---|
158 | - interpret/cjs-stub
|
---|
159 | .coffee:
|
---|
160 | - coffeescript/register
|
---|
161 | .coffee.md:
|
---|
162 | - coffeescript/register
|
---|
163 | .esbuild.js:
|
---|
164 | - esbuild-register/dist/node
|
---|
165 | .esbuild.jsx:
|
---|
166 | - esbuild-register/dist/node
|
---|
167 | .esbuild.ts:
|
---|
168 | - esbuild-register/dist/node
|
---|
169 | .esbuild.tsx:
|
---|
170 | - esbuild-register/dist/node
|
---|
171 | .esm.js:
|
---|
172 | - esm
|
---|
173 | .js:
|
---|
174 | - built-in node.js loader
|
---|
175 | .jsx:
|
---|
176 | - '@babel/register'
|
---|
177 | - sucrase/register/jsx
|
---|
178 | .litcoffee:
|
---|
179 | - coffeescript/register
|
---|
180 | .mdx:
|
---|
181 | - '@mdx-js/register'
|
---|
182 | .mjs:
|
---|
183 | - interpret/mjs-stub
|
---|
184 | .sucrase.js:
|
---|
185 | - sucrase/dist/register
|
---|
186 | .sucrase.jsx:
|
---|
187 | - sucrase/dist/register
|
---|
188 | .sucrase.ts:
|
---|
189 | - sucrase/dist/register
|
---|
190 | .sucrase.tsx:
|
---|
191 | - sucrase/dist/register
|
---|
192 | .swc.js:
|
---|
193 | - '@swc/register'
|
---|
194 | .swc.jsx:
|
---|
195 | - '@swc/register'
|
---|
196 | .swc.ts:
|
---|
197 | - '@swc/register'
|
---|
198 | .swc.tsx:
|
---|
199 | - '@swc/register'
|
---|
200 | .ts:
|
---|
201 | - ts-node/register
|
---|
202 | - sucrase/register/ts
|
---|
203 | - '@babel/register'
|
---|
204 | - esbuild-register/dist/node
|
---|
205 | - '@swc/register'
|
---|
206 | .tsx:
|
---|
207 | - ts-node/register
|
---|
208 | - sucrase/register/tsx
|
---|
209 | - '@babel/register'
|
---|
210 | - esbuild-register/dist/node
|
---|
211 | - '@swc/register'
|
---|
212 | ```
|
---|
213 |
|
---|
214 | ## License
|
---|
215 |
|
---|
216 | MIT
|
---|
217 |
|
---|
218 | <!-- prettier-ignore-start -->
|
---|
219 |
|
---|
220 | [downloads-image]: https://img.shields.io/npm/dm/interpret.svg?style=flat-square
|
---|
221 |
|
---|
222 | [npm-url]: https://www.npmjs.com/package/interpret
|
---|
223 |
|
---|
224 | [npm-image]: https://img.shields.io/npm/v/interpret.svg?style=flat-square
|
---|
225 |
|
---|
226 | [ci-url]: https://github.com/gulpjs/interpret/actions?query=workflow:dev
|
---|
227 |
|
---|
228 | [ci-image]: https://img.shields.io/github/workflow/status/gulpjs/interpret/dev?style=flat-square
|
---|
229 |
|
---|
230 | [coveralls-url]: https://coveralls.io/r/gulpjs/interpret
|
---|
231 |
|
---|
232 | [coveralls-image]: https://img.shields.io/coveralls/gulpjs/interpret/master.svg?style=flat-square
|
---|
233 |
|
---|
234 | <!-- prettier-ignore-end -->
|
---|
235 |
|
---|
236 | <!-- prettier-ignore-start -->
|
---|
237 |
|
---|
238 | [Liftoff]: http://github.com/gulpjs/liftoff
|
---|
239 |
|
---|
240 | [rechoir]: http://github.com/gulpjs/rechoir
|
---|
241 |
|
---|
242 | [require.extensions]: https://nodejs.org/api/modules.html#requireextensions
|
---|
243 |
|
---|
244 | <!-- prettier-ignore-end -->
|
---|