feat(filing-cabinet): type definitions for v2.5 (#42753)

- type definitions
- tests

https://github.com/dependents/node-filing-cabinet#usage

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-03-02 20:07:53 +01:00 committed by GitHub
parent 0d448d3e5d
commit 0fe2fee2ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,19 @@
import cabinet = require('filing-cabinet');
const result = cabinet({
partial: 'somePartialPath',
directory: 'path/to/all/files',
filename: 'path/to/parent/file',
ast: {},
config: 'path/to/requirejs/config',
webpackConfig: 'path/to/webpack/config',
nodeModulesConfig: {
entry: 'module',
},
tsConfig: 'path/to/typescript/config',
});
result; // $ExpectType string
cabinet.register('.scss', (partial, filename, directory, config) => {
return `file.scss`;
});

59
types/filing-cabinet/index.d.ts vendored Normal file
View File

@ -0,0 +1,59 @@
// Type definitions for filing-cabinet 2.5
// Project: https://github.com/mrjoelkemp/node-filing-cabinet
// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace cabinet {
interface Options {
/** the dependency path */
partial: string;
/** the path to all files */
directory: string;
/** the path to the file containing the partial */
filename: string;
/**
* the parsed AST for filename
* Useful optimization for avoiding a parse of filename
*/
ast?: any;
/**
* `requirejs` config for resolving aliased JavaScript modules
*/
config?: any;
/**
* `webpack` config for resolving aliased JavaScript modules
*/
webpackConfig?: any;
/**
* config for resolving entry file for `node_modules`.
* This value overrides the main attribute in the `package.json` file;
* used in conjunction with the `packageFilter` of the resolve package
*/
nodeModulesConfig?: any;
/**
* Path to a typescript configuration.
* Could also be an object representing a pre-parsed typescript config
*/
tsConfig?: string | object;
/**
* For typescript files, whether to prefer *.js over *.d.ts
*/
noTypeDefinitions?: boolean;
}
type Resolver = (partial: string, filename: string, directory: string, config?: any) => void;
/**
* Register a custom lookup resolver for a file extension
* 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
* @param extension the extension of the file that should use the custom resolver (ex: '.py', '.php')
* @param resolver A resolver of partial paths
*/
function register(extension: string, resolver: Resolver): void;
}
declare function cabinet(options: cabinet.Options): string;
export = cabinet;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"filing-cabinet-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }