瀏覽代碼

Merge pull request #3384 from blink1073/vendor-finder

JupyterLab bundle cleanup
Afshin Darian 7 年之前
父節點
當前提交
e72e317847

+ 5 - 2
buildutils/src/build.ts

@@ -6,6 +6,8 @@
 import * as fs from 'fs-extra';
 import * as glob from 'glob';
 import * as path from 'path';
+import * as utils from './utils';
+
 
 /**
  *  A namespace for JupyterLab build utilities.
@@ -100,7 +102,7 @@ namespace Build {
     packageNames.forEach(function(name) {
       const packageDataPath = require.resolve(path.join(name, 'package.json'));
       const packageDir = path.dirname(packageDataPath);
-      const packageData = require(packageDataPath);
+      const packageData = utils.readJSONFile(packageDataPath);
       const extension = normalizeExtension(packageData);
       const { schemaDir, themeDir } = extension;
 
@@ -112,7 +114,8 @@ namespace Build {
         // Remove the existing directory if necessary.
         if (fs.existsSync(destination)) {
           try {
-            const oldPackageData = require(path.join(destination, 'package.json'));
+            const oldPackagePath = path.join(destination, 'package.json');
+            const oldPackageData = utils.readJSONFile(oldPackagePath);
             if (oldPackageData.version === packageData.version) {
               fs.removeSync(destination);
             }

+ 28 - 0
dev_mode/package.json

@@ -146,6 +146,34 @@
       "@phosphor/coreutils",
       "@phosphor/widgets"
     ],
+    "vendor": [
+      "@phosphor/algorithm",
+      "@phosphor/application",
+      "@phosphor/commands",
+      "@phosphor/coreutils",
+      "@phosphor/datagrid",
+      "@phosphor/disposable",
+      "@phosphor/domutils",
+      "@phosphor/dragdrop",
+      "@phosphor/messaging",
+      "@phosphor/properties",
+      "@phosphor/signaling",
+      "@phosphor/virtualdom",
+      "@phosphor/widgets",
+      "ajv",
+      "ansi_up",
+      "codemirror",
+      "comment-json",
+      "es6-promise",
+      "marked",
+      "moment",
+      "path-posix",
+      "react",
+      "react-dom",
+      "sanitize-html",
+      "url-parse",
+      "xterm"
+    ],
     "version": "0.31.0.dev0",
     "linkedPackages": {
       "@jupyterlab/application": "../packages/application",

+ 2 - 3
dev_mode/webpack.config.js

@@ -101,12 +101,11 @@ JupyterLabPlugin.prototype.apply = function(compiler) {
 JupyterLabPlugin.prototype._first = true;
 
 
+
 module.exports = {
   entry: {
     main: ['whatwg-fetch', path.resolve(buildDir, 'index.out.js')],
-    vendor: [
-      'react', 'react-dom', 'codemirror', 'xterm'
-    ]
+    vendor: jlab.vendor
   },
   output: {
     path: path.resolve(buildDir),

+ 1 - 0
packages/vega2-extension/package.json

@@ -39,6 +39,7 @@
     "vega-lite": "~1.0.16"
   },
   "devDependencies": {
+    "@types/node": "~8.0.47",
     "rimraf": "~2.6.2",
     "typescript": "~2.6.2"
   },

+ 27 - 8
packages/vega2-extension/src/index.ts

@@ -18,6 +18,7 @@ import {
 /**
  * Import vega-embed in this manner due to how it is exported.
  */
+// Import only the typings for vega-embed - do not use for values.
 import embed = require('vega-embed');
 
 
@@ -99,18 +100,36 @@ class RenderedVega extends Widget implements IRenderMime.IRenderer {
       spec: updatedData
     };
 
-    return new Promise<void>((resolve, reject) => {
-      embed(this.node, embedSpec, (error: any, result: any): any => {
-        resolve(undefined);
-        // This is copied out for now as there is a bug in JupyterLab
-        // that triggers and infinite rendering loop when this is done.
-        // let imageData = result.view.toImageURL();
-        // imageData = imageData.split(',')[1];
-        // this._injector('image/png', imageData);
+    return this._ensureMod().then(embedFunc => {
+      return new Promise<void>((resolve, reject) => {
+        embedFunc(this.node, embedSpec, (error: any, result: any): any => {
+          resolve(undefined);
+          // This is copied out for now as there is a bug in JupyterLab
+          // that triggers and infinite rendering loop when this is done.
+          // let imageData = result.view.toImageURL();
+          // imageData = imageData.split(',')[1];
+          // this._injector('image/png', imageData);
+        });
       });
     });
   }
 
+  /**
+   * Initialize the vega-embed module.
+   */
+  private _ensureMod(): Promise<typeof embed> {
+    return new Promise((resolve, reject) => {
+      (require as any).ensure(['vega-embed'], (require: NodeRequire) => {
+        resolve(require('vega-embed'));
+      },
+      (err: any) => {
+        reject(err);
+      },
+      'vega2'
+      );
+    });
+  }
+
   private _mimeType: string;
   private _mode: string;
 }

+ 2 - 3
packages/vega2-extension/tsconfig.json

@@ -8,8 +8,7 @@
     "moduleResolution": "node",
     "target": "ES5",
     "outDir": "./lib",
-    "lib": ["ES5", "ES2015.Promise", "DOM", "ES2015.Collection"],
-    "types": []
+    "lib": ["ES5", "ES2015.Promise", "DOM", "ES2015.Collection"]
   },
   "include": ["src/*"]
-}
+}