<commit_before>import chalk from 'chalk'
import express from 'express'
import path from 'path'

export class Watcher {
	httpServer = null
	lastPort = null
	dirs = null
	server = null
	restarting = false

	constructor(httpServer, dirs) {
		this.httpServer = httpServer

		if(dirs.length === 1 && Array.isArray(dirs[0])) {
			dirs = dirs[0]
		}

		this.dirs = dirs
	}

	async watch() {
		const watcher = require('chokidar').watch(this.dirs)

		watcher.on('all', async () => {
			if(this.restarting) {
				return
			}

			files:
			for(const file of Object.keys(require.cache)) {
				dirs:
				for(const dir of this.dirs) {
					if(file.indexOf(dir) !== 0) {
						continue dirs
					}

					delete require.cache[file]
					continue files
				}
			}

			await this.restart()
		})

		console.log(chalk.yellow('Watching %s'), this.dirs.map(dir => path.relative(process.cwd(), dir)))
		await this.restart()
	}

	async restart() {
		this.restarting = true

		if(!this.server.isNil) {
			console.log(chalk.yellow('Restarting'))
			const oldServer = this.server
			this.server = null

			await oldServer.destroy()
		}

		this.server = await this.serve()
		this.restarting = false
	}
<commit_msg>Re-added chokidar.on(ready) to HttpServer/Watcher<commit_after>import chalk from 'chalk'
import express from 'express'
import path from 'path'

export class Watcher {
	httpServer = null
	lastPort = null
	dirs = null
	server = null
	restarting = false

	constructor(httpServer, dirs) {
		this.httpServer = httpServer

		if(dirs.length === 1 && Array.isArray(dirs[0])) {
			dirs = dirs[0]
		}

		this.dirs = dirs
	}

	async watch() {
		const watcher = require('chokidar').watch(this.dirs)

		watcher.on('ready', () => {
			watcher.on('all', async () => {
				if(this.restarting) {
					return
				}

				files:
				for(const file of Object.keys(require.cache)) {
					dirs:
					for(const dir of this.dirs) {
						if(file.indexOf(dir) !== 0) {
							continue dirs
						}

						delete require.cache[file]
						continue files
					}
				}

				await this.restart()
			})
		})

		console.log(chalk.yellow('Watching %s'), this.dirs.map(dir => path.relative(process.cwd(), dir)))
		await this.restart()
	}

	async restart() {
		this.restarting = true

		if(!this.server.isNil) {
			console.log(chalk.yellow('Restarting'))
			const oldServer = this.server
			this.server = null

			await oldServer.destroy()
		}

		this.server = await this.serve()
		this.restarting = false
	}

{'fraction_non_alphanumeric': 0.1402439024390244, 'fraction_numerical': 0.0032520325203252032, 'mean_word_length': 2.9951298701298703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '5686894', 'n_tokens_mistral': 1062, 'n_tokens_neox': 877, 'n_words': 184}