Skip to content

Commit

Permalink
Draft two shared bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Oct 10, 2024
1 parent be5b3ed commit e461fb9
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ config.rst
package-lock.json

share/jupyter/voila/templates/base/static/*voila.js
share/jupyter/voila/templates/base/static/*ipywidgets7shared.js
share/jupyter/voila/templates/base/static/*ipywidgets8shared.js
share/jupyter/voila/templates/base/static/*treepage.js
share/jupyter/voila/templates/base/static/*voila-style.js
share/jupyter/voila/templates/base/static/*.woff
Expand Down
1 change: 1 addition & 0 deletions packages/voila/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"@jupyter-widgets/base": "^6.0.10",
"@jupyter-widgets/base7": "npm:@jupyter-widgets/[email protected]",
"@jupyter-widgets/controls": "^5.0.11",
"@jupyter-widgets/controls7": "npm:@jupyter-widgets/[email protected]",
"@jupyter-widgets/jupyterlab-manager": "^5.0.13",
"@jupyterlab/application": "^4.0.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/voila/src/ipywidgets7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const baseWidgets7Plugin: JupyterFrontEndPlugin<void> = {
name: '@jupyter-widgets/base',
version: JUPYTER_WIDGETS_VERSION,
exports: () => {
require('./ipywidgets7shared');
return require('@jupyter-widgets/base7') as any;
}
});
Expand All @@ -52,6 +53,7 @@ export const controlWidgets7Plugin: JupyterFrontEndPlugin<void> = {
name: '@jupyter-widgets/controls',
version: JUPYTER_CONTROLS_VERSION,
exports: () => {
require('./ipywidgets7shared');
const controlsWidgets = require('@jupyter-widgets/controls7') as any;
require('@jupyter-widgets/controls7/css/widgets-base.css');
return controlsWidgets;
Expand Down
11 changes: 11 additions & 0 deletions packages/voila/src/ipywidgets7shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/***************************************************************************
* Copyright (c) 2024, Voilà contributors *
* Copyright (c) 2024, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

export * as base from '@jupyter-widgets/base7';
export * as controls from '@jupyter-widgets/controls7';
63 changes: 63 additions & 0 deletions packages/voila/src/ipywidgets8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/***************************************************************************
* Copyright (c) 2024, Voilà contributors *
* Copyright (c) 2024, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

import * as base from '@jupyter-widgets/base';
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';

const JUPYTER_WIDGETS_VERSION = '2.0.0';
const JUPYTER_CONTROLS_VERSION = '2.0.0';

/**
* The base widgets.
*/
export const baseWidgets8Plugin: JupyterFrontEndPlugin<void> = {
id: `@jupyter-widgets/jupyterlab-manager:base-${JUPYTER_WIDGETS_VERSION}`,
requires: [base.IJupyterWidgetRegistry],
autoStart: true,
activate: (
app: JupyterFrontEnd,
registry: base.IJupyterWidgetRegistry
): void => {
registry.registerWidget({
name: '@jupyter-widgets/base',
version: JUPYTER_WIDGETS_VERSION,
exports: () => {
require('./ipywidgets8shared');
return require('@jupyter-widgets/base') as any;
}
});
}
};

