Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(esm): add support for .gmrc as an ES Module #140

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/commands/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ interface Options {
*/
export async function getSettings(options: Options = {}): Promise<Settings> {
const { configFile } = options;
const tryRequire = (path: string): Settings => {
const tryRequire = async (path: string): Promise<Settings> => {
// If the file is e.g. `foo.js` then Node `require('foo.js')` would look in
// `node_modules`; we don't want this - instead force it to be a relative
// path.
const relativePath = resolve(process.cwd(), path);

try {
return require(relativePath);
try {
return (await import(relativePath)).default;
guillaumervls marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
return require(relativePath);
}
} catch (e) {
throw new Error(
`Failed to import '${relativePath}'; error:\n ${e.stack.replace(
Expand Down