feat(schema): allow configuring type hoists with typescript.hoist

This commit is contained in:
Daniel Roe 2024-03-15 10:59:41 -07:00
parent 9d08cdfd1f
commit 85166cced7
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
2 changed files with 12 additions and 1 deletions

View File

@ -63,7 +63,7 @@ async function initNuxt (nuxt: Nuxt) {
nuxtCtx.set(nuxt) nuxtCtx.set(nuxt)
nuxt.hook('close', () => nuxtCtx.unset()) 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 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) const path = await _resolvePath(pkg, { url: nuxt.options.modulesDir }).then(r => resolvePackageJSON(r)).catch(() => null)
if (!path) { return } if (!path) { return }

View File

@ -26,6 +26,17 @@ export default defineUntypedSchema({
$resolve: val => val ?? null $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. * Include parent workspace in the Nuxt project. Mostly useful for themes and module authors.
*/ */