aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-resolver/src/resolvers/url_resolver.ts
blob: 180b0c9f6192d0a300ef954da5b2d8428fe5aeda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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,
            };
        }
        return undefined;
    }
}