Skip to content

Commit

Permalink
Create modules.ts
Browse files Browse the repository at this point in the history
#1

`virtual:astro-svgs` 模块支持
  • Loading branch information
JakiChen committed Nov 19, 2024
1 parent d01f7d8 commit 3256d0e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { InjectedType } from "astro";
import { type SVGsOptions, name } from ".";
import { compose } from "./core";

export async function virtual(opts: SVGsOptions): Promise<InjectedType> {
let filename = "types.d.ts";

const { symbolIds } = await compose(opts);
const SymbolId =
symbolIds.length > 0
? symbolIds.map((id) => `\t| '${id}'`).join("\n\t")
: "\t| null"; // Fallback for empty symbolIds

const content =
`declare module 'virtual:${name}' {\n\texport type SymbolId =\n\t${SymbolId};\n\texport const file: string;\n}`.trim();

return { filename, content };
}

0 comments on commit 3256d0e

Please sign in to comment.