JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 958
  • Score
    100M100P100Q105816F
  • License MIT

load a module from either CWD or npm CLI directory

Package Exports

  • load-from-cwd-or-npm

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (load-from-cwd-or-npm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

load-from-cwd-or-npm

NPM version Build Status Build status Coverage Status Dependency Status

Load a module from either CWD or npm CLI directory

const loadFromCwdOrNpm = require('load-from-cwd-or-npm');

// $ npm ls npm-regustry-client
// > └── (empty)

loadFromCwdOrNpm('npm-regustry-client').then(RegClient => {
  const client = new RegClient();
  client.get('https://registry.npmjs.org/npm', {timeout: 1000}, (error, data, raw, res) => {
    // ...
  });
});

Installation

Use npm.

npm install load-from-cwd-or-npm

API

const loadFromCwdOrNpm = require('load-from-cwd-or-npm');

loadFromCwdOrNpm(moduleId, [compareFn])

moduleId: String (a module ID)
compareFn: Function (a function to compare two package versions)
Return: Object (a Promise instance)

It loads a module with the given module ID from either of these two directories:

  1. node_modules in the current working directory
  2. node_modules in the directory where npm CLI in installed

The returned promise will be fulfilled with a string of the resolved file path, or rejected when it fails to find the module.

loadFromCwdOrNpm('./lib/install').then(resolvedPath => {
  resolvedPath; //=> '/usr/local/lib/node_modules/npm/lib/install.js'
});

loadFromCwdOrNpm('lib/install').catch(err => {
  err.message; //=> 'Cannot find module: "lib/install" from npm directory (/usr/local/lib/node_modules/npm).'
});

License

Copyright (c) 2015 Shinnosuke Watanabe

Licensed under the MIT License.