Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: replace is-promise dependency with instanceof check #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading