@@ -64,7 +64,12 @@ func (p *PnpApi) RefreshManifest() error {
6464 return nil
6565}
6666
67- func (p * PnpApi ) ResolveToUnqualified (specifier string , parentPath string ) (string , error ) {
67+ type PnpError struct {
68+ Message * diagnostics.Message
69+ Args []any
70+ }
71+
72+ func (p * PnpApi ) ResolveToUnqualified (specifier string , parentPath string ) (string , * PnpError ) {
6873 if p .manifest == nil {
6974 panic ("ResolveToUnqualified called with no PnP manifest available" )
7075 }
@@ -112,13 +117,13 @@ func (p *PnpApi) ResolveToUnqualified(specifier string, parentPath string) (stri
112117 if referenceOrAlias == nil {
113118 if isNodeJSBuiltin (specifier ) {
114119 if isDependencyTreeRoot (p .manifest , parentLocator ) {
115- return "" , errors . New ( diagnostics .Your_application_tried_to_access_0_While_this_module_is_usually_interpreted_as_a_Node_builtin_your_resolver_is_running_inside_a_non_Node_resolution_context_where_such_builtins_are_ignored_Since_0_isn_t_otherwise_declared_in_your_dependencies_this_makes_the_require_call_ambiguous_and_unsound_Required_package_Colon_0_1_Required_by_Colon_2 . Format ( ident , ident , viaSuffix (specifier , ident ), parentPath ))
120+ return "" , & PnpError { Message : diagnostics .Your_application_tried_to_access_0_While_this_module_is_usually_interpreted_as_a_Node_builtin_your_resolver_is_running_inside_a_non_Node_resolution_context_where_such_builtins_are_ignored_Since_0_isn_t_otherwise_declared_in_your_dependencies_this_makes_the_require_call_ambiguous_and_unsound_Required_package_Colon_0_1_Required_by_Colon_2 , Args : [] any { ident , ident , viaSuffix (specifier , ident ), parentPath }}
116121 }
117- return "" , errors . New ( diagnostics .X_0_tried_to_access_1_While_this_module_is_usually_interpreted_as_a_Node_builtin_your_resolver_is_running_inside_a_non_Node_resolution_context_where_such_builtins_are_ignored_Since_1_isn_t_otherwise_declared_in_0_s_dependencies_this_makes_the_require_call_ambiguous_and_unsound_Required_package_Colon_1_2_Required_by_Colon_3 . Format ( parentLocator .Name , ident , ident , parentLocator .Name , ident , viaSuffix (specifier , ident ), parentPath ))
122+ return "" , & PnpError { Message : diagnostics .X_0_tried_to_access_1_While_this_module_is_usually_interpreted_as_a_Node_builtin_your_resolver_is_running_inside_a_non_Node_resolution_context_where_such_builtins_are_ignored_Since_1_isn_t_otherwise_declared_in_0_s_dependencies_this_makes_the_require_call_ambiguous_and_unsound_Required_package_Colon_1_2_Required_by_Colon_3 , Args : [] any { parentLocator .Name , ident , ident , parentLocator .Name , ident , viaSuffix (specifier , ident ), parentPath }}
118123 }
119124
120125 if isDependencyTreeRoot (p .manifest , parentLocator ) {
121- return "" , errors . New ( diagnostics .Your_application_tried_to_access_0_but_it_isn_t_declared_in_your_dependencies_this_makes_the_require_call_ambiguous_and_unsound_Required_package_Colon_0_1_Required_by_Colon_2 . Format ( ident , ident , viaSuffix (specifier , ident ), parentPath ))
126+ return "" , & PnpError { Message : diagnostics .Your_application_tried_to_access_0_but_it_isn_t_declared_in_your_dependencies_this_makes_the_require_call_ambiguous_and_unsound_Required_package_Colon_0_1_Required_by_Colon_2 , Args : [] any { ident , ident , viaSuffix (specifier , ident ), parentPath }}
122127 }
123128
124129 brokenAncestors := findBrokenPeerDependencies (specifier , parentLocator )
@@ -133,9 +138,9 @@ func (p *PnpApi) ResolveToUnqualified(specifier string, parentPath string) (stri
133138 }
134139
135140 if len (brokenAncestors ) > 0 && allBrokenAreRoots {
136- return "" , errors . New ( diagnostics .Your_application_tried_to_access_0_a_peer_dependency_this_isn_t_allowed_as_there_is_no_ancestor_to_satisfy_the_requirement_Use_a_devDependency_if_needed_Required_package_Colon_0_Required_by_Colon_1 . Format ( ident , ident , parentPath ))
141+ return "" , & PnpError { Message : diagnostics .Your_application_tried_to_access_0_a_peer_dependency_this_isn_t_allowed_as_there_is_no_ancestor_to_satisfy_the_requirement_Use_a_devDependency_if_needed_Required_package_Colon_0_Required_by_Colon_1 , Args : [] any { ident , ident , parentPath }}
137142 } else {
138- return "" , errors . New ( diagnostics .X_0_tried_to_access_1_a_peer_dependency_but_it_isn_t_provided_by_its_ancestors_Slashyour_application_this_makes_the_require_call_ambiguous_and_unsound_Required_package_Colon_1_Required_by_Colon_2 . Format ( parentLocator .Name , ident , ident , parentPath ))
143+ return "" , & PnpError { Message : diagnostics .X_0_tried_to_access_1_a_peer_dependency_but_it_isn_t_provided_by_its_ancestors_Slashyour_application_this_makes_the_require_call_ambiguous_and_unsound_Required_package_Colon_1_Required_by_Colon_2 , Args : [] any { parentLocator .Name , ident , ident , parentPath }}
139144 }
140145 }
141146
@@ -159,7 +164,7 @@ func (p *PnpApi) findClosestPnpManifest() (*PnpManifestData, error) {
159164 }
160165
161166 if tspath .IsDiskPathRoot (directoryPath ) {
162- return nil , errors .New (diagnostics . X_no_PnP_manifest_found . Format () )
167+ return nil , errors .New ("no PnP manifest found" )
163168 }
164169
165170 directoryPath = tspath .GetDirectoryPath (directoryPath )
@@ -176,7 +181,7 @@ func (p *PnpApi) GetPackage(locator *Locator) *PackageInfo {
176181 return packageInfo
177182}
178183
179- func (p * PnpApi ) FindLocator (parentPath string ) (* Locator , error ) {
184+ func (p * PnpApi ) FindLocator (parentPath string ) (* Locator , * PnpError ) {
180185 if parentPath == "" {
181186 return nil , nil
182187 }
@@ -186,11 +191,8 @@ func (p *PnpApi) FindLocator(parentPath string) (*Locator, error) {
186191
187192 if p .manifest .ignorePatternData != nil {
188193 match , err := p .manifest .ignorePatternData .MatchString (relativePath )
189- if err != nil {
190- return nil , err
191- }
192194
193- if match {
195+ if err == nil && match {
194196 return nil , nil
195197 }
196198 }
@@ -222,7 +224,7 @@ func (p *PnpApi) FindLocator(parentPath string) (*Locator, error) {
222224 }
223225
224226 if bestLocator == nil {
225- return nil , errors . New ( diagnostics .X_no_package_found_for_path_0 . Format ( relativePath ))
227+ return nil , & PnpError { Message : diagnostics .X_no_package_found_for_path_0 , Args : [] any { relativePath }}
226228 }
227229
228230 return bestLocator , nil
@@ -252,16 +254,16 @@ func (p *PnpApi) ResolveViaFallback(name string) *PackageDependency {
252254 return nil
253255}
254256
255- func (p * PnpApi ) ParseBareIdentifier (specifier string ) (ident string , modulePath string , err error ) {
257+ func (p * PnpApi ) ParseBareIdentifier (specifier string ) (ident string , modulePath string , err * PnpError ) {
256258 if len (specifier ) == 0 {
257- return "" , "" , errors . New ( diagnostics .Empty_specifier_Colon_0 . Format ( specifier ))
259+ return "" , "" , & PnpError { Message : diagnostics .Empty_specifier_Colon_0 , Args : [] any { specifier }}
258260 }
259261
260262 firstSlash := strings .Index (specifier , "/" )
261263
262264 if specifier [0 ] == '@' {
263265 if firstSlash == - 1 {
264- return "" , "" , errors . New ( diagnostics .Invalid_specifier_Colon_0 . Format ( specifier ))
266+ return "" , "" , & PnpError { Message : diagnostics .Invalid_specifier_Colon_0 , Args : [] any { specifier }}
265267 }
266268
267269 secondSlash := strings .Index (specifier [firstSlash + 1 :], "/" )
0 commit comments