{"name":"filing-cabinet","version":"5.5.0","keywords":["lookup","es6","amd","commonjs","sass","less","stylus","svelte","vue","partial","resolution","paths"],"author":{"name":"Joel Kemp","email":"joel@mrjoelkemp.com"},"license":"MIT","_id":"filing-cabinet@5.5.0","maintainers":[{"name":"pahen","email":"patrik.henningsson@gmail.com"},{"name":"mrjoelkemp","email":"mrjoelkemp@gmail.com"},{"name":"xhmikosr","email":"xhmikosr@gmail.com"}],"homepage":"https://github.com/dependents/node-filing-cabinet","bugs":{"url":"https://github.com/dependents/node-filing-cabinet/issues"},"xo":{"rules":{"curly":["error","multi-line"],"comma-dangle":["error","never"],"prefer-template":"error","arrow-body-style":"off","operator-linebreak":["error","after"],"capitalized-comments":"off","object-curly-spacing":["error","always"],"unicorn/prefer-module":"off","space-before-function-paren":["error","never"],"unicorn/prefer-node-protocol":"off","unicorn/prevent-abbreviations":"off","unicorn/prefer-top-level-await":"off","unicorn/no-anonymous-default-export":"off"},"space":true,"ignores":["test/fixtures/*"],"overrides":[{"envs":["mocha"],"files":"test/**/*.js"}]},"bin":{"filing-cabinet":"bin/cli.js"},"dist":{"shasum":"662300da2dec3941a66cffdb235d24b60beb02b8","tarball":"http://registry-npm.ywwl.com/filing-cabinet/download/filing-cabinet-5.5.0.tgz","fileCount":5,"integrity":"sha512-X7QtHYxo0gcVPV7SqhxSMJqM4q8uKWQWQieJNa0jEmL0yW6RIhHUr06FmdkF9aOHDKMDP3j1zlNMqRSBj2BmDg==","signatures":[{"sig":"MEQCICeR+NePPsZVUu6kypwdSIKuimB8LjtnXiLJOO9H046aAiBY30dIXzqtSWIZZ9xoO3Vw9dfmYNPXCdh4HGeZ7Mp4Eg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":28580,"size":8664,"noattachment":false,"key":"/filing-cabinet/-/filing-cabinet-5.5.0.tgz"},"main":"index.js","engines":{"node":">=18"},"gitHead":"7feaaff80d48d95cff110fa6ddf82ed4d5a6f049","scripts":{"fix":"xo --fix","lint":"xo","test":"npm run lint && npm run mocha","mocha":"mocha","test:ci":"c8 npm run mocha"},"_npmUser":{"name":"xhmikosr","email":"xhmikosr@gmail.com"},"repository":{"url":"git+https://github.com/dependents/node-filing-cabinet.git","type":"git"},"_npmVersion":"11.12.1","description":"Find files based on partial paths","directories":{},"_nodeVersion":"24.15.0","dependencies":{"resolve":"^1.22.12","commander":"^12.1.0","typescript":"^5.9.3","sass-lookup":"^6.1.2","stylus-lookup":"^6.1.2","tsconfig-paths":"^4.2.0","app-module-path":"^2.2.0","enhanced-resolve":"^5.21.0","module-definition":"^6.0.2","module-lookup-amd":"^9.1.3","resolve-dependency-path":"^4.0.1"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","xo":"^0.60.0","mocha":"^11.7.5","sinon":"^19.0.5"},"_npmOperationalInternal":{"tmp":"tmp/filing-cabinet_5.5.0_1778330988122_0.35863336691777614","host":"s3://npm-registry-packages-npm-production"},"readme":"# filing-cabinet\n\n[![CI](https://img.shields.io/github/actions/workflow/status/dependents/node-filing-cabinet/ci.yml?branch=main&label=CI&logo=github)](https://github.com/dependents/node-filing-cabinet/actions/workflows/ci.yml?query=branch%3Amain)\n[![npm version](https://img.shields.io/npm/v/filing-cabinet?logo=npm&logoColor=fff)](https://www.npmjs.com/package/filing-cabinet)\n[![npm downloads](https://img.shields.io/npm/dm/filing-cabinet)](https://www.npmjs.com/package/filing-cabinet)\n\n> Get the file associated with a dependency/partial's path\n\n## Installation\n\n```sh\nnpm install filing-cabinet\n```\n\n## Quick Start\n\n### ESM\n\n```js\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport cabinet from 'filing-cabinet';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nconst result = cabinet({\n  // import Button from './button'\n  partial: './button',\n  filename: path.join(__dirname, 'src', 'app.js'),\n  directory: __dirname\n});\n```\n\n### CommonJS\n\n```js\nconst { default: cabinet } = require('filing-cabinet');\n```\n\n### Options\n\n```js\nconst result = cabinet({\n  // import Button from './button'\n  partial: './button',\n  filename: path.join(__dirname, 'src', 'app.js'),\n  directory: __dirname\n});\n\nif (result) {\n  console.log(result); // -> /absolute/path/to/src/button.js\n} else {\n  console.error('Dependency could not be resolved');\n}\n```\n\n## API\n\n| Member | Type | Description |\n| --- | --- | --- |\n| `cabinet(options)` | `Function` | Resolve a dependency to an absolute path |\n| `cabinet.register(extension, resolver)` | `Function` | Register a custom resolver for a file extension |\n| `cabinet.unregister(extension)` | `Function` | Remove a registered resolver |\n| `cabinet.getLookup(extension)` | `Function` | Get the resolver for a file extension |\n| `cabinet.supportedFileExtensions` | `string[]` | All currently registered file extensions |\n\n### `cabinet(options: CabinetOptions)`\n\nResolves a dependency string from the context of a file.\n\n**Returns:** `string` - absolute path to the resolved file, or an empty string if it could not be resolved.\n\n#### Options\n\n| Option | Type | Required | Description |\n| --- | --- | --- | --- |\n| `partial` | `string` | **Yes** | Dependency path to resolve |\n| `directory` | `string` | **Yes** | Project root path used for resolution |\n| `filename` | `string` | **Yes** | Path to the file containing `partial` |\n| `ast` | `Object` | No | Pre-parsed AST for `filename` (avoids reparsing in JS module type detection) |\n| `config` | `string \\| Object` | No | **JS only.** RequireJS config (path or object) for AMD resolution |\n| `configPath` | `string` | No | **JS only.** Path to the RequireJS config file when `config` is an object |\n| `webpackConfig` | `string` | No | **JS only.** Webpack config path for webpack-style resolution; if the config exports an array, the first config is used |\n| `nodeModulesConfig` | `Object \\| Function` | No | Controls package entry selection when resolving from `node_modules` (see examples below) |\n| `nodeModulesConfig.entry` | `string` | No | Object form: field name to prefer instead of `main` (for example `module`) |\n| `nodeModulesConfig` (function) | `Function` | No | Function form: custom [`resolve` packageFilter](https://github.com/browserify/resolve#resolveid-opts-cb) callback for full control of package entry selection |\n| `tsConfig` | `string \\| Object` | No | **TS only.** TypeScript config path or pre-parsed config object |\n| `tsConfigPath` | `string` | No | **TS only.** (Virtual) path to tsconfig when `tsConfig` is an object; needed for [Path Mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) |\n| `noTypeDefinitions` | `boolean` | No | **TS only.** Prefer `*.js` over `*.d.ts` when resolving TypeScript dependencies |\n| `fileSystem` | `Object` | No | An alternative `fs` implementation to use for reading `tsConfigPath` |\n\n#### `nodeModulesConfig` examples\n\nObject form - use a specific `package.json` field instead of `main`:\n\n```js\ncabinet({\n  partial: 'some-package',\n  filename: '/path/to/file.js',\n  directory: '/path/to',\n  nodeModulesConfig: { entry: 'module' }\n});\n```\n\nFunction form - full control via a custom `packageFilter`:\n\n```js\ncabinet({\n  partial: 'some-package',\n  filename: '/path/to/file.js',\n  directory: '/path/to',\n  nodeModulesConfig: (pkg) => {\n    // prefer \"module\", fall back to \"main\"\n    pkg.main = pkg.module ?? pkg.main;\n    return pkg;\n  }\n});\n```\n\n### `cabinet.register(extension: string, resolver: (options: Object) => string)`\n\nRegister a custom resolver for a file extension.\n\n**Parameters:**\n\n* `extension` (`string`, required) - file extension to handle (for example `.py`, `.php`)\n* `resolver` (`(options: Object) => string`, required) - function that receives the same `options` object passed to `cabinet(options)` and returns a resolved absolute path or an empty string\n\n**Returns:** `void`\n\n```js\ncabinet.register('.py', (options) => {\n  // resolve options.partial relative to options.filename\n  return '/resolved/path/to/file.py';\n});\n```\n\nFor examples of resolver implementations, take a look at the built-in resolvers:\n\n* [sass-lookup](https://github.com/dependents/node-sass-lookup)\n* [stylus-lookup](https://github.com/dependents/node-stylus-lookup)\n* [module-lookup-amd](https://github.com/dependents/node-module-lookup-amd)\n\nIf no resolver is registered for an extension, filing-cabinet falls back to a generic file resolver with extension defaulting behavior.\n\n### `cabinet.unregister(extension: string)`\n\nRemove the resolver registered for `extension`.\n\n**Parameters:**\n\n* `extension` (`string`, required) - file extension whose resolver should be removed\n\n**Returns:** `void`\n\n```js\ncabinet.unregister('.py');\n```\n\n### `cabinet.getLookup(extension: string)`\n\nReturn the resolver function registered for `extension`, or `undefined` if none is registered.\n\n**Parameters:**\n\n* `extension` (`string`, required) - file extension to look up\n\n**Returns:** `Function | undefined`\n\n```js\nconst resolver = cabinet.getLookup('.ts'); // built-in TypeScript resolver\n```\n\n### `cabinet.supportedFileExtensions`\n\nA `string[]` of all currently registered file extensions. Updated automatically by `register()` and `unregister()`.\n\n```js\nconsole.log(cabinet.supportedFileExtensions);\n// ['.js', '.jsx', '.less', '.sass', '.scss', '.styl', '.svelte', '.ts', '.tsx', '.vue']\n```\n\n## Supported Languages\n\nBy default, filing-cabinet supports:\n\n* JavaScript (CommonJS, AMD, ES6)\n* TypeScript\n* Sass (`.scss`, `.sass`), Less (`.less`), and Stylus (`.styl`)\n* Svelte\n* Vue\n\n## Package `#imports` Field\n\nfiling-cabinet automatically resolves [Node.js package `imports`](https://nodejs.org/api/packages.html#subpath-imports) (dependencies starting with `#`) for both JavaScript and TypeScript files.\n\n## CLI\n\nInstall globally:\n\n```sh\nnpm install -g filing-cabinet\n```\n\nRun:\n\n```sh\nfiling-cabinet [options] <path>\n```\n\nRun `filing-cabinet --help` for full usage.\n\n## License\n\n[MIT](LICENSE)\n","publish_time":1778330988287,"_cnpm_publish_time":1778330988287,"dist-tags":{"latest":"6.0.0"}}