New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require 'package' instead of 'package/' so webpack activates sharing #9300
Conversation
This addresses the underlying problem in at least part of jupyterlab#9289. Webpack module federation was not creating shared modules for the direct extensions, only for their dependencies. For example, @jupyterlab/application was packaged as a shared module, but @jupyterlab/application-extension was not. The reasoning here is a bit subtle. The problem came down to how these top-level extensions were imported. The template made the require statements similar to @jupyterlab/application-extension/, with a trailing slash (which was nominally a slash between the package name and the actual import in the package, but mostly that actual import was an empty string, so we’d just be left with a trailing slash). However, webpack interpreted that trailing slash as indicating the import was only for paths starting with the package name, and not as a top-level package import. This meant that webpack did not see that these modules were being used, so did not include them in the list of modules packaged as shared modules. In other words, these top-level imports were treated as this case: https://github.com/webpack/webpack/blob/7415a618460795874fdf95c8f03363ea96709d52/lib/sharing/ProvideSharedPlugin.js#L97-L99 instead of as this case: https://github.com/webpack/webpack/blob/7415a618460795874fdf95c8f03363ea96709d52/lib/sharing/ProvideSharedPlugin.js#L100-L102 The fix here is simple - only put the slash in the require statement if we actually have a path to import.
Thanks for making a pull request to JupyterLab! To try out this branch on binder, follow this link: |
To check this manually: conda create -y -n jlab-9289 python nodejs
conda activate jlab-9289
pip install --pre jupyterlab
git clone https://github.com/jasongrout/provider.git
git clone https://github.com/jasongrout/consumer.git
cd provider
npm install
jupyter labextension install .
cd ..
cd consumer
jlpm add <ABSOLUTE PATH TO ../provider> # or manually edit package.json to give the absolute path to provider
pip install . Check things with Now do Now edit pushd <PATH TO site-packages/jupyterlab/staging>
curl https://patch-diff.githubusercontent.com/raw/jupyterlab/jupyterlab/pull/9300.patch | patch -p2
popd
jupyter lab build
jupyter lab Things should work now (no relevant errors, console logs as above). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Wondering what would happen in the case where the
export const IProvider = new Token<string>(
'provider:plugin'
);
import { IProvider } from 'token';
const extension: JupyterFrontEndPlugin<IProvider> = {
id: 'provider:plugin',
provides: IProvider,
autoStart: true,
activate: (app: JupyterFrontEnd): IProvider => {
console.log('JupyterLab extension provider is activated!');
return 'PROVIDER_STRING';
}
};
import {IProvider} from 'token';
const extension: JupyterFrontEndPlugin<void> = {
id: 'consumer',
autoStart: true,
requires: [IProvider],
activate: (app: JupyterFrontEnd, provider: IProvider) => {
console.log('JupyterLab extension consumer is activated!');
console.log(`Provider token is ${provider}`);
}
}; Still with:
|
Note to self: check #9310 as this should address this use case. |
References
This addresses the underlying problem in at least part of #9289.
Code changes
Webpack module federation was not creating shared modules for the direct extensions, only for their dependencies. For example, @jupyterlab/application was packaged as a shared module, but @jupyterlab/application-extension was not.
The reasoning here is a bit subtle. The problem came down to how these top-level extensions were imported. The template made the require statements similar to @jupyterlab/application-extension/, with a trailing slash (which was nominally a slash between the package name and the actual import in the package, but mostly that actual import was an empty string, so we’d just be left with a trailing slash). However, webpack interpreted that trailing slash as indicating the import was only for paths starting with the package name, and not as a top-level package import. This meant that webpack did not see that these modules were being used, so did not include them in the list of modules packaged as shared modules. In other words, these top-level imports were treated as this case:
https://github.com/webpack/webpack/blob/7415a618460795874fdf95c8f03363ea96709d52/lib/sharing/ProvideSharedPlugin.js#L97-L99
instead of as this case:
https://github.com/webpack/webpack/blob/7415a618460795874fdf95c8f03363ea96709d52/lib/sharing/ProvideSharedPlugin.js#L100-L102
The fix here is simple - only put the slash in the require statement if we actually have a path to import.
User-facing changes
Backwards-incompatible changes