Skip to content

Commit

Permalink
fix(package): use provided tsconfig when calling emitDts (#12612)
Browse files Browse the repository at this point in the history
Handles second task of sveltejs/language-tools#2355
  • Loading branch information
quentinderoubaix authored Sep 6, 2024
1 parent 2752d30 commit c584dc2
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 264 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-rings-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/package': patch
---

fix: use input tsconfig when calling emitDts
2 changes: 1 addition & 1 deletion packages/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"kleur": "^4.1.5",
"sade": "^1.8.1",
"semver": "^7.5.4",
"svelte2tsx": "~0.7.0"
"svelte2tsx": "~0.7.16"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/package/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function do_build(options, analyse_code) {
const files = scan(input, extensions);

if (options.types) {
await emit_dts(input, temp, options.cwd, alias, files);
await emit_dts(input, temp, options.cwd, alias, files, tsconfig);
}

for (const file of files) {
Expand Down Expand Up @@ -137,7 +137,7 @@ export async function watch(options) {

if (!errored && options.types) {
try {
await emit_dts(input, output, options.cwd, alias, files);
await emit_dts(input, output, options.cwd, alias, files, tsconfig);
console.log('Updated .d.ts files');
} catch (e) {
errored = true;
Expand Down
6 changes: 4 additions & 2 deletions packages/package/src/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { load_pkg_json } from './config.js';
* @param {string} cwd
* @param {Record<string, string>} alias
* @param {import('./types.js').File[]} files
* @param {string | undefined} tsconfig
*/
export async function emit_dts(input, output, cwd, alias, files) {
export async function emit_dts(input, output, cwd, alias, files, tsconfig) {
const tmp = `${output}/__package_types_tmp__`;
rimraf(tmp);
mkdirp(tmp);
Expand All @@ -32,7 +33,8 @@ export async function emit_dts(input, output, cwd, alias, files) {
svelteShimsPath: no_svelte_3
? require.resolve('svelte2tsx/svelte-shims-v4.d.ts')
: require.resolve('svelte2tsx/svelte-shims.d.ts'),
declarationDir: path.relative(cwd, tmp)
declarationDir: path.relative(cwd, tmp),
tsconfig
});

const handwritten = new Set();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ declare const __propDef: {
astring: string;
};
};
exports?: {};
bindings?: string;
};
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ declare const __propDef: {
[evt: string]: CustomEvent<any>;
};
slots: {};
exports?: {};
bindings?: string;
};
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ declare const __propDef: {
[evt: string]: CustomEvent<any>;
};
slots: {};
exports?: {};
bindings?: string;
};
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ declare const __propDef: {
[evt: string]: CustomEvent<any>;
};
slots: {};
exports?: {};
bindings?: string;
};
export type TestProps = typeof __propDef.props;
export type TestEvents = typeof __propDef.events;
Expand Down
3 changes: 2 additions & 1 deletion packages/package/test/fixtures/svelte-3-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext"
"module": "ESNext",
"verbatimModuleSyntax": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ declare const __propDef: {
astring: string;
};
};
exports?: {};
bindings?: string;
};
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ declare const __propDef: {
[evt: string]: CustomEvent<any>;
};
slots: {};
exports?: {};
bindings?: string;
};
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ declare const __propDef: {
astring: string;
};
};
exports?: {};
bindings?: string;
};
export type TestProps = typeof __propDef.props;
export type TestEvents = typeof __propDef.events;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ declare const __propDef: {
[evt: string]: CustomEvent<any>;
};
slots: {};
exports?: {};
bindings?: string;
};
export type Test2Props = typeof __propDef.props;
export type Test2Events = typeof __propDef.events;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext"
"module": "ESNext",
"verbatimModuleSyntax": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ declare const __propDef: {
astring: string;
};
};
exports?: {};
bindings?: string;
};
export type TestProps = typeof __propDef.props;
export type TestEvents = typeof __propDef.events;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"verbatimModuleSyntax": true,
"moduleResolution": "NodeNext"
}
}
3 changes: 1 addition & 2 deletions packages/package/test/watch/expected/Test.svelte
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<script>export let answer;
</script>
<script lang="ts">export let answer: number</script>
2 changes: 2 additions & 0 deletions packages/package/test/watch/expected/Test.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ declare const __propDef: {
[evt: string]: CustomEvent<any>;
};
slots: {};
exports?: {};
bindings?: string;
};
export type TestProps = typeof __propDef.props;
export type TestEvents = typeof __propDef.events;
Expand Down
Loading

0 comments on commit c584dc2

Please sign in to comment.