From 4cb1117d5d8567906dcc6984a08b7dc3af03ae5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Tue, 2 Aug 2022 11:02:03 +0200 Subject: [PATCH] fix: support components/content in layers for extends --- src/module.ts | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/module.ts b/src/module.ts index 370f442ec..c8f298cb8 100644 --- a/src/module.ts +++ b/src/module.ts @@ -346,27 +346,30 @@ export default defineNuxtModule({ }) // Register user global components - const globalComponents = resolve(nuxt.options.srcDir, 'components/content') - const dirStat = await fs.promises.stat(globalComponents).catch(() => null) - if (dirStat && dirStat.isDirectory()) { - logger.success('Using `~/components/content` for components in Markdown') - nuxt.hook('components:dirs', (dirs) => { - // Unshift to make it before ~/components - dirs.unshift({ - path: globalComponents, - global: true, - pathPrefix: false, - prefix: '' + for (const layer of nuxt.options._layers) { + const srcDir = layer.config.srcDir + const globalComponents = resolve(srcDir, 'components/content') + const dirStat = await fs.promises.stat(globalComponents).catch(() => null) + if (dirStat && dirStat.isDirectory()) { + if (nuxt.options._layers.length === 1) { + logger.success('Using `~/components/content` for components in Markdown') + } + nuxt.hook('components:dirs', (dirs) => { + dirs.unshift({ + path: globalComponents, + global: true, + pathPrefix: false, + prefix: '' + }) }) - }) - } else { - const componentsDir = resolve(nuxt.options.srcDir, 'components/') - const componentsDirStat = await fs.promises.stat(componentsDir).catch(() => null) - - if (componentsDirStat && componentsDirStat.isDirectory()) { - // TODO: watch for file creation and tell Nuxt to restart - // Not possible for now since directories are hard-coded: https://github.com/nuxt/framework/blob/5b63ae8ad54eeb3cb49479da8f32eacc1a743ca0/packages/nuxi/src/commands/dev.ts#L94 - logger.info('Please create `~/components/content` and restart the Nuxt server to use components in Markdown') + } else if (nuxt.options._layers.length === 1) { + const componentsDir = resolve(srcDir, 'components/') + const componentsDirStat = await fs.promises.stat(componentsDir).catch(() => null) + if (componentsDirStat && componentsDirStat.isDirectory()) { + // TODO: watch for file creation and tell Nuxt to restart + // Not possible for now since directories are hard-coded: https://github.com/nuxt/framework/blob/5b63ae8ad54eeb3cb49479da8f32eacc1a743ca0/packages/nuxi/src/commands/dev.ts#L94 + logger.info('Please create `~/components/content` and restart the Nuxt server to use components in Markdown') + } } }