Package Exports
- sb-resolve
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 (sb-resolve) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Resolve
sb-resolve is a node module that supports require.resolve's lookup algorithm but with advance configurations.
Installation
npm install --save sb-resolveAPI
type $Options = {
fs?: {
stat?: ((filePath: string) => Promise<FS.Stats>),
readFile?: ((filePath: string) => Promise<string>)
},
root?: string | Array<string>,
alias?: Object, // Example: {react: 'preact-compat'}
extensions?: Array<string>,
packageMains?: Array<string>,
moduleDirectories?: Array<string>
} = {
fs: {
stat: promisify(FS.stat),
readFile: promisify(FS.readFile),
},
root: [path.resolve('./')],
alias: {},
extensions: ['.js', '.json'],
packageMains: ['browser', 'main'],
moduleDirectories: ['node_modules']
}
function isLocal(request: string): boolean
function isCore(request: string): boolean
function resolve(request: string, requestDirectory: string, options: $Options): Promise<string>
export { isLocal, isCore }
export default resolveExamples
import resolve, { isCore } from 'sb-resolve'
console.log(isCore('fs')) // true
console.log(isCore('babel')) // false
resolve('babel', __dirname).then(function(mainFile) {
console.log(mainFile) // /tmp/test/node_modules/babel/index.js
})Notes
To give developers full control over the resolution, this module does not keep looking for moduleDirectories upwards, to add those directories, you must manually add those node_modules directories' absolute paths to moduleDirectories or add their parent folders in root
License
This project is licensed under the terms of MIT License. See the LICENSE file for more info.