mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
[cosmiconfig] update definitions for v5 (#25624)
* [cosmiconfig] update definitions for v5 * Move v4 files into v4 directory * Make recommended changes, use exported interfaces and functions * Remove sample-config.json file * Change config from type to interface
This commit is contained in:
committed by
Sheetal Nandi
parent
01d6a921e3
commit
ca6596df7a
@@ -1,41 +1,23 @@
|
||||
import cosmiconfig = require("cosmiconfig");
|
||||
import cosmiconfig, { CosmiconfigResult } from "cosmiconfig";
|
||||
import * as path from "path";
|
||||
|
||||
const asyncExplorer = cosmiconfig("yourModuleName", {
|
||||
packageProp: "yourModuleName",
|
||||
rc: ".yourModuleNamerc",
|
||||
js: "yourModuleName.config.js",
|
||||
rcStrictJson: false,
|
||||
rcExtensions: false,
|
||||
stopDir: "someDir",
|
||||
cache: true,
|
||||
sync: false,
|
||||
transform: ({ config, filePath }) => ({ config, filePath }),
|
||||
format: "js"
|
||||
const explorer = cosmiconfig("yourModuleName", {
|
||||
searchPlaces: [],
|
||||
loaders: {},
|
||||
packageProp: "yourModuleName",
|
||||
stopDir: "someDir",
|
||||
cache: true,
|
||||
transform: (result: CosmiconfigResult) => result,
|
||||
ignoreEmptySearchPlaces: false,
|
||||
});
|
||||
|
||||
Promise.all([
|
||||
asyncExplorer.load(),
|
||||
asyncExplorer.load("start/search/here"),
|
||||
asyncExplorer.load(null, "load/this/file.json")
|
||||
explorer.search(path.join(__dirname)),
|
||||
explorer.searchSync(path.join(__dirname)),
|
||||
explorer.load(path.join(__dirname, "sample-config.json")),
|
||||
explorer.loadSync(path.join(__dirname, "sample-config.json")),
|
||||
]).then(result => result);
|
||||
|
||||
asyncExplorer.load().then(({ config, filePath }) => ({ config, filePath }));
|
||||
|
||||
asyncExplorer.clearFileCache();
|
||||
asyncExplorer.clearDirectoryCache();
|
||||
asyncExplorer.clearCaches();
|
||||
|
||||
const syncExplorer = cosmiconfig("yourModuleName", {
|
||||
packageProp: "yourModuleName",
|
||||
rc: ".yourModuleNamerc",
|
||||
js: "yourModuleName.config.js",
|
||||
rcStrictJson: false,
|
||||
rcExtensions: false,
|
||||
stopDir: "someDir",
|
||||
cache: true,
|
||||
sync: true,
|
||||
transform: ({ config, filePath }) => ({ config, filePath }),
|
||||
format: "js"
|
||||
});
|
||||
|
||||
const { config, filePath } = syncExplorer.load();
|
||||
explorer.clearLoadCache();
|
||||
explorer.clearSearchCache();
|
||||
explorer.clearCaches();
|
||||
|
||||
Vendored
+41
-46
@@ -1,63 +1,58 @@
|
||||
// Type definitions for cosmiconfig 4.0
|
||||
// Type definitions for cosmiconfig 5.0
|
||||
// Project: https://github.com/davidtheclark/cosmiconfig
|
||||
// Definitions by: ozum <https://github.com/ozum>
|
||||
// szeck87 <https://github.com/szeck87>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
interface Result {
|
||||
config: object;
|
||||
filePath: string;
|
||||
/// <reference types="node" />
|
||||
|
||||
export interface Config {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
packageProp?: string | false;
|
||||
rc?: string | false;
|
||||
js?: string | false;
|
||||
rcStrictJson?: boolean;
|
||||
rcExtensions?: boolean;
|
||||
stopDir?: string;
|
||||
cache?: boolean;
|
||||
transform?: (result: Result) => Promise<Result> | Result;
|
||||
configPath?: string;
|
||||
format?: "json" | "yaml" | "js";
|
||||
export type CosmiconfigResult = {
|
||||
config: Config;
|
||||
filePath: string;
|
||||
isEmpty?: boolean;
|
||||
} | null;
|
||||
|
||||
export interface LoaderResult {
|
||||
config: Config | null;
|
||||
filepath: string;
|
||||
}
|
||||
|
||||
// Default is false and makes load() method async
|
||||
interface AsyncOptions extends Options {
|
||||
sync?: false;
|
||||
export type SyncLoader = (filepath: string, content: string) => Config | null;
|
||||
export type AsyncLoader = (filepath: string, content: string) => Config | null | Promise<object | null>;
|
||||
|
||||
export interface LoaderEntry {
|
||||
sync?: SyncLoader;
|
||||
async?: AsyncLoader;
|
||||
}
|
||||
|
||||
// Makes load() method sync
|
||||
interface SyncOptions extends Options {
|
||||
sync: true;
|
||||
export interface Loaders {
|
||||
[key: string]: LoaderEntry;
|
||||
}
|
||||
|
||||
interface Explorer {
|
||||
clearFileCache(): void;
|
||||
clearDirectoryCache(): void;
|
||||
clearCaches(): void;
|
||||
export interface Explorer {
|
||||
search(searchFrom: string): Promise<null | CosmiconfigResult>;
|
||||
searchSync(searchFrom: string): null | CosmiconfigResult;
|
||||
load(loadPath: string): Promise<CosmiconfigResult>;
|
||||
loadSync(loadPath: string): CosmiconfigResult;
|
||||
clearLoadCache(): void;
|
||||
clearSearchCache(): void;
|
||||
clearCaches(): void;
|
||||
}
|
||||
|
||||
interface AsyncExplorer extends Explorer {
|
||||
// You should provide either searchPath or configPath for load method. To disallow both, overloaded definitions added.
|
||||
load(searchPath?: string): Promise<Result>;
|
||||
load(searchPath: null | undefined, configPath?: string): Promise<Result>;
|
||||
// These are the user options with defaults applied.
|
||||
export interface ExplorerOptions {
|
||||
stopDir?: string;
|
||||
cache?: boolean;
|
||||
transform?: (result: CosmiconfigResult) => Promise<CosmiconfigResult> | CosmiconfigResult;
|
||||
packageProp?: string;
|
||||
loaders?: Loaders;
|
||||
searchPlaces?: string[];
|
||||
ignoreEmptySearchPlaces?: boolean;
|
||||
}
|
||||
|
||||
interface SyncExplorer extends Explorer {
|
||||
// You should provide either searchPath or configPath for load method. To disallow both, overloaded definitions added.
|
||||
load(searchPath?: string): Result;
|
||||
load(searchPath: null | undefined, configPath?: string): Result;
|
||||
}
|
||||
|
||||
declare function cosmiconfig(
|
||||
moduleName: string,
|
||||
options: SyncOptions
|
||||
): SyncExplorer;
|
||||
|
||||
declare function cosmiconfig(
|
||||
moduleName: string,
|
||||
options?: AsyncOptions
|
||||
): AsyncExplorer;
|
||||
|
||||
export = cosmiconfig;
|
||||
export default function cosmiconfig(moduleName: string, options: ExplorerOptions): Explorer;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import cosmiconfig = require("cosmiconfig");
|
||||
|
||||
const asyncExplorer = cosmiconfig("yourModuleName", {
|
||||
packageProp: "yourModuleName",
|
||||
rc: ".yourModuleNamerc",
|
||||
js: "yourModuleName.config.js",
|
||||
rcStrictJson: false,
|
||||
rcExtensions: false,
|
||||
stopDir: "someDir",
|
||||
cache: true,
|
||||
sync: false,
|
||||
transform: ({ config, filePath }) => ({ config, filePath }),
|
||||
format: "js"
|
||||
});
|
||||
|
||||
Promise.all([
|
||||
asyncExplorer.load(),
|
||||
asyncExplorer.load("start/search/here"),
|
||||
asyncExplorer.load(null, "load/this/file.json")
|
||||
]).then(result => result);
|
||||
|
||||
asyncExplorer.load().then(({ config, filePath }) => ({ config, filePath }));
|
||||
|
||||
asyncExplorer.clearFileCache();
|
||||
asyncExplorer.clearDirectoryCache();
|
||||
asyncExplorer.clearCaches();
|
||||
|
||||
const syncExplorer = cosmiconfig("yourModuleName", {
|
||||
packageProp: "yourModuleName",
|
||||
rc: ".yourModuleNamerc",
|
||||
js: "yourModuleName.config.js",
|
||||
rcStrictJson: false,
|
||||
rcExtensions: false,
|
||||
stopDir: "someDir",
|
||||
cache: true,
|
||||
sync: true,
|
||||
transform: ({ config, filePath }) => ({ config, filePath }),
|
||||
format: "js"
|
||||
});
|
||||
|
||||
const { config, filePath } = syncExplorer.load();
|
||||
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
// Type definitions for cosmiconfig 4.0
|
||||
// Project: https://github.com/davidtheclark/cosmiconfig
|
||||
// Definitions by: ozum <https://github.com/ozum>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
interface Result {
|
||||
config: object;
|
||||
filePath: string;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
packageProp?: string | false;
|
||||
rc?: string | false;
|
||||
js?: string | false;
|
||||
rcStrictJson?: boolean;
|
||||
rcExtensions?: boolean;
|
||||
stopDir?: string;
|
||||
cache?: boolean;
|
||||
transform?: (result: Result) => Promise<Result> | Result;
|
||||
configPath?: string;
|
||||
format?: "json" | "yaml" | "js";
|
||||
}
|
||||
|
||||
// Default is false and makes load() method async
|
||||
interface AsyncOptions extends Options {
|
||||
sync?: false;
|
||||
}
|
||||
|
||||
// Makes load() method sync
|
||||
interface SyncOptions extends Options {
|
||||
sync: true;
|
||||
}
|
||||
|
||||
interface Explorer {
|
||||
clearFileCache(): void;
|
||||
clearDirectoryCache(): void;
|
||||
clearCaches(): void;
|
||||
}
|
||||
|
||||
interface AsyncExplorer extends Explorer {
|
||||
// You should provide either searchPath or configPath for load method. To disallow both, overloaded definitions added.
|
||||
load(searchPath?: string): Promise<Result>;
|
||||
load(searchPath: null | undefined, configPath?: string): Promise<Result>;
|
||||
}
|
||||
|
||||
interface SyncExplorer extends Explorer {
|
||||
// You should provide either searchPath or configPath for load method. To disallow both, overloaded definitions added.
|
||||
load(searchPath?: string): Result;
|
||||
load(searchPath: null | undefined, configPath?: string): Result;
|
||||
}
|
||||
|
||||
declare function cosmiconfig(
|
||||
moduleName: string,
|
||||
options: SyncOptions
|
||||
): SyncExplorer;
|
||||
|
||||
declare function cosmiconfig(
|
||||
moduleName: string,
|
||||
options?: AsyncOptions
|
||||
): AsyncExplorer;
|
||||
|
||||
export = cosmiconfig;
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": ["../../"],
|
||||
"paths": {
|
||||
"cosmiconfig": [ "cosmiconfig/v4" ]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts", "cosmiconfig-tests.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user