Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[copy-dir] Add definition #4496

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions definitions/npm/copy-dir_v1.x.x/flow_v0.83.x-/copy-dir_v1.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
declare module 'copy-dir' {
declare type Options = {|
/**
* keep addTime or modifyTime if true
*/
utimes?:
| boolean
| {|
atime: string | number | Date,
mtime: string | number | Date,
|},
/**
* keep file mode if true
*/
mode?: boolean | number,
/**
* cover if file exists
*/
cover?: boolean,
/**
* file filter
*/
filter?:
| boolean
| (state: string, filepath: string, filename: string) => boolean,
|};

declare type Callback = (error: Error) => void

declare module.exports: {|
(from: string, to: string, options?: Options, callback?: Callback): void,
sync: (from: string, to: string, options?: Options) => void,
|};
}
113 changes: 113 additions & 0 deletions definitions/npm/copy-dir_v1.x.x/flow_v0.83.x-/test_copy-dir_v1.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// @flow
import { describe, test } from 'flow-typed-test';
import copydir from 'copy-dir';

describe('copy-dir', () => {
describe('async', () => {
test('basic', () => {
(copydir('from', 'to'): void);
// $FlowExpectedError[incompatible-call]
copydir();
// $FlowExpectedError[incompatible-call]
copydir('from');
// $FlowExpectedError[incompatible-cast]
(copydir('from', 'to'): string)
});

test('takes options', () => {
copydir('from', 'to', {});
copydir('from', 'to', {
utimes: true,
mode: true,
cover: true,
filter: true,
});
copydir('from', 'to', {
utimes: {
atime: 1,
mtime: 1,
},
});
copydir('from', 'to', {
mode: 1,
});
copydir('from', 'to', {
filter: () => true,
});

copydir('from', 'to', {
// $FlowExpectedError[incompatible-call]
utimes: '',
});
copydir('from', 'to', {
// $FlowExpectedError[incompatible-call]
mode: '',
});
copydir('from', 'to', {
// $FlowExpectedError[incompatible-call]
cover: '',
});
copydir('from', 'to', {
// $FlowExpectedError[incompatible-call]
filter: '',
});
});

test('callback', () => {
copydir('from', 'to', undefined, (err: Error) => {
return undefined;
});
});
});

describe('sync', () => {
test('basic', () => {
(copydir.sync('from', 'to'): void);
// $FlowExpectedError[incompatible-call]
copydir.sync();
// $FlowExpectedError[incompatible-call]
copydir.sync('from');
// $FlowExpectedError[incompatible-cast]
(copydir.sync('from', 'to'): string)
});

test('takes options', () => {
copydir.sync('from', 'to', {});
copydir.sync('from', 'to', {
utimes: true,
mode: true,
cover: true,
filter: true,
});
copydir.sync('from', 'to', {
utimes: {
atime: 1,
mtime: 1,
},
});
copydir.sync('from', 'to', {
mode: 1,
});
copydir.sync('from', 'to', {
filter: () => true,
});

copydir.sync('from', 'to', {
// $FlowExpectedError[incompatible-call]
utimes: '',
});
copydir.sync('from', 'to', {
// $FlowExpectedError[incompatible-call]
mode: '',
});
copydir.sync('from', 'to', {
// $FlowExpectedError[incompatible-call]
cover: '',
});
copydir.sync('from', 'to', {
// $FlowExpectedError[incompatible-call]
filter: '',
});
});
});
});
Loading