Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: webpack_runner.js

Issue 29549786: Issue 5535 - Replace our module system with webpack (Closed)
Patch Set: Only use special info-loader for adblockpluschrome/lib/info.js Created Oct. 3, 2017, 10:07 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webpack.config.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 const path = require("path"); 18 const path = require("path");
19 const process = require("process");
20
21 const MemoryFS = require("memory-fs");
22 const webpack = require("webpack");
19 23
20 let {EXTENSION_PATH, ENTRY_POINTS, OUTPUT_PATH, BUNDLE_NAME, 24 let {EXTENSION_PATH, ENTRY_POINTS, OUTPUT_PATH, BUNDLE_NAME,
21 RESOLVE_PATHS, INFO_PATH} = require("process").env; 25 RESOLVE_PATHS} = require("process").env;
22 26
23 module.exports = { 27 // Copied from adblockpluscore/test_runner.js
28 function webpackInMemory(bundleFilename, options)
29 {
30 return new Promise((resolve, reject) =>
31 {
32 // Based on this example
33 // https://webpack.js.org/api/node/#custom-file-systems
34 let memoryFS = new MemoryFS();
35
36 options.output = {filename: bundleFilename, path: "/"};
37 let webpackCompiler = webpack(options);
38 webpackCompiler.outputFileSystem = memoryFS;
39
40 webpackCompiler.run((err, stats) =>
41 {
42 // Error handling is based on this example
43 // https://webpack.js.org/api/node/#error-handling
44 if (err)
45 {
46 let reason = err.stack || err;
47 if (err.details)
48 reason += "\n" + err.details;
49 reject(reason);
50 }
51 else if (stats.hasErrors())
52 reject(stats.toJson().errors);
53 else
54 {
55 let bundle = memoryFS.readFileSync("/" + bundleFilename, "utf-8");
56 memoryFS.unlinkSync("/" + bundleFilename);
57 resolve(bundle);
58 }
59 });
60 });
61 }
62
63 webpackInMemory(BUNDLE_NAME, {
24 context: EXTENSION_PATH, 64 context: EXTENSION_PATH,
25 devtool: "source-map", 65 devtool: "inline-source-map",
26 entry: ENTRY_POINTS.split(" "), 66 entry: ENTRY_POINTS.split(" "),
67 module: {
68 rules: [{
69 include: path.join(EXTENSION_PATH, "lib", "info.js"),
70 use: ["info-loader"]
71 }]
72 },
27 output: { 73 output: {
28 path: OUTPUT_PATH, 74 path: OUTPUT_PATH,
29 filename: BUNDLE_NAME 75 filename: BUNDLE_NAME
30 }, 76 },
31 resolve: { 77 resolve: {
32 modules: RESOLVE_PATHS.split(" "), 78 modules: RESOLVE_PATHS.split(" "),
33 alias: { 79 alias: {
34 info$: INFO_PATH,
35 // Prevent builtin Node.js modules from being used instead of our own when 80 // Prevent builtin Node.js modules from being used instead of our own when
36 // the names clash. Once relative paths are used this won't be necessary. 81 // the names clash. Once relative paths are used this won't be necessary.
37 url$: "url.js", 82 url$: "url.js",
38 events$: "events.js", 83 events$: "events.js",
39 punycode$: "punycode.js" 84 punycode$: "punycode.js"
40 }, 85 },
41 plugins: [ 86 plugins: [
42 function() 87 function()
43 { 88 {
44 // Our old module system in packagerChrome.py used to prefix 89 // Our old module system in packagerChrome.py used to prefix
(...skipping 19 matching lines...) Expand all
64 return this.doResolve( 109 return this.doResolve(
65 "resolve", Object.assign({}, request, {request: fixed_target}), 110 "resolve", Object.assign({}, request, {request: fixed_target}),
66 "Changed prefixed path using legacy buildtools syntax from " + 111 "Changed prefixed path using legacy buildtools syntax from " +
67 target + " to " + fixed_target, 112 target + " to " + fixed_target,
68 callback 113 callback
69 ); 114 );
70 }); 115 });
71 } 116 }
72 ] 117 ]
73 }, 118 },
119 resolveLoader: {
120 modules: [path.resolve(__dirname)]
121 },
74 stats: { 122 stats: {
75 assets: false, 123 assets: false,
76 children: false, 124 children: false,
77 chunks: false, 125 chunks: false,
78 errorDetails: true, 126 errorDetails: true,
79 errors: true, 127 errors: true,
80 hash: false, 128 hash: false,
81 modules: false, 129 modules: false,
82 publicPath: false, 130 publicPath: false,
83 reasons: false, 131 reasons: false,
84 source: false, 132 source: false,
85 timings: false, 133 timings: false,
86 version: false, 134 version: false,
87 warnings: true 135 warnings: true
88 } 136 }
89 }; 137 }).then(console.log, e =>
138 {
139 // I would prefer to simply leave the exception unhandled, since we want the
140 // script to end in that case. Unfortunatley though Node.js displays a
141 // deprecation warning if we do:
142 // "[DEP0018] DeprecationWarning: Unhandled promise rejections are
143 // deprecated. In the future, promise rejections that are not handled
144 // will terminate the Node.js process with a non-zero exit code."
145 console.error(e.join("\n"));
146 process.exit(1);
147 });
OLDNEW
« no previous file with comments | « webpack.config.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld