Created
November 25, 2020 03:06
-
-
Save tankywoo/3da39f45751da31268fcaf0a8e431a6e to your computer and use it in GitHub Desktop.
Fix gitbook-cli graceful-fs/polyfills.js cb.apply is not a function problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As gitbook-cli is no longer maintained, there is a bug for its required library. | |
> /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287 | |
> if (cb) cb.apply(this, arguments) | |
> ^ | |
> TypeError: cb.apply is not a function | |
> at /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18 | |
For MacOS, the patch file is: | |
/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js | |
ref: | |
- https://stackoverflow.com/a/64211387/1276501 | |
- https://github.com/isaacs/node-graceful-fs/commit/168bdb8f0bb3174e8499d4bc5878deead4172c39 | |
--- polyfills.js 2020-11-25 10:50:00.000000000 +0800 | |
+++ polyfills.js 2020-11-25 10:50:10.000000000 +0800 | |
@@ -279,13 +279,21 @@ | |
if (!orig) return orig | |
// Older versions of Node erroneously returned signed integers for | |
// uid + gid. | |
- return function (target, cb) { | |
- return orig.call(fs, target, function (er, stats) { | |
- if (!stats) return cb.apply(this, arguments) | |
+ return function (target, options, cb) { | |
+ if (typeof options === 'function') { | |
+ cb = options | |
+ options = null | |
+ } | |
+ function callback(err, stats) { | |
+ if (!stats && cb) return cb.apply(this, arguments) | |
if (stats.uid < 0) stats.uid += 0x100000000 | |
if (stats.gid < 0) stats.gid += 0x100000000 | |
if (cb) cb.apply(this, arguments) | |
- }) | |
+ } | |
+ if (options) { | |
+ return orig.call(fs, target, options, callback); | |
+ } | |
+ return orig.call(fs, target, callback); | |
} | |
} | |
@@ -293,8 +301,14 @@ | |
if (!orig) return orig | |
// Older versions of Node erroneously returned signed integers for | |
// uid + gid. | |
- return function (target) { | |
- var stats = orig.call(fs, target) | |
+ return function (target, options) { | |
+ var stats | |
+ if (options) { | |
+ stats = orig.call(fs, target, options) | |
+ } else { | |
+ stats = orig.call(fs, target) | |
+ } | |
+ | |
if (stats.uid < 0) stats.uid += 0x100000000 | |
if (stats.gid < 0) stats.gid += 0x100000000 | |
return stats; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment