File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,20 @@ function validate (name) {
8080 errors . push ( 'name cannot start with a period' )
8181 }
8282
83+ if ( pkg . match ( / ^ _ / ) ) {
84+ errors . push ( 'name cannot start with an underscore' )
85+ }
86+
87+ blacklist . forEach ( function ( blacklistedName ) {
88+ if ( pkg . toLowerCase ( ) === blacklistedName ) {
89+ errors . push ( blacklistedName + ' is a blacklisted name' )
90+ }
91+ } )
92+
93+ if ( builtins . includes ( pkg . toLowerCase ( ) ) ) {
94+ warnings . push ( pkg + ' is a core module name' )
95+ }
96+
8397 if ( encodeURIComponent ( user ) === user && encodeURIComponent ( pkg ) === pkg ) {
8498 return done ( warnings , errors )
8599 }
Original file line number Diff line number Diff line change @@ -26,6 +26,26 @@ test('validate-npm-package-name', function (t) {
2626 warnings : [ 'name can no longer contain special characters ("~\'!()*")' ] ,
2727 } )
2828
29+ // Scoped package validation for blacklisted names, underscore starts, and core modules
30+
31+ t . same ( validate ( '@user/node_modules' ) , {
32+ validForNewPackages : false ,
33+ validForOldPackages : false ,
34+ errors : [ 'node_modules is a blacklisted name' ] ,
35+ } )
36+
37+ t . same ( validate ( '@user/_package' ) , {
38+ validForNewPackages : false ,
39+ validForOldPackages : false ,
40+ errors : [ 'name cannot start with an underscore' ] ,
41+ } )
42+
43+ t . same ( validate ( '@user/http' ) , {
44+ validForNewPackages : false ,
45+ validForOldPackages : true ,
46+ warnings : [ 'http is a core module name' ] ,
47+ } )
48+
2949 // Invalid
3050
3151 t . same ( validate ( null ) , {
You can’t perform that action at this time.
0 commit comments