Exemple #1
0
    def eslint_supportdir(self, task_workdir):
        """ Returns the path where the ESLint is bootstrapped.
    
    :param string task_workdir: The task's working directory
    :returns: The path where ESLint is bootstrapped and whether or not it is configured
    :rtype: (string, bool)
    """
        bootstrapped_support_path = os.path.join(task_workdir, 'eslint')

        # TODO(nsaechao): Should only have to check if the "eslint" dir exists in the task_workdir
        # assuming fingerprinting works as intended.

        # If the eslint_setupdir is not provided or missing required files, then
        # clean up the directory so that Pants can install a pre-defined eslint version later on.
        # Otherwise, if there is no configurations changes, rely on the cache.
        # If there is a config change detected, use the new configuration.
        configured = False
        if self.eslint_setupdir:
            configured = self._binary_util.is_bin_valid(
                self.eslint_setupdir, [
                    BinaryUtil.BinaryFileSpec('package.json'),
                    BinaryUtil.BinaryFileSpec('yarn.lock')
                ])
        if not configured:
            safe_mkdir(bootstrapped_support_path, clean=True)
        else:
            binary_file_specs = [
                BinaryUtil.BinaryFileSpec(
                    f, hash_file(os.path.join(self.eslint_setupdir, f)))
                for f in ['yarn.lock', 'package.json']
            ]
            installed = self._binary_util.is_bin_valid(
                bootstrapped_support_path, binary_file_specs)
            if not installed:
                self._configure_eslinter(bootstrapped_support_path)
        return bootstrapped_support_path, configured