From 0fa0a38d5168a1767843fdb0a43c00aa30b8670f Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Wed, 6 Jul 2022 11:58:43 +0200 Subject: [PATCH] [fix] export CompileOptions (#7658) It's used by SvelteKit and in order to properly use it under the new TS moduleResolution NodeNext it needs to be part of a file that is defined in the exports map --- generate-type-definitions.js | 19 +++++++++++++++---- src/compiler/index.ts | 1 + src/runtime/index.ts | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/generate-type-definitions.js b/generate-type-definitions.js index 6cad31807f0e..00b079eb5d69 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 14d55f5470de..76eb45d37fb3 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 08b25ba2ca4e..2029f67a0464 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';