Index: ensure_dependencies.py |
=================================================================== |
--- a/ensure_dependencies.py |
+++ b/ensure_dependencies.py |
@@ -39,16 +39,18 @@ |
# from a specific Git repository, specifying the revision ID. |
adblockpluschrome = git:git@github.com:user/adblockpluschrome.git@1fad3a7 |
''' |
SKIP_DEPENDENCY_UPDATES = os.environ.get( |
'SKIP_DEPENDENCY_UPDATES', '' |
).lower() not in ('', '0', 'false') |
+NPM_LOCKFILE = '.npm_install_lock' |
+ |
class Mercurial(): |
def istype(self, repodir): |
return os.path.exists(os.path.join(repodir, '.hg')) |
def clone(self, source, target): |
if not source.endswith('/'): |
source += '/' |
@@ -266,20 +268,29 @@ |
# production dependencies declared, we don't need to run npm and can |
# bail out early. |
if not package_data.get('dependencies', False): |
return |
except IOError: |
return |
try: |
- cmd = ['npm', 'install', '--only=production', '--loglevel=warn'] |
+ # Create an empty file, which gets deleted after successfully |
+ # installing Node.js dependencies. |
+ lockfile_path = os.path.join(target, NPM_LOCKFILE) |
+ open(lockfile_path, 'a').close() |
+ |
+ cmd = ['npm', 'install', '--only=production', |
+ '--loglevel=warn', '--no-package-lock'] |
subprocess.check_output(cmd, cwd=target) |
+ repo_types[vcs].ignore(os.path.join(target, NPM_LOCKFILE), target) |
repo_types[vcs].ignore(os.path.join(target, 'node_modules'), target) |
+ |
+ os.remove(lockfile_path) |
except OSError as e: |
import errno |
if e.errno == errno.ENOENT: |
logging.error('Failed to install Node.js dependencies for %s,' |
' please ensure Node.js is installed.', target) |
else: |
raise |
@@ -360,17 +371,18 @@ |
if not (vcs and source and rev): |
logging.warning('No valid source / revision found to create %s' % target) |
continue |
repo_cloned = ensure_repo(repodir, parenttype, target, vcs, |
_root.get(vcs, ''), source) |
repo_updated = update_repo(target, vcs, rev) |
- if repo_cloned or repo_updated: |
+ recent_npm_failed = os.path.exists(os.path.join(target, NPM_LOCKFILE)) |
+ if repo_cloned or repo_updated or recent_npm_failed: |
resolve_npm_dependencies(target, vcs) |
resolve_deps(target, level + 1, self_update=False, |
overrideroots=overrideroots, skipdependencies=skipdependencies) |
if self_update and '_self' in config and '*' in config['_self']: |
source = safe_join(repodir, config['_self']['*']) |
try: |
with io.open(source, 'rb') as handle: |