0.1.0 • Published 6 years ago
@make-mjs/path v0.1.0
@make-mjs/path
Manipulate MJS module path
Examples
Internal Modules
import getMjsPath from '@make-mjs/path'
const mjsPath: string = await getMjsPath({
modulePath: './foo/bar/baz', // leading '.' or '..' is required to be recognized as internal
/* ...and more options... */
})Result:
- If
./foo/bar/bazpoints to a directory without apackage.json,mjsPathwould be./foo/bar/baz/index.mjs. - If
./foo/bar/bazdoes not point to a directory,mjsPathwould be./foo/bar/baz.mjs. - For other cases, read the tests.
External Modules
import getMjsPath from '@make-mjs/path'
const mjsPath: string = await getMjsPath({
modulePath: 'foo/bar/baz',
moduleContainer: [
'node_modules'
],
/* ...and more options... */
})Result:
- If
node_modules/foo/bar/bazpoints to a directory without apackage.json,mjsPathwould befoo/bar/baz/index.mjs. - If
node_modules/foo/bar/bazpoints to a directory that contains apackage.jsonthat have"module"points tomodule.mjs,mjsPathwould befoo/bar/baz/module.mjs. - If
node_modules/foo/baz.jspoints to a file,mjsPathwould befoo/bar/baz.mjs. - For other cases, read the tests.