Skip to content
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

Export tokens #414

Merged
merged 1 commit into from
Nov 20, 2020
Merged

Export tokens #414

merged 1 commit into from
Nov 20, 2020

Conversation

martinRenou
Copy link
Member

@martinRenou martinRenou commented Nov 20, 2020

Export tokens for other extensions to depend on them.

If tokens are not exported, one can retrieve them doing e.g.:

import { ILSPAdapterManager } from '@krassowski/jupyterlab-lsp/lib/tokens';

But this code will be compiled by webpack into

/* harmony import */ var _krassowski_jupyterlab_lsp_lib_tokens__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @krassowski/jupyterlab-lsp/lib/tokens */ "./node_modules/@krassowski/jupyterlab-lsp/lib/tokens.js");

Meaning that the third-party extension now ships its own copy of @krassowski/jupyterlab-lsp, with its own definition of the Tokens.

If we export the tokens, third-party extensions are able to do:

import { ILSPAdapterManager } from '@krassowski/jupyterlab-lsp';

Which compiles to:

/* harmony import */ var _krassowski_jupyterlab_lsp__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @krassowski/jupyterlab-lsp */ "webpack/sharing/consume/default/@krassowski/jupyterlab-lsp");

Meaning that all extensions which depend on those tokens will use the same tokens.

This is very important in JupyterLab 3 and the new federated modules, during the plugin activation, because JupyterLab relies on the Token instances themselves, not the name of the token.

Third-party extensions will be able to define jupyterlab-lsp as a shared packages (a package that is shared with other extensions) so it's not duplicated and bundled in all third-party extensions.

They can enable this by adding the following in their package.json:

"jupyterlab": {
    "extension": true,
    "outputDir": "my_extension/labextension",
    "sharedPackages": {
      "@krassowski/jupyterlab-lsp": {
        "bundled": false,
        "singleton": true
      }
    }
  }

https://github.com/jupyterlab/jupyterlab/blob/b29bfeb81e707dcb963d7d8e39a5d2ca1a036546/builder/metadata_schema.json#L28-L62

Signed-off-by: martinRenou <martin.renou@gmail.com>
@bollwyvl
Copy link
Collaborator

bollwyvl commented Nov 20, 2020 via email

@krassowski
Copy link
Member

Thank you. Probably the thing that caused me problems when I was trying to extend from outside....

@krassowski krassowski merged commit e872f80 into jupyter-lsp:master Nov 20, 2020
@martinRenou martinRenou deleted the export_tokens branch November 21, 2020 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants