Browse Source

Merge pull request #8037 from saulshanabrook/dev-extension

Add ability to include third party extension in dev mode
Steven Silvester 4 years ago
parent
commit
85b48e7b85

+ 5 - 1
buildutils/src/ensure-repo.ts

@@ -155,7 +155,11 @@ function ensureJupyterlab(): string[] {
   corePackage.jupyterlab.extensions = {};
   corePackage.jupyterlab.mimeExtensions = {};
   corePackage.jupyterlab.linkedPackages = {};
-  corePackage.dependencies = {};
+  // start with known external dependencies
+  corePackage.dependencies = Object.assign(
+    {},
+    corePackage.jupyterlab.externalExtensions
+  );
   corePackage.resolutions = {};
 
   const singletonPackages: string[] = corePackage.jupyterlab.singletonPackages;

+ 1 - 0
dev_mode/package.json

@@ -232,6 +232,7 @@
       "@jupyterlab/pdf-extension": "",
       "@jupyterlab/vega5-extension": ""
     },
+    "externalExtensions": {},
     "buildDir": "./static",
     "outputDir": ".",
     "singletonPackages": [

+ 18 - 1
dev_mode/webpack.config.js

@@ -19,10 +19,27 @@ const package_data = require('./package.json');
 const jlab = package_data.jupyterlab;
 const extensions = jlab.extensions;
 const mimeExtensions = jlab.mimeExtensions;
+const { externalExtensions } = jlab;
 const packageNames = Object.keys(mimeExtensions).concat(
-  Object.keys(extensions)
+  Object.keys(extensions),
+  Object.keys(externalExtensions)
 );
 
+// go throught each external extension
+// add to mapping of extension and mime extensions, of package name
+// to path of the extension.
+for (const key in externalExtensions) {
+  const {
+    jupyterlab: { extension, mimeExtension }
+  } = require(`${key}/package.json`);
+  if (extension !== undefined) {
+    extensions[key] = extension === true ? '' : extension;
+  }
+  if (mimeExtension !== undefined) {
+    mimeExtensions[key] = mimeExtension === true ? '' : mimeExtension;
+  }
+}
+
 // Ensure a clear build directory.
 const buildDir = plib.resolve(jlab.buildDir);
 if (fs.existsSync(buildDir)) {

+ 18 - 0
docs/source/developer/extension_dev.rst

@@ -248,6 +248,24 @@ not enabled in our build configuration. To build a compatible package set
 ``output.libraryTarget`` to ``"commonjs2"`` in your Webpack configuration.
 (see `this <https://github.com/saulshanabrook/jupyterlab-webpack>`__ example repo).
 
+Another option to try out your extension with a local version of JupyterLab is to add it to the
+list of locally installed packages and to have JupyterLab register your extension when it starts up.
+
+You can do this by adding your extension to the ``jupyterlab.externalExtensions`` key
+in the ``dev_mode/package.json`` file. It should be a mapping
+of extension name to version, just like in ``dependencies``. Then run ``jlpm run integrity``
+and these extensions should be added automatically to the ``dependencies`` and pulled in.
+
+When you then run ``jlpm run build && jupyter lab --dev`` or ``jupyter lab --dev --watch`` this extension
+will be loaded by default. For example, this is how you can add the Jupyter Widgets
+extensions:
+
+::
+
+    "externalExtensions": {
+      "@jupyter-widgets/jupyterlab-manager": "2.0.0"
+    },
+
 If you publish your extension on ``npm.org``, users will be able to install
 it as simply ``jupyter labextension install <foo>``, where ``<foo>`` is
 the name of the published ``npm`` package. You can alternatively provide a