Sfoglia il codice sorgente

Merge pull request #730 from blink1073/revert

Switch back to a single WebPack config
Jason Grout 8 anni fa
parent
commit
cf49834138

+ 30 - 3
jupyterlab/index.js

@@ -14,8 +14,35 @@ require('jupyterlab/lib/default-theme/index.css');
 
 var lab = new JupyterLab();
 
-lab.registerPlugins(jupyter.application.plugins);
+lab.registerPlugins([
+  require('jupyterlab/lib/about/plugin').aboutExtension,
+  require('jupyterlab/lib/clipboard/plugin').clipboardProvider,
+  require('jupyterlab/lib/commandpalette/plugin').commandPaletteProvider,
+  require('jupyterlab/lib/console/plugin').consoleExtension,
+  require('jupyterlab/lib/csvwidget/plugin').csvHandlerExtension,
+  require('jupyterlab/lib/docregistry/plugin').docRegistryProvider,
+  require('jupyterlab/lib/editorwidget/plugin').editorHandlerProvider,
+  require('jupyterlab/lib/faq/plugin').faqExtension,
+  require('jupyterlab/lib/filebrowser/plugin').fileBrowserProvider,
+  require('jupyterlab/lib/help/plugin').helpHandlerExtension,
+  require('jupyterlab/lib/imagewidget/plugin').imageHandlerExtension,
+  require('jupyterlab/lib/inspector/plugin').inspectorProvider,
+  require('jupyterlab/lib/leafletwidget/plugin').mapHandlerExtension,
+  require('jupyterlab/lib/landing/plugin').landingExtension,
+  require('jupyterlab/lib/main/plugin').mainExtension,
+  require('jupyterlab/lib/mainmenu/plugin').mainMenuProvider,
+  require('jupyterlab/lib/markdownwidget/plugin').markdownHandlerExtension,
+  require('jupyterlab/lib/notebook/plugin').notebookTrackerProvider,
+  require('jupyterlab/lib/rendermime/plugin').renderMimeProvider,
+  require('jupyterlab/lib/running/plugin').runningSessionsExtension,
+  require('jupyterlab/lib/services/plugin').servicesProvider,
+  require('jupyterlab/lib/shortcuts/plugin').shortcutsExtension,
+  require('jupyterlab/lib/terminal/plugin').terminalExtension,
+  require('jupyterlab/lib/notebook/codemirror/plugin').rendererProvider,
+  require('jupyterlab/lib/console/codemirror/plugin').rendererProvider
+
+
+  // require('jupyter-js-widgets-labextension/lib/plugin').widgetManagerExtension,
+]);
 
 window.onload = function() { lab.start(); }
-
-module.exports = lab;

+ 0 - 10
jupyterlab/lab.html

@@ -16,9 +16,7 @@ Distributed under the terms of the Modified BSD License.
     <script src="{{static_url("components/jquery/jquery.min.js") }}" type="text/javascript" charset="utf-8"></script> <!-- window.$ -->
     <script src="{{static_url("components/jquery-ui/ui/minified/jquery-ui.min.js") }}" type="text/javascript" charset="utf-8"></script> <!-- extends window.$ -->
     <link href="{{static_prefix}}/vendor.css" rel="stylesheet">
-    <link href="{{static_prefix}}/codemirror.css" rel="stylesheet">
     <link href="{{static_prefix}}/jupyterlab.css" rel="stylesheet">
-    <link href="{{static_prefix}}/main.css" rel="stylesheet">
 </head>
 
 
@@ -31,16 +29,8 @@ Distributed under the terms of the Modified BSD License.
   "notebookPath": "{{notebook_path | urlencode}}"
 }</script>
 
-<script src="{{static_prefix}}/codemirror.bundle.js" type="text/javascript" charset="utf-8"></script>
-<script src="{{static_prefix}}/phosphor.bundle.js" type="text/javascript" charset="utf-8"></script>
-<script src="{{static_prefix}}/jupyter-js-services.bundle.js" type="text/javascript" charset="utf-8"></script>
 <script src="{{static_prefix}}/vendor.bundle.js" type="text/javascript" charset="utf-8"></script>
 <script src="{{static_prefix}}/jupyterlab.bundle.js" type="text/javascript" charset="utf-8"></script>
