Browse Source

Handle CommonJS modules.

Afshin Darian 7 năm trước cách đây
mục cha
commit
d383d687fd
3 tập tin đã thay đổi với 41 bổ sung12 xóa
  1. 1 0
      jupyterlab/commands.py
  2. 20 6
      jupyterlab/index.app.js
  3. 20 6
      jupyterlab/index.js

+ 1 - 0
jupyterlab/commands.py

@@ -753,6 +753,7 @@ def _toggle_extension(extension, value, app_dir=None, logger=None):
     """
     app_dir = get_app_dir(app_dir)
     extensions = _get_extensions(app_dir)
+    config = _get_build_config(app_dir)
     disabled = config.get('disabledExtensions', [])
     if value and extension not in disabled:
         disabled.append(extension)

+ 20 - 6
jupyterlab/index.app.js

@@ -64,8 +64,15 @@ function main() {
         }
         if (!isDisabled('{{@key}}')) {
             var module = require('{{@key}}/{{this}}');
-            if (Array.isArray(module.default)) {
-                module.default.forEach(function(plugin) {
+            var extension = module.default;
+
+            // Handle CommonJS exports.
+            if (!module.hasOwnProperty('__esModule')) {
+              extension = module;
+            }
+
+            if (Array.isArray(extension)) {
+                extension.forEach(function(plugin) {
                     if (isDeferred(plugin.id)) {
                         ignorePlugins.push(plugin.id);
                     }
@@ -74,7 +81,7 @@ function main() {
                     }
                 });
             } else {
-                mimeExtensions.push(module);
+                mimeExtensions.push(extension);
             }
         }
     } catch (e) {
@@ -100,8 +107,15 @@ function main() {
         }
         if (!isDisabled('{{@key}}')) {
             var module = require('{{@key}}/{{this}}');
-            if (Array.isArray(module.default)) {
-                module.default.forEach(function(plugin) {
+            var extension = module.default;
+
+            // Handle CommonJS exports.
+            if (!module.hasOwnProperty('__esModule')) {
+              extension = module;
+            }
+
+            if (Array.isArray(extension)) {
+                extension.forEach(function(plugin) {
                     if (isDeferred(plugin.id)) {
                         ignorePlugins.push(plugin.id);
                     }
@@ -110,7 +124,7 @@ function main() {
                     }
                 });
             } else {
-                lab.registerPluginModule(module);
+                lab.registerPluginModule(extension);
             }
         }
     } catch (e) {

+ 20 - 6
jupyterlab/index.js

@@ -64,8 +64,15 @@ function main() {
         }
         if (!isDisabled('{{@key}}')) {
             var module = require('{{@key}}/{{this}}');
-            if (Array.isArray(module.default)) {
-                module.default.forEach(function(plugin) {
+            var extension = module.default;
+
+            // Handle CommonJS exports.
+            if (!module.hasOwnProperty('__esModule')) {
+              extension = module;
+            }
+
+            if (Array.isArray(extension)) {
+                extension.forEach(function(plugin) {
                     if (isDeferred(plugin.id)) {
                         ignorePlugins.push(plugin.id);
                     }
@@ -74,7 +81,7 @@ function main() {
                     }
                 });
             } else {
-                mimeExtensions.push(module);
+                mimeExtensions.push(extension);
             }
         }
     } catch (e) {
@@ -100,8 +107,15 @@ function main() {
         }
         if (!isDisabled('{{@key}}')) {
             var module = require('{{@key}}/{{this}}');
-            if (Array.isArray(module.default)) {
-                module.default.forEach(function(plugin) {
+            var extension = module.default;
+
+            // Handle CommonJS exports.
+            if (!module.hasOwnProperty('__esModule')) {
+              extension = module;
+            }
+
+            if (Array.isArray(extension)) {
+                extension.forEach(function(plugin) {
                     if (isDeferred(plugin.id)) {
                         ignorePlugins.push(plugin.id);
                     }
@@ -110,7 +124,7 @@ function main() {
                     }
                 });
             } else {
-                lab.registerPluginModule(module);
+                lab.registerPluginModule(extension);
             }
         }
     } catch (e) {