mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
feat(find-cache-dir): update to v3.2 (#42550)
- v2 for backward compatibility - migrate return type from `null` to `undefined` https://github.com/avajs/find-cache-dir#readme Thanks!
This commit is contained in:
parent
a9a04857c6
commit
d328f3b1d0
@ -1,16 +1,16 @@
|
||||
import findCacheDir = require('find-cache-dir');
|
||||
|
||||
findCacheDir({ name: 'unicorns' }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', files: 'foo' }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', files: ['foo', 'bar'] }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', cwd: 'foo' }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', create: true }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', thunk: false }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns' }); // $ExpectType string | undefined
|
||||
findCacheDir({ name: 'unicorns', files: 'foo' }); // $ExpectType string | undefined
|
||||
findCacheDir({ name: 'unicorns', files: ['foo', 'bar'] }); // $ExpectType string | undefined
|
||||
findCacheDir({ name: 'unicorns', cwd: 'foo' }); // $ExpectType string | undefined
|
||||
findCacheDir({ name: 'unicorns', create: true }); // $ExpectType string | undefined
|
||||
findCacheDir({ name: 'unicorns', thunk: false }); // $ExpectType string | undefined
|
||||
findCacheDir({}); // $ExpectError
|
||||
findCacheDir(); // $ExpectError
|
||||
|
||||
const thunk = findCacheDir({ name: 'unicorns', thunk: true });
|
||||
thunk; // $ExpectType ((...pathParts: string[]) => string) | null
|
||||
thunk; // $ExpectType ((...pathParts: string[]) => string) | undefined
|
||||
|
||||
if (thunk) {
|
||||
thunk(); // $ExpectType string
|
||||
|
||||
17
types/find-cache-dir/index.d.ts
vendored
17
types/find-cache-dir/index.d.ts
vendored
@ -1,20 +1,19 @@
|
||||
// Type definitions for find-cache-dir 2.0
|
||||
// Type definitions for find-cache-dir 3.2
|
||||
// Project: https://github.com/avajs/find-cache-dir#readme
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = findCacheDir;
|
||||
|
||||
/**
|
||||
* Finds the cache directory using the supplied options. The algorithm tries to find a `package.json` file,
|
||||
* searching every parent directory of the `cwd` specified (or implied from other options).
|
||||
* @param options
|
||||
* @returns A string containing the absolute path to the cache directory, or null if package.json was never found.
|
||||
* Finds the cache directory using the supplied options.
|
||||
* The algorithm tries to find a `package.json` file, searching every parent directory of the `cwd` specified
|
||||
* (or implied from other options). It returns a `string` containing the absolute path to the cache directory,
|
||||
* or `undefined` if `package.json` was never found or if the `node_modules` directory is unwritable.
|
||||
*/
|
||||
declare function findCacheDir(
|
||||
options: findCacheDir.OptionsWithThunk
|
||||
): ((...pathParts: string[]) => string) | null;
|
||||
declare function findCacheDir(options: findCacheDir.Options): string | null;
|
||||
declare function findCacheDir(options: findCacheDir.OptionsWithThunk): ((...pathParts: string[]) => string) | undefined;
|
||||
declare function findCacheDir(options: findCacheDir.Options): string | undefined;
|
||||
|
||||
declare namespace findCacheDir {
|
||||
interface Options {
|
||||
|
||||
19
types/find-cache-dir/v2/find-cache-dir-tests.ts
Normal file
19
types/find-cache-dir/v2/find-cache-dir-tests.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import findCacheDir = require('find-cache-dir');
|
||||
|
||||
findCacheDir({ name: 'unicorns' }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', files: 'foo' }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', files: ['foo', 'bar'] }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', cwd: 'foo' }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', create: true }); // $ExpectType string | null
|
||||
findCacheDir({ name: 'unicorns', thunk: false }); // $ExpectType string | null
|
||||
findCacheDir({}); // $ExpectError
|
||||
findCacheDir(); // $ExpectError
|
||||
|
||||
const thunk = findCacheDir({ name: 'unicorns', thunk: true });
|
||||
thunk; // $ExpectType ((...pathParts: string[]) => string) | null
|
||||
|
||||
if (thunk) {
|
||||
thunk(); // $ExpectType string
|
||||
thunk('bar.js'); // $ExpectType string
|
||||
thunk('baz', 'quz.js'); // $ExpectType string
|
||||
}
|
||||
57
types/find-cache-dir/v2/index.d.ts
vendored
Normal file
57
types/find-cache-dir/v2/index.d.ts
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
// Type definitions for find-cache-dir 2.0
|
||||
// Project: https://github.com/avajs/find-cache-dir#readme
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = findCacheDir;
|
||||
|
||||
/**
|
||||
* Finds the cache directory using the supplied options. The algorithm tries to find a `package.json` file,
|
||||
* searching every parent directory of the `cwd` specified (or implied from other options).
|
||||
* @param options
|
||||
* @returns A string containing the absolute path to the cache directory, or null if package.json was never found.
|
||||
*/
|
||||
declare function findCacheDir(
|
||||
options: findCacheDir.OptionsWithThunk
|
||||
): ((...pathParts: string[]) => string) | null;
|
||||
declare function findCacheDir(options: findCacheDir.Options): string | null;
|
||||
|
||||
declare namespace findCacheDir {
|
||||
interface Options {
|
||||
/**
|
||||
* Should be the same as your project name in `package.json`.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* An array of files that will be searched for a common parent directory.
|
||||
* This common parent directory will be used in lieu of the `cwd` option below.
|
||||
*/
|
||||
files?: string | string[];
|
||||
|
||||
/**
|
||||
* Directory to start searching for a `package.json` from.
|
||||
*/
|
||||
cwd?: string;
|
||||
|
||||
/**
|
||||
* If `true`, the directory will be created synchronously before returning.
|
||||
* @default false
|
||||
*/
|
||||
create?: boolean;
|
||||
|
||||
/**
|
||||
* If `true`, this modifies the return type to be a function that is a thunk for `path.join(theFoundCacheDirectory)`.
|
||||
* @default false
|
||||
*/
|
||||
thunk?: boolean;
|
||||
}
|
||||
|
||||
interface OptionsWithThunk extends Options {
|
||||
/**
|
||||
* If `true`, this modifies the return type to be a function that is a thunk for `path.join(theFoundCacheDirectory)`.
|
||||
* @default false
|
||||
*/
|
||||
thunk: true;
|
||||
}
|
||||
}
|
||||
28
types/find-cache-dir/v2/tsconfig.json
Normal file
28
types/find-cache-dir/v2/tsconfig.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"paths": {
|
||||
"find-cache-dir": [
|
||||
"find-cache-dir/v2"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"find-cache-dir-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/find-cache-dir/v2/tslint.json
Normal file
1
types/find-cache-dir/v2/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user