diff --git a/generate-type-definitions.js b/generate-type-definitions.js index 6cad31807f0..00b079eb5d6 100644 --- a/generate-type-definitions.js +++ b/generate-type-definitions.js @@ -5,9 +5,20 @@ const { readFileSync, writeFileSync } = require('fs'); execSync('tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly'); -// We need to add these types to the index.d.ts here because if we add them before building, the build will fail, +// We need to add these types to the .d.ts files here because if we add them before building, the build will fail, // because the TS->JS transformation doesn't know these exports are types and produces code that fails at runtime. // We can't use `export type` syntax either because the TS version we're on doesn't have this feature yet. -const path = 'types/runtime/index.d.ts'; -const content = readFileSync(path, 'utf8'); -writeFileSync(path, content.replace('SvelteComponentTyped', 'SvelteComponentTyped, ComponentType, ComponentConstructorOptions, ComponentProps')); + +function modify(path, modifyFn) { + const content = readFileSync(path, 'utf8'); + writeFileSync(path, modifyFn(content)); +} + +modify( + 'types/runtime/index.d.ts', + content => content.replace('SvelteComponentTyped', 'SvelteComponentTyped, ComponentType, ComponentConstructorOptions, ComponentProps') +); +modify( + 'types/compiler/index.d.ts', + content => content + '\nexport { CompileOptions, ModuleFormat, EnableSourcemap, CssHashGetter } from "./interfaces"' +); diff --git a/src/compiler/index.ts b/src/compiler/index.ts index 14d55f5470d..76eb45d37fb 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -4,3 +4,4 @@ export { default as preprocess } from './preprocess/index'; export { walk } from 'estree-walker'; export const VERSION = '__VERSION__'; +// additional exports added through generate-type-definitions.js diff --git a/src/runtime/index.ts b/src/runtime/index.ts index 08b25ba2ca4..2029f67a046 100644 --- a/src/runtime/index.ts +++ b/src/runtime/index.ts @@ -13,5 +13,5 @@ export { createEventDispatcher, SvelteComponentDev as SvelteComponent, SvelteComponentTyped - // additional exports added through post-typegen.js + // additional exports added through generate-type-definitions.js } from 'svelte/internal';