Skip to content

Commit

Permalink
refactor!: replace is-promise dependency with instanceof check
Browse files Browse the repository at this point in the history
BREAKING: drops support for non-native promises

Closes pillarjs#136

Signed-off-by: Jon Koops <[email protected]>
  • Loading branch information
jonkoops committed Oct 27, 2024
1 parent 878b0e0 commit 0508c6a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
==================
Expand Down
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* @private
*/

const isPromise = require('is-promise')
const Layer = require('./lib/layer')
const methods = require('methods')
const mixin = require('utils-merge')
Expand Down Expand Up @@ -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'))
})
Expand Down
5 changes: 2 additions & 3 deletions lib/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* @private
*/

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

/**
Expand Down Expand Up @@ -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'))
})
Expand Down Expand Up @@ -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'))
})
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0508c6a

Please sign in to comment.