Skip to content

Commit 2e9de94

Browse files
committed
fix: use URL.canParse instead of runtime deprecated url.parse api
1 parent dbc9ef1 commit 2e9de94

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

lib/normalize-data.js

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

3-
const url = require('node:url')
43
const hostedGitInfo = require('hosted-git-info')
54
const validateLicense = require('validate-npm-package-license')
65

@@ -123,8 +122,7 @@ function normalizeData (data, changes) {
123122
if (typeof data.bugs === 'string') {
124123
if (isEmail(data.bugs)) {
125124
data.bugs = { email: data.bugs }
126-
/* eslint-disable-next-line node/no-deprecated-api */
127-
} else if (url.parse(data.bugs).protocol) {
125+
} else if (URL.canParse(data.bugs)) {
128126
data.bugs = { url: data.bugs }
129127
} else {
130128
changes?.push(`Bug string field must be url, email, or {email,url}`)
@@ -140,8 +138,7 @@ function normalizeData (data, changes) {
140138
const oldBugs = data.bugs
141139
data.bugs = {}
142140
if (oldBugs.url) {
143-
/* eslint-disable-next-line node/no-deprecated-api */
144-
if (typeof (oldBugs.url) === 'string' && url.parse(oldBugs.url).protocol) {
141+
if (URL.canParse(oldBugs.url)) {
145142
data.bugs.url = oldBugs.url
146143
} else {
147144
changes?.push('bugs.url field must be a string url. Deleted.')
@@ -216,8 +213,7 @@ function normalizeData (data, changes) {
216213
changes?.push('homepage field must be a string url. Deleted.')
217214
delete data.homepage
218215
} else {
219-
/* eslint-disable-next-line node/no-deprecated-api */
220-
if (!url.parse(data.homepage).protocol) {
216+
if (!URL.canParse(data.homepage)) {
221217
data.homepage = 'http://' + data.homepage
222218
}
223219
}

0 commit comments

Comments
 (0)