mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 11:10:48 +00:00
Skip loadScriptSource
if we know the preload is already supposed to be a module (#164405)
This commit is contained in:
parent
5f14f1b13b
commit
5c1f34e212
1 changed files with 17 additions and 9 deletions
|
@ -247,17 +247,16 @@ async function webviewPreloads(ctx: PreloadContext) {
|
|||
return new Function(...args.map(([k]) => k), functionSrc)(...args.map(([, v]) => v));
|
||||
};
|
||||
|
||||
const runKernelPreload = async (url: string, originalUri: string, forceLoadAsModule: boolean): Promise<void> => {
|
||||
async function runKernelPreload(url: string, originalUri: string, forceLoadAsModule: boolean): Promise<void> {
|
||||
if (forceLoadAsModule) {
|
||||
return activateModuleKernelPreload(url);
|
||||
}
|
||||
|
||||
const text = await loadScriptSource(url, originalUri);
|
||||
const isModule = /\bexport\b.*\bactivate\b/.test(text);
|
||||
try {
|
||||
if (isModule || forceLoadAsModule) {
|
||||
const module: KernelPreloadModule = await __import(url);
|
||||
if (!module.activate) {
|
||||
console.error(`Notebook preload (${url}) looks like a module but does not export an activate function`);
|
||||
return;
|
||||
}
|
||||
return module.activate(createKernelContext());
|
||||
if (isModule) {
|
||||
return activateModuleKernelPreload(url);
|
||||
} else {
|
||||
return invokeSourceWithGlobals(text, { ...kernelPreloadGlobals, scriptUrl: url });
|
||||
}
|
||||
|
@ -265,7 +264,16 @@ async function webviewPreloads(ctx: PreloadContext) {
|
|||
console.error(e);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function activateModuleKernelPreload(url: string) {
|
||||
const module: KernelPreloadModule = await __import(url);
|
||||
if (!module.activate) {
|
||||
console.error(`Notebook preload '${url}' was expected to be a module but it does not export an 'activate' function`);
|
||||
return;
|
||||
}
|
||||
return module.activate(createKernelContext());
|
||||
}
|
||||
|
||||
const dimensionUpdater = new class {
|
||||
private readonly pending = new Map<string, webviewMessages.DimensionUpdate>();
|
||||
|
|
Loading…
Reference in a new issue