How to use rechoir - 10 common examples

To help you get started, we’ve selected a few rechoir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gulpjs / interpret / test / index.js View on Github external
this.skip();
        } else if (nodeVersion.major < minVersion.major) {
          this.skip();
        }
      }

      this.timeout(0);

      var expected;

      process.chdir(path.join(__dirname, fixtureDir));

      shell.exec('npm install', { silent: true });

      // TODO: log failures
      rechoir.prepare(extensions, fixture);

      switch (extension) {
        case '.ts':
        case '.tsx':
        case '.esm.js':
          expected = {
            default: {
              data: {
                trueKey: true,
                falseKey: false,
                subKey: {
                  subProp: 1,
                },
              },
            },
          };
github agershun / alasql / node_modules / gulp / node_modules / liftoff / index.js View on Github external
}

  // load any modules which were requested to be required
  if (preload.length) {
    // unique results first
    preload.filter(function (value, index, self) {
      return self.indexOf(value) === index;
    }).forEach(function (dep) {
      this.requireLocal(dep, findCwd(opts));
    }, this);
  }

  // use rechoir to autoload any required modules
  var autoloads;
  if (configPath) {
    autoloads = rechoir.prepare(this.extensions, configPath, cwd, true);
    if (autoloads instanceof Error) {
      autoloads = autoloads.failures;
    }
    if (Array.isArray(autoloads)) {
      autoloads.forEach(function (attempt) {
        if (attempt.error) {
          this.emit('requireFail', attempt.moduleName, attempt.error);
        } else {
          this.emit('require', attempt.moduleName, attempt.module);
        }
      }, this);
    }
  }

  return {
    cwd: cwd,
github danielbuechele / goofy / server / node_modules / gulp / node_modules / liftoff / index.js View on Github external
}

  // load any modules which were requested to be required
  if (preload.length) {
    // unique results first
    preload.filter(function (value, index, self) {
      return self.indexOf(value) === index;
    }).forEach(function (dep) {
      this.requireLocal(dep, findCwd(opts));
    }, this);
  }

  // use rechoir to autoload any required modules
  var autoloads;
  if (configPath) {
    autoloads = rechoir.prepare(this.extensions, configPath, cwd, true);
    if (autoloads instanceof Error) {
      autoloads = autoloads.failures;
    }
    if (Array.isArray(autoloads)) {
      autoloads.forEach(function (attempt) {
        if (attempt.error) {
          this.emit('requireFail', attempt.moduleName, attempt.error);
        } else {
          this.emit('require', attempt.moduleName, attempt.module);
        }
      }, this);
    }
  }

  return {
    cwd: cwd,
github js-cli / js-liftoff / lib / register_loader.js View on Github external
module.exports = function(eventEmitter, extensions, configPath, cwd) {
  extensions = extensions || {};

  if (typeof configPath !== 'string') {
    return;
  }

  var autoloads = rechoir.prepare(extensions, configPath, cwd, true);
  if (autoloads instanceof Error) { // Only errors
    autoloads.failures.forEach(function(failed) {
      eventEmitter.emit('loader:failure', failed.moduleName, failed.error);
    });
    return;
  }

  if (!Array.isArray(autoloads)) { // Already required or no config.
    return;
  }

  var succeeded = autoloads[autoloads.length - 1];
  eventEmitter.emit('loader:success', succeeded.moduleName, succeeded.module);
};
github kotarella1110 / cordova-plugin-webpack / src / utils / webpackHelpers.ts View on Github external
export const webpackConfig = (cwd: string, configPath?: string) => {
  const resolvedConfigPath = (() => {
    if (!configPath) {
      return defaultWebpackConfigPath(cwd);
    }
    if (path.isAbsolute(configPath)) {
      return path.resolve(configPath);
    }
    return path.resolve(cwd, configPath);
  })();

  // register module loaders
  rechoir.prepare(interpret.extensions, resolvedConfigPath);

  const config: {
    default: webpack.Configuration;
    // eslint-disable-next-line global-require, import/no-dynamic-require
  } = require(resolvedConfigPath);

  return config.default || config;
};
github urbanairship / frock / lib / register-handler.js View on Github external
function register (name) {
    if (handlers.has(name)) {
      return handlers.get(name)
    }

    const handlerPath = resolve(name, {basedir: pwd, extensions: ['.js', '.ts']})

    try {
      rechoir.prepare(extensions, handlerPath)
    } catch (e) {
      // pass, but log the error
      log.error(`Error preparing transform for ${name}\n  ${e.message}`)
    }

    const handler = _require(handlerPath)

    handlers.set(name, handler.default || handler)
    paths.set(name, handlerPath)

    // only perform package version checks for installable mocks
    if (handlerPath.includes('node_modules')) {
      let pkgPath
      let lpkg

      try {
github zeit / pkg / test / test-79-npm / rechoir / rechoir.js View on Github external
'use strict';

var path = require('path');
var config = require('interpret').extensions;
var rechoir = require('rechoir');
require('coffee-script/register');
rechoir.prepare(config, './fixture.coffee');
var filename = path.join(__dirname, 'fixture.coffee');
var coffee = require(filename);

if (typeof coffee.root === 'function') {
  console.log('ok');
}
github Andyliwr / FE-learning-load / 前端小demo / es6Toes5 / node_modules / liftoff / lib / register_loader.js View on Github external
module.exports = function(eventEmitter, extensions, configPath, cwd) {
  extensions = extensions || {};

  if (!isString(configPath)) {
    return;
  }

  var autoloads = rechoir.prepare(extensions, configPath, cwd, true);
  if (autoloads instanceof Error) {
    autoloads = autoloads.failures;
  }

  if (Array.isArray(autoloads)) {
    autoloads.forEach(function (attempt) {
      if (attempt.error) {
        eventEmitter.emit('requireFail', attempt.moduleName, attempt.error);
      } else {
        eventEmitter.emit('require', attempt.moduleName, attempt.module);
      }
    });
  }
};
github shellscape / webpack-nano / lib / config.js View on Github external
const requireLoader = (extension) => {
  try {
    rechoir.prepare(fileTypes, `config${extension}`, cwd);
  } catch (e) {
    let message;
    if (/no module loader/i.test(e.message)) {
      const [, fileType] = e.message.match(/(".+").$/);
      message = `A loader could not be found for the ${fileType} file type`;
    } else {
      const modules = e.failures.map(({ moduleName }) => `\n    ${moduleName}`);
      message = `${e.message.slice(0, -1)}:${modules}`;
    }

    const error = new RangeError(message);
    error.code = 'ERR_MODULE_LOADER';
    throw error;
  }
};
github shellscape / webpack-serve / lib / config.js View on Github external
const requireLoader = (extension) => {
  try {
    rechoir.prepare(fileTypes, `config${extension}`, cwd);
  } catch (e) {
    let message;
    if (/no module loader/i.test(e.message)) {
      const [, fileType] = e.message.match(/(".+").$/);
      message = `A loader could not be found for the ${fileType} file type`;
    } else {
      const modules = e.failures.map(({ moduleName }) => `\n    ${moduleName}`);
      message = `${e.message.slice(0, -1)}:${modules}`;
    }

    const error = new RangeError(message);
    error.code = 'ERR_MODULE_LOADER';
    throw error;
  }
};

rechoir

Prepare a node environment to require files with different extensions.

MIT
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis

Popular rechoir functions