Bug 1291049 - update webpack config for inspector html draft
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 07 Nov 2016 16:16:09 +0100
changeset 437816 6d3af18a261ab2395c26c6919d5aba22b06554dd
parent 437815 6dc26546730ed1ab04e55edd3ccff540bc9a14d2
child 437817 1ec889ef11f8eb22123b073ed00932668495b649
child 437820 13111fa8f3da3713cb1505595bed35c145ef49c3
push id35517
push userjdescottes@mozilla.com
push dateFri, 11 Nov 2016 16:33:44 +0000
bugs1291049
milestone52.0a1
Bug 1291049 - update webpack config for inspector html MozReview-Commit-ID: 2Ule3ydGtuj
.gitignore
.hgignore
devtools/client/webpack.config.js
devtools/client/webpack/prefs-loader.js
devtools/client/webpack/rewrite-event-emitter.js
--- a/.gitignore
+++ b/.gitignore
@@ -71,16 +71,17 @@ python/psutil/**/*.pyd
 python/psutil/build/
 
 # Ignore chrome.manifest files from the devtools loader
 devtools/client/chrome.manifest
 devtools/shared/chrome.manifest
 
 # Ignore node_modules directories in devtools
 devtools/**/node_modules
+devtools/client/inspector/inspector.bundle.js
 
 # Tag files generated by GNU Global
 GTAGS
 GRTAGS
 GSYMS
 GPATH
 
 # Git clone directory for updating web-platform-tests
--- a/.hgignore
+++ b/.hgignore
@@ -75,16 +75,17 @@
 .git/
 
 # Ignore chrome.manifest files from the devtools loader
 ^devtools/client/chrome.manifest$
 ^devtools/shared/chrome.manifest$
 
 # Ignore node_modules directories in devtools
 ^devtools/.*/node_modules/
+^devtools/client/inspector/inspector.bundle.js
 
 # git checkout of libstagefright
 ^media/libstagefright/android$
 
 # Tag files generated by GNU Global
 GTAGS
 GRTAGS
 GSYMS
