callstack / callstack/linaria

Record "requiredFiles" in babel result, for cache key purposes

Open
#1,401 0 comments 1 reaction 0 assignees View on GitHub
feature: proposal 💬 needs: triage 🏷
Dominant language
TypeScript
Stars
12.4k
Forks
413
PR merge metrics
No merged PRs in 30d

Description

## Describe the feature

Add "requiredFiles" to the babel result, that lists the file paths + hashes of each file that gets used in static evaluation.

## Motivation

Something we've done and found useful is recording the files that get required during static evaluation in the babel result (the paths, and the sha1 of each file). This is useful as it lets us cache the result of transforms, and know when to bust this cache too. We're using [metro](https://metrobundler.dev/) as our build system, which has a per-file cache for transformations. This means that a file like this:

```ts
import { constant } from './file';

css`
background: ${constant}
`;
```

that we need to bust the cache if the `constant` changes.

## Possible implementations

We figured this out on the version of linaria we're on, in `module.ts` (at least in the version we're on, I'm sure this is possible in the latest linaria, too)

```ts
const requiredFile = {
file: path.relative(id, filename),
sha1: hashString(code)
};
this.requiredFiles.push(requiredFile);
```

## Related Issues

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.