Skip to content

Commit

Permalink
fix: Correction to FS watcher subscription logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
thsig authored and edvald committed Apr 25, 2018
1 parent dd0a4fe commit 5969914
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
16 changes: 7 additions & 9 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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}` })
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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([
Expand All @@ -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")
Expand Down

0 comments on commit 5969914

Please sign in to comment.