• Stars
    star
    259
  • Rank 157,669 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A dictionary of file extensions and associated module loaders.

interpret

NPM version Downloads Build Status Coveralls Status

A dictionary of file extensions and associated module loaders.

What is it

This is used by Liftoff to automatically require dependencies for configuration files, and by rechoir for registering module loaders.

How to use it

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:

  1. If the value is null, do nothing.
  2. If the value is a string, try to require it.
  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.
  4. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.

API

This module provides two top-level properties: extensions and jsVariants.

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.

extensions

A mapping of file extensions to modules which provide a require.extensions loader.

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, 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.

A sample of an entry containing multiple hooks would look like:

{
  '.ts': [
    'ts-node/register',
    'sucrase/register/ts',
    {
      module: '@babel/register',
      register: function(hook) {
        hook({
          extensions: '.ts',
          rootMode: 'upward-optional',
          ignore: [ignoreNonBabelAndNodeModules],
        });
      },
    },
  ],
}

Supported extensions and their hooks

.babel.js:
  - '@babel/register'
.babel.jsx:
  - '@babel/register'
.babel.ts:
  - '@babel/register'
.babel.tsx:
  - '@babel/register'
.cjs:
  - interpret/cjs-stub
.coffee:
  - coffeescript/register
.coffee.md:
  - coffeescript/register
.cts:
  - ts-node/register
.esbuild.js:
  - esbuild-register/dist/node
.esbuild.jsx:
  - esbuild-register/dist/node
.esbuild.ts:
  - esbuild-register/dist/node
.esbuild.tsx:
  - esbuild-register/dist/node
.esm.js:
  - esm
.js:
  - built-in node.js loader
.json:
  - built-in node.js loader
.json5:
  - json5/lib/register
.jsx:
  - '@babel/register'
  - sucrase/register/jsx
.litcoffee:
  - coffeescript/register
.mdx:
  - '@mdx-js/register'
.mjs:
  - interpret/mjs-stub
.node:
  - built-in node.js loader
.sucrase.js:
  - sucrase/dist/register
.sucrase.jsx:
  - sucrase/dist/register
.sucrase.ts:
  - sucrase/dist/register
.sucrase.tsx:
  - sucrase/dist/register
.swc.js:
  - '@swc/register'
.swc.jsx:
  - '@swc/register'
.swc.ts:
  - '@swc/register'
.swc.tsx:
  - '@swc/register'
.toml:
  - toml-require
.ts:
  - ts-node/register
  - sucrase/register/ts
  - '@babel/register'
  - esbuild-register/dist/node
  - '@swc/register'
.tsx:
  - ts-node/register
  - sucrase/register/tsx
  - '@babel/register'
  - esbuild-register/dist/node
  - '@swc/register'
.yaml:
  - yaml-hook/register
.yml:
  - yaml-hook/register

jsVariants

The jsVariants is the same mapping as above, but only include the extensions which are variants of JavaScript.

Supported extensions and their hooks

.babel.js:
  - '@babel/register'
.babel.jsx:
  - '@babel/register'
.babel.ts:
  - '@babel/register'
.babel.tsx:
  - '@babel/register'
.cjs:
  - interpret/cjs-stub
.coffee:
  - coffeescript/register
.coffee.md:
  - coffeescript/register
.esbuild.js:
  - esbuild-register/dist/node
.esbuild.jsx:
  - esbuild-register/dist/node
.esbuild.ts:
  - esbuild-register/dist/node
.esbuild.tsx:
  - esbuild-register/dist/node
.esm.js:
  - esm
.js:
  - built-in node.js loader
.jsx:
  - '@babel/register'
  - sucrase/register/jsx
.litcoffee:
  - coffeescript/register
.mdx:
  - '@mdx-js/register'
.mjs:
  - interpret/mjs-stub
.sucrase.js:
  - sucrase/dist/register
.sucrase.jsx:
  - sucrase/dist/register
.sucrase.ts:
  - sucrase/dist/register
.sucrase.tsx:
  - sucrase/dist/register
.swc.js:
  - '@swc/register'
.swc.jsx:
  - '@swc/register'
.swc.ts:
  - '@swc/register'
.swc.tsx:
  - '@swc/register'
.ts:
  - ts-node/register
  - sucrase/register/ts
  - '@babel/register'
  - esbuild-register/dist/node
  - '@swc/register'
.tsx:
  - ts-node/register
  - sucrase/register/tsx
  - '@babel/register'
  - esbuild-register/dist/node
  - '@swc/register'

License

MIT

More Repositories

1

gulp

A toolkit to automate & enhance your workflow
JavaScript
32,962
star
2

vinyl

Virtual file format.
JavaScript
1,272
star
3

vinyl-fs

Vinyl adapter for the file system.
JavaScript
966
star
4

liftoff

Launch your command line tool with ease.
JavaScript
840
star
5

gulp-util

[deprecated] - See https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
JavaScript
829
star
6

gulp-cli

Command Line Interface for gulp.
JavaScript
397
star
7

plugins

[Unused] Very old plugin search website
JavaScript
280
star
8

undertaker

Task registry that allows composition through series/parallel methods.
JavaScript
198
star
9

glob-stream

Readable streamx interface over anymatch.
JavaScript
178
star
10

bach

Compose your async functions with elegance.
JavaScript
133
star
11

