Skip to content

Commit 820d6c0

Browse files
committed
npm provider: Improve error message for unresolved modules
1 parent 9cf6640 commit 820d6c0

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

lib/graph/providers/npm.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,20 @@ class Npm {
6969

7070
async _resolveModulePath(baseDir, moduleName) {
7171
log.verbose(`Resolving module path for '${moduleName}'...`);
72-
let packageJsonPath = await resolveModulePath(moduleName + "/package.json", {
73-
basedir: baseDir,
74-
preserveSymlinks: false
75-
});
76-
packageJsonPath = await realpath(packageJsonPath);
72+
try {
73+
let packageJsonPath = await resolveModulePath(moduleName + "/package.json", {
74+
basedir: baseDir,
75+
preserveSymlinks: false
76+
});
77+
packageJsonPath = await realpath(packageJsonPath);
7778

78-
const modulePath = path.dirname(packageJsonPath);
79-
log.verbose(`Resolved module ${moduleName} to path ${modulePath}`);
80-
return modulePath;
79+
const modulePath = path.dirname(packageJsonPath);
80+
log.verbose(`Resolved module ${moduleName} to path ${modulePath}`);
81+
return modulePath;
82+
} catch (err) {
83+
throw new Error(
84+
`Unable to locate module ${moduleName} via resolve logic: ${err.message}`);
85+
}
8186
}
8287

8388
async _getNode(modulePath, optional) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
specVersion: "2.3"
3+
type: application
4+
metadata:
5+
name: err.app.a
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Error Application A</title>
5+
</head>
6+
<body>
7+
8+
</body>
9+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"_version": "1.1.0",
3+
"sap.app": {
4+
"_version": "1.1.0",
5+
"id": "id1",
6+
"type": "application",
7+
"applicationVersion": {
8+
"version": "1.2.2"
9+
},
10+
"embeds": ["embedded"],
11+
"title": "{{title}}"
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function test(paramA) {
2+
var variableA = paramA;
3+
console.log(variableA);
4+
}
5+
test();

test/lib/graph/providers/npm.integration.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ test("Error: missing package.json", async (t) => {
209209
t.is(error.message, `Failed to locate package.json for directory ${dir}`);
210210
});
211211

212-
test.skip("Error: missing dependency", async (t) => {
212+
test("Error: missing dependency", async (t) => {
213213
const npmProvider = new NpmProvider({
214214
cwd: errApplicationAPath
215215
});
216216
const error = await t.throwsAsync(testGraphCreationDfs(t, npmProvider, []));
217-
t.is(error.message, "[npm translator] Could not locate " +
218-
"module library.xx via resolve logic (error: Cannot find module 'library.xx/package.json' from '" +
219-
errApplicationAPath + "') or in a collection");
217+
t.is(error.message,
218+
`Unable to locate module library.xx via resolve logic: Cannot find module 'library.xx/package.json' from ` +
219+
`'${errApplicationAPath}'`);
220220
});

0 commit comments

Comments
 (0)