Skip to content

Commit 7d78306

Browse files
committed
fix!: deprecate hoistDependencies
1 parent 273a96d commit 7d78306

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

README.md

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,6 @@ npm i nuxt-module-utils
1616

1717
## Usage
1818

19-
### `hoistDependencies(hoist: string[])`
20-
21-
> [!NOTE]
22-
> [Nuxt `4.0.0+` now supports modules adding to `typescript.hoist`](https://github.com/nuxt/nuxt/pull/32601), this utility is only needed to support projects using Nuxt `3.x` with `compatibilityVersion: 4`.
23-
24-
While Nuxt provides the `typescript.hoist` option to generate aliases for nested dependencies within pnpm monorepos, it is processed before modules are set up.
25-
26-
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`.
27-
28-
```ts
29-
// src/module.ts
30-
import { defineNuxtModule } from '@nuxt/kit'
31-
import { hoistDependencies } from 'nuxt-module-utils'
32-
33-
export default defineNuxtModule({
34-
async setup() {
35-
await hoistDependencies(['my-lib', 'my-other-lib'])
36-
}
37-
})
38-
```
39-
4019
### `getLayerModuleOptions<T>(layer: NuxtConfigLayer, configKey: string, name: string)`
4120

4221
Get module options from a given Nuxt layer.
@@ -70,6 +49,25 @@ export default defineNuxtModule<ModuleOptions>({
7049
})
7150
```
7251

52+
### `hoistDependencies(hoist: string[])`
53+
54+
> [!WARNING]
55+
> Deprecated and will be removed in v1 - [Nuxt `4.0.0` supports modules adding to `typescript.hoist`](https://github.com/nuxt/nuxt/pull/32601)
56+
57+
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`.
58+
59+
```ts
60+
// src/module.ts
61+
import { defineNuxtModule } from '@nuxt/kit'
62+
import { hoistDependencies } from 'nuxt-module-utils'
63+
64+
export default defineNuxtModule({
65+
async setup() {
66+
await hoistDependencies(['my-lib', 'my-other-lib'])
67+
}
68+
})
69+
```
70+
7371
## Sponsors
7472

7573
<p align="center">

src/hoist.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ async function resolveTypePath(path: string, subpath: string, searchPaths = tryU
3434
* @param nuxt - The Nuxt instance.
3535
*
3636
* @see [Nuxt source](https://github.com/nuxt/nuxt/blob/5146bed75eb1a6617e2fb17ea97b3d121cd94930/packages/nuxt/src/core/nuxt.ts#L188-L290)
37+
* @deprecated Module support for `typescript.hoist` was added in Nuxt 4.0.0.
3738
*/
3839
export async function hoistDependencies(hoist: string[], nuxt = useNuxt()) {
3940
const isVersion4 = (await readPackageJSON("nuxt"))?.version?.startsWith("4");

0 commit comments

Comments
 (0)