-<script src="{{static_prefix}}/plugins.bundle.js" type="text/javascript" charset="utf-8"></script>
-
-<!-- TODO: Insert third party plugins here using template -->
-
-<script src="{{static_prefix}}/main.bundle.js" type="text/javascript" charset="utf-8"></script>
 </body>
 
 </html>

+ 0 - 30
jupyterlab/plugins.js

@@ -1,30 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-
-module.exports = [
-  require('jupyterlab/lib/about/plugin').aboutExtension,
-  require('jupyterlab/lib/clipboard/plugin').clipboardProvider,
-  require('jupyterlab/lib/commandpalette/plugin').commandPaletteProvider,
-  require('jupyterlab/lib/console/plugin').consoleExtension,
-  require('jupyterlab/lib/csvwidget/plugin').csvHandlerExtension,
-  require('jupyterlab/lib/docregistry/plugin').docRegistryProvider,
-  require('jupyterlab/lib/editorwidget/plugin').editorHandlerProvider,
-  require('jupyterlab/lib/faq/plugin').faqExtension,
-  require('jupyterlab/lib/filebrowser/plugin').fileBrowserProvider,
-  require('jupyterlab/lib/help/plugin').helpHandlerExtension,
-  require('jupyterlab/lib/imagewidget/plugin').imageHandlerExtension,
-  require('jupyterlab/lib/inspector/plugin').inspectorProvider,
-  require('jupyterlab/lib/leafletwidget/plugin').mapHandlerExtension,
-  require('jupyterlab/lib/landing/plugin').landingExtension,
-  require('jupyterlab/lib/main/plugin').mainExtension,
-  require('jupyterlab/lib/mainmenu/plugin').mainMenuProvider,
-  require('jupyterlab/lib/markdownwidget/plugin').markdownHandlerExtension,
-  require('jupyterlab/lib/notebook/plugin').notebookTrackerProvider,
-  require('jupyterlab/lib/rendermime/plugin').renderMimeProvider,
-  require('jupyterlab/lib/running/plugin').runningSessionsExtension,
-  require('jupyterlab/lib/services/plugin').servicesProvider,
-  require('jupyterlab/lib/shortcuts/plugin').shortcutsExtension,
-  require('jupyterlab/lib/terminal/plugin').terminalExtension,
-  require('jupyterlab/lib/notebook/codemirror/plugin').rendererProvider,
-  require('jupyterlab/lib/console/codemirror/plugin').rendererProvider
-];

+ 26 - 116
jupyterlab/webpack.config.js

@@ -5,65 +5,27 @@
 // See https://github.com/webpack/css-loader/issues/144
 require('es6-promise').polyfill();
 
-var fs = require('fs');
 var webpack = require('webpack');
 var ExtractTextPlugin = require('extract-text-webpack-plugin');
 var findImports = require('find-imports');
-var helpers = require('jupyterlab/scripts/extension_helpers');
-var externals = require('jupyterlab/scripts/externals');
 
 console.log('Generating config...');
 
 // Get the list of vendor files.
 var VENDOR_FILES = findImports('../lib/**/*.js', { flatten: true });
 
