Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setupFileResolver() {
const fileResolver = {};
fileResolver.protocol = new Protocol(
'file-resolver',
() => true,
window.parent
);
fileResolver.isFile = path =>
fileResolver.protocol.sendMessage({ m: 'isFile', p: path });
fileResolver.readFile = path =>
fileResolver.protocol.sendMessage({ m: 'readFile', p: path });
this.fileResolver = fileResolver;
}
this.listener = listen((message: any) => {
switch (message.type) {
case 'initialized': {
if (this.iframe) {
if (this.iframe.contentWindow) {
registerFrame(this.iframe.contentWindow, this.bundlerURL);
if (this.options.fileResolver) {
this.fileResolverProtocol = new Protocol(
'file-resolver',
async (data: { m: 'isFile' | 'readFile'; p: string }) => {
if (data.m === 'isFile') {
return this.options.fileResolver!.isFile(data.p);
}
return this.options.fileResolver!.readFile(data.p);
},
this.iframe.contentWindow
);
}
}
this.updatePreview();
}
break;