Index: webpack_runner.js |
diff --git a/webpack.config.js b/webpack_runner.js |
similarity index 58% |
rename from webpack.config.js |
rename to webpack_runner.js |
index 3e061af1b2a4a25c60a261bd31ba91db127f05f5..61aef524c3071be3e47d253781ef6c4937156c1a 100644 |
--- a/webpack.config.js |
+++ b/webpack_runner.js |
@@ -16,14 +16,60 @@ |
*/ |
const path = require("path"); |
+const process = require("process"); |
+ |
+const MemoryFS = require("memory-fs"); |
+const webpack = require("webpack"); |
let {EXTENSION_PATH, ENTRY_POINTS, OUTPUT_PATH, BUNDLE_NAME, |
- RESOLVE_PATHS, INFO_PATH} = require("process").env; |
+ RESOLVE_PATHS} = require("process").env; |
+ |
+// Copied from adblockpluscore/test_runner.js |
+function webpackInMemory(bundleFilename, options) |
+{ |
+ return new Promise((resolve, reject) => |
+ { |
+ // Based on this example |
+ // https://webpack.js.org/api/node/#custom-file-systems |
+ let memoryFS = new MemoryFS(); |
+ |
+ options.output = {filename: bundleFilename, path: "/"}; |
+ 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); |
+ else |
+ { |
+ let bundle = memoryFS.readFileSync("/" + bundleFilename, "utf-8"); |
+ memoryFS.unlinkSync("/" + bundleFilename); |
+ resolve(bundle); |
+ } |
+ }); |
+ }); |
+} |
-module.exports = { |
+webpackInMemory(BUNDLE_NAME, { |
context: EXTENSION_PATH, |
- devtool: "source-map", |
+ devtool: "inline-source-map", |
entry: ENTRY_POINTS.split(" "), |
+ module: { |
+ rules: [{ |
+ include: path.join(EXTENSION_PATH, "lib", "info.js"), |
+ use: ["info-loader"] |
+ }] |
+ }, |
output: { |
path: OUTPUT_PATH, |
filename: BUNDLE_NAME |
@@ -31,7 +77,6 @@ module.exports = { |
resolve: { |
modules: RESOLVE_PATHS.split(" "), |
alias: { |
- info$: INFO_PATH, |
// 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", |
@@ -71,6 +116,9 @@ module.exports = { |
} |
] |
}, |
+ resolveLoader: { |
+ modules: [path.resolve(__dirname)] |
+ }, |
stats: { |
assets: false, |
children: false, |
@@ -86,4 +134,14 @@ module.exports = { |
version: false, |
warnings: true |
} |
-}; |
+}).then(console.log, e => |
+{ |
+ // I would prefer to simply leave the exception unhandled, since we want the |
+ // script to end in that case. Unfortunatley though Node.js displays a |
+ // deprecation warning if we do: |
+ // "[DEP0018] DeprecationWarning: Unhandled promise rejections are |
+ // deprecated. In the future, promise rejections that are not handled |
+ // will terminate the Node.js process with a non-zero exit code." |
+ console.error(e.join("\n")); |
+ process.exit(1); |
+}); |