Skip to content

Support one-to-many transforms #3

Open
@novemberborn

Description

@novemberborn

Currently transforms are one-to-one. It'd be useful if the transform implementation could return multiple values. For instance with AVA we'll want to cache static analysis of the test files.

There should also be an interface for accessing cached values, given the cache directory and the hash. Again in AVA the transform implementation writes source maps to disk, coordinating their location with the test worker which needs to read them. This could be done through caching-transform itself.

(Source maps should still be written to disk in order to play nice with source-map-support, but the precompiler could do that without having to coordinate with the worker.)

My proposal is to allow the transform() implementation to return an object. Keys can be used to access particular results, values must be strings or buffers. When called for an input that has already been cached a similar object can be returned.

Currently caching-transform is a factory for a transform function. We could add a get(hash, key?) method. Without the key the default result (string / buffer / object) is returned. With the key a specific value is returned. If there is no value for the hash or key, null is returned.

We could write a JSON object to disk, though that'd be tricky with binary data. It also means that getting a particular value would require the entire cache entry to be read into memory. Alternatively we could write a simple packing implementation that allows random access. (Tar would be an obvious solution, but existing implementations seem to be asynchronous, and as far as I can tell tar requires you to seek for individual files.) A final option is to write a "header" and individual results as separate files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions