Skip to content

Commit 0508c6a

Browse files
committed
refactor!: replace is-promise dependency with instanceof check
BREAKING: drops support for non-native promises Closes #136 Signed-off-by: Jon Koops <[email protected]>
1 parent 878b0e0 commit 0508c6a

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

HISTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ unreleased
44
* Remove `Object.setPrototypeOf` polyfill
55
* Use `Array.flat` instead of `array-flatten` package
66
* Replace `methods` dependency with standard library
7+
* Replace `is-promise` dependency with `instanceof` check (drops support for non-native promises)
78

89
2.0.0 / 2024-09-09
910
==================

index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @private
1313
*/
1414

15-
const isPromise = require('is-promise')
1615
const Layer = require('./lib/layer')
1716
const methods = require('methods')
1817
const mixin = require('utils-merge')
@@ -639,7 +638,7 @@ function processParams (params, layer, called, req, res, done) {
639638

640639
try {
641640
const ret = fn(req, res, paramCallback, paramVal, key)
642-
if (isPromise(ret)) {
641+
if (ret instanceof Promise) {
643642
ret.then(null, function (error) {
644643
paramCallback(error || new Error('Rejected promise'))
645644
})

lib/layer.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @private
1313
*/
1414

15-
const isPromise = require('is-promise')
1615
const pathRegexp = require('path-to-regexp')
1716

1817
/**
@@ -113,7 +112,7 @@ Layer.prototype.handleError = function handleError (error, req, res, next) {
113112
const ret = fn(error, req, res, next)
114113

115114
// wait for returned promise
116-
if (isPromise(ret)) {
115+
if (ret instanceof Promise) {
117116
ret.then(null, function (error) {
118117
next(error || new Error('Rejected promise'))
119118
})
@@ -145,7 +144,7 @@ Layer.prototype.handleRequest = function handleRequest (req, res, next) {
145144
const ret = fn(req, res, next)
146145

147146
// wait for returned promise
148-
if (isPromise(ret)) {
147+
if (ret instanceof Promise) {
149148
ret.then(null, function (error) {
150149
next(error || new Error('Rejected promise'))
151150
})

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"license": "MIT",
1010
"repository": "pillarjs/router",
1111
"dependencies": {
12-
"is-promise": "4.0.0",
1312
"parseurl": "~1.3.3",
1413
"path-to-regexp": "^8.0.0",
1514
"utils-merge": "1.0.1"

0 commit comments

Comments
 (0)