Skip to content

Commit 0fa0a38

Browse files
authored
[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
1 parent a3ecb44 commit 0fa0a38

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

generate-type-definitions.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@ const { readFileSync, writeFileSync } = require('fs');
55

66
execSync('tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly');
77

8-
// We need to add these types to the index.d.ts here because if we add them before building, the build will fail,
8+
// We need to add these types to the .d.ts files here because if we add them before building, the build will fail,
99
// because the TS->JS transformation doesn't know these exports are types and produces code that fails at runtime.
1010
// We can't use `export type` syntax either because the TS version we're on doesn't have this feature yet.
11-
const path = 'types/runtime/index.d.ts';
12-
const content = readFileSync(path, 'utf8');
13-
writeFileSync(path, content.replace('SvelteComponentTyped', 'SvelteComponentTyped, ComponentType, ComponentConstructorOptions, ComponentProps'));
11+
12+
function modify(path, modifyFn) {
13+
const content = readFileSync(path, 'utf8');
14+
writeFileSync(path, modifyFn(content));
15+
}
16+
17+
modify(
18+
'types/runtime/index.d.ts',
19+
content => content.replace('SvelteComponentTyped', 'SvelteComponentTyped, ComponentType, ComponentConstructorOptions, ComponentProps')
20+
);
21+
modify(
22+
'types/compiler/index.d.ts',
23+
content => content + '\nexport { CompileOptions, ModuleFormat, EnableSourcemap, CssHashGetter } from "./interfaces"'
24+
);

src/compiler/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export { default as preprocess } from './preprocess/index';
44
export { walk } from 'estree-walker';
55

66
export const VERSION = '__VERSION__';
7+
// additional exports added through generate-type-definitions.js

src/runtime/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ export {
1313
createEventDispatcher,
1414
SvelteComponentDev as SvelteComponent,
1515
SvelteComponentTyped
16-
// additional exports added through post-typegen.js
16+
// additional exports added through generate-type-definitions.js
1717
} from 'svelte/internal';

0 commit comments

Comments
 (0)