@@ -2,35 +2,34 @@ import { existsSync } from 'fs'
2
2
import { defu } from 'defu'
3
3
import { join , relative , resolve } from 'pathe'
4
4
import { findPath , useNuxt , tryResolveModule , resolveAlias } from '@nuxt/kit'
5
- import type { Arrayable , EditorSupportConfig , ExposeConfig , InjectPosition , ModuleOptions , ViewerConfig } from './types'
5
+ import type { EditorSupportConfig , ExposeConfig , InjectPosition , ModuleOptions , ViewerConfig } from './types'
6
6
7
7
/**
8
8
* Resolves all configPath values for an application
9
9
*
10
10
* @param path configPath for a layer
11
11
* @returns array of resolved paths
12
12
*/
13
- export const resolveConfigPath = async ( path : Arrayable < string > ) => (
14
- await Promise . all (
13
+ const resolveConfigPath = async ( path : ModuleOptions [ 'configPath' ] ) =>
14
+ Promise . all (
15
15
( Array . isArray ( path ) ? path : [ path ] )
16
16
. filter ( Boolean )
17
17
. map ( ( path ) => findPath ( path , { extensions : [ '.js' , '.cjs' , '.mjs' , '.ts' ] } ) )
18
- )
19
- ) . filter ( ( i ) : i is string => Boolean ( i ) )
18
+ ) . then ( ( paths ) => paths . filter ( ( p ) : p is string => Boolean ( p ) ) )
20
19
21
20
/**
22
21
*
23
22
* @param srcDir
24
23
* @returns array of resolved content globs
25
24
*/
26
- export const resolveContentPaths = ( srcDir : string , nuxt = useNuxt ( ) ) => {
25
+ const resolveContentPaths = ( srcDir : string , nuxtOptions = useNuxt ( ) . options ) => {
27
26
const r = ( p : string ) => p . startsWith ( srcDir ) ? p : resolve ( srcDir , p )
28
27
const extensionFormat = ( s : string [ ] ) => s . length > 1 ? `.{${ s . join ( ',' ) } }` : `.${ s . join ( '' ) || 'vue' } `
29
28
30
29
const defaultExtensions = extensionFormat ( [ 'js' , 'ts' , 'mjs' ] )
31
- const sfcExtensions = extensionFormat ( Array . from ( new Set ( [ '.vue' , ...nuxt . options . extensions ] ) ) . map ( e => e . replace ( / ^ \. * / , '' ) ) )
30
+ const sfcExtensions = extensionFormat ( Array . from ( new Set ( [ '.vue' , ...nuxtOptions . extensions ] ) ) . map ( e => e . replace ( / ^ \. * / , '' ) ) )
32
31
33
- const importDirs = [ ...( nuxt . options . imports ?. dirs || [ ] ) ] . map ( r )
32
+ const importDirs = [ ...( nuxtOptions . imports ?. dirs || [ ] ) ] . map ( r )
34
33
const [ composablesDir , utilsDir ] = [ resolve ( srcDir , 'composables' ) , resolve ( srcDir , 'utils' ) ]
35
34
36
35
if ( ! importDirs . includes ( composablesDir ) ) importDirs . push ( composablesDir )
@@ -39,16 +38,16 @@ export const resolveContentPaths = (srcDir: string, nuxt = useNuxt()) => {
39
38
return [
40
39
r ( `components/**/*${ sfcExtensions } ` ) ,
41
40
...( ( ) => {
42
- if ( nuxt . options . components ) {
43
- return ( Array . isArray ( nuxt . options . components ) ? nuxt . options . components : typeof nuxt . options . components === 'boolean' ? [ 'components' ] : nuxt . options . components . dirs ) . map ( d => `${ resolveAlias ( typeof d === 'string' ? d : d . path ) } /**/*${ sfcExtensions } ` )
41
+ if ( nuxtOptions . components ) {
42
+ return ( Array . isArray ( nuxtOptions . components ) ? nuxtOptions . components : typeof nuxtOptions . components === 'boolean' ? [ 'components' ] : nuxtOptions . components . dirs ) . map ( d => `${ resolveAlias ( typeof d === 'string' ? d : d . path ) } /**/*${ sfcExtensions } ` )
44
43
}
45
44
return [ ]
46
45
} ) ( ) ,
47
46
48
- nuxt . options . dir . layouts && r ( `${ nuxt . options . dir . layouts } /**/*${ sfcExtensions } ` ) ,
49
- ...( [ true , undefined ] . includes ( nuxt . options . pages ) ? [ r ( `${ nuxt . options . dir . pages } /**/*${ sfcExtensions } ` ) ] : [ ] ) ,
47
+ nuxtOptions . dir . layouts && r ( `${ nuxtOptions . dir . layouts } /**/*${ sfcExtensions } ` ) ,
48
+ ...( [ true , undefined ] . includes ( nuxtOptions . pages ) ? [ r ( `${ nuxtOptions . dir . pages } /**/*${ sfcExtensions } ` ) ] : [ ] ) ,
50
49
51
- nuxt . options . dir . plugins && r ( `${ nuxt . options . dir . plugins } /**/*${ defaultExtensions } ` ) ,
50
+ nuxtOptions . dir . plugins && r ( `${ nuxtOptions . dir . plugins } /**/*${ defaultExtensions } ` ) ,
52
51
...importDirs . map ( d => `${ d } /**/*${ defaultExtensions } ` ) ,
53
52
54
53
r ( `{A,a}pp${ sfcExtensions } ` ) ,
@@ -63,27 +62,32 @@ export const resolveContentPaths = (srcDir: string, nuxt = useNuxt()) => {
63
62
* @param nuxt
64
63
* @returns [configuration paths, default resolved content paths]
65
64
*/
66
- export const resolveModulePaths = async ( configPath : ModuleOptions [ 'configPath' ] , nuxt = useNuxt ( ) ) : Promise < [ string [ ] , string [ ] ] > => (
67
- ( nuxt . options . _layers && nuxt . options . _layers . length > 1 )
68
- // Support `extends` directories
69
- ? ( await Promise . all (
70
- // nuxt.options._layers is from rootDir to nested level
71
- // We need to reverse the order to give the deepest tailwind.config the lowest priority
72
- nuxt . options . _layers . slice ( ) . reverse ( ) . map ( async ( layer ) => ( [
65
+ export const resolveModulePaths = async ( configPath : ModuleOptions [ 'configPath' ] , nuxt = useNuxt ( ) ) => {
66
+ const mainPaths : [ string [ ] , string [ ] ] = [ await resolveConfigPath ( configPath ) , resolveContentPaths ( nuxt . options . srcDir , nuxt . options ) ]
67
+
68
+ if ( Array . isArray ( nuxt . options . _layers ) && nuxt . options . _layers . length > 1 ) {
69
+ const layerPaths = await Promise . all (
70
+ nuxt . options . _layers . slice ( 1 ) . reverse ( ) . map ( async ( layer ) : Promise < [ string [ ] , string [ ] ] > => ( [
73
71
await resolveConfigPath ( layer ?. config ?. tailwindcss ?. configPath || join ( layer . cwd , 'tailwind.config' ) ) ,
74
- resolveContentPaths ( layer ?. config ?. srcDir || layer . cwd )
72
+ resolveContentPaths ( layer ?. config ?. srcDir || layer . cwd , defu ( layer . config , nuxt . options ) as typeof nuxt . options )
75
73
] ) ) )
76
- ) . reduce ( ( prev , curr ) => prev . map ( ( p , i ) => p . concat ( curr [ i ] ) ) ) as any
77
- : [ await resolveConfigPath ( configPath ) , resolveContentPaths ( nuxt . options . srcDir ) ]
78
- )
74
+
75
+ layerPaths . forEach ( ( [ configPaths , contentPaths ] ) => {
76
+ mainPaths [ 0 ] . push ( ...configPaths )
77
+ mainPaths [ 1 ] . push ( ...contentPaths )
78
+ } )
79
+ }
80
+
81
+ return mainPaths
82
+ }
79
83
80
84
/**
81
85
*
82
86
* @param cssPath
83
87
* @param nuxt
84
88
* @returns [resolvedCss, loggerMessage]
85
89
*/
86
- export async function resolveCSSPath ( cssPath : Exclude < ModuleOptions [ 'cssPath' ] , Array < any > > , nuxt = useNuxt ( ) ) : Promise < [ string | false , string ] > {
90
+ export async function resolveCSSPath ( cssPath : Exclude < ModuleOptions [ 'cssPath' ] , Array < any > > , nuxt = useNuxt ( ) ) : Promise < [ string | false , string ] > {
87
91
if ( typeof cssPath === 'string' ) {
88
92
return existsSync ( cssPath )
89
93
? [ cssPath , `Using Tailwind CSS from ~/${ relative ( nuxt . options . srcDir , cssPath ) } ` ]
@@ -117,7 +121,7 @@ export const resolveEditorSupportConfig = (config: ModuleOptions['editorSupport'
117
121
*
118
122
* @returns index in the css array
119
123
*/
120
- export function resolveInjectPosition ( css : string [ ] , position : InjectPosition = 'first' ) {
124
+ export function resolveInjectPosition ( css : string [ ] , position : InjectPosition = 'first' ) {
121
125
if ( typeof ( position ) === 'number' ) {
122
126
return ~ ~ Math . min ( position , css . length + 1 )
123
127
}
4 commit comments
dargmuesli commentedon Feb 1, 2024
What was the motivation behind this change? With this change my projects don't override their base layer's theme extension anymore 🤔
Having this on a base layer:
and this on the actual project:
shows yellow instead of overriding it with red after v
6.11.1
.ineshbose commentedon Feb 1, 2024
@dargmuesli this change was important to prepare for #795; it makes sense semantically to use moduleOptions over layer[0], because like nuxt/ui uses installModule and it wouldn't have worked otherwise.
I think I see what caused your issue though, thanks for reporting - instead of mainPaths.push, we're looking at mainPaths.unshift - let me fix that or you can open a PR in that time!
ineshbose commentedon Feb 1, 2024
@dargmuesli fix made. Can you try out nightly and confirm please, will release then.
dargmuesli commentedon Feb 1, 2024
@ineshbose yes, the nightly fixes the issue for me! ❤️ Thank you!