/**
* The control widgets.
*/
export const controlWidgets8Plugin: JupyterFrontEndPlugin<void> = {
id: `@jupyter-widgets/jupyterlab-manager:controls-${JUPYTER_CONTROLS_VERSION}`,
requires: [base.IJupyterWidgetRegistry],
autoStart: true,
activate: (
app: JupyterFrontEnd,
registry: base.IJupyterWidgetRegistry
): void => {
registry.registerWidget({
name: '@jupyter-widgets/controls',
version: JUPYTER_CONTROLS_VERSION,
exports: () => {
require('./ipywidgets8shared');
const controlsWidgets = require('@jupyter-widgets/controls') as any;
require('@jupyter-widgets/controls/css/widgets-base.css');
return controlsWidgets;
}
});
}
};
11 changes: 11 additions & 0 deletions packages/voila/src/ipywidgets8shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/***************************************************************************
* Copyright (c) 2024, Voilà contributors *
* Copyright (c) 2024, QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

export * as base from '@jupyter-widgets/base';
export * as controls from '@jupyter-widgets/controls';
6 changes: 5 additions & 1 deletion packages/voila/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { VoilaApp } from './app';
import plugins from './voilaplugins';
import { baseWidgets7Plugin, controlWidgets7Plugin } from './ipywidgets7';
import { baseWidgets8Plugin, controlWidgets8Plugin } from './ipywidgets8';
import { VoilaServiceManager } from './services/servicemanager';
import { VoilaShell } from './shell';
import {
Expand Down Expand Up @@ -46,7 +47,10 @@ async function main() {
plugins,
// For backward compat with ipywidgets 7
baseWidgets7Plugin,
controlWidgets7Plugin
controlWidgets7Plugin,
// For compat with ipywidgets 8
baseWidgets8Plugin,
controlWidgets8Plugin
];

if (shouldUseMathJax2()) {
Expand Down
95 changes: 89 additions & 6 deletions packages/voila/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,29 @@ const distRoot = path.resolve(
'static'
);

const shared = {};
const voilaIndexSharedPackages = {};
for (const dependency of Object.keys(data.dependencies)) {
// TODO Why can we not share those?
// Do not share jupyter-widgets packages in the Voila index
if (
['@jupyter-widgets/base7', '@jupyter-widgets/controls7'].includes(
[
'@jupyter-widgets/base7',
'@jupyter-widgets/base',
'@jupyter-widgets/controls7',
'@jupyter-widgets/controls'
].includes(
dependency
)
) {
continue;
}

shared[dependency] = data.dependencies[dependency];
voilaIndexSharedPackages[dependency] = data.dependencies[dependency];
}

module.exports = [
/*
* Voila main index
*/
merge(baseConfig, {
mode: 'development',
entry: {
Expand All @@ -109,7 +117,7 @@ module.exports = [
name: ['_JUPYTERLAB', 'CORE_LIBRARY_FEDERATION']
},
name: 'CORE_FEDERATION',
shared
shared: voilaIndexSharedPackages
})
],
resolve: {
Expand All @@ -118,12 +126,87 @@ module.exports = [
}
}
}),
/*
* Voila styles
*/
merge(baseConfig, {
entry: './' + path.relative(__dirname, styleEntryPoint),
mode: 'production',
output: {
path: distRoot,
filename: 'voila-style.js'
}
})
}),
/*
* jupyter-widgets 7 packages
*/
merge(baseConfig, {
mode: 'development',
entry: {
ipywidgets7shared: ['./publicpath.js', './' + path.relative(__dirname, path.join(buildDir, 'ipywidgets7shared.js'))]
},
output: {
path: distRoot,
library: {
type: 'var',
name: ['_JUPYTERLAB', 'CORE_OUTPUT']
},
filename: '[name].js',
chunkFilename: '[name].ipywidgets7shared.js'
},
plugins: [
new ModuleFederationPlugin({
library: {
type: 'var',
name: ['_JUPYTERLAB', 'CORE_LIBRARY_FEDERATION']
},
name: 'CORE_FEDERATION',
shared: {
'@jupyter-widgets/base': data.dependencies['@jupyter-widgets/base7'],
'@jupyter-widgets/controls': data.dependencies['@jupyter-widgets/controls7']
}
})
],
resolve: {
fallback: {
util: require.resolve('util/')
}
}
}),
/*
* jupyter-widgets 8 packages
*/
merge(baseConfig, {
mode: 'development',
entry: {
ipywidgets8shared: ['./publicpath.js', './' + path.relative(__dirname, path.join(buildDir, 'ipywidgets8shared.js'))]
},
output: {
path: distRoot,
library: {
type: 'var',
name: ['_JUPYTERLAB', 'CORE_OUTPUT']
},
filename: '[name].js',
chunkFilename: '[name].ipywidgets8shared.js'
},
plugins: [
new ModuleFederationPlugin({
library: {
type: 'var',
name: ['_JUPYTERLAB', 'CORE_LIBRARY_FEDERATION']
},
name: 'CORE_FEDERATION',
shared: {
'@jupyter-widgets/base': data.dependencies['@jupyter-widgets/base'],
'@jupyter-widgets/controls': data.dependencies['@jupyter-widgets/controls']
}
})
],
resolve: {
fallback: {
util: require.resolve('util/')
}
}
}),
].concat(extras);
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5151,6 +5151,7 @@ __metadata:
dependencies:
"@jupyter-widgets/base": ^6.0.10
"@jupyter-widgets/base7": "npm:@jupyter-widgets/[email protected]"
"@jupyter-widgets/controls": ^5.0.11
"@jupyter-widgets/controls7": "npm:@jupyter-widgets/[email protected]"
"@jupyter-widgets/jupyterlab-manager": ^5.0.13
"@jupyterlab/application": ^4.0.0
Expand Down

0 comments on commit e461fb9

Please sign in to comment.