From 596991441cf2c344efeeadfdd2b88f5135dd3ce2 Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Mon, 23 Apr 2018 16:09:28 +0200 Subject: [PATCH] fix: Correction to FS watcher subscription logic. --- src/plugin-context.ts | 2 +- src/watch.ts | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/plugin-context.ts b/src/plugin-context.ts index 3321e796bd..22730e57aa 100644 --- a/src/plugin-context.ts +++ b/src/plugin-context.ts @@ -391,7 +391,7 @@ export function createPluginContext(garden: Garden): PluginContext { } } - const watcher = new FSWatcher() + const watcher = new FSWatcher(ctx.projectRoot) // TODO: should the prefix here be different or set explicitly per run? await watcher.watchModules(modules, "addTasksForAutoReload/", diff --git a/src/watch.ts b/src/watch.ts index cd60301444..705348525d 100644 --- a/src/watch.ts +++ b/src/watch.ts @@ -9,6 +9,7 @@ import { map as bluebirdMap } from "bluebird" import { Client } from "fb-watchman" import { keyBy } from "lodash" +import { relative, resolve } from "path" import { Module } from "./types/module" import { PluginContext } from "./plugin-context" @@ -36,7 +37,7 @@ export async function watchModules( } } - const watcher = new FSWatcher() + const watcher = new FSWatcher(ctx.projectRoot) await watcher.watchModules(modules, "addTasksForAutoReload/", async (changedModule) => { ctx.log.info({ msg: `files changed for module ${changedModule.name}` }) @@ -81,7 +82,7 @@ export class FSWatcher { private readonly client private capabilityCheckComplete: boolean - constructor() { + constructor(private projectRoot: string) { this.client = new Client() this.capabilityCheckComplete = false } @@ -120,15 +121,13 @@ export class FSWatcher { await bluebirdMap(modules || [], async (module) => { const subscriptionKey = FSWatcher.subscriptionKey(subscriptionPrefix, module) + const modulePath = resolve(this.projectRoot, module.path) - const result = await this.command(["watch-project", module.path]) - - // console.log("watching", modulePath) + const result = await this.command(["watch-project", modulePath]) + const relModulePath = relative(result.watch, modulePath) const subscriptionRequest = { - // expression: ["anyof", - // ["dirname", modulePath, ["depth", "ge", 0]] - // ] + expression: ["dirname", relModulePath, ["depth", "ge", 0]] } await this.command([ @@ -139,7 +138,6 @@ export class FSWatcher { }) this.on("subscription", async (response) => { - // console.log("file changed:", response) const changedModule = modulesBySubscriptionKey[response.subscription] if (!changedModule) { console.log("no module found for changed file, skipping auto-rebuild")