@@ -21,11 +21,11 @@ export function getComponentMeta(component: string, options?: Options): Componen
21
21
...options
22
22
}
23
23
const fullPath = isAbsolute ( component ) ? component : withBase ( component , opts . rootDir )
24
- let cachePath = join ( opts . cacheDir , ` ${ component } .json` )
24
+ let cachePath = undefined
25
25
if ( opts . cache ) {
26
26
try {
27
27
const content = readFileSync ( fullPath , { encoding : 'utf8' , flag : 'r' } )
28
- const cacheId = component . split ( '/' ) . pop ( ) ?. replace ( / \. / g, '_' ) + '-' + hash ( 'sha1' , content ) . slice ( 0 , 12 )
28
+ const cacheId = component . split ( '/' ) . pop ( ) ?. replace ( / \. / g, '_' ) + '-- ' + hash ( 'sha1' , content ) . slice ( 0 , 12 )
29
29
cachePath = join ( opts . cacheDir , `${ cacheId } .json` )
30
30
} catch ( error ) {
31
31
throw new Error ( `Error reading file ${ fullPath } : ${ error } ` )
@@ -36,6 +36,27 @@ export function getComponentMeta(component: string, options?: Options): Componen
36
36
}
37
37
}
38
38
39
+ const componentMeta = _getComponentMeta ( fullPath , opts )
40
+
41
+ if ( cachePath ) {
42
+ const cache = JSON . stringify ( { cachedAt : Date . now ( ) , ...componentMeta } )
43
+ if ( ! existsSync ( opts . cacheDir ) ) {
44
+ mkdirSync ( opts . cacheDir , { recursive : true } )
45
+ }
46
+ writeFileSync ( cachePath , cache , { encoding : 'utf8' , flag : 'w' } )
47
+ }
48
+
49
+ return componentMeta
50
+ }
51
+
52
+ /**
53
+ * Create new checker and get component meta
54
+ *
55
+ * @param fullPath full path of the component
56
+ * @param opts options
57
+ * @returns component meta
58
+ */
59
+ function _getComponentMeta ( fullPath : string , opts : Options ) {
39
60
const checker = createCheckerByJson (
40
61
opts . rootDir ,
41
62
{
@@ -45,20 +66,7 @@ export function getComponentMeta(component: string, options?: Options): Componen
45
66
exclude : [ ]
46
67
} ,
47
68
)
48
-
49
- const meta = checker . getComponentMeta ( fullPath )
50
- const refinedMeta = refineMeta ( meta )
51
-
52
- if ( opts . cache ) {
53
- const cache = JSON . stringify ( {
54
- cachedAt : Date . now ( ) ,
55
- ...refinedMeta ,
56
- } )
57
- if ( ! existsSync ( opts . cacheDir ) ) {
58
- mkdirSync ( opts . cacheDir , { recursive : true } )
59
- }
60
- writeFileSync ( cachePath , cache , { encoding : 'utf8' , flag : 'w' } )
61
- }
62
-
63
- return refinedMeta
64
- }
69
+ return refineMeta (
70
+ checker . getComponentMeta ( fullPath )
71
+ )
72
+ }
0 commit comments