@@ -39,7 +39,7 @@ export abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDe
3939 constructor (
4040 protected readonly rootDir : string ,
4141 private readonly tempDirManager : TmpDir
42- ) { }
42+ ) { }
4343
4444 public async getNodeModules ( { cancellationToken, packageName } : { cancellationToken : CancellationToken ; packageName : string } ) : Promise < NodeModuleInfo [ ] > {
4545 const tree : ProdDepType = await this . getDependenciesTree ( this . installOptions . manager )
@@ -172,6 +172,7 @@ export abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDe
172172 }
173173
174174 // 2. Handle file: and file:// protocol or pnpm-style virtual paths
175+ // Try file: protocol for virtualPath
175176 if ( virtualPath ?. startsWith ( "file:" ) ) {
176177 const filePath = virtualPath . replace ( / ^ f i l e : ( \/ \/ ) ? / , "" )
177178 const normalizedPath = filePath . replace ( / \/ / g, path . sep )
@@ -192,10 +193,23 @@ export abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDe
192193 // Relative to root
193194 candidatePaths . push ( path . resolve ( this . rootDir , normalizedPath ) )
194195
195- // If the path contains .pnpm, also try the non-pnpm version
196- const pnpmMatch = normalizedPath . match ( / \. p n p m [ / \\ ] [ ^ / \\ ] + [ / \\ ] n o d e _ m o d u l e s [ / \\ ] ( .+ ) $ / )
197- if ( pnpmMatch ) {
198- const pkgName = pnpmMatch [ 1 ] . replace ( / \\ / g, "/" )
196+ // Extract package name from various pnpm path patterns
197+ let pkgName : string | null = null
198+
199+ // Pattern 1: .pnpm/@types+fs-extra@9.0.13/node_modules/@types/fs-extra
200+ const pnpmMatch1 = normalizedPath . match ( / \. p n p m [ / \\ ] [ ^ / \\ ] + [ / \\ ] n o d e _ m o d u l e s [ / \\ ] ( .+ ) $ / )
201+ if ( pnpmMatch1 ) {
202+ pkgName = pnpmMatch1 [ 1 ] . replace ( / \\ / g, '/' )
203+ }
204+
205+ // Pattern 2: @types+node@22.13.17/node_modules/@types/node
206+ const pnpmMatch2 = normalizedPath . match ( / ( [ ^ / \\ ] + @ [ ^ / \\ ] + ) [ / \\ ] n o d e _ m o d u l e s [ / \\ ] ( .+ ) $ / )
207+ if ( pnpmMatch2 && ! pkgName ) {
208+ pkgName = pnpmMatch2 [ 2 ] . replace ( / \\ / g, '/' )
209+ }
210+
211+ if ( pkgName ) {
212+ log . error ( { normalizedPath, extractedPkgName : pkgName } , "extracted package name from pnpm path" )
199213
200214 // Try in rootDir
201215 candidatePaths . push ( path . resolve ( this . rootDir , "node_modules" , pkgName ) )
@@ -210,11 +224,9 @@ export abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDe
210224 if ( next === current ) break
211225 current = next
212226 }
213-
214- log . debug ( { normalizedPath, extractedPkgName : pkgName } , "extracted package name from pnpm path" )
215227 }
216228
217- log . debug ( { pkg, virtualPath, candidatePaths } , "trying to resolve file dependency" )
229+ log . error ( { pkg, virtualPath, candidatePaths } , "trying to resolve file dependency" )
218230
219231 // Try each candidate path
220232 for ( const candidatePath of candidatePaths ) {
@@ -223,7 +235,7 @@ export abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDe
223235 const pkgJsonPath = path . join ( candidatePath , "package.json" )
224236 if ( await exists ( pkgJsonPath ) ) {
225237 const resolvedPath = await fs . realpath ( candidatePath )
226- log . debug ( { pkg, resolvedPath } , "resolved file dependency" )
238+ log . error ( { pkg, resolvedPath } , "resolved file dependency" )
227239 return resolvedPath
228240 }
229241 } catch {
@@ -234,7 +246,7 @@ export abstract class NodeModulesCollector<ProdDepType extends Dependency<ProdDe
234246
235247 // None of the candidates worked
236248 if ( isOptionalDependency ) {
237- log . debug ( { pkg, virtualPath, candidatePaths } , "optional file dependency not found" )
249+ log . error ( { pkg, virtualPath, candidatePaths } , "optional file dependency not found" )
238250 return null
239251 }
240252
0 commit comments