Bug 1365014 - inspector.html add shims for sdk, uuid, lazy requires;r=gl
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 11 May 2017 23:43:01 +0200
changeset 358592 4e4b275723774ef9260ea40bc6a80d0bd01ab3b4
parent 358591 eaffbb42ef8ec0cc6a647e2845be36ca00152dd6
child 358593 e7c7370fdd5457cd71bacc6e452a9d928fde8083
push id90353
push userryanvm@gmail.com
push dateWed, 17 May 2017 00:10:47 +0000
treeherdermozilla-inbound@41958333867b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1365014
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1365014 - inspector.html add shims for sdk, uuid, lazy requires;r=gl MozReview-Commit-ID: CtYnDV4V0HU
devtools/client/inspector/webpack.config.js
devtools/client/inspector/webpack/devtools-utils-sham.js
devtools/client/inspector/webpack/rewrite-css-logic-importer.js
devtools/client/inspector/webpack/rewrite-lazy-require.js
devtools/client/inspector/webpack/rewrite-react-redux.js
devtools/client/inspector/webpack/rewrite-sdk-lazy-require.js
devtools/client/inspector/webpack/uuid-sham.js
--- a/devtools/client/inspector/webpack.config.js
+++ b/devtools/client/inspector/webpack.config.js
@@ -18,17 +18,20 @@ module.exports = envConfig => {
       path.join(__dirname, "local-toolbox.js")
     ],
     output: {
       path: path.join(__dirname, "assets/build"),
       filename: "inspector.js",
       publicPath: "/"
     },
     module: {
-      noParse: /(debugger\/new)|netmonitor\/panel\.js/i,
+      noParse: [
+        /netmonitor\/panel\.js/i,
+        /debugger\/new\/panel\.js/i
+      ],
 
       // Disable handling of unknown requires
       unknownContextRegExp: /$^/,
       unknownContextCritical: false,
 
       // Disable handling of requires with a single expression
       exprContextRegExp: /$^/,
       exprContextCritical: false,
@@ -37,31 +40,54 @@ module.exports = envConfig => {
       wrappedContextCritical: true,
 
       loaders: [
         {
           test: /event-emitter/,
           exclude: /node_modules/,
           loaders: [path.join(__dirname, "./webpack/rewrite-event-emitter")],
         }, {
-          // Replace all references to this.browserRequire() by require() in
-          // client/inspector/*.js files
           test: /client(\/|\\)inspector(\/|\\).*\.js$/,
-          loaders: [path.join(__dirname, "./webpack/rewrite-browser-require")],
+          loaders: [
+            // Replace all references to this.browserRequire() by require()
+            path.join(__dirname, "./webpack/rewrite-browser-require"),
+            // Replace all references to loader.lazyRequire() by require()
+            path.join(__dirname, "./webpack/rewrite-lazy-require"),
+          ],
+        }, {
+          test: /shared(\/|\\)inspector(\/|\\)css-logic\.js$/,
+          loaders: [
+            // Replace a very specific lazy importer, which should really be moved to
+            // /server ...
+            path.join(__dirname, "./webpack/rewrite-css-logic-importer"),
+          ],
+        }, {
+          test: /react-redux\.js$/,
+          loaders: [
+            // Replace dynamic paths in react-redux file
+            path.join(__dirname, "./webpack/rewrite-react-redux"),
+          ],
+        }, {
+          // Replace all references sdk's lazyRequire by require()
+          test: /sdk(\/|\\).*\.js$/,
+          loaders: [path.join(__dirname, "./webpack/rewrite-sdk-lazy-require")],
         }
       ]
     },
     resolveLoader: {
       root: [
         path.resolve("./node_modules"),
         path.resolve("./webpack"),
       ]
     },
     resolve: {
       alias: {
+        "react": "devtools/client/shared/vendor/react",
+        "redux": "devtools/client/shared/vendor/redux",
+        "react-dom": "devtools/client/shared/vendor/react-dom",
         "acorn/util/walk": path.join(__dirname, "../../shared/acorn/walk"),
         "acorn": path.join(__dirname, "../../shared/acorn"),
         "devtools/client/framework/about-devtools-toolbox":
           path.join(__dirname, "./webpack/about-devtools-sham.js"),
         "devtools/client/framework/attach-thread":
           path.join(__dirname, "./webpack/attach-thread-sham.js"),
         "devtools/client/framework/target-from-url":
           path.join(__dirname, "./webpack/target-from-url-sham.js"),
@@ -74,22 +100,22 @@ module.exports = envConfig => {
           path.join(__dirname, "./webpack/devtools-utils-sham.js"),
         "devtools/shared/locales": path.join(__dirname, "../../shared/locales/en-US"),
         "devtools/shared/platform": path.join(__dirname, "../../shared/platform/content"),
         "devtools": path.join(__dirname, "../../"),
         "gcli": path.join(__dirname, "../../shared/gcli/source/lib/gcli"),
         "method": path.join(__dirname, "../../../addon-sdk/source/lib/method"),
         "modules/libpref/init/all":
           path.join(__dirname, "../../../modules/libpref/init/all.js"),
+        "sdk/util/uuid":
+          path.join(__dirname, "./webpack/uuid-sham.js"),
         "sdk": path.join(__dirname, "../../../addon-sdk/source/lib/sdk"),
         "Services": path.join(__dirname, "../shared/shim/Services.js"),
         "toolkit/locales":
           path.join(__dirname, "../../../toolkit/locales/en-US/chrome/global"),
-        "react": "devtools/client/shared/vendor/react",
-        "react-dom": "devtools/client/shared/vendor/react-dom",
       },
     },
 
     plugins: [
       new webpack.DefinePlugin({
         "isWorker": JSON.stringify(false),
         "reportError": "console.error",
         "AppConstants": "{ DEBUG: true, DEBUG_JS_MODULES: true }",
--- a/devtools/client/inspector/webpack/devtools-utils-sham.js
+++ b/devtools/client/inspector/webpack/devtools-utils-sham.js
@@ -5,9 +5,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* global setImmediate */
 
 "use strict";
 
 module.exports = {
   executeSoon: setImmediate,
+  isGenerator: function (fn) {
+    if (typeof fn !== "function") {
+      return false;
+    }
+    let proto = Object.getPrototypeOf(fn);
+    if (!proto) {
+      return false;
+    }
+    let ctor = proto.constructor;
+    if (!ctor) {
+      return false;
+    }
+    return ctor.name == "GeneratorFunction";
+  }
 };
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/webpack/rewrite-css-logic-importer.js
@@ -0,0 +1,14 @@
+/* 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";
+
+module.exports = function (content) {
+  this.cacheable && this.cacheable();
+
+  return content.replace(
+    "loader.lazyImporter(this, \"findCssSelector\", \"resource://gre/modules/css-selector.js\");",
+    "let findCssSelector = function () {};"
+  );
+};
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/webpack/rewrite-lazy-require.js
@@ -0,0 +1,14 @@
+/* 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";
+
+module.exports = function (content) {
+  this.cacheable && this.cacheable();
+
+  return content.replace(
+    /loader.lazyRequireGetter\(this,\s*"([^"]+)",[^"]*"([^"]+)", true\);/g,
+    "let { $1 } = require(\"$2\")"
+  );
+};
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/webpack/rewrite-react-redux.js
@@ -0,0 +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";
+
+module.exports = function (content) {
+  this.cacheable && this.cacheable();
+
+  return content.replace(
+    "require(REACT_PATH)",
+    "require(\"devtools/client/shared/vendor/react\")"
+  ).replace(
+    "require(REDUX_PATH)",
+    "require(\"devtools/client/shared/vendor/redux\")"
+  );
+};
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/webpack/rewrite-sdk-lazy-require.js
@@ -0,0 +1,13 @@
+/* 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";
+
+module.exports = function (content) {
+  this.cacheable && this.cacheable();
+  return content.replace(
+    /lazyRequire\(this,\s*([^,]+),\s*"([^"]+)"\);/g,
+    "let { $2 } = require($1)"
+  );
+};
new file mode 100644
--- /dev/null
+++ b/devtools/client/inspector/webpack/uuid-sham.js
@@ -0,0 +1,19 @@
+/* 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 s4 = function () {
+  return Math.floor((1 + Math.random()) * 0x10000)
+             .toString(16)
+             .substring(1);
+};
+
+let uuid = function () {
+  return "ss-s-s-s-sss".replace(/s/g, function () {
+    return s4();
+  });
+};
+
+module.exports = { uuid };