Index: webpack_runner.js |
diff --git a/webpack_runner.js b/webpack_runner.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..356e694462b095b440b312e6eea0c3ac4bba6942 |
--- /dev/null |
+++ b/webpack_runner.js |
@@ -0,0 +1,137 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-present eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+const path = require("path"); |
+const process = require("process"); |
+ |
+const MemoryFS = require("memory-fs"); |
+const webpack = require("webpack"); |
+ |
+let {BOUNDARY, BUNDLES, EXTENSION_PATH, |
+ RESOLVE_PATHS} = JSON.parse(process.argv[2]); |
+ |
+// Copied from adblockpluscore/test_runner.js |
+function webpackInMemory(options) |
+{ |
+ return new Promise((resolve, reject) => |
+ { |
+ // Based on this example |
+ // https://webpack.js.org/api/node/#custom-file-systems |
+ let memoryFS = new MemoryFS(); |
+ |
+ let webpackCompiler = webpack(options); |
+ webpackCompiler.outputFileSystem = memoryFS; |
+ |
+ webpackCompiler.run((err, stats) => |
+ { |
+ // Error handling is based on this example |
+ // https://webpack.js.org/api/node/#error-handling |
+ if (err) |
+ { |
+ let reason = err.stack || err; |
+ if (err.details) |
+ reason += "\n" + err.details; |
+ reject(reason); |
+ } |
+ else if (stats.hasErrors()) |
+ reject(stats.toJson().errors.join("\n")); |
+ else |
+ { |
+ let filepath = path.join(options.output.path, options.output.filename); |
+ let bundle = memoryFS.readFileSync(filepath, "utf-8"); |
+ memoryFS.unlinkSync(filepath); |
+ resolve([bundle, stats]); |
+ } |
+ }); |
+ }); |
+} |
+ |
+// Since the cost of starting Node.js and loading all the modules is hugely |
+// larger than actually producing bundles we avoid paying it multiple times. |
+// To acheive this we output all the required bundles - along with their |
+// names - in one go. |
+for (let {BUNDLE_NAME, ENTRY_POINTS} of BUNDLES) |
+{ |
+ webpackInMemory({ |
+ context: EXTENSION_PATH, |
+ devtool: "inline-source-map", |
+ module: { |
+ rules: [{ |
+ include: path.join(EXTENSION_PATH, "lib", "info.js"), |
+ use: ["info-loader"] |
+ }] |
+ }, |
+ entry: ENTRY_POINTS, |
+ output: { |
+ path: "/", |
+ filename: BUNDLE_NAME |
+ }, |
+ resolve: { |
+ modules: RESOLVE_PATHS, |
+ alias: { |
+ // Prevent builtin Node.js modules from being used instead of our own |
+ // when the names clash. Once relative paths are used this won't be |
+ // necessary. |
+ url$: "url.js", |
+ events$: "events.js", |
+ punycode$: "punycode.js" |
+ }, |
+ plugins: [ |
+ function() |
+ { |
+ // Our old module system in packagerChrome.py used to prefix |
+ // module names with the name of their parent directory and an |
+ // underscore - but only when that directory wasn't called |
+ // "lib". This plugin is for backwards compatability, but can |
+ // be removed once use of that deprecated syntax has been |
+ // replaced. |
+ this.plugin("described-resolve", (request, callback) => |
+ { |
+ let target = request.request; |
+ |
+ let prefix_index = target.indexOf("_"); |
+ if (prefix_index == -1) |
+ return callback(); |
+ |
+ let prefix = target.substring(0, prefix_index); |
+ if (prefix == "lib") |
+ return callback(); |
+ |
+ let fixed_target = path.join(prefix, |
+ target.substring(prefix_index + 1)); |
+ return this.doResolve( |
+ "resolve", Object.assign({}, request, {request: fixed_target}), |
+ "Changed prefixed path using legacy buildtools syntax from " + |
+ target + " to " + fixed_target, |
+ callback |
+ ); |
+ }); |
+ } |
+ ] |
+ }, |
+ resolveLoader: { |
+ modules: [path.resolve(__dirname)] |
+ } |
+ }).then(([bundle, stats]) => |
+ { |
+ console.log(BUNDLE_NAME, BOUNDARY, bundle, BOUNDARY); |
+ }).catch(e => |
+ { |
+ console.error(e); |
+ process.exit(1); |
+ }); |
+} |