-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't fail if can't find file and add json support
- Loading branch information
Showing
5 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
import resolve from "resolve"; | ||
|
||
const extensions = [ | ||
".js", | ||
".jsx", | ||
".json", | ||
".sass", | ||
".scss", | ||
".svg", | ||
".ts", | ||
".tsx", | ||
]; | ||
|
||
/** Checks if the file exists */ | ||
export const canResolve = (id: string, basedir: string) => { | ||
try { | ||
resolve.sync(id, { basedir, extensions }); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
}; | ||
|
||
/** Resolve with a list of predefined extensions. */ | ||
export const customResolve = (id: string, basedir: string) => { | ||
return resolve.sync(id, { | ||
basedir, | ||
extensions: [".js", ".jsx", ".sass", ".scss", ".svg", ".ts", ".tsx"], | ||
}); | ||
return resolve.sync(id, { basedir, extensions }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters