forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependency-not-found-error.js
More file actions
34 lines (29 loc) · 986 Bytes
/
dependency-not-found-error.js
File metadata and controls
34 lines (29 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// @flow
import { actions, dispatch } from 'codesandbox-api';
import SandboxError from './sandbox-error';
export default class DependencyNotFoundError extends SandboxError {
constructor(dependencyName: string, fromPath: ?string) {
super();
this.path = dependencyName;
const [root, second] = dependencyName.split('/');
// If the package starts with a @ it's scoped, we should add the second
// part of the name in that case
const parsedName = root.startsWith('@') ? `${root}/${second}` : root;
this.suggestions = [
{
title: `Add ${parsedName} as dependency`,
action: () => {
dispatch(actions.source.dependencies.add(parsedName));
},
},
];
this.name = 'DependencyNotFoundError';
this.message = `Could not find dependency: '${parsedName}'`;
if (fromPath) {
this.message += ` relative to '${fromPath}'`;
}
}
type = 'dependency-not-found';
severity = 'error';
path: string;
}