(rootDir: string, nuxtOptions: NuxtOptions | NuxtConfig = useNuxt().options)
| 62 | })) |
| 63 | |
| 64 | const resolveContentConfig = (rootDir: string, nuxtOptions: NuxtOptions | NuxtConfig = useNuxt().options): ResolvedConfig => { |
| 65 | const r = (p: string) => isAbsolute(p) || p.startsWith(rootDir) ? p : resolve(rootDir, p) |
| 66 | const withSrcDir = (p: string) => r(nuxtOptions.srcDir && !p.startsWith(nuxtOptions.srcDir) ? resolve(nuxtOptions.srcDir, p) : p) |
| 67 | // const withAppDir = (p: string) => r(nuxtOptions.appDir && !p.startsWith(nuxtOptions.appDir) ? resolve(nuxtOptions.appDir, p) : p) |
| 68 | |
| 69 | const formatExtensions = (s: string[]) => s.length > 1 ? `.{${s.join(',')}}` : `.${s.join('') || 'vue'}` |
| 70 | const defaultExtensions = formatExtensions(['js', 'ts', 'mjs']) |
| 71 | const sfcExtensions = formatExtensions(Array.from(new Set(['.vue', ...(nuxtOptions.extensions || nuxt.options.extensions)])).map(e => e?.replace(/^\.*/, '')).filter((v): v is string => Boolean(v))) |
| 72 | |
| 73 | const importDirs = [...(nuxtOptions.imports?.dirs || [])].filter((v): v is string => Boolean(v)).map(withSrcDir) |
| 74 | const [composablesDir, utilsDir] = [withSrcDir('composables'), withSrcDir('utils')] |
| 75 | |
| 76 | if (!importDirs.includes(composablesDir)) importDirs.push(composablesDir) |
| 77 | if (!importDirs.includes(utilsDir)) importDirs.push(utilsDir) |
| 78 | |
| 79 | const isLayer = rootDir !== nuxt.options.rootDir |
| 80 | |
| 81 | const pagePaths: string[] = [] |
| 82 | const pageFiles = pagesContentPath.tryUse() |
| 83 | |
| 84 | if (moduleOptions.experimental?.strictScanContentPaths && pageFiles && pageFiles.length) { |
| 85 | // replace filenames like [...path].vue with ?...path?.vue because [ and ] are reserved in glob matching |
| 86 | if (!isLayer) pagePaths.push(...pageFiles.map(p => p.replaceAll(/\[(\.+)([^.].*)\]/g, '?$1$2?'))) |
| 87 | } |
| 88 | // @ts-expect-error pages can be an object |
| 89 | else if (nuxtOptions.pages !== false && nuxtOptions.pages?.enabled !== false) { |
| 90 | pagePaths.push(withSrcDir(`${nuxtOptions.dir?.pages || 'pages'}/**/*${sfcExtensions}`)) |
| 91 | } |
| 92 | |
| 93 | const componentPaths: string[] = [] |
| 94 | const componentFiles = componentsContentPath.tryUse() |
| 95 | |
| 96 | if (moduleOptions.experimental?.strictScanContentPaths && componentFiles && componentFiles.length) { |
| 97 | if (!isLayer) componentPaths.push(...componentFiles) |
| 98 | } |
| 99 | else { |
| 100 | componentPaths.push( |
| 101 | withSrcDir(`components/**/*${sfcExtensions}`), |
| 102 | ...(() => { |
| 103 | if (nuxtOptions.components) { |
| 104 | return (Array.isArray(nuxtOptions.components) ? nuxtOptions.components : typeof nuxtOptions.components === 'boolean' ? ['components'] : (nuxtOptions.components.dirs || [])).map((d) => { |
| 105 | const valueToResolve = typeof d === 'string' ? d : d?.path |
| 106 | return valueToResolve ? `${resolveAlias(valueToResolve)}/**/*${sfcExtensions}` : '' |
| 107 | }).filter(Boolean) |
| 108 | } |
| 109 | return [] |
| 110 | })(), |
| 111 | ) |
| 112 | } |
| 113 | |
| 114 | return { |
| 115 | config: { |
| 116 | content: { |
| 117 | files: [ |
| 118 | ...componentPaths, |
| 119 | nuxtOptions.dir?.layouts && withSrcDir(`${nuxtOptions.dir.layouts}/**/*${sfcExtensions}`), |
| 120 | nuxtOptions.dir?.plugins && withSrcDir(`${nuxtOptions.dir.plugins}/**/*${defaultExtensions}`), |
| 121 | ...importDirs.map(d => `${d}/**/*${defaultExtensions}`), |
no test coverage detected