Skip to content

Commit f6c9ac5

Browse files
Remove moduleRoot config option
1 parent 37153d3 commit f6c9ac5

File tree

3 files changed

+10
-44
lines changed

3 files changed

+10
-44
lines changed

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,10 @@ To configure JSDoc to use the plugin, add the following to the JSDoc configurati
1414
"plugins": [
1515
"jsdoc-plugin-typescript"
1616
],
17-
"typescript": {
18-
"moduleRoot": "src" // optional
19-
}
2017
```
2118

2219
See http://usejsdoc.org/about-configuring-jsdoc.html for more details on how to configure JSDoc.
2320

24-
If `typescript.moduleRoot` is specified, the plugin will assume module ids are relative to that directory and format them as such. For example, `@type {import("./folder/file").Class}` will be converted to `@type {module:folder/file.Class}`. The file extension is removed along with any leading `../` segments (if the referenced module is outside `moduleRoot`).
25-
26-
In the absence of `typescript.moduleRoot`, the plugin will mirror the method JSDoc uses to assign module ids:
27-
28-
1. Parse the referenced module for an `@module` tag.
29-
2. If a tag is found and it has an explicit id, use that.
30-
3. If a tag is found, but it doesn't have an explicit id, use the module's file path relative to the nearest shared parent directory, and remove the file extension.
31-
3221
## What this plugin does
3322

3423
When using the `class` keyword for defining classes (required by TypeScript), JSDoc requires `@classdesc` and `@extends` annotations. With this plugin, no `@classdesc` and `@extends` annotations are needed.
@@ -121,6 +110,14 @@ This syntax is also used when referring to types of `@typedef`s and `@enum`s.
121110
*/
122111
```
123112

113+
## Module id resolution
114+
115+
For resolving module ids, this plugin mirrors the method used by JSDoc:
116+
117+
1. Parse the referenced module for an `@module` tag.
118+
2. If a tag is found and it has an explicit id, use that.
119+
3. If a tag is found, but it doesn't have an explicit id, use the module's file path relative to the nearest shared parent directory, and remove the file extension.
120+
124121
## Contributing
125122

126123
If you are interested in making a contribution to the project, please see the [contributing page](./contributing.md) for details on getting your development environment set up.

index.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,18 @@ const fs = require('fs');
44
const env = require('jsdoc/env'); // eslint-disable-line import/no-unresolved
55
const addInherited = require('jsdoc/augment').addInherited; // eslint-disable-line import/no-unresolved
66

7-
const config = env.conf;
8-
const moduleRoot = config.typescript ? config.typescript.moduleRoot : undefined;
9-
const moduleRootAbsolute = moduleRoot
10-
? path.join(process.cwd(), moduleRoot)
11-
: undefined;
12-
13-
if (moduleRootAbsolute && !fs.existsSync(moduleRootAbsolute)) {
14-
throw new Error(
15-
'Directory "' +
16-
moduleRootAbsolute +
17-
'" does not exist. Check the "typescript.moduleRoot" config option for jsdoc-plugin-typescript',
18-
);
19-
}
20-
217
const importRegEx =
228
/import\(["']([^"']*)["']\)(?:\.([^ \.\|\}><,\)=#\n]*))?([ \.\|\}><,\)=#\n])/g;
239
const typedefRegEx = /@typedef \{[^\}]*\} (\S+)/g;
2410
const noClassdescRegEx = /@(typedef|module|type)/;
2511
const extensionReplaceRegEx = /\.m?js$/;
2612
const extensionEnsureRegEx = /(\.js)?$/;
2713
const slashRegEx = /\\/g;
28-
const leadingPathSegmentRegEx = /^(.?.[/\\])+/;
2914

3015
const moduleInfos = {};
3116
const fileNodes = {};
3217
const resolvedPathCache = new Set();
3318

34-
// Without explicit module ids, JSDoc will use the nearest shared parent directory
3519
/** @type {string} */
3620
let implicitModuleRoot;
3721

@@ -76,14 +60,6 @@ function getModuleId(modulePath) {
7660
return moduleInfos[modulePath].id;
7761
}
7862

79-
// Use moduleRoot if set
80-
if (moduleRootAbsolute) {
81-
return path
82-
.relative(moduleRootAbsolute, modulePath)
83-
.replace(extensionReplaceRegEx, '')
84-
.replace(leadingPathSegmentRegEx, '');
85-
}
86-
8763
// Search for explicit module id
8864
if (fileNodes[modulePath]) {
8965
for (const comment of fileNodes[modulePath].comments) {

test/template/config.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@
55
"destination": "test/dest/actual.json"
66
},
77
"source": {
8-
"include": [
9-
"test/src"
10-
]
8+
"include": ["test/src"]
119
},
1210
"tags": {
1311
"allowUnknownTags": true
1412
},
15-
"plugins": [
16-
"index.js"
17-
],
18-
"typescript": {
19-
"moduleRoot": "test/src"
20-
}
13+
"plugins": ["index.js"]
2114
}

0 commit comments

Comments
 (0)