Skip to content

Commit

Permalink
refactor: simplify extension logic
Browse files Browse the repository at this point in the history
  • Loading branch information
samchungy committed Nov 30, 2021
1 parent e64d144 commit 053a962
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ export function extractFileNames(
// replace only last instance to allow the same name for file and handler
const fileName = h.substring(0, fnNameLastAppearanceIndex);

// Check if the .ts files exists. If so return that to watch
if (fs.existsSync(path.join(cwd, fileName + '.ts'))) {
return { entry: path.relative(cwd, fileName) + '.ts', func, functionAlias };
}

// Check if the .js files exists. If so return that to watch
if (fs.existsSync(path.join(cwd, fileName + '.js'))) {
return { entry: path.relative(cwd, fileName) + '.js', func, functionAlias };
const extensions = ['.ts', '.js'];
for (const extension of extensions) {
// Check if the .{extension} files exists. If so return that to watch
if (fs.existsSync(path.join(cwd, fileName + extension))) {
return { entry: path.relative(cwd, fileName + extension), func, functionAlias };
}
}

// Can't find the files. Watch will have an exception anyway. So throw one with error.
Expand Down

0 comments on commit 053a962

Please sign in to comment.