def install_dependencies(package_config, npm): name = package_config['name'] is_node_package = package_config['isNodePackage'] package_type = 'Node' if is_node_package else 'Atom' logging.info('Installing dependencies for %s package %s...', package_type, name) # Link private node dependencies. src_path = package_config['packageRootAbsolutePath'] node_modules_path = os.path.join(src_path, 'node_modules') fs.mkdirs(node_modules_path) for local_dependency, local_dependency_config in package_config[ 'localDependencies'].items(): src_dir = local_dependency_config['packageRootAbsolutePath'] dest_dir = os.path.join(node_modules_path, local_dependency) symlink(src_dir, dest_dir, relative=True) link_dependencys_executable(node_modules_path, local_dependency) # Install other public node dependencies. npm.install( src_path, local_packages=package_config['localDependencies'], include_dev_dependencies=package_config['includeDevDependencies']) logging.info('Done installing dependencies for %s', name) is_node_package = package_config.get('isNodePackage') if not is_node_package: logging.info('Running `apm link %s`...', src_path) cmd_args = ['apm', 'link', src_path] fs.cross_platform_check_output(cmd_args) logging.info('Done linking %s', name)
def install_dependencies(package_config, npm, copy_local_dependencies=False): name = package_config['name'] is_node_package = package_config['isNodePackage'] package_type = 'Node' if is_node_package else 'Atom' logging.info('Installing dependencies for %s package %s...', package_type, name) # Link private node dependencies. src_path = package_config['packageRootAbsolutePath'] node_modules_path = os.path.join(src_path, 'node_modules') fs.mkdirs(node_modules_path) for local_dependency, local_dependency_config in package_config['localDependencies'].items(): src_dir = local_dependency_config['packageRootAbsolutePath'] dest_dir = os.path.join(node_modules_path, local_dependency) if copy_local_dependencies: shutil.copytree(src_dir, dest_dir, True); else: symlink(src_dir, dest_dir, relative=True) link_dependencys_executable(node_modules_path, local_dependency) # Install other public node dependencies. npm.install(src_path, local_packages=package_config['localDependencies'], include_dev_dependencies=True) logging.info('Done installing dependencies for %s', name) is_node_package = package_config.get('isNodePackage') if not is_node_package: logging.info('Running `apm link %s`...', src_path) cmd_args = ['apm', 'link', src_path] fs.cross_platform_check_output(cmd_args) logging.info('Done linking %s', name)
def _execute(self, cmd_args, cwd=None): if self._verbose: output = fs.cross_platform_check_output(cmd_args, cwd=cwd, stderr=subprocess.STDOUT) print(output) else: with open(os.devnull, 'w') as devnull: output = fs.cross_platform_check_output(cmd_args, cwd=cwd, stderr=devnull) return output
def _execute(self, cmd_args, repository_directory=None): cmd_args.insert(0, 'git') if repository_directory: cmd_args.insert(1, '-C') cmd_args.insert(2, repository_directory) if self._verbose: output = fs.cross_platform_check_output(cmd_args, stderr=subprocess.STDOUT) print output else: with open(os.devnull, 'w') as devnull: output = fs.cross_platform_check_output(cmd_args, stderr=devnull) return output
def create_placeholder(path_to_package_json): metadata = json_load(path_to_package_json) # Verify that this represents a Node package. nuclide = metadata.get('nuclide', None) if not isinstance(nuclide, dict): return False if nuclide.get('packageType', None) != 'Node': return False # Verfy that the package has a description. if not metadata.get('description', None): print('package.json must include a description: %s' % path_to_package_json) return False # Verify that the npm user is "fb". npm_user = fs.cross_platform_check_output(['npm', 'whoami']).rstrip() if npm_user != 'fb': print(('You must be the "fb" user to publish a Nuclide package to npm, but you were "%s". ' + 'Find someone who has the appropriate credentials to do the publish for you.') % npm_user) return False # Write out the package.json to a temp directory. tmp_dir = tempfile.mkdtemp('npm-publish') tmp_package_json = os.path.join(tmp_dir, 'package.json') json_dump(metadata, tmp_package_json) # Run `npm publish`. subprocess.check_call(['npm', 'publish'], cwd=tmp_dir) return True
def check_dependency(binary, expected_version): # Since flow v0.18.1 `--version` was deprecated in favor a `version` command cmd = [binary, '--version'] if binary != 'flow' else [binary, 'version'] actual_version = fs.cross_platform_check_output(cmd).rstrip() if actual_version != expected_version: raise Exception(('Incorrect %s version. Found %s, expected %s. ' + 'Use the --no-version option to ignore this test.') % (binary, actual_version, expected_version))
def install_dependencies(package_config, npm, copy_local_dependencies=False): name = package_config['name'] is_node_package = package_config['isNodePackage'] package_type = 'Node' if is_node_package else 'Atom' logging.info('Installing dependencies for %s package %s...', package_type, name) # Link private node dependencies. src_path = package_config['packageRootAbsolutePath'] node_modules_path = os.path.join(src_path, 'node_modules') fs.mkdirs(node_modules_path) for local_dependency, local_dependency_config in package_config[ 'localDependencies'].items(): src_dir = local_dependency_config['packageRootAbsolutePath'] dest_dir = os.path.join(node_modules_path, local_dependency) if copy_local_dependencies: shutil.copytree(src_dir, dest_dir, True) else: symlink(src_dir, dest_dir, relative=True) link_dependencys_executable(node_modules_path, local_dependency) # Install other public node dependencies. # # We store the sha sum of package.json under the node_modules directory. If # the sum matches, we skip the call to `npm install`. sum_path = os.path.join(node_modules_path, 'package.json.sum') package_json_path = os.path.join(src_path, 'package.json') package_json_sum = hashlib.sha1( read_file(package_json_path).encode('utf-8')).hexdigest() valid_sum = read_file(sum_path) == package_json_sum if valid_sum: logging.info('Dependencies for %s already installed', name) else: npm.install(src_path, local_packages=package_config['localDependencies'], include_dev_dependencies=True) write_file(sum_path, package_json_sum) logging.info('Done installing dependencies for %s', name) is_node_package = package_config.get('isNodePackage') if not is_node_package: logging.info('Running `apm link %s`...', src_path) cmd_args = ['apm', 'link', src_path] fs.cross_platform_check_output(cmd_args) logging.info('Done linking %s', name)
def install_dependencies(package_config, npm, copy_local_dependencies=False): name = package_config["name"] is_node_package = package_config["isNodePackage"] package_type = "Node" if is_node_package else "Atom" logging.info("Installing dependencies for %s package %s...", package_type, name) # Link private node dependencies. src_path = package_config["packageRootAbsolutePath"] node_modules_path = os.path.join(src_path, "node_modules") fs.mkdirs(node_modules_path) for local_dependency, local_dependency_config in package_config["localDependencies"].items(): src_dir = local_dependency_config["packageRootAbsolutePath"] dest_dir = os.path.join(node_modules_path, local_dependency) if copy_local_dependencies: shutil.copytree(src_dir, dest_dir, True) else: symlink(src_dir, dest_dir, relative=True) link_dependencys_executable(node_modules_path, local_dependency) # Install other public node dependencies. # # We store the sha sum of package.json under the node_modules directory. If # the sum matches, we skip the call to `npm install`. sum_path = os.path.join(node_modules_path, "package.json.sum") package_json_path = os.path.join(src_path, "package.json") package_json_sum = hashlib.sha1(read_file(package_json_path)).hexdigest() valid_sum = read_file(sum_path) == package_json_sum if valid_sum: logging.info("Dependencies for %s already installed", name) else: npm.install(src_path, local_packages=package_config["localDependencies"], include_dev_dependencies=True) write_file(sum_path, package_json_sum) logging.info("Done installing dependencies for %s", name) is_node_package = package_config.get("isNodePackage") if not is_node_package: logging.info("Running `apm link %s`...", src_path) cmd_args = ["apm", "link", src_path] fs.cross_platform_check_output(cmd_args) logging.info("Done linking %s", name)
def install_dependencies(package_config, npm, copy_local_dependencies=False): name = package_config['name'] is_node_package = package_config['isNodePackage'] package_type = 'Node' if is_node_package else 'Atom' logging.info('Installing dependencies for %s package %s...', package_type, name) # Link private node dependencies. src_path = package_config['packageRootAbsolutePath'] node_modules_path = os.path.join(src_path, 'node_modules') fs.mkdirs(node_modules_path) for local_dependency, local_dependency_config in package_config['localDependencies'].items(): src_dir = local_dependency_config['packageRootAbsolutePath'] dest_dir = os.path.join(node_modules_path, local_dependency) if copy_local_dependencies: shutil.copytree(src_dir, dest_dir, True); else: symlink(src_dir, dest_dir, relative=True) link_dependencys_executable(node_modules_path, local_dependency) # Install other public node dependencies. # # We store the sha sum of package.json under the node_modules directory. If # the sum matches, we skip the call to `npm install`. sum_path = os.path.join(node_modules_path, 'package.json.sum') package_json_path = os.path.join(src_path, 'package.json') package_json_sum = hashlib.sha1(read_file(package_json_path)).hexdigest() valid_sum = read_file(sum_path) == package_json_sum if valid_sum: logging.info('Dependencies for %s already installed', name) else: npm.install(src_path, local_packages=package_config['localDependencies'], include_dev_dependencies=True) write_file(sum_path, package_json_sum) logging.info('Done installing dependencies for %s', name) is_node_package = package_config.get('isNodePackage') if not is_node_package: logging.info('Running `apm link %s`...', src_path) cmd_args = ['apm', 'link', src_path] fs.cross_platform_check_output(cmd_args) logging.info('Done linking %s', name)
def _verify_node(): '''Ensures that Node v0.12.0 or later is on the user's $PATH.''' # As noted in _install_apm_and_npm_os_x(), ultimately that function should be responsible for # doing this work. # First, check for the presence of node. Make sure it is at least v0.12.0. node_executable = platform_checker.get_node_executable() if _is_executable_on_path(node_executable): node_version = fs.cross_platform_check_output([node_executable, '--version']).rstrip() if semver.find_version_in_range([node_version], '>=0.12.0'): return raise Exception('Must install Node v0.12.0 or later. Not found in %s' % os.environ['PATH'])
def _verify_node(): '''Ensures that Node v0.12.0 or later is on the user's $PATH.''' # As noted in _install_apm_and_npm_os_x(), ultimately that function should be responsible for # doing this work. # First, check for the presence of node. Make sure it is at least v0.12.0. node_executable = platform_checker.get_node_executable() if _is_executable_on_path(node_executable): node_version = fs.cross_platform_check_output([node_executable, '--version']).rstrip() major, minor = re.match(r'^v(\d+)\.(\d+)\.(\d+)$', node_version).group(1, 2) if int(major) > 0 or int(minor) >= 12: return raise Exception('Must install Node v0.12.0 or later. Not found in %s' % os.environ['PATH'])
def _verify_node(): '''Ensures that Node v4.1.1 or later is on the user's $PATH.''' # As noted in _install_apm_and_npm_os_x(), ultimately that function should be responsible for # doing this work. # First, check for the presence of node. Make sure it is at least v4.1.1. node_executable = platform_checker.get_node_executable() if _is_executable_on_path(node_executable): node_version = fs.cross_platform_check_output([node_executable, '--version']).rstrip() major, minor, patch = re.match(r'^v(\d+)\.(\d+)\.(\d+)$', node_version).group(1, 2, 3) if (int(major), int(minor), int(patch)) >= (4, 1, 1): return raise Exception('Must install Node v4.1.1 or later. Not found in %s' % os.environ['PATH'])
def _verify_node(): '''Ensures that Node v0.12.0 or later is on the user's $PATH.''' # As noted in _install_apm_and_npm_os_x(), ultimately that function should be responsible for # doing this work. # First, check for the presence of node. Make sure it is at least v0.12.0. node_executable = platform_checker.get_node_executable() if _is_executable_on_path(node_executable): node_version = fs.cross_platform_check_output( [node_executable, '--version']).rstrip() if semver.find_version_in_range([node_version], '>=0.12.0'): return raise Exception('Must install Node v0.12.0 or later. Not found in %s' % os.environ['PATH'])
def _do_transpile(self, babel_file): # Store output in memory and then use it to overwrite the original file. transpiled_js = fs.cross_platform_check_output([ platform_checker.get_node_executable(), self._transpile_script, babel_file, ]) # Note that the generated file will often still start with 'use babel', in which case we # want to strip that line to ensure that Atom does not try to transpile the file again. # Note that this is not always the case. The transpiled file might start with: # # Object.defineProperty(exports, '__esModule', { # # in which case stripping the first line would leave the file in an unparseable state. end_of_first_line = transpiled_js.index('\n') first_line = transpiled_js[:end_of_first_line] if has_babel_pragma(first_line): transpiled_js = transpiled_js[end_of_first_line + 1:] with open(babel_file, 'w') as f: f.write(transpiled_js)
def check_dependency(binary, expected_version): actual_version = fs.cross_platform_check_output([binary, '--version']).rstrip() if actual_version != expected_version: raise Exception(('Incorrect %s version. Found %s, expected %s. ' + 'Use the --no-version option to ignore this test.') % (binary, actual_version, expected_version))
def get_list_of_packages(package_type): stdout = fs.cross_platform_check_output( ['./scripts/dev/packages', '--package-type', package_type], cwd=path_to_nuclide_repo) # Split by newlines and then remove the last element, which will be the empty string. return stdout.split('\n')[:-1]