identify-resource
Resolve the file paths to js, css, and html dependencies.
Usage
resolve(sourcepath, id, [options]): resolve the path for id
from sourcepath
.
id
can be an absolute filepath, relative filepath, "node_modules" reference, or "node_modules" file reference.
Available options
include:
fileExtensions
: hash of valid file extensions by type, used to resolve ids with missing file extension (default{ js: 'js', 'json', css: 'css', html: 'html' }
)sources
: array of source directories (in addition to cwd and "node_modules") in which to search for files (default[]
)
$ npm install identify-resource
/projects/myproject/index.js
var bar = boo = http = ;
/project/myproject/index.css
;
/projects/myproject/node_modules/boo/package.json
var resolve = resolve; // Resolve relative pathconsole; //=> '/projects/myproject/bar.js' // Resolve node_modulesconsole; //=> '/projects/myproject/node_modules/boo/index.js' // Resolve native node modulesconsole; //=> 'false' // Resolve cssconsole;//=> '/projects/myproject/bar.css'
Configuring the package.json browser
field enables overriding default behaviour:
/projects/myproject/package.json
// Alias native moduleconsole; //=> '/projects/myproject/lib/http.js'
See here for more details on using the browser
field.
identify(filepath, [options]): retrieve the id for filepath
. Id's are resolved from the cwd or "node_modules", as appropriate.
var identify = identify; ; //=> 'bar.js'; //=> 'boo/index.js#1.0.0'; //=> 'bar.css'
hasMultipleVersions(id): determine if more than one version of id
exists in resolve cache
clearCache(): clear the resolve cache