def append_package_json_entries(): with open(devtools_paths.package_json_path(), 'r+') as pkg_file: try: pkg_data = json.load(pkg_file) # Replace the dev deps. pkg_data[u'devDependencies'] = DEPS pkg_file.truncate(0) pkg_file.seek(0) json.dump(pkg_data, pkg_file, indent=2, sort_keys=True) except: print('Unable to fix: %s' % sys.exc_info()[0]) return True return False
def append_package_json_entries(): with open(devtools_paths.package_json_path(), 'r+') as pkg_file: try: pkg_data = load_json_file(pkg_file) # Replace the dev deps. pkg_data['devDependencies'] = DEPS pkg_file.truncate(0) pkg_file.seek(0) json.dump(pkg_data, pkg_file, indent=2, separators=(',', ': ')) pkg_file.write('\n') except: print('Unable to fix: %s' % sys.exc_info()[0]) return True return False
def remove_package_json_entries(): with open(devtools_paths.package_json_path(), 'r+') as pkg_file: try: pkg_data = json.load(pkg_file) # Remove the dependencies and devDependencies from the root package.json # so that they can't be used to overwrite the node_modules managed by this file. for key in pkg_data.keys(): if key.find(u'dependencies') == 0 or key.find(u'devDependencies') == 0: pkg_data.pop(key) pkg_file.truncate(0) pkg_file.seek(0) json.dump(pkg_data, pkg_file, indent=2, sort_keys=True) except: print('Unable to fix: %s' % pkg) return True return False
def run_assert(): assert_errors_found = False try: with open(devtools_paths.package_json_path(), 'r') as pkg_file: pkg = json.load(pkg_file) if 'dependencies' in pkg: print('dependencies property found in package.json') assert_errors_found = True if 'devDependencies' in pkg: print('devDependencies property found in package.json') assert_errors_found = True except ValueError: print('Unable to parse package.json') assert_errors_found = True except FileNotFoundError: print('Unable to find package.json') assert_errors_found = True return assert_errors_found