Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-present eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
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/>. | |
16 */ | |
17 | |
18 const path = require("path"); | |
19 const process = require("process"); | |
20 | |
21 const MemoryFS = require("memory-fs"); | |
22 const webpack = require("webpack"); | |
23 | |
24 let {BOUNDARY, BUNDLES, EXTENSION_PATH, | |
25 RESOLVE_PATHS} = JSON.parse(process.argv[2]); | |
26 | |
27 // Since the cost of starting Node.js and loading all the modules is hugely | |
28 // larger than actually producing bundles we avoid paying it multiple times. | |
29 // To acheive this we output all the required bundles - along with their | |
Wladimir Palant
2017/10/09 10:54:55
Typo: achieve
kzar
2017/10/09 13:52:15
Done.
| |
30 // names - in one go. | |
31 let options = []; | |
32 for (let {BUNDLE_NAME, ENTRY_POINTS} of BUNDLES) | |
33 { | |
34 options.push({ | |
35 context: EXTENSION_PATH, | |
36 devtool: "source-map", | |
37 module: { | |
38 rules: [{ | |
39 include: path.join(EXTENSION_PATH, "lib", "info.js"), | |
40 use: ["info-loader"] | |
41 }] | |
42 }, | |
43 entry: ENTRY_POINTS, | |
44 output: { | |
45 path: "/", | |
46 filename: BUNDLE_NAME | |
47 }, | |
48 resolve: { | |
49 modules: RESOLVE_PATHS, | |
50 alias: { | |
51 // Prevent builtin Node.js modules from being used instead of our own | |
52 // when the names clash. Once relative paths are used this won't be | |
53 // necessary. | |
54 url$: "url.js", | |
55 events$: "events.js", | |
56 punycode$: "punycode.js" | |
57 }, | |
58 plugins: [ | |
59 function() | |
60 { | |
61 // Our old module system in packagerChrome.py used to prefix | |
62 // module names with the name of their parent directory and an | |
63 // underscore - but only when that directory wasn't called | |
64 // "lib". This plugin is for backwards compatability, but can | |
65 // be removed once use of that deprecated syntax has been | |
66 // replaced. | |
67 this.plugin("described-resolve", (request, callback) => | |
68 { | |
69 let target = request.request; | |
70 | |
71 let prefix_index = target.indexOf("_"); | |
72 if (prefix_index == -1) | |
73 return callback(); | |
74 | |
75 let prefix = target.substring(0, prefix_index); | |
76 if (prefix == "lib") | |
77 return callback(); | |
78 | |
79 let fixed_target = path.join(prefix, | |
80 target.substring(prefix_index + 1)); | |
81 return this.doResolve( | |
82 "resolve", Object.assign({}, request, {request: fixed_target}), | |
83 "Changed prefixed path using legacy buildtools syntax from " + | |
84 target + " to " + fixed_target, | |
85 callback | |
86 ); | |
87 }); | |
88 } | |
89 ] | |
90 }, | |
91 resolveLoader: { | |
92 modules: [path.resolve(__dirname)] | |
93 } | |
94 }); | |
95 } | |
96 | |
97 // Based on this example | |
98 // https://webpack.js.org/api/node/#custom-file-systems | |
99 let memoryFS = new MemoryFS(); | |
100 let webpackCompiler = webpack(options); | |
101 | |
102 webpackCompiler.outputFileSystem = memoryFS; | |
103 webpackCompiler.run((err, stats) => | |
104 { | |
105 // Error handling is based on this example | |
106 // https://webpack.js.org/api/node/#error-handling | |
107 if (err) | |
108 { | |
109 let reason = err.stack || err; | |
110 if (err.details) | |
111 reason += "\n" + err.details; | |
112 throw new Error(reason); | |
113 } | |
114 else if (stats.hasErrors()) | |
115 throw new Error(stats.toJson().errors.join("\n")); | |
116 else | |
117 { | |
118 for (let config of options) | |
119 { | |
120 let filepath = path.join(config.output.path, config.output.filename); | |
121 let mappath = filepath + ".map"; | |
122 console.log(filepath, BOUNDARY, | |
123 memoryFS.readFileSync(filepath, "utf-8"), BOUNDARY, | |
124 mappath, BOUNDARY, | |
125 memoryFS.readFileSync(mappath, "utf-8"), BOUNDARY); | |
Wladimir Palant
2017/10/09 10:54:56
How about printing JSON instead of this boundary h
kzar
2017/10/09 13:52:15
Done.
| |
126 memoryFS.unlinkSync(filepath); | |
127 memoryFS.unlinkSync(mappath); | |
128 } | |
129 } | |
130 }); | |
OLD | NEW |