How to use the @hint/utils-network.getAsUri function in @hint/utils-network

To help you get started, we’ve selected a few @hint/utils-network examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webhintio / hint / packages / utils-tests-helpers / src / hint-runner.ts View on Github external
const runHint = async (t: ExecutionContext, hintTest: HintLocalTest) => {

        try {
            if (hintTest.before) {
                await hintTest.before(t);
            }

            const hintConfig = createConfig(hintId, connector, configs);
            const resources = resourceLoader.loadResources(hintConfig);
            const engine = new Engine(hintConfig, resources);

            // Can assume `getAsUri(hintTest.path)` is not `null` since these are controlled test inputs.
            const target = getAsUri(hintTest.path)!;
            const results = await engine.executeOn(target);

            await engine.close();

            if (hintTest.after) {
                await hintTest.after(t);
            }

            const sources = new Map();

            for (const result of results) {
                if (!sources.has(result.resource)) {
                    sources.set(result.resource, await requestSource(result.resource, connector));
                }
            }
github webhintio / hint / packages / connector-local / src / connector.ts View on Github external
private async fetchData(target: string, options?: IFetchOptions): Promise {
        const content: NetworkData = await this.fetchContent(target, undefined, options);
        const uri = getAsUri(target);

        return {
            element: null,
            request: content.request,
            resource: uri ? url.format(uri) : /* istanbul ignore next */ '',
            response: content.response
        };
    }
github webhintio / hint / packages / connector-local / src / connector.ts View on Github external
public async fetchContent(target: string, headers?: object, options?: IFetchOptions): Promise {
        /*
         * target can have one of these forms:
         *   - /path/to/file
         *   - C:/path/to/file
         *   - file:///path/to/file
         *   - file:///C:/path/to/file
         *
         * That's why we need to parse it to an URL
         * and then get the path string.
         */
        const uri = getAsUri(target);
        const filePath: string = uri ? asPathString(uri).replace('%20', ' ') : '';
        const rawContent: Buffer = options && options.content ? Buffer.from(options.content) : await readFileAsBuffer(filePath);
        const contentType = getContentTypeData(null as any, filePath, null, rawContent);
        let content = '';

        if (isTextMediaType(contentType.mediaType || '')) {
            content = rawContent.toString(contentType.charset || undefined);
        }

        // Need to do some magic to create a fetch::end::*
        return {
            request: {} as any,
            response: {
                body: {
                    content,
                    rawContent,
github webhintio / hint / packages / utils-json / src / final-config.ts View on Github external
error.resource = originalPathUri && originalPathUri.toString() || lastPath;

            return error;
        }

        delete finalConfigJSON.extends;

        try {
            const extendedConfig = loadJSONFile(configPath);

            configIncludes.push(configPath);

            finalConfigJSON = merge({}, extendedConfig, finalConfigJSON);
        } catch (err) {
            const lastPathUri = getAsUri(lastPath);

            err.resource = lastPathUri && lastPathUri.toString() || lastPath;

            return err;
        }
    }

    return finalConfigJSON;
};