AppView in a box as a Vite plugin thing hatk.dev
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: extract registerHatkResolveHook and use in main.ts and test.ts

The $hatk module alias needs a Node.js resolve hook for dynamic import()
in scanServerDir. Previously only test.ts had it — now main.ts uses the
same shared hook so production also resolves $hatk correctly.

Bumps to 0.0.1-alpha.29.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+27 -14
+1 -1
packages/hatk/package.json
··· 1 1 { 2 2 "name": "@hatk/hatk", 3 - "version": "0.0.1-alpha.28", 3 + "version": "0.0.1-alpha.29", 4 4 "license": "MIT", 5 5 "bin": { 6 6 "hatk": "dist/cli.js"
+5
packages/hatk/src/main.ts
··· 1 1 #!/usr/bin/env node 2 2 import { mkdirSync, writeFileSync, existsSync } from 'node:fs' 3 3 import { dirname, resolve } from 'node:path' 4 + import { registerHatkResolveHook } from './resolve-hatk.ts' 5 + import { pathToFileURL } from 'node:url' 6 + import { registerHooks } from 'node:module' 4 7 import { log } from './logger.ts' 5 8 import { loadConfig } from './config.ts' 6 9 import { loadLexicons, storeLexicons, discoverCollections, buildSchemas } from './database/schema.ts' ··· 35 38 36 39 const configPath = process.argv[2] || 'hatk.config.ts' 37 40 const configDir = dirname(resolve(configPath)) 41 + 42 + registerHatkResolveHook() 38 43 39 44 logMemory('startup') 40 45
+19
packages/hatk/src/resolve-hatk.ts
··· 1 + import { resolve } from 'node:path' 2 + import { pathToFileURL } from 'node:url' 3 + import { registerHooks } from 'node:module' 4 + 5 + /** 6 + * Register a Node.js module resolve hook so dynamic import() of server files 7 + * can resolve the $hatk alias to the generated entry points. 8 + */ 9 + export function registerHatkResolveHook(): void { 10 + const hatkUrl = pathToFileURL(resolve('hatk.generated.ts')).href 11 + const hatkClientUrl = pathToFileURL(resolve('hatk.generated.client.ts')).href 12 + registerHooks({ 13 + resolve(specifier, context, nextResolve) { 14 + if (specifier === '$hatk/client') return { url: hatkClientUrl, shortCircuit: true } 15 + if (specifier === '$hatk') return { url: hatkUrl, shortCircuit: true } 16 + return nextResolve(specifier, context) 17 + }, 18 + }) 19 + }
+2 -13
packages/hatk/src/test.ts
··· 1 1 import { resolve, dirname } from 'node:path' 2 - import { pathToFileURL } from 'node:url' 3 - import { registerHooks } from 'node:module' 4 2 import { readdirSync, readFileSync } from 'node:fs' 3 + import { registerHatkResolveHook } from './resolve-hatk.ts' 5 4 import YAML from 'yaml' 6 5 import { loadConfig, type HatkConfig } from './config.ts' 7 6 import { ··· 72 71 * but it will NOT work with --pool=threads (multiple tests sharing a process). 73 72 */ 74 73 export async function createTestContext(): Promise<TestContext> { 75 - // Register Node.js module resolve hook so raw import() of server files 76 - // can resolve the $hatk alias to the generated entry points. 77 - const hatkUrl = pathToFileURL(resolve('hatk.generated.ts')).href 78 - const hatkClientUrl = pathToFileURL(resolve('hatk.generated.client.ts')).href 79 - registerHooks({ 80 - resolve(specifier, context, nextResolve) { 81 - if (specifier === '$hatk/client') return { url: hatkClientUrl, shortCircuit: true } 82 - if (specifier === '$hatk') return { url: hatkUrl, shortCircuit: true } 83 - return nextResolve(specifier, context) 84 - }, 85 - }) 74 + registerHatkResolveHook() 86 75 87 76 const configPath = findConfigPath() 88 77 const config = await loadConfig(configPath)