Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9036160

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

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/normalize-data.js

Lines changed: 3 additions & 4 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

@@ -124,7 +123,7 @@ function normalizeData (data, changes) {
124123
if (isEmail(data.bugs)) {
125124
data.bugs = { email: data.bugs }
126125
/* 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}`)
@@ -141,7 +140,7 @@ function normalizeData (data, changes) {
141140
data.bugs = {}
142141
if (oldBugs.url) {
143142
/* eslint-disable-next-line node/no-deprecated-api */
144-
if (typeof (oldBugs.url) === 'string' && url.parse(oldBugs.url).protocol) {
143+
if (typeof (oldBugs.url) === 'string' && URL.canParse(oldBugs.url)) {
145144
data.bugs.url = oldBugs.url
146145
} else {
147146
changes?.push('bugs.url field must be a string url. Deleted.')
@@ -217,7 +216,7 @@ function normalizeData (data, changes) {
217216
delete data.homepage
218217
} else {
219218
/* eslint-disable-next-line node/no-deprecated-api */
220-
if (!url.parse(data.homepage).protocol) {
219+
if (!URL.canParse(data.homepage)) {
221220
data.homepage = 'http://' + data.homepage
222221
}
223222
}

0 commit comments

Comments
 (0)