Skip to content
Draft
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
10 changes: 4 additions & 6 deletions lib/type-defs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const url = require('url')
const path = require('path')
const Stream = require('stream').Stream
const os = require('os')
Expand Down Expand Up @@ -63,10 +62,9 @@ function validateBoolean (data, k, val) {
}

function validateUrl (data, k, val) {
// Changing this would be a breaking change in the npm cli
/* eslint-disable-next-line node/no-deprecated-api */
val = url.parse(String(val))
if (!val.host) {
try {
val = new URL(String(val))
} catch {
return false
}
data[k] = val.href
Expand All @@ -82,7 +80,7 @@ function validateStream (data, k, val) {
module.exports = {
String: { type: String, validate: validateString },
Boolean: { type: Boolean, validate: validateBoolean },
url: { type: url, validate: validateUrl },
url: { type: URL, validate: validateUrl },
Number: { type: Number, validate: validateNumber },
path: { type: path, validate: validatePath },
Stream: { type: Stream, validate: validateStream },
Expand Down
7 changes: 3 additions & 4 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ test('clean: no types does not throw', () => {
test('other tests', () => {
const Stream = require('stream')
const path = require('path')
const url = require('url')

const shorthands =
{ s: ['--loglevel', 'silent'],
Expand Down Expand Up @@ -145,16 +144,16 @@ test('other tests', () => {
loglevel: ['silent', 'win', 'error', 'warn', 'info', 'verbose', 'silly'],
long: Boolean,
'node-version': [false, String],
npaturl: url,
npaturl: URL,
npat: Boolean,
'onload-script': [false, String],
outfd: [Number, Stream],
parseable: Boolean,
pre: Boolean,
prefix: path,
proxy: url,
proxy: URL,
'rebuild-bundle': Boolean,
registry: url,
registry: URL,
searchopts: String,
searchexclude: [null, String],
shell: path,
Expand Down
Loading