feat(ncp): Add support for top‑level export (#39273)

* feat(ncp): Add support for top‑level export

* test(ncp): Fix tests on TypeScript < 2.6

* refactor(ncp): Apply Prettier formatting

* chore(ncp): Remove `.editorconfig` 😡
This commit is contained in:
ExE Boss
2019-11-04 10:00:26 -08:00
committed by Nathan Shively-Sanders
parent 165ec21fb4
commit c84905685e
4 changed files with 150 additions and 141 deletions
+62 -11
View File
@@ -1,20 +1,71 @@
// Type definitions for ncp v2.0.0
// Type definitions for ncp 2.0
// Project: https://github.com/AvianFlu/ncp
// Definitions by: Bart van der Schoor <https://github.com/bartvds>
// Benoit Lemaire <https://github.com/belemaire>
// ExE Boss <https://github.com/ExE-Boss>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import * as fs from 'fs';
export function ncp(source: string, destination: string, callback: (err: Error) => void): void;
export function ncp(source: string, destination: string, options: Options, callback: (err: Error) => void): void;
declare namespace ncp {
interface File {
name: string;
mode: number;
interface Options {
filter?: RegExp | ((filename: string) => boolean);
transform?: (read: NodeJS.ReadableStream, write: NodeJS.WritableStream) => void;
clobber?: boolean;
dereference?: boolean;
stopOnErr?: boolean;
errs?: NodeJS.WritableStream;
limit?: number;
/** Accessed time */
atime: Date;
/** Modified time */
mtime: Date;
}
interface Options {
filter?: RegExp | ((filename: string) => boolean);
transform?: (read: NodeJS.ReadableStream, write: NodeJS.WritableStream, file: File) => void;
clobber?: boolean;
dereference?: boolean;
stopOnErr?: boolean;
errs?: fs.PathLike;
limit?: number;
}
}
declare const ncp: {
(source: string, destination: string, callback: (err: Error[] | null) => void): void;
(
source: string,
destination: string,
options: ncp.Options & { stopOnErr: true },
callback: (err: Error | null) => void,
): void;
(
source: string,
destination: string,
options: ncp.Options & { errs?: undefined },
callback: (err: Error[] | null) => void,
): void;
(
source: string,
destination: string,
options: ncp.Options & { errs: fs.PathLike },
callback: (err: fs.WriteStream | null) => void,
): void;
(
source: string,
destination: string,
options: ncp.Options,
callback: (err: Error | Error[] | fs.WriteStream | null) => void,
): void;
ncp: typeof ncp;
/**
* **NOTE:** This function provides design-time support for util.promisify.
*
* It does not exist at runtime.
*/
__promisify__(source: string, destination: string, options?: ncp.Options): Promise<void>;
};
export = ncp;
+69 -28
View File
@@ -1,39 +1,80 @@
import ncp = require('ncp');
import stream = require('stream');
import { ncp as ncpCB } from 'ncp';
import * as util from 'util';
var opts: ncp.Options;
opts = {};
opts = {
filter: /abc/
};
opts = {
filter: (filename: string) => true
};
opts = {
transform: (read: NodeJS.ReadableStream, write: NodeJS.WritableStream) => {
/**
* The `expectType` function from https://www.npmjs.com/package/tsd,
* except instead of returning `void`, it returns `T`.
*/
declare function expectType<T>(t: T): T;
}
};
let opts: ncp.Options = {};
const errs = Buffer.alloc(4096);
const opts$StreamErr = (opts = { errs });
opts = { filter: /abc/ };
opts = { filter: (filename: string) => true };
opts = {
clobber: false
};
opts = {
dereference: false
};
opts = {
stopOnErr: false
};
opts = {
errs: new stream.Writable()
};
opts = {
limit: 512
transform: (read: NodeJS.ReadableStream, write: NodeJS.WritableStream, file: ncp.File) => {
file; // $ExpectType File
file.name; // $ExpectType string
file.mode; // $ExpectType number
file.atime; // $ExpectType Date
file.mtime; // $ExpectType Date
},
};
opts = { clobber: false };
opts = { dereference: false };
opts = { stopOnErr: false };
opts = { limit: 512 };
ncp.ncp('foo', 'bar', (err: Error) => {
// $ExpectType Options
opts;
ncp('foo', 'bar', err => {
err; // $ExpectType Error[] | null
});
ncp.ncp('foo', 'bar', opts, (err: Error) => {
ncp(
'foo',
'bar',
{
stopOnErr: true,
},
err => {
err; // $ExpectType Error | null
},
);
ncp(
'foo',
'bar',
{
errs,
stopOnErr: true,
},
err => {
err; // $ExpectType Error | null
},
);
ncp('foo', 'bar', opts$StreamErr, err => {
err; // $ExpectType WriteStream | null
});
ncp.ncp('foo', 'bar', err => {
err; // $ExpectType Error[] | null
});
ncp.ncp('foo', 'bar', opts, err => {
err; // $ExpectType Error | Error[] | WriteStream | null
});
// $ExpectType (source: string, destination: string, options?: Options | undefined) => Promise<void>
expectType<(source: string, destination: string, options?: ncp.Options) => Promise<void>>(util.promisify(ncp));
// $ExpectType (source: string, destination: string, options?: Options | undefined) => Promise<void>
expectType<(source: string, destination: string, options?: ncp.Options) => Promise<void>>(util.promisify(ncp.ncp));
// Both import forms are identical
expectType<typeof ncp.ncp>(ncpCB);
expectType<typeof ncpCB>(ncp.ncp);
+18 -22
View File
@@ -1,23 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ncp-tests.ts"
]
}
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ncp-tests.ts"
]
}
+1 -80
View File
@@ -1,80 +1 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"npm-naming": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}
{ "extends": "dtslint/dt.json" }