From 0508c6a7615c3056a38c972c4212972d0c03d771 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Sun, 27 Oct 2024 16:23:33 +0100 Subject: [PATCH] refactor!: replace `is-promise` dependency with `instanceof` check BREAKING: drops support for non-native promises Closes #136 Signed-off-by: Jon Koops --- HISTORY.md | 1 + index.js | 3 +-- lib/layer.js | 5 ++--- package.json | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 5f69004..0f84543 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ unreleased * Remove `Object.setPrototypeOf` polyfill * Use `Array.flat` instead of `array-flatten` package * Replace `methods` dependency with standard library +* Replace `is-promise` dependency with `instanceof` check (drops support for non-native promises) 2.0.0 / 2024-09-09 ================== diff --git a/index.js b/index.js index b806282..5cdc73e 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,6 @@ * @private */ -const isPromise = require('is-promise') const Layer = require('./lib/layer') const methods = require('methods') const mixin = require('utils-merge') @@ -639,7 +638,7 @@ function processParams (params, layer, called, req, res, done) { try { const ret = fn(req, res, paramCallback, paramVal, key) - if (isPromise(ret)) { + if (ret instanceof Promise) { ret.then(null, function (error) { paramCallback(error || new Error('Rejected promise')) }) diff --git a/lib/layer.js b/lib/layer.js index e2fcba8..0694591 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -12,7 +12,6 @@ * @private */ -const isPromise = require('is-promise') const pathRegexp = require('path-to-regexp') /** @@ -113,7 +112,7 @@ Layer.prototype.handleError = function handleError (error, req, res, next) { const ret = fn(error, req, res, next) // wait for returned promise - if (isPromise(ret)) { + if (ret instanceof Promise) { ret.then(null, function (error) { next(error || new Error('Rejected promise')) }) @@ -145,7 +144,7 @@ Layer.prototype.handleRequest = function handleRequest (req, res, next) { const ret = fn(req, res, next) // wait for returned promise - if (isPromise(ret)) { + if (ret instanceof Promise) { ret.then(null, function (error) { next(error || new Error('Rejected promise')) }) diff --git a/package.json b/package.json index cbbba3b..9003083 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "license": "MIT", "repository": "pillarjs/router", "dependencies": { - "is-promise": "4.0.0", "parseurl": "~1.3.3", "path-to-regexp": "^8.0.0", "utils-merge": "1.0.1"