@@ -5,31 +5,37 @@ import {
55import { dirname , join } from 'path' ;
66import type { JsResolverEntry } from '@aws-amplify/data-schema-types' ;
77import { AmplifyDataError } from './types.js' ;
8+ import fs from 'fs' ;
89
910/**
1011 * Resolve JS Resolver Handler or Sql Reference Handler entry path to absolute path
1112 * @param entry handler entry
1213 * @returns resolved absolute file path
1314 */
1415export const resolveEntryPath = ( entry : JsResolverEntry ) : string => {
15- const unresolvedImportLocationError = new AmplifyUserError < AmplifyDataError > (
16- 'UnresolvedEntryPathError' ,
17- {
18- message :
19- 'Could not determine import path to construct absolute code path from relative path: ' +
20- JSON . stringify ( entry ) ,
21- resolution : 'Consider using an absolute path instead.' ,
22- } ,
23- ) ;
24-
2516 if ( typeof entry === 'string' ) {
26- return entry ;
17+ if ( fs . existsSync ( entry ) ) {
18+ return entry ;
19+ }
20+ throw new AmplifyUserError < AmplifyDataError > ( 'InvalidPathError' , {
21+ message : `Cannot find file at ${ entry } ` ,
22+ resolution : `Check that the file exists at ${ entry } and is readable` ,
23+ } ) ;
2724 }
2825
29- const filePath = new FilePathExtractor ( entry . importLine ) . extract ( ) ;
30- if ( filePath ) {
31- return join ( dirname ( filePath ) , entry . relativePath ) ;
26+ const importPath = new FilePathExtractor ( entry . importLine ) . extract ( ) ;
27+
28+ if ( importPath ) {
29+ const filePath = join ( dirname ( importPath ) , entry . relativePath ) ;
30+ if ( filePath && fs . existsSync ( filePath ) ) {
31+ return filePath ;
32+ }
3233 }
3334
34- throw unresolvedImportLocationError ;
35+ throw new AmplifyUserError < AmplifyDataError > ( 'UnresolvedEntryPathError' , {
36+ message :
37+ 'Could not determine import path to construct absolute code path from relative path: ' +
38+ JSON . stringify ( entry ) ,
39+ resolution : 'Consider using an absolute path instead.' ,
40+ } ) ;
3541} ;
0 commit comments