Require package module from highest or list of module.
for more desc see here
-
requireFromParentUp(id: string, startModule?: NodeModule)
{:.language-ts} => parent-require -
requireFromTopParent(id: string, startModule?: NodeModule)
{.ts} => top-require -
getModuleByExports(exports)
=> which-module
- support NodeJS.ErrnoException, Error object will has
code='MODULE_NOT_FOUND'
.
so we can know when error happen is can't found module or it has other error - split function, so u can custom it
- other api see here
npm install up-require
-
root
- index
- node_modules/
chai@3
- packages/
-
sub1_pkg/
- node_modules/
chai@1
- index
- node_modules/
-
sub2_pkg/
- node_modules/
chai@2
- index
-
sub3_of_sub2_pkg/
- node_modules/
chai@1
- index
- node_modules/
- node_modules/
-
-
requireFromTopParent<T = any>(id: string, startModule?: NodeModule)
=> top-require -
requireFromParentUp<T = any>(id: string, startModule?: NodeModule)
=> parent-require -
getModuleByExports
=> which-module
alias name
upRequire
= requireUp
= requireFromTopParent
import requireFromTopParent, { getModuleByID, requireFromParentUp } from 'up-require';
import { requireFromTopParent, getModuleByID, requireFromParentUp } from 'up-require';
const requireFromTopParent = require('up-require').requireFromTopParent;
require('chai') => chai@1
requireFromParentUp('chai', module) => chai@3
requireFromTopParent('chai', module) => chai@3
requireFromTopParent('chai') => chai@3
require('chai') => chai@1
requireFromParentUp('chai', module) => chai@2
requireFromTopParent('chai', module) => chai@3
requireFromTopParent('chai') => chai@3
console.log(`only return when chai is required`, getModuleByID('chai'));
console.log(`when chai is not required , will require it`, getModuleByID('chai', true));
- Creator of original Parent Require Jared Hanson
- Lukasz Sielski
Copyright (c) 2014 Lukasz Sielski <http://lukaszsielski.pl/> Copyright (c) 2013 Jared Hanson <http://jaredhanson.net/>