Forráskód Böngészése

Add ability to include third party extension in dev mode

Saul Shanabrook 5 éve
szülő
commit
3bb871477b

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

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

+ 2 - 0
dev_mode/package.json

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

+ 10 - 2
dev_mode/webpack.config.js

@@ -20,7 +20,15 @@ var jlab = package_data.jupyterlab;
 var extensions = jlab.extensions;
 var mimeExtensions = jlab.mimeExtensions;
 var packageNames = Object.keys(mimeExtensions).concat(Object.keys(extensions));
+const { externalExtensions, externalMimeExtension } = jlab;
 
+// set values to '' b/c regular extensions also have '' values.
+for (const key in externalExtensions) {
+  externalExtensions[key] = '';
+}
+for (const key in externalMimeExtension) {
+  externalMimeExtension[key] = '';
+}
 // Ensure a clear build directory.
 var buildDir = plib.resolve(jlab.buildDir);
 if (fs.existsSync(buildDir)) {
@@ -38,8 +46,8 @@ var extraConfig = Build.ensureAssets({
 var source = fs.readFileSync('index.js').toString();
 var template = Handlebars.compile(source);
 var data = {
-  jupyterlab_extensions: extensions,
-  jupyterlab_mime_extensions: mimeExtensions
+  jupyterlab_extensions: { ...extensions, ...externalExtensions },
+  jupyterlab_mime_extensions: { ...mimeExtensions, ...externalMimeExtension }
 };
 var result = template(data);
 

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

@@ -226,6 +226,26 @@ 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` or
+`jupyterlab.externalMimeExtensions` keys in the `dev_mode/package.json` file. It should be a mapping
+of extension name to version, just like a 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"
+      },
+      "externalMimeExtensions": {},
+      ...
+
 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