 Issue 29762564:
  Issue 6625 - Expose webpack's resolve.alias to the packagers  (Closed)
    
  
    Issue 29762564:
  Issue 6625 - Expose webpack's resolve.alias to the packagers  (Closed) 
  | Left: | ||
| Right: | 
| OLD | NEW | 
|---|---|
| 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 glob | 6 import glob | 
| 7 import io | 7 import io | 
| 8 import json | 8 import json | 
| 9 import os | 9 import os | 
| 10 import re | 10 import re | 
| 11 import struct | 11 import struct | 
| 12 import subprocess | 12 import subprocess | 
| 13 import sys | 13 import sys | 
| 14 import random | 14 import random | 
| 15 import posixpath | 15 import posixpath | 
| 16 | 16 | 
| 17 import ConfigParser | |
| 
Sebastian Noack
2018/04/26 11:30:39
Nit: ConfigParser is a corelib module. So it goes
 
tlucas
2018/04/26 11:40:58
Done.
 | |
| 18 | |
| 17 from packager import (readMetadata, getDefaultFileName, getBuildVersion, | 19 from packager import (readMetadata, getDefaultFileName, getBuildVersion, | 
| 18 getTemplate, get_extension, Files, get_app_id) | 20 getTemplate, get_extension, Files, get_app_id) | 
| 19 | 21 | 
| 20 defaultLocale = 'en_US' | 22 defaultLocale = 'en_US' | 
| 21 | 23 | 
| 22 | 24 | 
| 23 def getIgnoredFiles(params): | 25 def getIgnoredFiles(params): | 
| 24 return {'store.description'} | 26 return {'store.description'} | 
| 25 | 27 | 
| 26 | 28 | 
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 ).encode('utf-8') + '\n' | 150 ).encode('utf-8') + '\n' | 
| 149 | 151 | 
| 150 | 152 | 
| 151 def create_bundles(params, files, bundle_tests): | 153 def create_bundles(params, files, bundle_tests): | 
| 152 base_extension_path = params['baseDir'] | 154 base_extension_path = params['baseDir'] | 
| 153 info_templates = { | 155 info_templates = { | 
| 154 'chrome': 'chromeInfo.js.tmpl', | 156 'chrome': 'chromeInfo.js.tmpl', | 
| 155 'edge': 'edgeInfo.js.tmpl', | 157 'edge': 'edgeInfo.js.tmpl', | 
| 156 'gecko': 'geckoInfo.js.tmpl', | 158 'gecko': 'geckoInfo.js.tmpl', | 
| 157 } | 159 } | 
| 160 aliases = { | |
| 161 # To use our custom loader for the info module we must first set up an | |
| 162 # alias to a file that exists. | |
| 163 'info$': os.path.join(os.path.dirname(__file__), 'info.js'), | |
| 164 # Prevent builtin Node.js modules from being used instead of our own | |
| 165 # when the names clash. Once relative paths are used this won't be | |
| 166 # necessary. | |
| 167 'url$': 'url.js', | |
| 168 'events$': 'events.js', | |
| 169 'punycode$': 'punycode.js', | |
| 170 } | |
| 171 try: | |
| 172 aliases.update( | |
| 173 {k: v for k, v in params['metadata'].items('module_alias')}, | |
| 
Sebastian Noack
2018/04/26 11:30:39
Nit: The dict comprehension here is redundant.
 
tlucas
2018/04/26 11:40:58
Done.
 | |
| 174 ) | |
| 175 except ConfigParser.NoSectionError: | |
| 176 pass | |
| 158 | 177 | 
| 159 # Historically we didn't use relative paths when requiring modules, so in | 178 # Historically we didn't use relative paths when requiring modules, so in | 
| 160 # order for webpack to know where to find them we need to pass in a list of | 179 # order for webpack to know where to find them we need to pass in a list of | 
| 161 # resolve paths. Going forward we should always use relative paths, once we | 180 # resolve paths. Going forward we should always use relative paths, once we | 
| 162 # do that consistently this can be removed. See issues 5760, 5761 and 5762. | 181 # do that consistently this can be removed. See issues 5760, 5761 and 5762. | 
| 163 resolve_paths = [os.path.join(base_extension_path, dir, 'lib') | 182 resolve_paths = [os.path.join(base_extension_path, dir, 'lib') | 
| 164 for dir in ['', 'adblockpluscore', 'adblockplusui']] | 183 for dir in ['', 'adblockpluscore', 'adblockplusui']] | 
| 165 | 184 | 
| 166 info_template = getTemplate(info_templates[params['type']]) | 185 info_template = getTemplate(info_templates[params['type']]) | 
| 167 info_module = info_template.render( | 186 info_module = info_template.render( | 
| 168 basename=params['metadata'].get('general', 'basename'), | 187 basename=params['metadata'].get('general', 'basename'), | 
| 169 version=params['version'], | 188 version=params['version'], | 
| 170 ).encode('utf-8') | 189 ).encode('utf-8') | 
| 171 | 190 | 
| 172 configuration = { | 191 configuration = { | 
| 173 'bundles': [], | 192 'bundles': [], | 
| 174 'extension_path': base_extension_path, | 193 'extension_path': base_extension_path, | 
| 175 'info_module': info_module, | 194 'info_module': info_module, | 
| 176 'resolve_paths': resolve_paths, | 195 'resolve_paths': resolve_paths, | 
| 196 'aliases': aliases, | |
| 177 } | 197 } | 
| 178 | 198 | 
| 179 for item in params['metadata'].items('bundles'): | 199 for item in params['metadata'].items('bundles'): | 
| 180 name, value = item | 200 name, value = item | 
| 181 base_item_path = os.path.dirname(item.source) | 201 base_item_path = os.path.dirname(item.source) | 
| 182 | 202 | 
| 183 bundle_file = os.path.relpath(os.path.join(base_item_path, name), | 203 bundle_file = os.path.relpath(os.path.join(base_item_path, name), | 
| 184 base_extension_path) | 204 base_extension_path) | 
| 185 entry_files = [os.path.join(base_item_path, module_path) | 205 entry_files = [os.path.join(base_item_path, module_path) | 
| 186 for module_path in value.split()] | 206 for module_path in value.split()] | 
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 if devenv: | 407 if devenv: | 
| 388 add_devenv_requirements(files, metadata, params) | 408 add_devenv_requirements(files, metadata, params) | 
| 389 | 409 | 
| 390 zipdata = files.zipToString() | 410 zipdata = files.zipToString() | 
| 391 signature = None | 411 signature = None | 
| 392 pubkey = None | 412 pubkey = None | 
| 393 if keyFile != None: | 413 if keyFile != None: | 
| 394 signature = signBinary(zipdata, keyFile) | 414 signature = signBinary(zipdata, keyFile) | 
| 395 pubkey = getPublicKey(keyFile) | 415 pubkey = getPublicKey(keyFile) | 
| 396 writePackage(outFile, pubkey, signature, zipdata) | 416 writePackage(outFile, pubkey, signature, zipdata) | 
| OLD | NEW |