util polyfill does not include callbackify, promisify and other utilities
関連するプルリクエストがすでにマージされています。
- #65 @MichaelDeBoey による — マージ済み
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript, node.js
- 領域
- build-system, tooling
調査の方向性
まず polyfills/util.js の実装を見つけ、エクスポートされているユーティリティを、issue に含まれている callbackify の diff と比較します。デフォルトエクスポートがどのように組み立てられているかを確認し、プロジェクトに既存の検証経路を特定します。完了の条件は、util polyfill が callbackify を公開し、報告された web3.js のユースケースでローカルパッチが不要になることです。
索引モデルが issue の本文から書いたものです。
説明
Hi there
Firstly, thanks for your work on this project! 🙂
It seems that the util polyfill is outdated and doesn't include callbackify. It would be awesome if you could add it or depend on node-util directly.
FWIW @remorses @ryanflorence I ended up discovering this because I use remix-run which uses @esbuild-plugins/node-modules-polyfill. Specifically web3.js uses callbackify somewhere in their codebase.
Here's the diff.
diff --git a/node_modules/rollup-plugin-node-polyfills/polyfills/util.js b/node_modules/rollup-plugin-node-polyfills/polyfills/util.js
index 2194380..a00ee54 100644
--- a/node_modules/rollup-plugin-node-polyfills/polyfills/util.js
+++ b/node_modules/rollup-plugin-node-polyfills/polyfills/util.js
@@ -18,6 +18,17 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
+ function getOwnPropertyDescriptors(obj) {
+ var keys = Object.keys(obj);
+ var descriptors = {};
+ for (var i = 0; i < keys.length; i++) {
+ descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
+ }
+ return descriptors;
+ };
+
import process from 'process';
var formatRegExp = /%[sdj%]/g;
export function format(f) {
@@ -572,6 +583,54 @@ function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
+function callbackifyOnRejected(reason, cb) {
+ // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
+ // Because `null` is a special error value in callbacks which means "no error
+ // occurred", we error-wrap so the callback consumer can distinguish between
+ // "the promise rejected with null" or "the promise fulfilled with undefined".
+ if (!reason) {
+ var newReason = new Error('Promise was rejected with a falsy value');
+ newReason.reason = reason;
+ reason = newReason;
+ }
+ return cb(reason);
+}
+
+export function callbackify(original) {
+ if (typeof original !== 'function') {
+ throw new TypeError('The "original" argument must be of type Function');
+ }
+
+ // We DO NOT return the promise as it gives the user a false sense that
+ // the promise is actually somehow related to the callback's execution
+ // and that the callback throwing will reject the promise.
+ function callbackified() {
+ var args = [];
+ for (var i = 0; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ }
+
+ var maybeCb = args.pop();
+ if (typeof maybeCb !== 'function') {
+ throw new TypeError('The last argument must be of type Function');
+ }
+ var self = this;
+ var cb = function() {
+ return maybeCb.apply(self, arguments);
+ };
+ // In true node style we process the callback on `nextTick` with all the
+ // implications (stack, `uncaughtException`, `async_hooks`)
+ original.apply(this, args)
+ .then(function(ret) { process.nextTick(cb.bind(null, null, ret)) },
+ function(rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
+ }
+
+ Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
+ Object.defineProperties(callbackified,
+ getOwnPropertyDescriptors(original));
+ return callbackified;
+}
+
export default {
inherits: inherits,
_extend: _extend,
@@ -594,5 +653,6 @@ export default {
inspect: inspect,
deprecate: deprecate,
format: format,
- debuglog: debuglog
+ debuglog: debuglog,
+ callbackify: callbackify,
}
This issue body was partially generated by patch-package.
- 主要言語
- JavaScript
- スター
- 142
- フォーク
- 64
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ionic-team/rollup-plugin-node-polyfills のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
ionic-team/rollup-plugin-node-polyfills#62 · コメント 2 件 · リアクション 6 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
ionic-team/rollup-plugin-node-polyfills#56 · リアクション 11 件 ·
-
Type Error Importerオープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
-
node:pathオープン
難易度 4/5 3〜5日 初心者へのやさしさ 20/100
ionic-team/rollup-plugin-node-polyfills#51 · リアクション 2 件 ·
ionic-team/rollup-plugin-node-polyfills の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
thedevs-network/kutt#1059 ·
-
good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
0. Needs triage 35-feedback bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信