CoolFace
Apppublic

Ejdjdososs/fable-ai

sourceHugging Facemitupdated 3mo agoView on Hugging Face
0likes
transform-file.ts57 linesDownload Raw Back to src
1import gensync, { type Handler } from "gensync";2 3import loadConfig from "./config/index.ts";4import type { InputOptions, ResolvedConfig } from "./config/index.ts";5import { run } from "./transformation/index.ts";6import type { FileResult, FileResultCallback } from "./transformation/index.ts";7import * as fs from "./gensync-utils/fs.ts";8 9type transformFileBrowserType = typeof import("./transform-file-browser");10type transformFileType = typeof import("./transform-file");11 12// Kind of gross, but essentially asserting that the exports of this module are the same as the13// exports of transform-file-browser, since this file may be replaced at bundle time with14// transform-file-browser.15// eslint-disable-next-line @typescript-eslint/no-unused-expressions16({}) as any as transformFileBrowserType as transformFileType;17 18const transformFileRunner = gensync(function* (19  filename: string,20  opts?: InputOptions,21): Handler<FileResult | null> {22  const options = { ...opts, filename };23 24  const config: ResolvedConfig | null = yield* loadConfig(options);25  if (config === null) return null;26 27  const code = yield* fs.readFile(filename, "utf8");28  return yield* run(config, code);29});30 31// @ts-expect-error TS doesn't detect that this signature is compatible32export function transformFile(33  filename: string,34  callback: FileResultCallback,35): void;36export function transformFile(37  filename: string,38  opts: InputOptions | undefined | null,39  callback: FileResultCallback,40): void;41export function transformFile(42  ...args: Parameters<typeof transformFileRunner.errback>43) {44  transformFileRunner.errback(...args);45}46 47export function transformFileSync(48  ...args: Parameters<typeof transformFileRunner.sync>49) {50  return transformFileRunner.sync(...args);51}52export function transformFileAsync(53  ...args: Parameters<typeof transformFileRunner.async>54) {55  return transformFileRunner.async(...args);56}57