Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
fix: Wrong baseDir in a watch mode (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim authored Sep 14, 2020
1 parent 7ed61fd commit 95893ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion core/garment/src/garment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type Subscription =
}
| {
type: 'file';
baseDir: string;
path: string;
targetPath: string;
level: SubscriptionLevel;
Expand Down Expand Up @@ -356,7 +357,7 @@ async function garmentFromWorkspace(
const rootDir =
subscription.type === 'glob'
? subscription.input.rootDir
: project.fullPath;
: subscription.baseDir

const files = Object.keys(changes)
.map(changedFilePath =>
Expand Down Expand Up @@ -416,6 +417,7 @@ async function garmentFromWorkspace(
type: 'file',
level: 'input',
path: dependency,
baseDir: output.targetBaseDir,
targetPath: output.target
});
}
Expand Down Expand Up @@ -567,6 +569,7 @@ async function garmentFromWorkspace(
type: 'file',
level: 'runner',
path,
baseDir: Path.dirname(path),
targetPath: path
});
}
Expand Down Expand Up @@ -615,6 +618,7 @@ async function garmentFromWorkspace(
type: 'file',
level: 'input',
path: dependency,
baseDir: output.targetBaseDir,
targetPath: output.target
});
}
Expand All @@ -634,6 +638,7 @@ async function garmentFromWorkspace(
type: 'file',
level: handlerOutput.target ? 'input' : 'runner',
path: dependency,
baseDir: handlerOutput.targetBaseDir,
targetPath: handlerOutput.target ?? dependency
});
}
Expand Down
13 changes: 11 additions & 2 deletions core/runner/src/OutputContainer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Level, Logger } from '@garment/logger';
import { File } from './types';
import { createHash } from 'crypto';
import * as Path from 'path';

export interface CacheProvider<T = any> {
has(id: string): Promise<boolean> | boolean;
Expand All @@ -27,6 +28,8 @@ export class OutputContainer {
readonly hash: string;
readonly target: string;

targetBaseDir: string;

constructor(
public readonly cacheProvider: CacheProvider,
target: string | File,
Expand All @@ -39,8 +42,14 @@ export class OutputContainer {
}
this.hash = hash.digest('hex');

this.target =
typeof target === 'string' ? target : target.absolutePath ?? target.path;
if (typeof target === 'string') {
this.target = target;
this.targetBaseDir = Path.dirname(target);
} else {
this.target = target.absolutePath ?? target.path;
this.targetBaseDir = target.baseDir ?? Path.dirname(this.target);
}

this.dependencies = dependencies.map(dep =>
typeof dep === 'string' ? dep : dep.absolutePath ?? dep.path
);
Expand Down

0 comments on commit 95893ec

Please sign in to comment.