11'use strict'
22const execa = require ( 'execa' )
33const npa = require ( 'npm-package-arg' )
4- const validatePackageName = require ( 'validate-npm-package-name' )
4+ const validateNpmPackageName = require ( 'validate-npm-package-name' )
55
66// Remove npm env vars from the commands, this
77// is so it respects the directory it is run in,
@@ -14,7 +14,8 @@ const env = Object.keys(process.env).reduce((e, key) => {
1414 return e
1515} , { } )
1616
17- module . exports . install = ( deps = [ ] , opts = { } ) => {
17+ module . exports . install = install
18+ function install ( deps = [ ] , opts = { } ) {
1819 if ( ! deps || ! deps . length ) {
1920 return Promise . resolve ( )
2021 }
@@ -38,12 +39,12 @@ module.exports.install = (deps = [], opts = {}) => {
3839 cwd : opts . directory || process . cwd ( ) ,
3940 stdio : opts . silent ? 'ignore' : 'pipe'
4041 } )
41- }
42+ } ;
4243
4344const packageTypes = [ 'tag' , 'git' , 'version' , 'range' , 'file' , 'directory' , 'remote' ]
4445
4546module . exports . normalizePackageName = normalizePackageName
46- async function normalizePackageName ( name , opts = { } ) {
47+ function normalizePackageName ( name , opts = { } ) {
4748 const allowedTypes = opts . allowedTypes || packageTypes
4849 const pkg = npa ( name )
4950
@@ -64,42 +65,43 @@ async function normalizePackageName (name, opts = {}) {
6465 case 'tag' :
6566 case 'version' :
6667 case 'range' :
67- validName ( pkg )
68+ validateName ( pkg )
6869 break
6970 }
7071
7172 return pkg
7273}
7374
74- function validName ( pkg ) {
75+ function validateName ( pkg ) {
7576 // Manual check because the validate package just says "name cannot be null"
7677 if ( ! pkg . name ) {
7778 throw new Error ( `Invalid package name (${ pkg . raw } - name cannot be empty)` )
7879 }
7980
80- const v = validatePackageName ( pkg . name )
81+ const v = validateNpmPackageName ( pkg . name )
8182 if ( v . errors || v . warnings ) {
8283 const msg = ( v . errors && v . errors [ 0 ] ) || ( v . warnings || v . warnings [ 0 ] )
8384 throw new Error ( `Invalid package name (${ pkg . raw } ${ msg ? ` - ${ msg } ` : '' } )` )
8485 }
8586}
8687
87- module . exports . validatePackageNames = validatePackageSpec
88+ module . exports . validatePackageSpec = validatePackageSpec
8889function validatePackageSpec ( name , opts = { } ) {
8990 const names = Array . isArray ( name ) ? name : [ name ]
9091 for ( let i = 0 ; i < names . length ; i ++ ) {
9192 try {
92- normalizePackageName ( names [ i ] )
93+ validatePackageName ( names [ i ] )
9394 } catch ( e ) {
9495 return e
9596 }
9697 }
9798 return true
98- }
99+ } ;
99100
100- module . exports . validatePackageName = async function ( name ) {
101+ module . exports . validatePackageName = validatePackageName
102+ function validatePackageName ( name ) {
101103 try {
102- await normalizePackageName ( name , {
104+ normalizePackageName ( name , {
103105 allowedTypes : [ 'tag' , 'range' , 'version' ]
104106 } )
105107 } catch ( e ) {
0 commit comments