istanbuljs / istanbuljs/caching-transform

Support one-to-many transforms

Open
#3 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
20
Forks
8
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.