core: add script default export support

This commit is contained in:
Koushik Dutta
2022-06-25 14:17:24 -07:00
parent 9d98059a89
commit cb3591e613
10 changed files with 41 additions and 19 deletions

View File

@@ -1,4 +1,8 @@
export interface ScriptDevice {
/**
* @deprecated Use export default instead.
* @param handler
*/
handle<T>(handler?: T & object): void;
handleTypes(...interfaces: string[]): void;
}

View File

@@ -82,7 +82,7 @@ export async function scryptedEval(device: ScryptedDeviceBase, script: string, e
console: device.console,
localStorage: device.storage,
device,
exports: {},
exports: {} as any,
ScryptedInterface,
ScryptedDeviceType,
});
@@ -102,7 +102,12 @@ export async function scryptedEval(device: ScryptedDeviceBase, script: string, e
}
try {
return await asyncFunction();
const value = await asyncFunction();
const defaultExport = allParams.exports.default;
return {
value,
defaultExport,
};
}
catch (e) {
device.log.e('Error running script.');