Skip to content

Commit 186f541

Browse files
authored
fix: scoped names validate exclusionlist/underscore/core module (#142)
This pull request updates terminology for clarity and inclusivity, modifies validation logic, and enhances test coverage for the `validate-npm-package-name` module. The most important changes include renaming to exclusion list, updating error messages, and adding new test cases for scoped package validation.
1 parent 8123f73 commit 186f541

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Below is a list of rules that valid `npm` package name should conform to.
2929
- package name should not start with `.` or `_`
3030
- package name should *not* contain any spaces
3131
- package name should *not* contain any of the following characters: `~)('!*`
32-
- 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:
32+
- 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:
3333
+ http
3434
+ stream
3535
+ node_modules

lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const { builtinModules: builtins } = require('module')
33

44
var scopedPackagePattern = new RegExp('^(?:@([^/]+?)[/])?([^/]+?)$')
5-
var blacklist = [
5+
var exclusionList = [
66
'node_modules',
77
'favicon.ico',
88
]
@@ -43,9 +43,9 @@ function validate (name) {
4343
}
4444

4545
// No funny business
46-
blacklist.forEach(function (blacklistedName) {
47-
if (name.toLowerCase() === blacklistedName) {
48-
errors.push(blacklistedName + ' is a blacklisted name')
46+
exclusionList.forEach(function (excludedName) {
47+
if (name.toLowerCase() === excludedName) {
48+
errors.push(excludedName + ' is not a valid package name')
4949
}
5050
})
5151

test/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ test('validate-npm-package-name', function (t) {
2626
warnings: ['name can no longer contain special characters ("~\'!()*")'],
2727
})
2828

29+
// Scoped package validation - only period start is checked, everything else is allowed
30+
31+
t.same(validate('@user/node_modules'), {
32+
validForNewPackages: true,
33+
validForOldPackages: true,
34+
})
35+
36+
t.same(validate('@user/_package'), {
37+
validForNewPackages: true,
38+
validForOldPackages: true,
39+
})
40+
41+
t.same(validate('@user/http'), {
42+
validForNewPackages: true,
43+
validForOldPackages: true,
44+
})
45+
2946
// Invalid
3047

3148
t.same(validate(null), {
@@ -98,12 +115,12 @@ test('validate-npm-package-name', function (t) {
98115
t.same(validate('node_modules'), {
99116
validForNewPackages: false,
100117
validForOldPackages: false,
101-
errors: ['node_modules is a blacklisted name'] })
118+
errors: ['node_modules is not a valid package name'] })
102119

103120
t.same(validate('favicon.ico'), {
104121
validForNewPackages: false,
105122
validForOldPackages: false,
106-
errors: ['favicon.ico is a blacklisted name'] })
123+
errors: ['favicon.ico is not a valid package name'] })
107124

108125
// Node/IO Core
109126

0 commit comments

Comments
 (0)