Skip to content

Commit

Permalink
fix #75: SAM - do not throw an error if file do not exists (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ServerlessLife authored Oct 10, 2024
1 parent e7dcabc commit cc67250
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/frameworks/samFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ export class SamFramework implements IFramework {

if (!codePath) {
const fileWithExtension = handlerParts[0];
const possibleCodePathsTs = `${fileWithExtension}.ts`;
const possibleCodePathsJs = `${fileWithExtension}.js`;
const possibleCodePaths = [
`${fileWithExtension}.ts`,
`${fileWithExtension}.js`,
possibleCodePathsTs,
possibleCodePathsJs,
`${fileWithExtension}.cjs`,
`${fileWithExtension}.mjs`,
];
Expand All @@ -183,10 +185,14 @@ export class SamFramework implements IFramework {
// ignore, file not found
}
}
}

if (!codePath) {
throw new Error(`Code path not found for function: ${func.Name}`);
if (!codePath) {
codePath = possibleCodePathsJs;

Logger.warn(
`[Function ${functionName}] Can not find code path for handler: ${handlerFull}. Using fallback: ${codePath}`,
);
}
}

const packageJsonPath = await findPackageJson(codePath);
Expand Down

0 comments on commit cc67250

Please sign in to comment.