Skip to content

Commit 2033987

Browse files
Fix getImplicitModuleRoot
1 parent 980a621 commit 2033987

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ const leadingPathSegmentRegEx = /^(.?.[/\\])+/;
3030
const moduleInfos = {};
3131
const fileNodes = {};
3232

33-
// Without explicit module ids, JSDoc will use the nearest shared ancestor directory
33+
// Without explicit module ids, JSDoc will use the nearest shared parent directory
3434
/** @type {string} */
3535
let implicitModuleRoot;
3636

37+
/**
38+
* @return {string} The nearest shared parent directory of all source files.
39+
*/
3740
function getImplicitModuleRoot() {
3841
if (implicitModuleRoot) {
3942
return implicitModuleRoot;
@@ -43,19 +46,21 @@ function getImplicitModuleRoot() {
4346
return process.cwd();
4447
}
4548

46-
implicitModuleRoot = env.sourceFiles[0];
49+
implicitModuleRoot = path.dirname(env.sourceFiles[0]);
4750

4851
env.sourceFiles.slice(1).forEach((filePath) => {
4952
if (filePath.startsWith(implicitModuleRoot)) {
50-
return implicitModuleRoot;
53+
return;
5154
}
5255

5356
const currParts = filePath.split(path.sep);
5457
const nearestParts = implicitModuleRoot.split(path.sep);
5558

5659
for (let i = 0; i < currParts.length; ++i) {
5760
if (currParts[i] !== nearestParts[i]) {
58-
return currParts.slice(0, i).join(path.sep);
61+
implicitModuleRoot = currParts.slice(0, i).join(path.sep);
62+
63+
return;
5964
}
6065
}
6166
});

0 commit comments

Comments
 (0)