(moduleOptions: ModuleOptions, nuxt = useNuxt())
| 18 | const resolvedConfigsCtx = getContext<Array<ResolvedConfig | null>>('twcss-resolved-configs') |
| 19 | |
| 20 | const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNuxt()) => { |
| 21 | const configUpdatedHook: Record<string, string> = {} |
| 22 | const { meta = { disableHMR: moduleOptions.disableHMR } } = twCtx.tryUse() ?? {} |
| 23 | const trackObjChanges = createObjProxy(configUpdatedHook, meta) |
| 24 | |
| 25 | const resolveConfigs = <T extends Partial<TWConfig> | string | undefined>(configs: T | T[], nuxt = useNuxt()) => |
| 26 | ((Array.isArray(configs) ? configs : [configs]) |
| 27 | .filter((c): c is NonNullable<T> => Boolean(c) && c !== join(nuxt.options.rootDir, 'tailwind.config')) |
| 28 | .map(async (config, idx, arr): Promise<ResolvedConfig | null> => { |
| 29 | if (typeof config !== 'string') { |
| 30 | const hasUnsafeProperty = checkUnsafeInlineConfig(config) |
| 31 | if (hasUnsafeProperty && !meta.disableHMR) { |
| 32 | logger.warn( |
| 33 | `The provided Tailwind configuration in your \`nuxt.config\` is non-serializable. Check \`${hasUnsafeProperty}\`. Falling back to providing the loaded configuration inlined directly to PostCSS loader..`, |
| 34 | 'Please consider using `tailwind.config` or a separate file (specifying in `configPath` of the module options) to enable it with additional support for IntelliSense and HMR. Suppress this warning with `quiet: true` in the module options.', |
| 35 | ) |
| 36 | meta.disableHMR = true |
| 37 | twCtx.set({ meta }) |
| 38 | } |
| 39 | |
| 40 | return { config } as { config: NonNullable<T> } |
| 41 | } |
| 42 | |
| 43 | const configFile = await (config.startsWith(nuxt.options.buildDir) ? config : findPath(config, { extensions: ['.js', '.cjs', '.mjs', '.ts'] })) |
| 44 | return configFile |
| 45 | ? loadConfig({ configFile }).then(async (resolvedConfig) => { |
| 46 | const { configFile: resolvedConfigFile = configFile } = resolvedConfig |
| 47 | const config = configMerger(undefined, resolvedConfig.config) |
| 48 | configUpdatedHook[resolvedConfigFile] = '' |
| 49 | |
| 50 | if (resolvedConfig.config?.purge && !resolvedConfig.config.content) { |
| 51 | configUpdatedHook[resolvedConfigFile] += 'cfg.content = cfg.purge;' |
| 52 | } |
| 53 | |
| 54 | await nuxt.callHook('tailwindcss:loadConfig', config, resolvedConfigFile, idx, arr as any) |
| 55 | trackObjChanges(resolvedConfigFile, resolvedConfig.config, config) |
| 56 | return { ...resolvedConfig, config } |
| 57 | }).catch((e) => { |
| 58 | logger.warn(`Failed to load config \`./${relative(nuxt.options.rootDir, configFile)}\` due to the error below. Skipping..\n`, e) |
| 59 | return null |
| 60 | }) |
| 61 | : null |
| 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) |
no test coverage detected