--- a/devtools/client/webpack.config.js
+++ b/devtools/client/webpack.config.js
@@ -1,14 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+const path = require("path");
+const webpack = require("webpack");
+
 module.exports = [{
   bail: true,
   entry: [
     "./sourceeditor/codemirror/addon/dialog/dialog.js",
     "./sourceeditor/codemirror/addon/search/searchcursor.js",
     "./sourceeditor/codemirror/addon/search/search.js",
     "./sourceeditor/codemirror/addon/edit/matchbrackets.js",
     "./sourceeditor/codemirror/addon/edit/closebrackets.js",
@@ -31,9 +34,113 @@ module.exports = [{
     "./sourceeditor/codemirror/addon/fold/foldgutter.js",
     "./sourceeditor/codemirror/lib/codemirror.js",
   ],
   output: {
     filename: "./sourceeditor/codemirror/codemirror.bundle.js",
     libraryTarget: "var",
     library: "CodeMirror",
   },
+}, {
+  bail: true,
+
+  entry: [
+    // Inspector bundle
+    "./inspector/inspector.js",
+    // Landing page + local environment pre-bundled from a fork of debugger.html.
+    "./inspector/inspector-html-server/main.js"
+  ],
+  output: {
+    filename: "./inspector/inspector.bundle.js",
+    library: "InspectorBundle",
+  },
+  module: {
+    // Disable handling of unknown requires
+    unknownContextRegExp: /$^/,
+    unknownContextCritical: false,
+
+    // Disable handling of requires with a single expression
+    exprContextRegExp: /$^/,
+    exprContextCritical: false,
+
+    // Warn for every expression in require
+    wrappedContextCritical: true,
+
+    loaders: [
+      {
+        test: /event-emitter/,
+        exclude: /node_modules/,
+        loaders: [__dirname + "/webpack/rewrite-event-emitter"],
+      },
+    ]
+  },
+  resolveLoader: {
+    root: [
+      path.resolve("./node_modules"),
+      path.resolve("./webpack"),
+    ]
+  },
+  resolve: {
+    alias: {
+      "devtools/shared/locales": path.join(__dirname, "../shared/locales/en-US"),
+      "devtools/client/locales": path.join(__dirname, "./locales/en-US"),
+      "toolkit/locales": path.join(__dirname, "../../toolkit/locales/en-US/chrome/global"),
+      "devtools/shared/platform": path.join(__dirname, "../shared/platform/content"),
+      devtools: path.join(__dirname, "../"),
+      Services: path.join(__dirname, "./shared/shim/Services.js"),
+      gcli: path.join(__dirname, "../shared/gcli/source/lib/gcli"),
+      acorn: path.join(__dirname, "../shared/acorn"),
+      "acorn/util/walk": path.join(__dirname, "../shared/acorn/walk"),
+      sdk: path.join(__dirname, "../../addon-sdk/source/lib/sdk"),
+      method: path.join(__dirname, "../../addon-sdk/source/lib/method"),
+      "modules/libpref/init/all": path.join(__dirname,
+                                            "../../modules/libpref/init/all.js"),
+    },
+  },
+
+  plugins: [
+    new webpack.DefinePlugin({
+      "isWorker": JSON.stringify(false),
+      "reportError": "console.error",
+      "AppConstants": "{ DEBUG: true, DEBUG_JS_MODULES: true }",
+      "loader": "{ lazyRequireGetter: () => {}, lazyGetter: () => {}, chromeRequire: () => {} }",
+      "dump": "console.log",
+    }),
+  ],
+
+  externals: [
+    /codemirror\//,
+    {
+      "promise": "var Promise",
+      "devtools/server/main": "{}",
+
+      // Just trying to get build to work.  These should be removed eventually:
+      "chrome": "{}",
+
+      // In case you end up in chrome-land you can use this to help track down issues.
+      // SDK for instance does a bunch of this so if you somehow end up importing an SDK
+      // dependency this might help for debugging:
+      // "chrome": `{
+      //   Cc: {
+      //     "@mozilla.org/uuid-generator;1": { getService: () => { return {} } },
+      //     "@mozilla.org/observer-service;1": { getService: () => { return {} } },
+      //   },
+      //   Ci: {},
+      //   Cr: {},
+      //   Cm: {},
+      //   components: { classesByID: () => {} , ID: () => {} }
+      // }`,
+
+      "resource://gre/modules/XPCOMUtils.jsm": "{}",
+      "resource://devtools/client/styleeditor/StyleEditorUI.jsm": "{}",
+      "resource://devtools/client/styleeditor/StyleEditorUtil.jsm": "{}",
+      "devtools/client/inspector/inspector-panel": "{}",
+      "devtools/server/actors/utils/audionodes.json": "{}",
+
+      "devtools/client/shared/developer-toolbar": "{}",
+
+      // From sdk.
+      "resource://gre/modules/Preferences.jsm": "{}",
+      "@loader/options": "{}",
+      "@loader/unload": "{}",
+    },
+  ],
 }];
new file mode 100644
--- /dev/null
+++ b/devtools/client/webpack/prefs-loader.js
@@ -0,0 +1,54 @@
+// Rewrite devtools.js or all.js, leaving just the relevant pref() calls.
+
+"use strict";
+
+const PREF_RX = new RegExp("^ *pref\\(\"devtools");
+
+module.exports = function (content) {
+  this.cacheable && this.cacheable();
+
+  // If we're reading devtools.js we have to do some reprocessing.
+  // If we're reading all.js we just assume we can dump all the
+  // conditionals.
+  let isDevtools = this.request.endsWith("/devtools.js");
+
+  // This maps the text of a "#if" to its truth value.  This has to
+  // cover all uses of #if in devtools.js.
+  const ifMap = {
+    "#if MOZ_UPDATE_CHANNEL == beta": false,
+    "#if defined(NIGHTLY_BUILD)": false,
+    "#ifdef NIGHTLY_BUILD": false,
+    "#ifdef MOZ_DEV_EDITION": false,
+    "#ifdef RELEASE_OR_BETA": true,
+    "#ifdef RELEASE_BUILD": true,
+  };
+
+  let lines = content.split("\n");
+  let ignoring = false;
+  let newLines = [];
+  let continuation = false;
+  for (let line of lines) {
+    if (line.startsWith("sticky_pref")) {
+      line = line.slice(7);
+    }
+
+    if (isDevtools) {
+      if (line.startsWith("#if")) {
+        if (!(line in ifMap)) {
+          throw new Error("missing line in ifMap: " + line);
+        }
+        ignoring = !ifMap[line];
+      } else if (line.startsWith("#else")) {
+        ignoring = !ignoring;
+      }
+    }
+
+    if (continuation || (!ignoring && PREF_RX.test(line))) {
+      newLines.push(line);
+
+      // The call to pref(...); might span more than one line.
+      continuation = !/\);/.test(line);
+    }
+  }
+  return newLines.join("\n");
+};
new file mode 100644
--- /dev/null
+++ b/devtools/client/webpack/rewrite-event-emitter.js
@@ -0,0 +1,22 @@
+// Remove the header code from event-emitter.js.  This code confuses
+// webpack.
+
+"use strict";
+
+module.exports = function (content) {
+  this.cacheable && this.cacheable();
+
+  let lines = content.split("\n");
+  let ignoring = false;
+  let newLines = [];
+  for (let line of lines) {
+    if (/function \(factory\)/.test(line)) {
+      ignoring = true;
+    } else if (/call\(this, function /.test(line)) {
+      ignoring = false;
+    } else if (!ignoring && line !== "});") {
+      newLines.push(line);
+    }
+  }
+  return newLines.join("\n");
+};