Skip to content

Commit

Permalink
chore: expose electrons built in modules in the REPL along with nodes (
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Jun 24, 2020
1 parent b2b5a6a commit abf2e9c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions default_app/main.ts
Expand Up @@ -168,6 +168,39 @@ function startRepl () {
process.exit(0);
});

function defineBuiltin (context: any, name: string, getter: Function) {
const setReal = (val: any) => {
// Deleting the property before re-assigning it disables the
// getter/setter mechanism.
delete context[name];
context[name] = val;
};

Object.defineProperty(context, name, {
get: () => {
const lib = getter();

delete context[name];
Object.defineProperty(context, name, {
get: () => lib,
set: setReal,
configurable: true,
enumerable: false
});

return lib;
},
set: setReal,
configurable: true,
enumerable: false
});
}

defineBuiltin(repl.context, 'electron', () => electron);
for (const api of Object.keys(electron) as (keyof typeof electron)[]) {
defineBuiltin(repl.context, api, () => electron[api]);
}

// Copied from node/lib/repl.js. For better DX, we don't want to
// show e.g 'contentTracing' at a higher priority than 'const', so
// we only trigger custom tab-completion when no common words are
Expand Down

0 comments on commit abf2e9c

Please sign in to comment.