fancy-log

Log things, prefixed with a timestamp.
JavaScript
120
star
12

findup-sync

Find the first file matching a given pattern in the current directory or the nearest ancestor directory.
JavaScript
98
star
13

glob-watcher

Watch globs and execute a function upon change, with intelligent defaults for debouncing and queueing.
JavaScript
80
star
14

glob-parent

Extract the non-magic parent path from a glob string.
JavaScript
79
star
15

async-done

Allows libraries to handle various caller provided asynchronous functions uniformly. Maps promises, observables, child processes and streams, and callbacks to callback style.
JavaScript
69
star
16

gulplog

Logger for gulp and gulp plugins.
JavaScript
56
star
17

v8flags

Get available v8 and Node.js flags.
JavaScript
56
star
18

rechoir

Prepare a node environment to require files with different extensions.
JavaScript
48
star
19

replace-ext

Replaces a file extension with another one.
JavaScript
46
star
20

gulpjs.github.io

The gulp website
JavaScript
45
star
21

ordered-read-streams

Combines array of streams into one Readable stream in strict order.
JavaScript
28
star
22

now-and-later

Map over an array or object of values in parallel or series, passing each through the async iterator, with optional lifecycle hooks.
JavaScript
24
star
23

hacker

Hack on your project easily. A liftoff proof-of-concept.
JavaScript
24
star
24

flagged-respawn

A tool for respawning node binaries when special flags are present.
JavaScript
21
star
25

artwork

Artwork for the gulp project
21
star
26

empty-dir

Check if a directory is empty.
JavaScript
20
star
27

sparkles

Namespaced global event emitter.
JavaScript
20
star
28

acceptance

Acceptance test suite for plugins
19
star
29

undertaker-forward-reference

Undertaker custom registry supporting forward referenced tasks.
JavaScript
19
star
30

plugin-error

Error handling for vinyl plugins. Just an abstraction of what's in gulp-util with minor reformatting.
JavaScript
19
star
31

glogg

Global logging utility.
JavaScript
18
star
32

lead

Sink your streams.
JavaScript
17
star
33

undertaker-registry

Default registry in gulp 4.
JavaScript
17
star
34

vinyl-sourcemap

Add/write sourcemaps to/from Vinyl files.
JavaScript
15
star
35

last-run

Capture and retrieve the last time a function was run
JavaScript
14
star
36

path-dirname

Node.js path.dirname() ponyfill
JavaScript
13
star
37

fined

Find a file given a declaration of locations.
JavaScript
12
star
38

async-settle

Settle an async function. It will always complete successfully with an object of the resulting state.
JavaScript
11
star
39

value-or-function

Normalize a value or function, applying extra args to the function
JavaScript
11
star
40

copy-props

Copy properties deeply between two objects
JavaScript
10
star
41

to-through

Wrap a Readable stream in a Transform stream.
JavaScript
10
star
42

semver-greatest-satisfied-range

Find the greatest satisfied semver range from an array of ranges.
JavaScript
9
star
43

mute-stdout

Mute and unmute stdout
JavaScript
9
star
44

resolve-options

Resolve an options object based on configuration.
JavaScript
9
star
45

has-gulplog

Check if gulplog is available before attempting to use it
JavaScript
9
star
46

clone-buffer

Easier Buffer cloning in node.
JavaScript
9
star
47

eslint-config-gulp

Sharable eslint config for gulp projects
JavaScript
8
star
48

async-once

Guarantee a node-style async function is only executed once.
JavaScript
8
star
49

fs-mkdirp-stream

Ensure directories exist before writing to them.
JavaScript
8
star
50

undertaker-common-tasks

Proof-of-concept custom registry that pre-defines tasks.
JavaScript
7
star
51

remove-bom-stream

Remove a UTF8 BOM at the start of the stream.
JavaScript
7
star
52

registry

[Unused] NPM on ElasticSearch
JavaScript
5
star
53

better-stats

A replacement for node's fs.Stats with more utility
JavaScript
5
star
54

theming-log

Creates a logger with theme for text decoration.
JavaScript
4
star
55

undertaker-task-metadata

Proof-of-concept custom registry that attaches metadata to each task.
JavaScript
4
star
56

replace-homedir

Replace user home in a string with another string. Useful for tildifying a path.
JavaScript
4
star
57

evented-require

Require modules and receive events.
JavaScript
3
star
58

each-props

Process object properties deeply.
JavaScript
3
star
59

vinyl-contents

Utility to read the contents of a vinyl file.
JavaScript
3
star
60

.boilerplate

The boilerplate template for gulp packages.
3
star
61

update-template

Updates a gulpjs repository to match our current scaffold.
JavaScript
3
star
62

vinyl-prepare

[deprecated] This module's API was never satisfactory and isn't used in gulp - please don't use.
JavaScript
3
star
63

parse-node-version

Turn node's process.version into something useful.
JavaScript
2
star
64

default-resolution

Get the default resolution time based on the current node version, optionally overridable
JavaScript
2
star
65

.github

GitHub template files for the gulpjs organization.
2
star
66

jscs-preset-gulp

Sharable jscs config for gulp projects
2
star
67

conventional-changelog-gulp

conventional-changelog gulp preset
JavaScript
1
star
68

emit-mapper

Re-emit events while mapping them to new names.
JavaScript
1
star