heroku / heroku/node-heroku-client

Replace deprecated url.parse() with new URL() in lib/url.js

Open
#170 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
193
Forks
42
Avg merge
17h 39m
Merged PRs (30d)
5

Description

## Summary

`lib/url.js` unconditionally uses `url.parse()`, which triggers [DEP0169](https://nodejs.org/api/deprecations.html#DEP0169) on Node.js 22+.

```js
var uu = url.parse(u)
```

This affects both `3.1.0` and `3.1.1`.

## Suggested Fix

Replace `url.parse()` with the WHATWG `URL` constructor:

```js
'use strict'

module.exports = function (u) {
if (u.indexOf('http') !== 0 && u.indexOf('https') !== 0) {
u = 'https://' + u
}

const uu = new URL(u)
const port = uu.port || (uu.protocol === 'https:' ? '443' : '80')
const secure = uu.protocol === 'https:' || uu.port === '443'

return { host: uu.hostname, port: parseInt(port), secure: secure }
}
```

## Environment

- Node.js 22+
- heroku-client 3.1.0 / 3.1.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.