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

fix: compatible with Node.js 14 #60

Merged
merged 2 commits into from Apr 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -11,6 +11,7 @@ node_js:
- "10"
- "12"
- "13"
- "14"

script:
- npm run eslint
Expand Down
5 changes: 4 additions & 1 deletion lib/fs.js
Expand Up @@ -89,6 +89,8 @@ function checkParentSync(path) {
function writeFile(path, data, options, callback) {
if (!path) throw new TypeError('path is required!');

if (!data) data = '';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test cases we use writeFile(path) to create an empty file (leave data as an undefined value) will no longer be accepted by Node.js 14.


if (!callback && typeof options === 'function') {
callback = options;
options = {};
Expand Down Expand Up @@ -127,6 +129,7 @@ function copyFile(src, dest, flags, callback) {
if (!dest) throw new TypeError('dest is required!');
if (typeof flags === 'function') {
callback = flags;
flags = undefined;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node.js 14 implemented a type check (nodejs/node@a13500f) so flags won't accept function any more.

}

return checkParent(dest).then(() => fsPromises.copyFile(src, dest, flags)).asCallback(callback);
Expand Down Expand Up @@ -190,7 +193,7 @@ async function _copyDir(src, dest, options, parent) {
return _copyDir(childSrc, childDest, options, currentPath);
}

return copyFile(childSrc, childDest, options).thenReturn(currentPath);
return copyFile(childSrc, childDest).thenReturn(currentPath);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options here is for copyDir ({ ignoreHidden, ignorePattern }) which is not related with copyFile, so I just simply remove it.

}), reduceFiles, []);
}

Expand Down