Skip to content

file

ts
function Source.file(path: string, options?: {
    alias?: string
    type?: boolean
}): Promise<Source | undefined>

Constructs a new source representing a file on disk. May return Promise<undefined> if the physical location on disk could not be resolved via SourceModule.resolve.

Example

ts
import { Source, Barrel } from "@monstermann/barrels";

const source = await Source.file("./source.ts");

// export * from "./source.ts"
Barrel.export(source);

Options

alias

Defines the alias that should be used when creating barrels.

ts
import { Source, Barrel } from "@monstermann/barrels";

const source = await Source.file("source.ts", {
    alias: "bar",
});

// export * from "./source.ts";
Barrel.export(source);

type

When enabled, treats this source as a type definition.

ts
import { Source, Barrel } from "@monstermann/barrels";

const source = await Source.file("source.ts", {
    type: true,
});

// export type * from "./source.ts";
Barrel.export(source);