-// Create the external library shims.
-// First make sure the build folder exists.
-try {
-  fs.mkdirSync('./build')
-} catch(err) {
-  if (err.code !== 'EEXIST') {
-    throw err;
-  }
-}
-for (var lib of ['phosphor', 'jupyterlab', 'jupyter-js-services']) {
-  var shim = helpers.createShim(lib);
-  fs.writeFileSync('./build/' + lib + '-shim.js', shim);
-}
-
-
-// The default `module.loaders` config.
-var loaders = [
-  { test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader') },
-  { test: /\.json$/, loader: 'json-loader' },
-  { test: /\.html$/, loader: 'file-loader' },
-  // jquery-ui loads some images
-  { test: /\.(jpg|png|gif)$/, loader: 'file-loader' },
-  // required to load font-awesome
-  { test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
-  { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
-  { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
-  { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader' },
-  { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=image/svg+xml' },
-]
-
 
 console.log('Generating bundles...');
 
-
-// The parallel Webpack build configurations.
-module.exports = [
-// Application bundles
-{
+module.exports = {
   entry: {
-    main: './index.js',
-    plugins: './plugins.js',
+    jupyterlab: './index.js',
+    vendor: VENDOR_FILES
   },
   output: {
-    path: './build',
+    path: __dirname + '/build',
     filename: '[name].bundle.js',
-    publicPath: './',
-    library: ['jupyter', 'application', '[name]']
+    publicPath: './lab/'
   },
   node: {
     fs: 'empty'
@@ -72,82 +34,30 @@ module.exports = [
   bail: true,
   devtool: 'source-map',
   module: {
-    loaders: loaders
-  },
-  plugins: [
-    new ExtractTextPlugin('[name].css')
-  ],
-  externals: externals.EXTERNALS
-},
-// JupyterLab bundles
-{
-  entry: {
-    jupyterlab: './build/jupyterlab-shim.js',
-    vendor: VENDOR_FILES
-  },
-  output: {
-      filename: 'jupyterlab.bundle.js',
-      path: './build',
-      publicPath: './',
-      library: ['jupyter', 'externals', 'jupyterlab']
-  },
-  module: {
-    loaders: loaders
+    loaders: [
+      { test: /\.css$/,
+        loader: ExtractTextPlugin.extract("style-loader", "css-loader", {
+          publicPath: './'
+        })
+      },
+      { test: /\.json$/, loader: 'json-loader' },
+      { test: /\.html$/, loader: 'file-loader' },
+      // jquery-ui loads some images
+      { test: /\.(jpg|png|gif)$/, loader: 'file-loader' },
+      // required to load font-awesome
+      { test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
+      { test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
+      { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
+      { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader' },
+      { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=image/svg+xml' }
+    ]
   },
   plugins: [
     new ExtractTextPlugin('[name].css'),
     new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js')
   ],
-  bail: true,
-  devtool: 'source-map',
-  externals: externals.EXTERNALS
-},
-// CodeMirror bundle
-{
-  entry: {
-    'codemirror': ['codemirror/lib/codemirror.css', 'codemirror']
-  },
-  output: {
-      filename: '[name].bundle.js',
-      path: './build',
-      publicPath: './',
-      library: ['jupyter', 'externals', 'codemirror']
-  },
-  module: {
-    loaders: loaders
-  },
-  plugins: [
-    new ExtractTextPlugin('[name].css')
-  ],
-  bail: true,
-  devtool: 'source-map'
-},
-// Jupyter-js-services bundle
-{
-  entry: './build/jupyter-js-services-shim.js',
-  output: {
-      filename: 'jupyter-js-services.bundle.js',
-      path: './build',
-      publicPath: './',
-      library: ['jupyter', 'externals', 'jupyter-js-services'],
-  },
-  module: {
-    loaders: loaders
-  },
-  bail: true,
-  devtool: 'source-map',
-  externals: externals.BASE_EXTERNALS
-},
-// Phosphor bundle
-{
-  entry: './build/phosphor-shim.js',
-  output: {
-      filename: 'phosphor.bundle.js',
-      path: './build',
-      publicPath: './',
-      library: ['jupyter', 'externals', 'phosphor']
-  },
-  bail: true,
-  devtool: 'source-map'
+  externals: {
+    jquery: '$',
+    'jquery-ui': '$'
+  }
 }
-]

+ 1 - 12
package.json

@@ -22,7 +22,6 @@
     "sanitize-html": "^1.12.0",
     "semver": "^5.3.0",
     "simulate-event": "^1.2.0",
-    "walk-sync": "^0.3.1",
     "xterm": "^1.1.3"
   },
   "devDependencies": {
@@ -92,18 +91,8 @@
     "lib/**/*.js",
     "lib/**/*.svg",
     "lib/**/*.gif",
-    "scripts/dedupe.js",
-    "scripts/extension_helpers.js",
-    "scripts/externals.js"
+    "scripts/dedupe.js"
   ],
-  "jupyter": {
-    "lab": {
-      "externals": {
-        "module": "./scripts/externals",
-        "name": "EXTERNALS"
-      }
-    }
-  },
   "author": "Project Jupyter",
   "license": "BSD-3-Clause",
   "bugs": {

+ 0 - 261
scripts/extension_helpers.js

@@ -1,261 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-
-var path = require('path');
-var walkSync = require('walk-sync');
-
-/**
-  Helper scripts to be used by extension authors (and extension extenders) in a
-  webpack.config.json to create builds that do not include upstream extensions.
-
-  Inspects the package.json of the user's package and those of its dependencies
-  to find extensions that should be excluded.
-
-  Slightly more than minimal valid setup in package.json:
-
-    {
-      "name": "foo-widget",
-      "jupyter": {
-        "lab": {
-          "main": "lab-extension.js"
-        }
-      },
-      "dependencies": {
-        "jupyterlab": "*",
-        "jupyter-js-widgets": "*"
-      }
-    }
-
-  Example usage in webpack.config.js:
-
-    var jlab_helpers = require('jupyterlab/scripts/extension_helpers');
-
-    module.exports = [{
-      entry: './src/lab/extension.js',
-      output: {
-        filename: 'lab-extension.js',
-        path: '../pythonpkg/static',
-        libraryTarget: 'this'
-      },
-      externals: jlab_helpers.upstreamExternals(require)
-    }];
-*/
-
-/**
- * Determine if a string starts with another.
- *
- * @param str (string) - the string possibly starting with the substring.
- *
- * @param query (string) - the substring whose presence we are testing.
- *
- * @returns true if str starts with query
- *
- * #### Notes
- * This is a cross-browser version of String.prototype.startsWith
- */
-function startsWith(str, query) {
-  return str.lastIndexOf(query, 0) === 0;
-}
-
-/**
- * Create a Webpack `externals` function for a shimmed external package.
- *
- * @param pkgName (string) - The name of the package
- *
- * @returns A function to be used as part of a WebPack config.
- */
-function createShimHandler(pkgName) {
-  return function(context, request, callback) {
-    // TODO: better path regex, probably only looking for .js or .css
-    // since that is all we save
-    if (startsWith(request, pkgName)) {
-      try {
-        var path = require.resolve(request);
-      } catch (err) {
-        return callback(err);
-      }
-      var index = path.indexOf(request);
-      path = path.slice(index + pkgName.length);
-      if (path.indexOf('/') === 0) {
-        path = path.slice(1);
-      }
-      var shim = 'var jupyter.externals["' + pkgName + '"]["' + path + '"]';
-      return callback(null, shim);
-    }
-    callback();
-  }
-}
-
-
-/**
- * Create a shim to export all of a library's modules to a namespaced object.
- *
- * @param modName (string) - The name of the module to shim.
- *
- * @param sourceFolder (string) - The source folder (defaults to `lib`).
- *
- * @returns The code used to export the entire package.
- */
-function createShim(modName, sourceFolder) {
-  var dirs = [];
-  var files = [];
-  var lines = ['var shim = {};'];
-
-  // Find the path to the module.
-  var modPath = require.resolve(modName + '/package.json');
-  sourceFolder = sourceFolder || 'lib';
-  modPath = path.posix.join(path.dirname(modPath), sourceFolder);
-
-  // Walk through the source tree.
-  var entries = walkSync.entries(modPath, {
-    directories: false,
-    globs: ['**/*.js', '**/*.css']
-  });
-  for (var i = 0; i < entries.length; i++) {
-    // Get the relative path to the entry.
-    var entryPath = path.posix.join(sourceFolder, entries[i].relativePath);
-    // Add an entries for each file.
-    lines.push('shim["' + entryPath + '"] = require("' + path.posix.join(modName, entryPath) + '");');
-  }
-  lines.push('module.exports = shim;');
-
-  return lines.join('\n');
-}
-
-
-/**
- * Determine whether a package is a JupyterLab extension.
- *
- * @param pkg (string) - The package.json object.
- *
- * @returns true if the package is a JupyterLab extension.
- */
-function isLabExtension(pkg){
-  try {
-    // for now, just try to load the key... could check whether file exists?
-    pkg['jupyter']['lab']['main']
-    return true;
-  } catch(err) {
-    return false;
-  }
-}
-
-/**
- * Recurse through dependencies, collecting all external functions.
- *
- * @param function - the environment require function.
- *
- * @param onlyUpstream - if true, do not return externals provided by this package
- *
- * @returns an externals object to be used in a Webpack config.
- *
- * #### Notes
- * A sample Webpack config will look like
- *
-    var jlab_helpers = require('jupyterlab/scripts/extension_helpers');
-
-    module.exports = [{
-      entry: './src/lab/extension.js',
-      output: {
-        filename: 'lab-extension.js',
-        path: '../pythonpkg/static',
-        libraryTarget: 'this'
-      },
-      externals: jlab_helpers.upstreamExternals(require)
-    }];
- */
-function upstreamExternals(_require, onlyUpstream) {
-  // Parse the externals of this package.
-
-  // remember which packages we have seen
-  var _seen = {};
-
-  /**
-   * Load the externals from a JupyterLab extension package.
-   *
-   * @param pkg_path (string) - the path on the filesystem to the package.
-   *
-   * @param pkg (object) - the package.json object.
-   *
-   * @returns an array containing the externals this package provides, excluding itself.
-   *
-   * #### Notes
-   * This returns an array containing the externals referred to in the
-   * package.json jupyter.lab.externals object:
-   *
-   * {module: "module-exporting-externals"}
-   *
-   * or
-   *
-   * {module: "module-exporting-externals", name: "exported-object"}
-   */
-  function _load_externals(pkg_path, pkg) {
-    var externals = pkg.jupyter.lab.externals;
-    if (externals) {
-      try {
-        var externalModule = _require(pkg_path + '/' + externals['module']);
-        if (externals['name']) {
-          pkgExternals = externalModule[externals['name']];
-        } else {
-          pkgExternals = externalModule;
-        }
-      } catch (err) {
-        console.error('Error importing externals for ' + pkg.name);
-      }
-    }
-    pkgExternals = pkgExternals || [];
-    if (!Array.isArray(pkgExternals)) {
-      pkgExternals = [pkgExternals];
-    }
-
-    return pkgExternals;
-  }
-
-
-  // return an array of strings, functions or regexen that can be deferenced by
-  // webpack `externals` config directive
-  // https://webpack.github.io/docs/configuration.html#externals
-  function _find_externals(pkg_path, root) {
-    var pkg = _require(pkg_path + '/package.json');
-    var pkgName = pkg['name'];
-    var lab_config;
-    var externals = [];
-
-    // only visit each named package once
-    _seen[pkgName] = true;
-
-    if (!isLabExtension(pkg)) {
-      return [];
-    }
-
-    console.info("Inspecting " + pkgName + " for externals it provides...");
-
-    if (!(root && onlyUpstream)) {
-      externals.push.apply(externals, _load_externals(pkg_path, pkg, _require));
-    }
-    if (!root) {
-      externals.push(createShimHandler(pkg['name']));
-    }
-
-    // Recurse through the dependencies, and collect externals
-    // for JupyterLab extensions
-    return Object.keys(pkg['dependencies'])
-      .filter(function(depName){ return !_seen[depName]; })
-      .reduce(function(externals, depName){
-        return externals.concat(
-          // We assume the node_modules is flat
-          // TODO: actually change directory before doing _find_externals?
-          _find_externals(depName));
-      }, externals);
-  }
-
-  var externals = _find_externals(".", true);
-  return externals;
-}
-
-module.exports = {
-  upstreamExternals: upstreamExternals,
-  isLabExtension: isLabExtension,
-  createShim: createShim,
-  createShimHandler: createShimHandler,
-};

+ 0 - 41
scripts/externals.js

@@ -1,41 +0,0 @@
-// Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
-
-var helpers = require('./extension_helpers');
-
-/**
- * The externals provided to libraries
- * this package builds (like jupyter-js-widgets).
- */
-var BASE_EXTERNALS = [
-  {
-    'jquery': '$',
-    'jquery-ui': '$'
-  },
-  helpers.createShimHandler('phosphor'),
-  function(context, request, callback) {
-    // CodeMirror imports get mangled to use an external bundle.
-    var codeMirrorPaths = [
-      'codemirror/mode/meta',
-      'codemirror', '../lib/codemirror',  '../../lib/codemirror',
-      'codemirror/lib/codemirror.css'
-    ];
-    if (codeMirrorPaths.indexOf(request) !== -1) {
-      return callback(null, 'var jupyter.externals.codemirror');
-    }
-    callback();
-  }
-];
-
-
-/**
- * The externals that this package provides.
- */
-var EXTERNALS = BASE_EXTERNALS.concat([
-  helpers.createShimHandler('jupyter-js-services')
-]);
-
-module.exports = {
-  BASE_EXTERNALS: BASE_EXTERNALS,
-  EXTERNALS: EXTERNALS
-};