module-lookup-amd
v10.0.1
Published
Resolve aliased dependency paths using a RequireJS config
Downloads
15,291,810
Readme
module-lookup-amd
Resolve AMD dependency paths to an absolute path on the filesystem
This module takes in a partial and synchronously gives back its absolute path on the filesystem.
I built this for Dependents' jump to dependency feature that lets you click on a module name and open the relevant file.
npm install module-lookup-amdUsage
ESM
import lookup from 'module-lookup-amd';
const realPath = lookup({
partial: 'someModule',
filename: 'file/containing/partial',
directory: 'path/to/all/js/files', // optional
config: 'path/to/my/requirejs/config', // optional
configPath: 'path/to/config/directory', // optional
fileSystem: {} // optional
});CommonJS
const { default: lookup } = require('module-lookup-amd');partial: the dependency that you want to lookupfilename: the path of the file that contains the dependency (i.e., parent module)directory: Used to resolve files if you're not using a requirejs configconfig: the path to your RequireJS configuration file- As an optimization, you can provide a pre-parsed config object (the contents of the RequireJS config in object form)
as
config. You are then required to provide aconfigPathordirectoryargument which is assumed to be the location where your config would have been.
- As an optimization, you can provide a pre-parsed config object (the contents of the RequireJS config in object form)
as
configPath: path to the config file (or its directory) used to determine the module resolution directory; inferred automatically whenconfigis a string pathfileSystem: An alternativefsimplementation to use for filesystem interactions. Defaults to Node.js'sfsimplementation if not supplied.
CLI
Assumes a global -g installation
lookup-amd -c path/to/my/config.js -f path/to/file/containing/dependency -d path/containing/all/files my/dependency/name