trucks-resolver-core

Abstract import resolver class

Usage no npm install needed!

<script type="module">
  import trucksResolverCore from 'https://cdn.skypack.dev/trucks-resolver-core';
</script>

README

Resolver

Abstract HTML import resolver

Implementation contract for protocol resolver plugins.

Install

npm i trucks-resolver-core --save


Usage

Resolver plugin implementations should extend this class, see the file and http plugins for example implementations.

API

Resolver

Abstract protocol resolver.

Resolver plugin implementations should create a subclass of this class and invoke registry.register() with a protocol and the derived class.

Resolver

public Resolver(state, href[, parent])

Create a resolver.

The file property is initialized to the canonical path for the href argument.

  • state Object compiler state.
  • href String source URL to resolve.
  • parent Object a parent resolver.
Throws
  • TypeError attempting to parse a bad href argument.

protocol

String protocol

Get the protocol from the href assigned to this resolver, if no protocol is found lookup is performed in a parent hierarchy.

file

String file

Absolute computed path for the URL.

This is initialized to the canonical path for the href argument passed to the constructor but implementations may overwrite this.

resolve

public resolve(cb)

Resolve the contents for the URL.

Implementors should invoke callback with an error and Buffer contents or an object representing compiler options:

(err, contents) => {}.

When the callback is invoked with compiler options it is treated as a nested compile pass using the given options which should have an input files array.

  • cb Function callback function.

getCanonicalPath

public getCanonicalPath()

Get a canonical path for the URL, used to determine if the resource has already been processed.

Typically implementors would convert this to an absolute path or absolute URL to ensure that duplicates can be resolved.

Returns the canonical file path to resolve.

License

MIT


Created by mkdoc on August 2, 2016