aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-resolver/src/resolvers/url_resolver.ts
blob: ef300e6dbad48552947f6e58bfbeb9468a7c43c7 (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 { ContractSource } from '../types';

import { Resolver } from './resolver';

export class URLResolver extends Resolver {
    // tslint:disable-next-line:prefer-function-over-method
    public resolveIfExists(importPath: string): ContractSource | undefined {
        const FILE_URL_PREXIF = 'file://';
        if (importPath.startsWith(FILE_URL_PREXIF)) {
            const filePath = importPath.substr(FILE_URL_PREXIF.length);
            const fileContent = fs.readFileSync(filePath).toString();
            return { source: fileContent, path: importPath, absolutePath: filePath };
        }
        return undefined;
    }
}