Home

Awesome

filing-cabinet

CI npm version npm downloads

Get the file associated with a dependency/partial's path

npm install filing-cabinet

Usage

const cabinet = require('filing-cabinet');

const result = cabinet({
  partial: 'somePartialPath',
  directory: 'path/to/all/files',
  filename: 'path/to/parent/file',
  ast: {}, // an optional AST representation of `filename`
  // Only for JavaScript files
  config: 'path/to/requirejs/config',
  webpackConfig: 'path/to/webpack/config',
  nodeModulesConfig: {
    entry: 'module'
  },
  tsConfig: 'path/to/tsconfig.json', // or an object
  tsConfigPath: 'path/to/tsconfig.json'
});

console.log(result); // /absolute/path/to/somePartialPath

Registered languages

By default, filing-cabinet provides support for the following languages:

You can register resolvers for new languages via cabinet.register(extension, resolver).

For examples of resolver implementations, take a look at the default language resolvers:

If a given extension does not have a registered resolver, cabinet will use a generic file resolver which is basically require('path').join with a bit of extension defaulting logic.

CLI

Requires a global install with npm install -g filing-cabinet

filing-cabinet [options] <dependencyPath>

See filing-cabinet --help for details on the options.

License

MIT