Index: webpack_runner.js |
diff --git a/webpack.config.js b/webpack_runner.js |
similarity index 59% |
rename from webpack.config.js |
rename to webpack_runner.js |
index 3e061af1b2a4a25c60a261bd31ba91db127f05f5..70527c5b130fb7f16d57e85aa724b56bf2c499d7 100644 |
--- a/webpack.config.js |
+++ b/webpack_runner.js |
@@ -16,22 +16,67 @@ |
*/ |
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} = 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; |
-module.exports = { |
+ 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]); |
+ } |
+ }); |
+ }); |
+} |
+ |
+webpackInMemory({ |
context: EXTENSION_PATH, |
- devtool: "source-map", |
- entry: ENTRY_POINTS.split(" "), |
+ devtool: "inline-source-map", |
+ module: { |
+ rules: [{ |
+ include: path.join(EXTENSION_PATH, "lib", "info.js"), |
+ use: ["info-loader"] |
+ }] |
+ }, |
+ entry: ENTRY_POINTS, |
output: { |
path: OUTPUT_PATH, |
filename: BUNDLE_NAME |
}, |
resolve: { |
- modules: RESOLVE_PATHS.split(" "), |
+ modules: RESOLVE_PATHS, |
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,19 +116,14 @@ module.exports = { |
} |
] |
}, |
- stats: { |
- assets: false, |
- children: false, |
- chunks: false, |
- errorDetails: true, |
- errors: true, |
- hash: false, |
- modules: false, |
- publicPath: false, |
- reasons: false, |
- source: false, |
- timings: false, |
- version: false, |
- warnings: true |
+ resolveLoader: { |
+ modules: [path.resolve(__dirname)] |
} |
-}; |
+}).then(([bundle, stats]) => |
+{ |
+ console.log(bundle); |
+}).catch(e => |
+{ |
+ console.error(e); |
+ process.exit(1); |
+}); |