Skip to content

Commit 9ee7692

Browse files
committed
docs: update documentation
1 parent 921af9f commit 9ee7692

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,25 @@ A collection of utility functions for Nuxt module authors.
1414
npm i nuxt-module-utils
1515
```
1616

17-
<!-- ## Usage
17+
## Usage
18+
19+
### `hoistDependencies(hoist: string[])`
20+
21+
While Nuxt provides the `typescript.hoist` option to generate aliases for nested dependencies within pnpm monorepos, it is processed before modules are set up.
22+
23+
The `hoistDependencies` utility allows you to hoist dependencies from within your module's `setup` function. It works by resolving the paths of the specified packages and adding them to Nuxt's TypeScript configuration, ensuring they are included in the generated `tsconfig.json`.
1824

1925
```ts
2026
// src/module.ts
21-
import { someUtil } from 'nuxt-module-utils'
27+
import { defineNuxtModule } from '@nuxt/kit'
28+
import { hoistDependencies } from 'nuxt-module-utils'
2229

2330
export default defineNuxtModule({
24-
setup() {
31+
async setup() {
32+
await hoistDependencies(['my-lib', 'my-other-lib'])
2533
}
2634
})
27-
``` -->
35+
```
2836

2937
## Sponsors
3038

src/hoist.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { version } from "nuxt/package.json";
77
const isVersion4 = version.startsWith("4");
88

99
/**
10-
* Adapted from Nuxt source code
11-
* https://github.com/nuxt/nuxt/blob/a0f9ddfe241bcf555f6305aa10c087a1fe64af87/packages/nuxt/src/core/utils/types.ts#L6
10+
* @see [Nuxt source](https://github.com/nuxt/nuxt/blob/a0f9ddfe241bcf555f6305aa10c087a1fe64af87/packages/nuxt/src/core/utils/types.ts#L6)
1211
*/
1312
async function resolveTypePath(path: string, subpath: string, searchPaths = tryUseNuxt()?.options.modulesDir) {
1413
try {
@@ -28,8 +27,15 @@ async function resolveTypePath(path: string, subpath: string, searchPaths = tryU
2827
}
2928

3029
/**
31-
* Adapted from Nuxt source code
32-
* https://github.com/nuxt/nuxt/blob/5146bed75eb1a6617e2fb17ea97b3d121cd94930/packages/nuxt/src/core/nuxt.ts
30+
* Hoist dependencies for TypeScript path mapping.
31+
*
32+
* This function is a workaround for module authors who need to hoist dependencies
33+
* for TypeScript path mapping, it mimics the behavior of `nuxt.options.typescript.hoist`
34+
*
35+
* @param hoist - An array of package names to hoist.
36+
* @param nuxt - The Nuxt instance.
37+
*
38+
* @see [Nuxt source](https://github.com/nuxt/nuxt/blob/5146bed75eb1a6617e2fb17ea97b3d121cd94930/packages/nuxt/src/core/nuxt.ts#L188-L290)
3339
*/
3440
export async function hoistDependencies(hoist: string[], nuxt = useNuxt()) {
3541
const packageJSON = await readPackageJSON(nuxt.options.rootDir).catch(() => ({} as PackageJson));

0 commit comments

Comments
 (0)