Skip to content

Commit 4695e87

Browse files
fix: use URL.canParse instead of runtime deprecated url.parse api (#150)
1 parent dbc9ef1 commit 4695e87

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

lib/normalize-data.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Originally normalize-package-data
22

3-
const url = require('node:url')
3+
const { URL } = require('node:url')
44
const hostedGitInfo = require('hosted-git-info')
55
const validateLicense = require('validate-npm-package-license')
66

@@ -123,8 +123,7 @@ function normalizeData (data, changes) {
123123
if (typeof data.bugs === 'string') {
124124
if (isEmail(data.bugs)) {
125125
data.bugs = { email: data.bugs }
126-
/* eslint-disable-next-line node/no-deprecated-api */
127-
} else if (url.parse(data.bugs).protocol) {
126+
} else if (URL.canParse(data.bugs)) {
128127
data.bugs = { url: data.bugs }
129128
} else {
130129
changes?.push(`Bug string field must be url, email, or {email,url}`)
@@ -140,8 +139,7 @@ function normalizeData (data, changes) {
140139
const oldBugs = data.bugs
141140
data.bugs = {}
142141
if (oldBugs.url) {
143-
/* eslint-disable-next-line node/no-deprecated-api */
144-
if (typeof (oldBugs.url) === 'string' && url.parse(oldBugs.url).protocol) {
142+
if (URL.canParse(oldBugs.url)) {
145143
data.bugs.url = oldBugs.url
146144
} else {
147145
changes?.push('bugs.url field must be a string url. Deleted.')
@@ -216,8 +214,7 @@ function normalizeData (data, changes) {
216214
changes?.push('homepage field must be a string url. Deleted.')
217215
delete data.homepage
218216
} else {
219-
/* eslint-disable-next-line node/no-deprecated-api */
220-
if (!url.parse(data.homepage).protocol) {
217+
if (!URL.canParse(data.homepage)) {
221218
data.homepage = 'http://' + data.homepage
222219
}
223220
}

0 commit comments

Comments
 (0)