Skip to content

Commit

Permalink
Revert process.cwd root default
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Knights committed Sep 3, 2024
1 parent b18436f commit 94d35ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ In the absence of `typescript.moduleRoot`, the plugin will mirror the method JSD

1. Parse the referenced module for an `@module` tag.
2. If a tag is found and it has an explicit id, use that.
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.

**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.
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.

## What this plugin does

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

**Named export:**

```js
/**
* @type {import("./path/to/module").exportName}
*/
```

**Default export:**

```js
/**
* @type {import("./path/to/module").default}
*/
```

**typeof type:**

```js
/**
* @type {typeof import("./path/to/module").exportName}
*/
```

**Template literal type**

```js
/**
* @type {`static:${dynamic}`}
*/
```

**@override annotations**

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

**Named export:**

```js
/**
* @type {module:path/to/module.exportName}
*/
```

**Default export assigned to a variable in the exporting module:**

```js
/**
* @type {module:path/to/module~variableOfDefaultExport}
Expand All @@ -93,20 +98,23 @@ are removed because they make JSDoc stop inheritance
This syntax is also used when referring to types of `@typedef`s and `@enum`s.

**Anonymous default export:**

```js
/**
* @type {module:path/to/module}
*/
```

**typeof type:**

```js
/**
* @type {Class<module:path/to/module.exportName>}
*/
```

**Template literal type**

```js
/**
* @type {'static:${dynamic}'}
Expand Down
10 changes: 2 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,15 @@ const fileNodes = {};
let implicitModuleRoot;

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

if (
!env.sourceFiles ||
env.sourceFiles.length === 0 ||
// If all files are in cwd
env.sourceFiles.every((f) => f.startsWith(process.cwd()))
) {
if (!env.sourceFiles || env.sourceFiles.length === 0) {
return process.cwd();
}

Expand Down

0 comments on commit 94d35ac

Please sign in to comment.