A specialized build tool for creating Svelte component libraries and packages
—
TypeScript compilation and declaration file generation with support for custom tsconfig files and path alias resolution.
Generates TypeScript declaration files (.d.ts) for the package.
/**
* Generate TypeScript declaration files
* @param input - Input directory path
* @param output - Output directory path for temp files
* @param final_output - Final output directory path
* @param cwd - Current working directory
* @param alias - Path alias mapping
* @param files - Array of files to process
* @param tsconfig - Optional path to tsconfig file
*/
function emit_dts(
input: string,
output: string,
final_output: string,
cwd: string,
alias: Record<string, string>,
files: File[],
tsconfig?: string
): Promise<void>;Usage Examples:
import { emit_dts } from "@sveltejs/package/src/typescript.js";
// Generate declaration files
await emit_dts(
"src/lib", // input directory
".svelte-kit/temp", // temp output
"dist", // final output
process.cwd(), // working directory
{ '$lib': 'src/lib' }, // aliases
files, // file list
"tsconfig.json" // tsconfig path
);
// Generate without custom tsconfig
await emit_dts(
"src/lib",
".svelte-kit/temp",
"dist",
process.cwd(),
{ '$lib': 'src/lib' },
files
);Transpiles TypeScript source code to JavaScript.
/**
* Transpile TypeScript to JavaScript
* @param tsconfig - Path to tsconfig file (optional)
* @param filename - Source file path
* @param source - TypeScript source code
* @returns Promise resolving to transpiled JavaScript
*/
function transpile_ts(
tsconfig: string | undefined,
filename: string,
source: string
): Promise<string>;Usage Examples:
import { transpile_ts } from "@sveltejs/package/src/typescript.js";
// Transpile with custom tsconfig
const jsCode = await transpile_ts(
"tsconfig.json",
"src/lib/utils.ts",
`
export function add(a: number, b: number): number {
return a + b;
}
`
);
// Transpile with default settings
const jsCode = await transpile_ts(
undefined,
"src/lib/helpers.ts",
`
interface User {
name: string;
age: number;
}
export const createUser = (name: string, age: number): User => ({ name, age });
`
);The emit_dts function:
The transpile_ts function:
Both functions support path alias resolution:
$lib aliases are resolved to the configured library directorykit.alias configuration are supportedThe TypeScript processing integrates with tsconfig.json:
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"strict": true,
"paths": {
"$lib": ["src/lib"],
"$lib/*": ["src/lib/*"]
}
},
"include": ["src/**/*"],
"exclude": ["**/*.test.ts"]
}Key compiler options supported:
TypeScript compilation errors are handled gracefully:
The TypeScript processing integrates with the main build system:
types option is enabledinterface File {
name: string;
dest: string;
base: string;
is_svelte: boolean;
}Install with Tessl CLI
npx tessl i tessl/npm-sveltejs--package