blob: ed96040d3dbe87282806c4158fa1ce60f9b6d462 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import * as fs from 'fs';
import * as path from 'path';
import { ContractSource } from '../types';
import { Resolver } from './resolver';
export class RelativeFSResolver extends Resolver {
private readonly _contractsDir: string;
constructor(contractsDir: string) {
super();
this._contractsDir = contractsDir;
}
// tslint:disable-next-line:prefer-function-over-method
public resolveIfExists(importPath: string): ContractSource | undefined {
const filePath = path.join(this._contractsDir, importPath);
if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) {
const fileContent = fs.readFileSync(filePath).toString();
return {
source: fileContent,
path: importPath,
};
}
return undefined;
}
}
|