import { AddModuleDeclarations, InjectedType } from './types.js'; export { DefaultExport, NamedExports, SharedTemplateOptions, TypeExports } from './types.js'; /** * # Build a declaration file for Astro Integrations * * @description This utility function is used to build a declaration file for use with Astro's `injectTypes` function added in the `astro:config:done` Integration Hook in `Astro 4.14.0`. This function is useful for generating TypeScript declaration files for Astro Integrations. * @returns A builder object with methods to add notes, modules, and make the file * @example Example Usage * ```ts * // Import and use the function * const dts = buildDeclarationFile(); * * // Add a note to the file * dts.addSingleLineNote(`This file was generated by '@my-example/module'`); * * // Add a Multi-line Note to the file * dts.addMultiLineNote(['It does some cool and helpful stuff', 'It also does some other cool stuff']); * * // Add a module with a default export and single line description * dts.addModule("example:module", { * defaultExport: { * typeDef: "import('@my-example/module').ExampleModule", * singleLineDescription: "This is the default Module", * } * }); * * // Write the file * const dtsFile = dts.makeFile(); * * // Output the file * console.log(dtsFile); * ``` * @example Example Output * ```ts * // This file was generated by '@my-example/module' * * // It does some cool and helpful stuff * // It also does some other cool stuff * * declare module 'example:module' { * //** This is the default Module * / * const defaultExport: import('@my-example/module').ExampleModule; * export default defaultExport; * } * ``` */ declare function buildDeclarationFile(): { /** * # Add a single line Note to your file * * @example * ```ts * // Import and use the function * const dts = buildDeclarationFile(); * * // Add a note to the file * dts.addSingleLineNote(`This file was generated by @my-example/module`); * ``` */ addSingleLineNote(note: string): void; /** * # Add a multi line Note to your file * * @example * ```ts * // Import and use the function * const dts = buildDeclarationFile(); * * // Add a note to the file * dts.addMultiLineNote(['This file was generated by `@my-example/module`', 'It does some cool and helpful stuff']); * ``` */ addMultiLineNote(note: string[]): void; /** * # Add a Module Declaration to your file * * @example * ```ts * // Import and use the function * const dts = buildDeclarationFile(); * * // Add a module with a default export and single line description * dts.addModule("example:module", { * defaultExport: { * typeDef: "import('@my-example/module').ExampleModule", * singleLineDescription: "This is the default Module", * } * }); * * // Add a module with named exports and multi-line descriptions * dts.addModule("example:module-two", { * namedExports: [ * { * typeDef: "import('@my-example/module').ExampleModuleTwo_typeOne", * name: "ExampleModuleTwo_typeOne", * multiLineDescription: [ "This is the second module", "It does some cool stuff" ], * }, * { * typeDef: "import('@my-example/module').ExampleModuleTwo_typeTwo", * name: "ExampleModuleTwo_typeTwo", * multiLineDescription: [ "# Type Two", "This Type is also important" ] * }, * ], * }); * ``` */ addModule(moduleName: string, declarations: AddModuleDeclarations): void; /** * # Add an Unformatted String to your file * * @example * ```ts * // Import and use the function * const dts = buildDeclarationFile(); * * // Add a string with your own formatting to the file * dts.addUnformattedString(`declare module 'example:module' { export const foo: string; }`); * ``` */ addUnformattedString(string: string): void; /** * # Make the Declaration File * * @returns The TypeScript Declaration File as a string for use with Astro's `injectTypes` function added in the `astro:config:done` Integration Hook in `Astro 4.14.0` * @example * ```ts * // Import and use the function * const dts = buildDeclarationFile(); * * // Add a note to the file * dts.addSingleLineNote(`This file was generated by @my-example/module`); * * // Build the example file * const dtsFile = dts.makeFile(); * ``` */ makeFile(): string; /** * # Make an Injected Type for Astro Integrations * * @param filename The name of the file to be injected * @returns An Injected Type for use with Astro's `injectTypes` function added in the `astro:config:done` Integration Hook in `Astro 4.14.0` * @example * ```ts * const integration: AstroIntegration = (opts: {}) => { * // Import and use the function * const dts = buildDeclarationFile(); * * // Add a note to the file * dts.addSingleLineNote(`This file was generated by '@my-example/module'`); * * // Add a module with a default export and single line description * dts.addModule("example:module", { * defaultExport: { * typeDef: "import('@my-example/module').ExampleModule", * singleLineDescription: "This is the default Module", * } * }); * * // Make the injectTypes options * const exampleDTS = dts.makeAstroInjectedType("example.d.ts"); * * // Astro Integration * return { * name: "@my-example/module", * hooks: { * "astro:config:done": ({ injectTypes }) => { * injectTypes(exampleDTS); * } * } * } * } * ``` */ makeAstroInjectedType(filename: string): InjectedType; }; export { AddModuleDeclarations, InjectedType, buildDeclarationFile, buildDeclarationFile as default };