Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ function declaresContentMappers(tsconfigPath: string): boolean {
}

/**
* Which backend `backendFor` would pick, as a cache-key component, without
* loading TypeScript: the forced kind, or tsgo (with its package and
* version) when the tsconfig declares `contentMappers` and a TypeScript 7
* package resolves.
* Which backend `backendFor` would pick, as a cache-key component: the
* forced kind, or tsgo (with its package and version) when the tsconfig
* declares `contentMappers` and a TypeScript 7 package resolves. Whether
* that package then loads depends on the Node version (`require()` of its
* ESM API needs 22.12+), so Node is part of the component too; the
* package is not loaded here — a cached replay never needs it.
*/
export function backendKindFor(tsconfigPath: string): string {
const forced = process.env['HVE_TS_BACKEND'];
if (forced === 'ts6') return 'ts6';
if (forced === 'tsgo' || declaresContentMappers(tsconfigPath)) {
const pkg = resolveTsgoPackage(path.dirname(tsconfigPath));
if (pkg) return `tsgo:${pkg.name}@${pkg.version}`;
if (pkg) return `tsgo:${pkg.name}@${pkg.version}:node${process.versions.node}`;
if (forced === 'tsgo') return 'none';
}
return 'ts6';
Expand Down
26 changes: 7 additions & 19 deletions lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import crypto from 'node:crypto';
import { fileURLToPath } from 'node:url';

import type { ComponentAttrs } from './builtin-components.js';
import { dependencySha, sha256 } from './deps.js';
import { dependencySha, sha256, tsconfigChainSha } from './deps.js';

// Walk up from this module looking for the nearest `package.json` so the
// version is found regardless of whether we're running from source
Expand Down Expand Up @@ -139,22 +139,10 @@ interface CacheEntry {
componentAttrMap: Array<[string, ComponentAttrs]>;
}

// In-memory cache for the SHA of each tsconfig file (read once per
// process; tsconfigs rarely change mid-run).
const tsconfigShaCache = new Map<string, string>();

// The tsconfig and every config it extends; `lib/deps.ts` re-validates
// the chain against the file system.
function getTsconfigSha(tsconfigPath: string): string {
const cached = tsconfigShaCache.get(tsconfigPath);
if (cached !== undefined) return cached;
let sha: string;
try {
const contents = fs.readFileSync(tsconfigPath, 'utf8');
sha = sha256(contents);
} catch {
sha = 'no-tsconfig';
}
tsconfigShaCache.set(tsconfigPath, sha);
return sha;
return tsconfigChainSha(tsconfigPath);
}

// Walk up from a file to find the project root (where node_modules/
Expand Down Expand Up @@ -306,10 +294,10 @@ interface TransformCacheEntry {
}

/** Everything the transform's output depends on besides the plugin itself. */
// Without Glint nothing crosses file boundaries, so the closure is not
// part of the key (and not computed).
// The closure matters with Glint off too: the resolver reads an imported
// component's template to substitute its tag.
function dependenciesForKey(filename: string, contents: string, tsconfigPath: string | null): string {
return process.env['HVE_GLINT'] === '0' ? 'no-glint' : dependencySha(filename, contents, tsconfigPath);
return CACHE_DISABLED ? 'disabled' : dependencySha(filename, contents, tsconfigPath);
}

export function transformCacheKey(filename: string, data: string, tsconfigPath: string | null, backendKind: string): string {
Expand Down
Loading
Loading