Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 30, 2022
1 parent 1c748d3 commit e92d85e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/babel-cli/src/babel/watcher.ts
@@ -1,13 +1,13 @@
import { createRequire } from "module";
import path from "path";

const fileToDeps = new Map();
const depToFiles = new Map();
const fileToDeps = new Map<string, Set<string>>();
const depToFiles = new Map<string, Set<string>>();

let isWatchMode = false;
let watcher;

export function enable({ enableGlobbing }) {
export function enable({ enableGlobbing }: { enableGlobbing: boolean }) {
isWatchMode = true;

const { FSWatcher } = requireChokidar();
Expand All @@ -26,6 +26,12 @@ export function enable({ enableGlobbing }) {
}

export function watch(filename: string): void {
if (!isWatchMode) {
throw new Error(
"Internal Babel error: .watch called when not in watch mode.",
);
}

watcher.add(path.resolve(filename));
}

Expand All @@ -39,6 +45,12 @@ export function watch(filename: string): void {
export function onFilesChange(
callback: (filenames: string[], event: string, cause: string) => void,
): void {
if (!isWatchMode) {
throw new Error(
"Internal Babel error: .onFilesChange called when not in watch mode.",
);
}

watcher.on("all", (event, filename) => {
if (event !== "change" && event !== "add") return;

Expand Down

0 comments on commit e92d85e

Please sign in to comment.