<commit_before>"use babel";

import reloadPackage from './reload-package';
import chokidar from 'chokidar';

export default class PackageWacher {
	constructor() {
		this.watcher = null;
	}

	watch(packageName) {
		if (this.watcher) {
			this.unwatch();
		}

		const packagePath = atom.packages.resolvePackagePath(packageName);

    this.watcher = chokidar.watch(packagePath, {
      persistent: true,
      ignoreInitial: true,
    });
    this.watcher.on('change', (filename) => {
    	const reloadGrammars = (filename.indexOf('grammars') >= 0);
    	reloadPackage(packageName, reloadGrammars);
    });

    atom.notifications.addInfo(`Start watching \`${packageName}\`.`);
	}

	unwatch() {
		if (this.watcher) {
			this.watcher.close();
			atom.notifications.addInfo('Stop watching.');
		}
	}
}
<commit_msg>Refine grammar path detection test.<commit_after>"use babel";

import reloadPackage from './reload-package';
import chokidar from 'chokidar';
import path from 'path';

export default class PackageWacher {
	constructor() {
		this.watcher = null;
	}

	watch(packageName) {
		if (this.watcher) {
			this.unwatch();
		}

		const packagePath = atom.packages.resolvePackagePath(packageName);

    this.watcher = chokidar.watch(packagePath, {
      persistent: true,
      ignoreInitial: true,
    });
    this.watcher.on('change', (filename) => {
      const dir = path.dirname(filename);
      const reloadGrammars = dir === path.join(packagePath, 'grammars');
      reloadPackage(packageName, reloadGrammars);
    });

    atom.notifications.addInfo(`Start watching \`${packageName}\`.`);
	}

	unwatch() {
		if (this.watcher) {
			this.watcher.close();
			atom.notifications.addInfo('Stop watching.');
		}
	}
}

{'fraction_non_alphanumeric': 0.14743589743589744, 'fraction_numerical': 0.0005827505827505828, 'mean_word_length': 3.7430939226519335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5682168', 'n_tokens_mistral': 601, 'n_tokens_neox': 563, 'n_words': 106}