electron/lib/common/define-properties.ts

18 lines
588 B
TypeScript
Raw Normal View History

const handleESModule = (loader: ElectronInternal.ModuleLoader) => () => {
2020-03-20 20:28:31 +00:00
const value = loader();
if (value.__esModule && value.default) return value.default;
return value;
};
// Attaches properties to |targetExports|.
export function defineProperties (targetExports: Object, moduleList: ElectronInternal.ModuleEntry[]) {
2020-03-20 20:28:31 +00:00
const descriptors: PropertyDescriptorMap = {};
for (const module of moduleList) {
descriptors[module.name] = {
enumerable: true,
get: handleESModule(module.loader)
2020-03-20 20:28:31 +00:00
};
}
2020-03-20 20:28:31 +00:00
return Object.defineProperties(targetExports, descriptors);
}