mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(degit): new type definition (#45756)
- definition files for 'Rich-Harris/degit' - tests https://github.com/Rich-Harris/degit#readme https://github.com/Rich-Harris/degit#javascript-api Thanks!
This commit is contained in:
parent
47bbd21d49
commit
e51f3c2609
38
types/degit/degit-tests.ts
Normal file
38
types/degit/degit-tests.ts
Normal file
@ -0,0 +1,38 @@
|
||||
/// <reference types="node" />
|
||||
import degit from 'degit';
|
||||
import { DegitError } from 'degit/utils';
|
||||
|
||||
const emitter = degit('user/repo', {
|
||||
cache: true,
|
||||
force: true,
|
||||
verbose: true,
|
||||
mode: 'git',
|
||||
});
|
||||
|
||||
emitter.on('info', info => {
|
||||
console.log(info.message);
|
||||
});
|
||||
emitter.on('warn', info => {
|
||||
console.log(info.message);
|
||||
});
|
||||
|
||||
emitter.clone('path/to/dest').then(() => {
|
||||
console.log('done');
|
||||
});
|
||||
emitter.remove('path/to/dir', 'path/to/dest', {
|
||||
action: 'remove',
|
||||
files: ['README.md'],
|
||||
});
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await emitter.clone('path/to/dest');
|
||||
} catch (error) {
|
||||
if (error instanceof DegitError) {
|
||||
error.code; // $ExpectType DegitErrorCode
|
||||
error.original; // $ExpectType Error | undefined
|
||||
error.ref; // $ExpectTpe string | undefined
|
||||
error.url; // $ExpectType string | undefined
|
||||
}
|
||||
}
|
||||
})();
|
||||
89
types/degit/index.d.ts
vendored
Normal file
89
types/degit/index.d.ts
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
// Type definitions for degit 2.8
|
||||
// Project: https://github.com/Rich-Harris/degit#readme
|
||||
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
export default function degit(src: string, opts: Options): Degit;
|
||||
|
||||
export class Degit extends EventEmitter {
|
||||
constructor(src: string, opts?: Options);
|
||||
|
||||
/**
|
||||
* @async
|
||||
*/
|
||||
clone(dest: string): Promise<void>;
|
||||
/**
|
||||
* @async
|
||||
*/
|
||||
remove(dir: string, dest: string, action: RemoveAction): Promise<void>;
|
||||
on(event: 'info' | 'warn', callback: (info: Info) => void): this;
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
* @default false
|
||||
*/
|
||||
cache?: boolean;
|
||||
/**
|
||||
* @default false
|
||||
*/
|
||||
force?: boolean;
|
||||
/**
|
||||
* @default undefined
|
||||
*/
|
||||
mode?: ValidModes;
|
||||
/**
|
||||
* @default false
|
||||
*/
|
||||
verbose?: boolean;
|
||||
}
|
||||
|
||||
// varia
|
||||
export type ValidModes = 'tar' | 'git';
|
||||
|
||||
export type InfoCode =
|
||||
| 'SUCCESS'
|
||||
| 'FILE_DOES_NOT_EXIST'
|
||||
| 'REMOVED'
|
||||
| 'DEST_NOT_EMPTY'
|
||||
| 'DEST_IS_EMPTY'
|
||||
| 'USING_CACHE'
|
||||
| 'FOUND_MATCH'
|
||||
| 'FILE_EXISTS'
|
||||
| 'PROXY'
|
||||
| 'DOWNLOADING'
|
||||
| 'EXTRACTING';
|
||||
|
||||
export type DegitErrorCode =
|
||||
| 'DEST_NOT_EMPTY'
|
||||
| 'MISSING_REF'
|
||||
| 'COULD_NOT_DOWNLOAD'
|
||||
| 'BAD_SRC'
|
||||
| 'UNSUPPORTED_HOST'
|
||||
| 'BAD_REF'
|
||||
| 'COULD_NOT_FETCH';
|
||||
|
||||
export interface Info {
|
||||
readonly code: string;
|
||||
readonly message: string;
|
||||
readonly repo: Degit;
|
||||
readonly dest: string;
|
||||
}
|
||||
|
||||
export interface Action {
|
||||
action: string;
|
||||
cache?: boolean;
|
||||
verbose?: boolean;
|
||||
}
|
||||
|
||||
export interface DegitAction extends Action {
|
||||
action: 'clone';
|
||||
src: string;
|
||||
}
|
||||
|
||||
export interface RemoveAction extends Action {
|
||||
action: 'remove';
|
||||
files: string[];
|
||||
}
|
||||
23
types/degit/tsconfig.json
Normal file
23
types/degit/tsconfig.json
Normal 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",
|
||||
"degit-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/degit/tslint.json
Normal file
1
types/degit/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
29
types/degit/utils.d.ts
vendored
Normal file
29
types/degit/utils.d.ts
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
import { DegitErrorCode } from './index';
|
||||
|
||||
export const degitConfigName: string;
|
||||
|
||||
export class DegitError extends Error {
|
||||
code: DegitErrorCode;
|
||||
original?: Error;
|
||||
ref?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export function tryRequire(
|
||||
file: string,
|
||||
opts?: {
|
||||
clearCache?: true;
|
||||
},
|
||||
): unknown;
|
||||
|
||||
export function exec(command: string): Promise<{ stdout: string; stderr: string }>;
|
||||
|
||||
export function mkdirp(dir: string): void;
|
||||
|
||||
export function fetch(url: string, dest: string, proxy: string): Promise<void>;
|
||||
|
||||
export function stashFiles(dir: string, dest: string): void;
|
||||
|
||||
export function unstashFiles(dir: string, dest: string): void;
|
||||
|
||||
export const base: string;
|
||||
Loading…
Reference in New Issue
Block a user