OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # This Source Code Form is subject to the terms of the Mozilla Public | 3 # This Source Code Form is subject to the terms of the Mozilla Public |
4 # License, v. 2.0. If a copy of the MPL was not distributed with this | 4 # License, v. 2.0. If a copy of the MPL was not distributed with this |
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 |
7 import sys | 7 import sys |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import re | 10 import re |
(...skipping 26 matching lines...) Expand all Loading... |
37 adblockplus = adblockplus hg:893426c6a6ab git:git@github.com:user/adblockplus.
git@b2ffd52b | 37 adblockplus = adblockplus hg:893426c6a6ab git:git@github.com:user/adblockplus.
git@b2ffd52b |
38 # Clone the adblockpluschrome repository into the adblockpluschrome directory, | 38 # Clone the adblockpluschrome repository into the adblockpluschrome directory, |
39 # from a specific Git repository, specifying the revision ID. | 39 # from a specific Git repository, specifying the revision ID. |
40 adblockpluschrome = git:git@github.com:user/adblockpluschrome.git@1fad3a7 | 40 adblockpluschrome = git:git@github.com:user/adblockpluschrome.git@1fad3a7 |
41 ''' | 41 ''' |
42 | 42 |
43 SKIP_DEPENDENCY_UPDATES = os.environ.get( | 43 SKIP_DEPENDENCY_UPDATES = os.environ.get( |
44 'SKIP_DEPENDENCY_UPDATES', '' | 44 'SKIP_DEPENDENCY_UPDATES', '' |
45 ).lower() not in ('', '0', 'false') | 45 ).lower() not in ('', '0', 'false') |
46 | 46 |
| 47 NPM_LOCKFILE = '.npm_install_lock' |
| 48 |
47 | 49 |
48 class Mercurial(): | 50 class Mercurial(): |
49 def istype(self, repodir): | 51 def istype(self, repodir): |
50 return os.path.exists(os.path.join(repodir, '.hg')) | 52 return os.path.exists(os.path.join(repodir, '.hg')) |
51 | 53 |
52 def clone(self, source, target): | 54 def clone(self, source, target): |
53 if not source.endswith('/'): | 55 if not source.endswith('/'): |
54 source += '/' | 56 source += '/' |
55 subprocess.check_call(['hg', 'clone', '--quiet', '--noupdate', source, t
arget]) | 57 subprocess.check_call(['hg', 'clone', '--quiet', '--noupdate', source, t
arget]) |
56 | 58 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 266 |
265 # In case a package.json does not exist at all or if there are no | 267 # In case a package.json does not exist at all or if there are no |
266 # production dependencies declared, we don't need to run npm and can | 268 # production dependencies declared, we don't need to run npm and can |
267 # bail out early. | 269 # bail out early. |
268 if not package_data.get('dependencies', False): | 270 if not package_data.get('dependencies', False): |
269 return | 271 return |
270 except IOError: | 272 except IOError: |
271 return | 273 return |
272 | 274 |
273 try: | 275 try: |
274 cmd = ['npm', 'install', '--only=production', '--loglevel=warn'] | 276 # Create an empty file, which gets deleted after successfully |
| 277 # installing Node.js dependencies. |
| 278 lockfile_path = os.path.join(target, NPM_LOCKFILE) |
| 279 open(lockfile_path, 'a').close() |
| 280 |
| 281 cmd = ['npm', 'install', '--only=production', |
| 282 '--loglevel=warn', '--no-package-lock'] |
275 subprocess.check_output(cmd, cwd=target) | 283 subprocess.check_output(cmd, cwd=target) |
276 | 284 |
| 285 repo_types[vcs].ignore(os.path.join(target, NPM_LOCKFILE), target) |
277 repo_types[vcs].ignore(os.path.join(target, 'node_modules'), target) | 286 repo_types[vcs].ignore(os.path.join(target, 'node_modules'), target) |
| 287 |
| 288 os.remove(lockfile_path) |
278 except OSError as e: | 289 except OSError as e: |
279 import errno | 290 import errno |
280 if e.errno == errno.ENOENT: | 291 if e.errno == errno.ENOENT: |
281 logging.error('Failed to install Node.js dependencies for %s,' | 292 logging.error('Failed to install Node.js dependencies for %s,' |
282 ' please ensure Node.js is installed.', target) | 293 ' please ensure Node.js is installed.', target) |
283 else: | 294 else: |
284 raise | 295 raise |
285 | 296 |
286 | 297 |
287 def ensure_repo(parentrepo, parenttype, target, type, root, sourcename): | 298 def ensure_repo(parentrepo, parenttype, target, type, root, sourcename): |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 vcs = key | 369 vcs = key |
359 source, rev = merge_seqs(sources.get('*'), sources.get(vcs)) | 370 source, rev = merge_seqs(sources.get('*'), sources.get(vcs)) |
360 | 371 |
361 if not (vcs and source and rev): | 372 if not (vcs and source and rev): |
362 logging.warning('No valid source / revision found to create %s' % ta
rget) | 373 logging.warning('No valid source / revision found to create %s' % ta
rget) |
363 continue | 374 continue |
364 | 375 |
365 repo_cloned = ensure_repo(repodir, parenttype, target, vcs, | 376 repo_cloned = ensure_repo(repodir, parenttype, target, vcs, |
366 _root.get(vcs, ''), source) | 377 _root.get(vcs, ''), source) |
367 repo_updated = update_repo(target, vcs, rev) | 378 repo_updated = update_repo(target, vcs, rev) |
368 if repo_cloned or repo_updated: | 379 recent_npm_failed = os.path.exists(os.path.join(target, NPM_LOCKFILE)) |
| 380 if repo_cloned or repo_updated or recent_npm_failed: |
369 resolve_npm_dependencies(target, vcs) | 381 resolve_npm_dependencies(target, vcs) |
370 resolve_deps(target, level + 1, self_update=False, | 382 resolve_deps(target, level + 1, self_update=False, |
371 overrideroots=overrideroots, skipdependencies=skipdependenc
ies) | 383 overrideroots=overrideroots, skipdependencies=skipdependenc
ies) |
372 | 384 |
373 if self_update and '_self' in config and '*' in config['_self']: | 385 if self_update and '_self' in config and '*' in config['_self']: |
374 source = safe_join(repodir, config['_self']['*']) | 386 source = safe_join(repodir, config['_self']['*']) |
375 try: | 387 try: |
376 with io.open(source, 'rb') as handle: | 388 with io.open(source, 'rb') as handle: |
377 sourcedata = handle.read() | 389 sourcedata = handle.read() |
378 except IOError as e: | 390 except IOError as e: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 args = parser.parse_args() | 429 args = parser.parse_args() |
418 | 430 |
419 if args.quiet: | 431 if args.quiet: |
420 logging.disable(logging.INFO) | 432 logging.disable(logging.INFO) |
421 | 433 |
422 repos = args.repos | 434 repos = args.repos |
423 if not len(repos): | 435 if not len(repos): |
424 repos = [os.path.dirname(__file__)] | 436 repos = [os.path.dirname(__file__)] |
425 for repo in repos: | 437 for repo in repos: |
426 resolve_deps(repo) | 438 resolve_deps(repo) |
OLD | NEW |