|
export async function startJupyterLiteServer(config?: LiteServerConfig): Promise<ServiceManager> { |
|
/** |
|
* This is sufficent to initialise the global object? |
|
*/ |
|
PageConfig.getOption(''); |
|
|
|
/** |
|
* Do not rely on a configuration being on the document body, accept configuration via arguments |
|
* and set options on the page config directly |
|
*/ |
|
const defaultLiteConfig = { |
|
litePluginSettings: { |
|
'@jupyterlite/pyodide-kernel-extension:kernel': { |
|
pipliteUrls: ['https://unpkg.com/@jupyterlite/pyodide-kernel@0.4.7/pypi/all.json'], |
|
pipliteWheelUrl: |
|
'https://unpkg.com/@jupyterlite/pyodide-kernel@0.4.7/pypi/piplite-0.4.7-py3-none-any.whl', |
|
}, |
|
}, |
|
enableMemoryStorage: true, |
|
settingsStorageDrivers: ['memoryStorageDriver'], |
|
}; |
|
PageConfig.setOption( |
|
'litePluginSettings', |
|
JSON.stringify({ ...defaultLiteConfig.litePluginSettings, ...config?.litePluginSettings }), |
|
); |
|
PageConfig.setOption( |
|
'enableMemoryStorage', |
|
JSON.stringify(config?.enableMemoryStorage ?? defaultLiteConfig.enableMemoryStorage), |
|
); |
|
PageConfig.setOption( |
|
'settingsStorageDrivers', |
|
JSON.stringify(config?.settingsStorageDrivers ?? defaultLiteConfig.settingsStorageDrivers), |
|
); |
|
|
|
/** |
|
* Seems like there are 4 different extensions we may want to handle |
|
* |
|
* liteExtension - essential, as these are how kernels are added |
|
* federatedExtension - general jupyterlab extensions |
|
* federatedMimeExtension - render extensions? e.g. @jupyterlab/javascript-extension, @jupyterlab/json-extension |
|
* federatedStyles - ? |
|
* |
|
* TODO we're not suppporting all of these yet |
|
*/ |
|
|
|
const litePluginsToRegister: JupyterLiteServer.IPluginModule[] = []; |
|
|
|
// Add the base serverlite extensions |
|
const baseServerExtensions = await Promise.all(serverExtensions); |
|
baseServerExtensions.forEach((p) => { |
|
for (const plugin of activePlugins(p)) { |
|
litePluginsToRegister.push(plugin); |
|
} |
|
}); |
|
|
|
// TODO get federated extensions in from config argument? |
|
const extensions: any[] = []; |
|
|
|
const liteExtensionPromises: any[] = [import('@jupyterlite/pyodide-kernel-extension')]; |
|
|
|
extensions.forEach((data) => { |
|
if (data.liteExtension) { |
|
liteExtensionPromises.push(createModule(data.name, data.extension)); |
|
return; |
|
} |
|
}); |
|
|
|
// Add the serverlite federated extensions. |
|
const federatedLiteExtensions = await Promise.allSettled(liteExtensionPromises); |
|
federatedLiteExtensions.forEach((p) => { |
|
if (p.status === 'fulfilled') { |
|
for (const plugin of activePlugins(p.value)) { |
|
litePluginsToRegister.push(plugin); |
|
} |
|
} else { |
|
console.error(p.reason); |
|
} |
|
}); |
|
|
|
// create the in-browser JupyterLite Server |
|
const jupyterLiteServer = new JupyterLiteServer({} as any); |
|
jupyterLiteServer.registerPluginModules(litePluginsToRegister); |
|
// start the server |
|
await jupyterLiteServer.start(); |
|
|
|
const { serviceManager } = jupyterLiteServer; |
|
await serviceManager.ready; |
|
|
|
// TODO |
|
return serviceManager as unknown as ServiceManager; |
|
} |
Opening an issue to track the update to the next JupyterLite 0.6.0 version, currently in alpha.
With jupyterlite/jupyterlite#1590, JupyterLite simplifies its code base and the way plugins are being loaded.
For thebe that would mean updating the use of
@jupyterlite/server-extensionand how "server" extensions are being loaded.Doing a quick search on the code base leads to the following places, for example:
thebe/packages/lite/package.json
Lines 51 to 52 in a04412e
thebe/packages/lite/src/jlite.ts
Lines 37 to 127 in a04412e
There is already a migration guide available here, which should highlight the major changes: https://jupyterlite.readthedocs.io/en/latest/migration.html#to-0-6-0.
The latest
0.6.0a3includes this change and is now available: https://github.com/jupyterlite/jupyterlite/releases/tag/v0.6.0a3I'll see if I can find some time to look into updating
thebeduring the JupyterLite 0.6.0 pre-release phase.