@@ -21,20 +21,28 @@ export function getImplementationFactory<T>(
21
21
const [ implementationModulePath , implementationExportName ] =
22
22
implementation . split ( '#' ) ;
23
23
return ( ) => {
24
- console . log ( 'resolving implementation' ) ;
24
+ console . log ( `Resolving implementation: ${ implementation } from ${ directory } ` ) ;
25
25
const modulePath = resolveImplementation (
26
26
implementationModulePath ,
27
27
directory ,
28
28
packageName ,
29
29
projects
30
30
) ;
31
+ console . log ( `Resolved module path: ${ modulePath } ` ) ;
31
32
if ( extname ( modulePath ) === '.ts' ) {
32
33
registerPluginTSTranspiler ( ) ;
33
34
}
35
+ try {
34
36
const module = require ( modulePath ) ;
35
37
return implementationExportName
36
38
? module [ implementationExportName ]
37
39
: module . default ?? module ;
40
+ } catch ( e ) {
41
+ console . error ( `Failed to require implementation at ${ modulePath } :` , e ) ;
42
+ throw new Error (
43
+ `Could not require implementation "${ implementation } " from "${ directory } ". Ensure the implementation is correctly exported.`
44
+ ) ;
45
+ }
38
46
} ;
39
47
}
40
48
@@ -50,6 +58,9 @@ export function resolveImplementation(
50
58
packageName : string ,
51
59
projects : Record < string , ProjectConfiguration >
52
60
) : string {
61
+
62
+ console . log ( `Resolving implementation: ${ implementationModulePath } from ${ directory } ` ) ;
63
+
53
64
const validImplementations = [ '' , '.js' , '.ts' ] . map (
54
65
( x ) => implementationModulePath + x
55
66
) ;
@@ -66,6 +77,7 @@ export function resolveImplementation(
66
77
projects
67
78
) ;
68
79
if ( maybeImplementationFromSource ) {
80
+ console . log ( `Resolved from source: ${ maybeImplementationFromSource } ` ) ;
69
81
return maybeImplementationFromSource ;
70
82
}
71
83
}
@@ -74,17 +86,26 @@ export function resolveImplementation(
74
86
for ( const maybeImplementation of validImplementations ) {
75
87
const maybeImplementationPath = join ( directory , maybeImplementation ) ;
76
88
if ( existsSync ( maybeImplementationPath ) ) {
89
+ console . log ( `Resolved from directory: ${ maybeImplementationPath } ` ) ;
77
90
return maybeImplementationPath ;
78
91
}
79
92
80
93
try {
81
- return require . resolve ( maybeImplementation , {
94
+ const resolved = require . resolve ( maybeImplementation , {
82
95
paths : [ directory ] ,
83
96
} ) ;
84
- } catch { }
97
+ console . log ( `Resolved via require.resolve: ${ resolved } ` ) ;
98
+ return resolved ;
99
+ } catch ( e ) {
100
+ console . error ( `Failed to resolve "${ maybeImplementation } " from "${ directory } ":` , e ) ;
101
+ // If it fails, we continue to the next valid implementation
102
+ // This is useful for cases where the implementation might be in a different format
103
+ // or if the file is not found in the expected location.
104
+ continue ;
105
+ }
85
106
}
86
107
87
- throw new Error (
108
+ throw new Error (
88
109
`Could not resolve "${ implementationModulePath } " from "${ directory } ".`
89
110
) ;
90
111
}
@@ -127,14 +148,19 @@ function tryResolveFromSource(
127
148
packageName : string ,
128
149
projects : Record < string , ProjectConfiguration >
129
150
) : string | null {
151
+ console . log ( `Trying to resolve from source: ${ path } in ${ directory } for package: ${ packageName } ` ) ;
152
+
130
153
packageToProjectMap ??=
131
154
getWorkspacePackagesMetadata ( projects ) . packageToProjectMap ;
132
155
const localProject = packageToProjectMap [ packageName ] ;
133
156
if ( ! localProject ) {
134
- // it doesn't match any of the package names from the local projects
157
+ console . log ( `No local project found for package: ${ packageName } ` ) ;
158
+ // it doesn't match any of the package names from the local projects
135
159
return null ;
136
160
}
137
161
162
+ console . log ( `Found local project for package: ${ packageName } at ${ localProject . root } ` ) ;
163
+
138
164
try {
139
165
const fromExports = resolveExports (
140
166
{
@@ -146,13 +172,16 @@ function tryResolveFromSource(
146
172
) ;
147
173
if ( fromExports && fromExports . length ) {
148
174
for ( const exportPath of fromExports ) {
149
- if ( existsSync ( join ( directory , exportPath ) ) ) {
150
- return join ( directory , exportPath ) ;
175
+ const fullPath = join ( directory , exportPath ) ;
176
+ if ( existsSync ( fullPath ) ) {
177
+ console . log ( `Resolved from exports: ${ fullPath } ` ) ;
178
+ return fullPath ;
151
179
}
152
180
}
153
181
}
154
- } catch { }
155
-
182
+ } catch ( e ) {
183
+ console . log ( `Failed to resolve from exports: ${ e . message } ` ) ;
184
+ }
156
185
/**
157
186
* Fall back to try to "guess" the source by checking the path in some common directories:
158
187
* - the root of the project
@@ -169,6 +198,7 @@ function tryResolveFromSource(
169
198
170
199
for ( const possiblePath of possiblePaths ) {
171
200
if ( existsSync ( possiblePath ) ) {
201
+ console . log ( `Resolved from fallback path: ${ possiblePath } ` ) ;
172
202
return possiblePath ;
173
203
}
174
204
}
0 commit comments