Git Product home page Git Product logo

interpret's Introduction

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.

API

extensions

Map file types to modules which provide a require.extensions loader.

{
  '.babel.js': {
    module: '@babel/register',
    register: function(hook) {
      hook({
        extensions: '.js',
        rootMode: 'upward-optional',
        ignore: [ignoreNonBabelAndNodeModules],
      });
    },
  },
  '.babel.ts': [
    {
      module: '@babel/register',
      register: function(hook) {
        hook({
          extensions: '.ts',
          rootMode: 'upward-optional',
          ignore: [ignoreNonBabelAndNodeModules],
        });
      },
    },
  ],
  '.coffee': 'coffeescript/register',
  '.coffee.md': 'coffeescript/register',
  '.esm.js': {
    module: 'esm',
    register: function(hook) {
      // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353
      // which only captures the final extension (.babel.js -> .js)
      var esmLoader = hook(module);
      require.extensions['.js'] = esmLoader('module')._extensions['.js'];
    },
  },
  '.js': null,
  '.json': null,
  '.json5': 'json5/lib/register',
  '.jsx': {
    module: '@babel/register',
    register: function(hook) {
      hook({
        extensions: '.jsx',
        rootMode: 'upward-optional',
        ignore: [ignoreNonBabelAndNodeModules],
      });
    },
  },
  '.litcoffee': 'coffeescript/register',
  '.mjs': '/absolute/path/to/interpret/mjs-stub.js',
  '.node': null,
  '.toml': {
    module: 'toml-require',
    register: function(hook) {
      hook.install();
    },
  },
  '.ts': [
    'ts-node/register',
    'sucrase/register/ts',
    {
      module: '@babel/register',
      register: function(hook) {
        hook({
          extensions: '.ts',
          rootMode: 'upward-optional',
          ignore: [ignoreNonBabelAndNodeModules],
        });
      },
    },
  ],
  '.tsx': [
    'ts-node/register',
    'sucrase/register',
    {
      module: '@babel/register',
      register: function(hook) {
        hook({
          extensions: '.tsx',
          rootMode: 'upward-optional',
          ignore: [ignoreNonBabelAndNodeModules],
        });
      },
    },
  ],
  '.yaml': 'yaml-hook/register',
  '.yml': 'yaml-hook/register',
}

jsVariants

Same as above, but only include the extensions which are javascript variants.

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.

  4. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw.

License

MIT

interpret's People

Contributors

phated avatar sttk avatar madcapjake avatar jamesknelson avatar ambroos avatar bwin avatar blakeembrey avatar trysound avatar delapouite avatar crteal avatar crutchcorn avatar flipsasser avatar geoffreybooth avatar hrkings avatar ilan-schemoul avatar jakxz avatar jednano avatar mmotorny avatar duereg avatar omrilitov avatar pdehaan avatar pspeter3 avatar hasparus avatar simonbuchan avatar zertosh avatar tiye avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.