Skip to content

Commit

Permalink
fix: support nested node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
gabidobo committed Sep 27, 2022
1 parent 78559e7 commit 4a4c0e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/module.js
Expand Up @@ -78,7 +78,7 @@ export const mapStackItemToSource = (item) => {

export const getNodeModuleName = (location) => {
const components = location.split('/');
const nodeModulesIndex = components.findIndex((v) => v === 'node_modules');
const nodeModulesIndex = components.lastIndexOf('node_modules');
let moduleName = components[nodeModulesIndex + 1];
// Names starting with `@` are organizations, so it's good to get
// a bit more context by also grabbing the next path component
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/module.test.js
Expand Up @@ -261,6 +261,14 @@ describe('module', () => {
).toBe('lodash');
});

test('should indicate module name for a nested node-modules path', () => {
expect(
getModuleNameFromLocation(
'/Users/jason/code/sandworm/node_modules/lodash/node_modules/react/index.js',
),
).toBe('react');
});

test('should grab full name for org paths', () => {
expect(
getModuleNameFromLocation(
Expand Down

0 comments on commit 4a4c0e7

Please sign in to comment.