Skip to content

Commit

Permalink
Merge pull request #4 from danieldietrich/decl-merging
Browse files Browse the repository at this point in the history
Exporting types
  • Loading branch information
danieldietrich authored Sep 23, 2019
2 parents a86fa91 + 6743a3f commit 5cad850
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@ import fs from 'fs';
import path from 'path';
import { promisify } from 'util';

// compatible to fs-extra.copy
type Options = {
overwrite?: boolean;
errorOnExist?: boolean;
dereference?: boolean;
preserveTimestamps?: boolean;
chown?: number;
chgrp?: number;
dryRun?: boolean;
filter?: (source: string, target: string, sourceStats: fs.Stats, targetStats: fs.Stats | undefined) => boolean | Promise<boolean>;
transform?: (data: Buffer, source: string, target: string, sourceStats: fs.Stats, targetStats: fs.Stats | undefined) => Buffer | Promise<Buffer>;
};

type Totals = {
directories: number;
files: number;
symlinks: number;
size: number; // not size on disk in blocks
};

/**
* Recursively copies a path.
*
Expand All @@ -30,7 +10,7 @@ type Totals = {
* @options copy options
* @returns a new Promise which is resolved with totals or rejected with an error
*/
export = async function copy(sourcePath: string, targetPath: string, options?: Options): Promise<Totals> {
async function copy(sourcePath: string, targetPath: string, options?: copy.Options): Promise<copy.Totals> {

// promisify all the things as long as fs.promises is stage-1 experimental
const lchown = promisify(fs.lchown);
Expand All @@ -46,7 +26,7 @@ export = async function copy(sourcePath: string, targetPath: string, options?: O
const writeFile = promisify(fs.writeFile);

// same defaults as fs-extra.copy
const defaultOptions: Options = {
const defaultOptions: copy.Options = {
overwrite: true,
errorOnExist: false,
dereference: false,
Expand Down Expand Up @@ -155,4 +135,29 @@ export = async function copy(sourcePath: string, targetPath: string, options?: O

// [files, directories, symlinks, size]
type SubTotals = [number, number, number, number];
};
}

namespace copy {

// compatible to fs-extra.copy
export type Options = {
overwrite?: boolean;
errorOnExist?: boolean;
dereference?: boolean;
preserveTimestamps?: boolean;
chown?: number;
chgrp?: number;
dryRun?: boolean;
filter?: (source: string, target: string, sourceStats: fs.Stats, targetStats: fs.Stats | undefined) => boolean | Promise<boolean>;
transform?: (data: Buffer, source: string, target: string, sourceStats: fs.Stats, targetStats: fs.Stats | undefined) => Buffer | Promise<Buffer>;
};

export type Totals = {
directories: number;
files: number;
symlinks: number;
size: number; // not size on disk in blocks
};
}

export = copy;
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"no-any": true,
"no-console": false,
"no-empty": false,
"no-namespace": false,
"no-null-keyword": false,
"object-literal-key-quotes": false,
"object-literal-sort-keys": false,
Expand Down

0 comments on commit 5cad850

Please sign in to comment.