From 85166cced759e6d72424ed6c60bab12d1e705cbf Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 15 Mar 2024 10:59:41 -0700 Subject: [PATCH] feat(schema): allow configuring type hoists with `typescript.hoist` --- packages/nuxt/src/core/nuxt.ts | 2 +- packages/schema/src/config/typescript.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 8cc2a95794a8..6efea3bb3c3f 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -63,7 +63,7 @@ async function initNuxt (nuxt: Nuxt) { nuxtCtx.set(nuxt) nuxt.hook('close', () => nuxtCtx.unset()) - const coreTypePackages = ['nitropack', 'defu', 'h3', '@unhead/vue', 'vue', 'vue-router', '@nuxt/schema'] + const coreTypePackages = nuxt.options.typescript.hoist || [] const paths = Object.fromEntries(await Promise.all(coreTypePackages.map(async (pkg) => { const path = await _resolvePath(pkg, { url: nuxt.options.modulesDir }).then(r => resolvePackageJSON(r)).catch(() => null) if (!path) { return } diff --git a/packages/schema/src/config/typescript.ts b/packages/schema/src/config/typescript.ts index 6cef2858b946..8c9eb2c2d0c9 100644 --- a/packages/schema/src/config/typescript.ts +++ b/packages/schema/src/config/typescript.ts @@ -26,6 +26,17 @@ export default defineUntypedSchema({ $resolve: val => val ?? null }, + /** + * Modules to generate deep aliases for within `compilerOptions.paths`. This does not yet support subpaths. + * It may be necessary when using Nuxt within a pnpm monorepo with `shamefully-hoist=false`. + */ + hoist: { + $resolve: (val) => { + const defaults = ['nitropack', 'defu', 'h3', '@unhead/vue', 'vue', 'vue-router', '@nuxt/schema'] + return val === false ? [] : (Array.isArray(val) ? val.concat(defaults) : defaults) + } + }, + /** * Include parent workspace in the Nuxt project. Mostly useful for themes and module authors. */