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: Addressed Wladimir's feedback Created Oct. 4, 2017, 1:08 p.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} = JSON.parse(process.argv[2]);
22 26
23 module.exports = { 27 // Copied from adblockpluscore/test_runner.js
28 function webpackInMemory(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 let webpackCompiler = webpack(options);
37 webpackCompiler.outputFileSystem = memoryFS;
38
39 webpackCompiler.run((err, stats) =>
40 {
41 // Error handling is based on this example
42 // https://webpack.js.org/api/node/#error-handling
43 if (err)
44 {
45 let reason = err.stack || err;
46 if (err.details)
47 reason += "\n" + err.details;
48 reject(reason);
49 }
50 else if (stats.hasErrors())
51 reject(stats.toJson().errors.join("\n"));
52 else
53 {
54 let filepath = path.join(options.output.path, options.output.filename);
55 let bundle = memoryFS.readFileSync(filepath, "utf-8");
56 memoryFS.unlinkSync(filepath);
57 resolve([bundle, stats]);
58 }
59 });
60 });
61 }
62
63 webpackInMemory({
24 context: EXTENSION_PATH, 64 context: EXTENSION_PATH,
25 devtool: "source-map", 65 devtool: "inline-source-map",
26 entry: ENTRY_POINTS.split(" "), 66 module: {
67 rules: [{
68 include: path.join(EXTENSION_PATH, "lib", "info.js"),
69 use: ["info-loader"]
70 }]
71 },
72 entry: ENTRY_POINTS,
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,
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 },
74 stats: { 119 resolveLoader: {
75 assets: false, 120 modules: [path.resolve(__dirname)]
76 children: false,
77 chunks: false,
78 errorDetails: true,
79 errors: true,
80 hash: false,
81 modules: false,
82 publicPath: false,
83 reasons: false,
84 source: false,
85 timings: false,
86 version: false,
87 warnings: true
88 } 121 }
89 }; 122 }).then(([bundle, stats]) =>
123 {
124 console.log(bundle);
125 }).catch(e =>
126 {
127 console.error(e);
128 process.exit(1);
129 });
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