Skip to content

Commit

Permalink
fix: async loading javascript config file (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElSalvo96 authored Jul 15, 2023
1 parent f86cf22 commit b2b2aed
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/keys/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ type UserKey = KeyDescription &
key: string;
};

/**
* Load custom module with simple require and absolute path
* Taken by https://github.com/webpack/webpack/issues/6680#issuecomment-644910348
* @param {string} path
*/
const requireDynamically = (path: string) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
eval(`require('${path.split("\\").join("/")}');`);

export async function menu(context: vscode.ExtensionContext): Promise<Menu> {
const originalMenu = defaultMenu();
const configFilePath = configPath(context);
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const userModule = await import(configFilePath.fsPath);
const userModule = await requireDynamically(configFilePath.fsPath);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const userSpecificMenu = userModule(originalMenu) as UserMenu;
return fromUserMenu(userSpecificMenu);
Expand Down

0 comments on commit b2b2aed

Please sign in to comment.