Skip to content

Commit 94d35ac

Browse files
Revert process.cwd root default
1 parent b18436f commit 94d35ac

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ In the absence of `typescript.moduleRoot`, the plugin will mirror the method JSD
2727

2828
1. Parse the referenced module for an `@module` tag.
2929
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 root directory, and remove the file extension.
31-
32-
**NOTE:** The root directory will be `process.cwd()` unless any source files are outside it, in which case, the root folder is considered the nearest shared parent directory of all source files.
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.
3331

3432
## What this plugin does
3533

@@ -44,31 +42,36 @@ TypeScript and JSDoc use a different syntax for imported types. This plugin conv
4442
### TypeScript
4543

4644
**Named export:**
45+
4746
```js
4847
/**
4948
* @type {import("./path/to/module").exportName}
5049
*/
5150
```
5251

5352
**Default export:**
53+
5454
```js
5555
/**
5656
* @type {import("./path/to/module").default}
5757
*/
5858
```
5959

6060
**typeof type:**
61+
6162
```js
6263
/**
6364
* @type {typeof import("./path/to/module").exportName}
6465
*/
6566
```
6667

6768
**Template literal type**
69+
6870
```js
6971
/**
7072
* @type {`static:${dynamic}`}
7173
*/
74+
```
7275

7376
**@override annotations**
7477

@@ -77,13 +80,15 @@ are removed because they make JSDoc stop inheritance
7780
### JSDoc
7881

7982
**Named export:**
83+
8084
```js
8185
/**
8286
* @type {module:path/to/module.exportName}
8387
*/
8488
```
8589

8690
**Default export assigned to a variable in the exporting module:**
91+
8792
```js
8893
/**
8994
* @type {module:path/to/module~variableOfDefaultExport}
@@ -93,20 +98,23 @@ are removed because they make JSDoc stop inheritance
9398
This syntax is also used when referring to types of `@typedef`s and `@enum`s.
9499

95100
**Anonymous default export:**
101+
96102
```js
97103
/**
98104
* @type {module:path/to/module}
99105
*/
100106
```
101107

102108
**typeof type:**
109+
103110
```js
104111
/**
105112
* @type {Class<module:path/to/module.exportName>}
106113
*/
107114
```
108115

109116
**Template literal type**
117+
110118
```js
111119
/**
112120
* @type {'static:${dynamic}'}

index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,15 @@ const fileNodes = {};
3535
let implicitModuleRoot;
3636

3737
/**
38-
* Without explicit module ids, JSDoc will use `process.cwd()` if all source files are within cwd.
39-
* If any source files are outside cwd, JSDoc will use the nearest shared parent directory.
38+
* Without explicit module ids, JSDoc will use the nearest shared parent directory.
4039
* @return {string} The implicit root path with which to resolve all module ids against.
4140
*/
4241
function getImplicitModuleRoot() {
4342
if (implicitModuleRoot) {
4443
return implicitModuleRoot;
4544
}
4645

47-
if (
48-
!env.sourceFiles ||
49-
env.sourceFiles.length === 0 ||
50-
// If all files are in cwd
51-
env.sourceFiles.every((f) => f.startsWith(process.cwd()))
52-
) {
46+
if (!env.sourceFiles || env.sourceFiles.length === 0) {
5347
return process.cwd();
5448
}
5549

0 commit comments

Comments
 (0)