Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

833 B
Raw Blame
const crypto = require('crypto')
const fs = require('fs')

const sucraseJest = require('@sucrase/jest-plugin')
const { getVersion } = require('sucrase')

// Jest reads imports from source text, where an import used only as a type looks like one that
// loads a module. Reading them from the transformed code keeps the imports that exist at run time.
module.exports = {
    extract(code, filePath, defaultExtract) {
        let source = code
        try {
            source = sucraseJest.process(code, filePath, {}).code
        } catch {
            // A file the transformer cannot parse keeps every import its source names.
        }
        return defaultExtract(source, filePath)
    },
    getCacheKey() {
        return crypto.createHash('sha1').update(fs.readFileSync(__filename)).update(getVersion()).digest('hex')
    },
}