@@ -63,6 +63,30 @@ function defaultWatchFolders() {
6363 }
6464}
6565
66+ /**
67+ * Extracts unique parts from a Yarn store directory.
68+ * @param {string } p
69+ * @returns {[string, string] }
70+ */
71+ function extractUniquePartsFromYarnStoreDir ( p ) {
72+ const parts = p . split ( "-" ) ;
73+ const length = parts . length ;
74+
75+ // Example: node_modules/.store/react-native-virtual-3e97acc5aa
76+ if ( parts [ length - 2 ] === "virtual" ) {
77+ return [ parts . slice ( 0 , length - 1 ) . join ( "-" ) , parts . slice ( - 1 ) . join ( "-" ) ] ;
78+ }
79+
80+ // Example: node_modules/.store/@react -native-assets-registry-npm-0.81.0-rc.5-d313abaf5e
81+ const index = parts . lastIndexOf ( "npm" ) ;
82+ if ( index > 0 ) {
83+ const pos = index + 1 ;
84+ return [ parts . slice ( 0 , pos ) . join ( "-" ) , parts . slice ( pos ) . join ( "-" ) ] ;
85+ }
86+
87+ throw new Error ( `Failed to parse Yarn store directory: ${ p } ` ) ;
88+ }
89+
6690/**
6791 * Returns the path to specified module; `undefined` if not found.
6892 *
@@ -107,14 +131,10 @@ function resolveUniqueModule(packageName, searchStartDir) {
107131 // - react-native -> node_modules/.store/react-native-virtual-3e97acc5aa/package
108132 if ( path . basename ( result ) === "package" && result . includes ( ".store" ) ) {
109133 const storePath = path . dirname ( result ) ;
110- const hashIndex = storePath . lastIndexOf ( "-" ) + 1 ;
111- const hashPart = storePath . substring ( hashIndex ) ;
112- const parent = path
113- . normalize ( storePath . substring ( 0 , hashIndex ) )
114- . replaceAll ( "\\" , "\\\\" )
115- . replaceAll ( "." , "\\." ) ;
134+ const [ pre , unique ] = extractUniquePartsFromYarnStoreDir ( storePath ) ;
135+ const preEscaped = pre . replaceAll ( "\\" , "\\\\" ) . replaceAll ( "." , "\\." ) ;
116136 const exclusionRE = new RegExp (
117- `${ parent } \\w+(?<!${ hashPart } )\\${ path . sep } package\\${ path . sep } .*`
137+ `${ preEscaped } -[-. \\w] +(?<!${ unique } )\\${ path . sep } package\\${ path . sep } .*`
118138 ) ;
119139 return [ result , exclusionRE ] ;
120140 }
@@ -278,6 +298,7 @@ module.exports = {
278298 defaultWatchFolders,
279299 excludeExtraCopiesOf,
280300 exclusionList,
301+ extractUniquePartsFromYarnStoreDir,
281302 resolveUniqueModule,
282303
283304 /**
0 commit comments