Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Below is a list of rules that valid `npm` package name should conform to.
- package name should not start with `.` or `_`
- package name should *not* contain any spaces
- package name should *not* contain any of the following characters: `~)('!*`
- package name *cannot* be the same as a node.js/io.js core module nor a reserved/blacklisted name. For example, the following names are invalid:
- package name *cannot* be the same as a node.js/io.js core module nor a reserved/excluded name. For example, the following names are invalid:
+ http
+ stream
+ node_modules
Expand Down
8 changes: 4 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const { builtinModules: builtins } = require('module')

var scopedPackagePattern = new RegExp('^(?:@([^/]+?)[/])?([^/]+?)$')
var blacklist = [
var exclusionList = [
'node_modules',
'favicon.ico',
]
Expand Down Expand Up @@ -43,9 +43,9 @@ function validate (name) {
}

// No funny business
blacklist.forEach(function (blacklistedName) {
if (name.toLowerCase() === blacklistedName) {
errors.push(blacklistedName + ' is a blacklisted name')
exclusionList.forEach(function (excludedName) {
if (name.toLowerCase() === excludedName) {
errors.push(excludedName + ' is not a valid package name')
}
})

Expand Down
21 changes: 19 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ test('validate-npm-package-name', function (t) {
warnings: ['name can no longer contain special characters ("~\'!()*")'],
})

// Scoped package validation - only period start is checked, everything else is allowed

t.same(validate('@user/node_modules'), {
validForNewPackages: true,
validForOldPackages: true,
})

t.same(validate('@user/_package'), {
validForNewPackages: true,
validForOldPackages: true,
})

t.same(validate('@user/http'), {
validForNewPackages: true,
validForOldPackages: true,
})

// Invalid

t.same(validate(null), {
Expand Down Expand Up @@ -98,12 +115,12 @@ test('validate-npm-package-name', function (t) {
t.same(validate('node_modules'), {
validForNewPackages: false,
validForOldPackages: false,
errors: ['node_modules is a blacklisted name'] })
errors: ['node_modules is not a valid package name'] })

t.same(validate('favicon.ico'), {
validForNewPackages: false,
validForOldPackages: false,
errors: ['favicon.ico is a blacklisted name'] })
errors: ['favicon.ico is not a valid package name'] })

// Node/IO Core

Expand Down
Loading