MCPcopy Create free account
hub / github.com/Effect-TS/effect / withGeneratedModule

Function withGeneratedModule

packages/effect/test/utils/generatedModule.ts:10–28  ·  view source on GitHub ↗
(
  source: string,
  use: (module: Module) => void | Promise<void>
)

Source from the content-addressed store, hash-verified

8const moduleDirectory = dirname(fileURLToPath(import.meta.url))
9
10export async function withGeneratedModule<Module>(
11 source: string,
12 use: (module: Module) => void | Promise<void>
13): Promise<void> {
14 const directory = mkdtempSync(join(moduleDirectory, ".generated-module-"))
15 try {
16 const file = join(directory, "module.mjs")
17 // Transpile only: enum artifacts need more than Node's type stripping.
18 const { code } = await transformWithOxc(source, "module.ts", {
19 typescript: { onlyRemoveTypeImports: true },
20 sourcemap: false
21 })
22 writeFileSync(file, code)
23 const module: Module = await import(pathToFileURL(file).href)
24 await use(module)
25 } finally {
26 rmSync(directory, { recursive: true, force: true })
27 }
28}
29
30/** Check all generated modules in one compiler invocation. */
31export async function checkGeneratedModules(sources: ReadonlyMap<string, string>): Promise<void> {

Callers 3

withReexportedHttpApiFunction · 0.90
Schema.test.tsFile · 0.90

Calls 2

joinFunction · 0.50
useFunction · 0.50

Tested by 1

withReexportedHttpApiFunction · 0.72