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

Side by Side Diff: packagerChrome.py

Issue 29549786: Issue 5535 - Replace our module system with webpack (Closed)
Patch Set: Tidy up JSON passed from packagerChrome.py Created Oct. 4, 2017, 1:23 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 | « package.json ('k') | webpack.config.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import errno 5 import errno
6 import io 6 import io
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 import shutil
11 from StringIO import StringIO 10 from StringIO import StringIO
12 import struct 11 import struct
13 import subprocess 12 import subprocess
14 import sys 13 import sys
15 import tempfile
16 14
17 from ensure_dependencies import read_deps 15 from ensure_dependencies import read_deps
18 from packager import (readMetadata, getDefaultFileName, getBuildVersion, 16 from packager import (readMetadata, getDefaultFileName, getBuildVersion,
19 getTemplate, Files) 17 getTemplate, Files)
20 18
21 defaultLocale = 'en_US' 19 defaultLocale = 'en_US'
22 20
23 21
24 def getIgnoredFiles(params): 22 def getIgnoredFiles(params):
25 return {'store.description'} 23 return {'store.description'}
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return manifest.encode('utf-8') 140 return manifest.encode('utf-8')
143 141
144 142
145 def create_bundles(params, files): 143 def create_bundles(params, files):
146 base_extension_path = params['baseDir'] 144 base_extension_path = params['baseDir']
147 info_templates = { 145 info_templates = {
148 'chrome': 'chromeInfo.js.tmpl', 146 'chrome': 'chromeInfo.js.tmpl',
149 'edge': 'edgeInfo.js.tmpl', 147 'edge': 'edgeInfo.js.tmpl',
150 'gecko-webext': 'geckoInfo.js.tmpl' 148 'gecko-webext': 'geckoInfo.js.tmpl'
151 } 149 }
152 info_module = None
153 150
154 # Historically we didn't use relative paths when requiring modules, so in 151 # Historically we didn't use relative paths when requiring modules, so in
155 # order for webpack to know where to find them we need to pass in a list of 152 # order for webpack to know where to find them we need to pass in a list of
156 # resolve paths. Going forward we should always use relative paths, once we 153 # resolve paths. Going forward we should always use relative paths, once we
157 # do that consistently this can be removed. See issues 5760, 5761 and 5762. 154 # do that consistently this can be removed. See issues 5760, 5761 and 5762.
158 resolve_paths = ' '.join( 155 resolve_paths = [os.path.join(base_extension_path, dir, 'lib')
159 [os.path.join(base_extension_path, dir, 'lib') 156 for dir in ['', 'adblockpluscore', 'adblockplusui']]
160 for dir in ['', 'adblockpluscore', 'adblockplusui']]
161 )
162 157
163 temp_dir = tempfile.mkdtemp() 158 info_template = getTemplate(info_templates[params['type']])
164 try: 159 info_module = info_template.render(
165 info_module = os.path.join(temp_dir, 'info.js') 160 basename=params['metadata'].get('general', 'basename'),
166 template = getTemplate(info_templates[params['type']]) 161 version=params['metadata'].get('general', 'version')
167 with open(info_module, 'w') as info_file: 162 ).encode('utf-8')
168 info_file.write(
169 template.render(
170 basename=params['metadata'].get('general', 'basename'),
171 version=params['metadata'].get('general', 'version')
172 ).encode('utf-8')
173 )
174 163
175 for item in params['metadata'].items('bundles'): 164 for item in params['metadata'].items('bundles'):
176 name, value = item 165 name, value = item
177 base_item_path = os.path.dirname(item.source) 166 base_item_path = os.path.dirname(item.source)
178 167
179 bundle_file = os.path.relpath(os.path.join(base_item_path, name), 168 bundle_file = os.path.relpath(os.path.join(base_item_path, name),
180 base_extension_path) 169 base_extension_path)
181 entry_files = [os.path.join(base_item_path, module_path) 170 entry_files = [os.path.join(base_item_path, module_path)
182 for module_path in value.split()] 171 for module_path in value.split()]
183 subprocess.check_call( 172 files[bundle_file] = subprocess.check_output(
184 ['npm', 'run-script', 'webpack', '--silent'], 173 ['node',
185 cwd=os.path.dirname(__file__), 174 os.path.join(os.path.dirname(__file__), 'webpack_runner.js'),
186 env={ 175 toJson({
187 'EXTENSION_PATH': base_extension_path, 176 'BUNDLE_NAME': bundle_file,
188 'ENTRY_POINTS': ' '.join(entry_files), 177 'ENTRY_POINTS': entry_files,
189 'OUTPUT_PATH': temp_dir, 178 'EXTENSION_PATH': base_extension_path,
190 'BUNDLE_NAME': bundle_file, 179 'INFO_MODULE': info_module,
191 'RESOLVE_PATHS': resolve_paths, 180 'RESOLVE_PATHS': resolve_paths
192 'INFO_PATH': info_module, 181 })]
193 'PATH': os.environ['PATH'] 182 )
194 }
195 )
196 for file_name in [bundle_file, bundle_file + '.map']:
197 with open(os.path.join(temp_dir, file_name), 'r') as f:
198 files[file_name] = f.read()
199 finally:
200 shutil.rmtree(temp_dir)
201 183
202 184
203 def toJson(data): 185 def toJson(data):
204 return json.dumps( 186 return json.dumps(
205 data, ensure_ascii=False, sort_keys=True, 187 data, ensure_ascii=False, sort_keys=True,
206 indent=2, separators=(',', ': ') 188 indent=2, separators=(',', ': ')
207 ).encode('utf-8') + '\n' 189 ).encode('utf-8') + '\n'
208 190
209 191
210 def import_string_webext(data, key, source): 192 def import_string_webext(data, key, source):
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 params, 'testIndex.html.tmpl', ('general', 'testScripts') 415 params, 'testIndex.html.tmpl', ('general', 'testScripts')
434 ) 416 )
435 417
436 zipdata = files.zipToString() 418 zipdata = files.zipToString()
437 signature = None 419 signature = None
438 pubkey = None 420 pubkey = None
439 if keyFile != None: 421 if keyFile != None:
440 signature = signBinary(zipdata, keyFile) 422 signature = signBinary(zipdata, keyFile)
441 pubkey = getPublicKey(keyFile) 423 pubkey = getPublicKey(keyFile)
442 writePackage(outFile, pubkey, signature, zipdata) 424 writePackage(outFile, pubkey, signature, zipdata)
OLDNEW
« no previous file with comments | « package.json ('k') | webpack.config.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld