Skip to content

Commit

Permalink
Module names that end in a trialing slash should not be considered bu…
Browse files Browse the repository at this point in the history
…iltin (#13)
  • Loading branch information
Robert Sweeney authored Jan 31, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 805fb76 commit 4d9b398
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ module.exports = moduleName => {
}

const slashIndex = moduleName.indexOf('/');
if (slashIndex !== -1) {
if (slashIndex !== -1 && slashIndex !== moduleName.length - 1) {
moduleName = moduleName.slice(0, slashIndex);
}

3 changes: 2 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -4,19 +4,20 @@ import isBuiltinModule from '.';
test('main', t => {
t.true(isBuiltinModule('fs'));
t.true(isBuiltinModule('console'));
t.true(isBuiltinModule('punycode'));

t.true(isBuiltinModule('fs/promises'));
t.true(isBuiltinModule('assert/strict'));

// These are actually not, but should not exist
t.true(isBuiltinModule('fs/'));
t.true(isBuiltinModule('fs/unknown'));
t.true(isBuiltinModule('fs/promises/unknown'));
t.true(isBuiltinModule('fs/promises?query=1'));

t.true(isBuiltinModule('node:fs'));
t.true(isBuiltinModule('node:fs/promises'));

t.false(isBuiltinModule('punycode/'));
t.false(isBuiltinModule('unicorn'));
t.false(isBuiltinModule('unknown'));
t.false(isBuiltinModule('FS'));

0 comments on commit 4d9b398

Please sign in to comment.