util polyfill does not include callbackify, promisify and other utilities
Một pull request liên quan đã được merge.
- #65 của @MichaelDeBoey — đã merge
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js
- Lĩnh vực
- build-system, tooling
Hướng nghiên cứu
Bắt đầu bằng cách xác định phần triển khai của polyfills/util.js và so sánh các tiện ích được export của nó với diff callbackify được đưa vào issue. Xác nhận cách default export được ghép lại và xác định quy trình validation hiện có của dự án; hoàn tất khi util polyfill cung cấp callbackify và use case web3.js được báo cáo không còn cần bản vá cục bộ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- JavaScript
- Star
- 142
- Fork
- 64
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ionic-team/rollup-plugin-node-polyfills
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
ionic-team/rollup-plugin-node-polyfills#62 · 2 bình luận · 6 reaction ·
-
Feature Request: http2 polyfillĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
ionic-team/rollup-plugin-node-polyfills#56 · 11 reaction ·
-
Type Error ImporterĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
-
node:pathĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
ionic-team/rollup-plugin-node-polyfills#51 · 2 reaction ·
Tất cả issue của ionic-team/rollup-plugin-node-polyfills
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bluerobotics/Cockpit-docs#48 ·
-
README is out of date: broken badge, wrong command name, wrong Node version, placeholder URLsĐang mởdocumentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PhyberApex/slds-json-schema-renderer#372 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
usage: a custom provider's balance meters ("…%" in the balance path) ignore the Left/Used switchĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] rag: sentence content can cross the reported sentence boundariesCó thể đã có người làm @LJK-ikun đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày