refactor: unify module-list format and exports/electron (#19697)

This commit is contained in:
Milan Burda 2019-08-23 11:18:58 +02:00 committed by Alexey Kuzmin
parent c6a8b7f959
commit 7825d043f2
18 changed files with 108 additions and 162 deletions

View file

@ -0,0 +1,17 @@
const handleESModule = (loader: ElectronInternal.ModuleLoader) => () => {
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[]) {
const descriptors: PropertyDescriptorMap = {}
for (const module of moduleList) {
descriptors[module.name] = {
enumerable: !module.private,
get: handleESModule(module.loader)
}
}
return Object.defineProperties(targetExports, descriptors)
}