aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-resolver/src/resolvers/fs_resolver.ts
blob: 248fa405e70bc7e2e8ddc88b95ebc3584cd8e9c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import * as fs from 'fs';
import * as path from 'path';

import { ContractSource } from '../types';

import { Resolver } from './resolver';

export class FSResolver extends Resolver {
    // tslint:disable-next-line:prefer-function-over-method
    public resolveIfExists(importPath: string): ContractSource | undefined {
        if (fs.existsSync(importPath) && fs.lstatSync(importPath).isFile()) {
            const fileContent = fs.readFileSync(importPath).toString();
            const absolutePath = path.resolve(importPath);
            return { source: fileContent, path: importPath, absolutePath } as any;
        }
        return undefined;
    }
}