def recursively_replace_dependencies(node_modules_path, kind, memo={}):
    '''Recursively traverse into node_modules/ and then each dependency's node_modules/
directory, replacing dependencies as we go.'''
    package_json_filename = os.sep.join([node_modules_path, 'package.json'])
    if os.path.isfile(package_json_filename):
        try:
            in_file = open(package_json_filename)
            package_json = json.loads(in_file.read())
            in_file.close()
            new_pkg_json, new_memos = replace_dependencies(package_json, kind, memo)
            memo.update(new_memos)
            out_file = open(package_json_filename, 'w')
            out_file.write(json.dumps(new_pkg_json, indent=4))
            out_file.close()
        except __HOLE__:
            sys.stderr.write('Could not read/write {0}'.format(package_json_filename))
    for name in os.listdir(node_modules_path):
        path = os.sep.join([node_modules_path, name])
        if os.path.isdir(path):
            recursively_replace_dependencies(path, kind, memo)
    return memo
dataset/ETHPy150Open zsck/npm-to-git/n2g.py/recursively_replace_dependencies