3.0.1 • Published 2 months ago

up-require v3.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
2 months ago

up-require

Require package module from highest or list of module.

base on

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

diff

  • 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

Install

npm install up-require

demo

structure

  • root
    • index
    • node_modules/
      • chai@3
    • packages/
      • sub1_pkg/
        • node_modules/
          • chai@1
        • index
      • sub2_pkg/
        • node_modules/
          • chai@2
        • index
        • sub3_of_sub2_pkg/
          • node_modules/
            • chai@1
          • index

base use

  • 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;

when use in sub1_pkg/index

require('chai') => chai@1
requireFromParentUp('chai', module) => chai@3
requireFromTopParent('chai', module) => chai@3
requireFromTopParent('chai') => chai@3

when use in sub3_of_sub2_pkg/index

require('chai') => chai@1
requireFromParentUp('chai', module) => chai@2
requireFromTopParent('chai', module) => chai@3
requireFromTopParent('chai') => chai@3

getModuleByID(id: string, requireIfNotExists?: boolean, req = require)

console.log(`only return when chai is required`, getModuleByID('chai'));
console.log(`when chai is not required , will require it`, getModuleByID('chai', true));

Credits

License

The MIT License

Copyright (c) 2014 Lukasz Sielski [http://lukaszsielski.pl/](http://lukaszsielski.pl/) Copyright (c) 2013 Jared Hanson [http://jaredhanson.net/](http://jaredhanson.net/)

3.0.1

2 months ago

3.0.0

7 months ago

2.0.11

1 year ago

2.0.10

1 year ago

2.0.5

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.3

2 years ago

2.0.4

2 years ago

2.0.2

2 years ago

2.0.1

3 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.0

6 years ago