Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
load-from-cwd-or-npm
Advanced tools
Readme
Load a module from either CWD or npm
CLI directory
const loadFromCwdOrNpm = require('load-from-cwd-or-npm');
// $ npm ls validate-npm-package-name
// > └── (empty)
(async () => {
require('validate-npm-package-name'); // throws a `MODULE_NOT_FOUND` error
const RegistryClient = await loadFromCwdOrNpm('validate-npm-package-name'); // doesn't throw
})();
npm install load-from-cwd-or-npm
const loadFromCwdOrNpm = require('load-from-cwd-or-npm');
moduleId: string
(a module ID without path separators (/
, \\
))
Return: Promise<any>
It loads a module with the given module ID from either of these two directories:
node_modules
in the current working directorynode_modules
in the directory where npm
CLI is installedIf the module ins't installed in CWD but included in the npm CLI dependencies, it loads the module from npm CLI directory.
// $ npm ls nopt
// > └── (empty)
(async () => {
const nopt = await loadFromCwdOrNpm('nopt'); //=> {[Function: nopt], clean: [Function: clean] ...}
})();
If the module ins't included in the npm CLI dependencies but installed in CWD, it loads the module from CWD.
// $ npm ls eslint
// > └── eslint@4.11.0
(async () => {
// npm doesn't depend on `eslint` module.
const eslint = await loadFromCwdOrNpm('eslint'); //=> {linter: EventEmitter { ... }, ...}
})();
If the module exists in both directories, it compares their package versions and loads the newer one.
// $ npm ls rimraf
// > └── rimraf@1.0.0
(async () => {
// Loaded from npm CLI directory because the CWD version is older
const rimraf = await loadFromCwdOrNpm('rimraf');
})();
The returned promise will be fulfilled with the loaded module, or rejected when it fails to find the module from either directories.
ISC License © 2017 - 2018 Shinnosuke Watanabe
FAQs
Load a module from either CWD or npm CLI directory
The npm package load-from-cwd-or-npm receives a total of 673 weekly downloads. As such, load-from-cwd-or-npm popularity was classified as not popular.
We found that load-from-cwd-or-npm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.