Skip to content

Commit 7829846

Browse files
author
Ives van Hoorne
committed
Support dependency not found for scoped packages
1 parent 3e97c9c commit 7829846

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/sandbox/errors/__snapshots__/dependency-not-found-error.test.js.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ Object {
2020
"path": "redux-form/immutable",
2121
}
2222
`;
23+
24+
exports[`it parses scoped packages 1`] = `
25+
Object {
26+
"dependency": "@vx/group",
27+
"path": "@vx/group",
28+
}
29+
`;

src/sandbox/errors/dependency-not-found-error.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
const parseDependencyName = (dependency: string) => {
2-
const match = dependency.match(/(.*?)\//);
3-
4-
if (match) return match[1];
5-
return dependency;
6-
};
7-
81
export default class DependencyNotFoundError extends Error {
92
constructor(dependencyName: string) {
103
super();
114

12-
const parsedName = parseDependencyName(dependencyName);
5+
const [root, second] = dependencyName.split('/');
6+
7+
// If the package starts with a @ it's scoped, we should add the second
8+
// part of the name in that case
9+
const parsedName = root.startsWith('@') ? `${root}/${second}` : root;
10+
1311
this.payload = {
1412
dependency: parsedName,
1513
path: dependencyName,
1614
};
17-
this.message = `Could not find dependency: '${parsedName}'`;
15+
this.message = `Could not find dependency: '${dependencyName}'`;
1816
}
1917
type = 'dependency-not-found';
2018
severity = 'error';

src/sandbox/errors/dependency-not-found-error.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ test('it parses dependency names with multiple slashes correctly', () => {
1717

1818
expect(error.payload).toMatchSnapshot();
1919
});
20+
21+
test('it parses scoped packages', () => {
22+
const error = new DependencyError('@vx/group');
23+
24+
expect(error.payload).toMatchSnapshot();
25+
});

0 commit comments

Comments
 (0)