From c8a07949789f11fb0cbf0a784a0455ea68a955a4 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Wed, 1 Feb 2023 22:27:38 +0100 Subject: [PATCH 1/7] fix: adjust declaration map paths closes #7793 --- .changeset/pretty-lizards-attend.md | 5 ++++ .../docs/30-advanced/70-packaging.md | 4 ++++ packages/package/package.json | 2 +- packages/package/src/typescript.js | 10 ++++++-- .../expected/Test.svelte | 8 +++++++ .../expected/Test.svelte.d.ts | 24 +++++++++++++++++++ .../expected/Test.svelte.d.ts.map | 1 + .../expected/index.d.ts | 2 ++ .../expected/index.d.ts.map | 1 + .../expected/index.js | 1 + .../expected/package.json | 13 ++++++++++ .../typescript-declaration-map/package.json | 7 ++++++ .../src/lib/Test.svelte | 9 +++++++ .../src/lib/index.ts | 1 + .../svelte.config.js | 5 ++++ .../typescript-declaration-map/tsconfig.json | 8 +++++++ packages/package/test/index.js | 9 ++++++- pnpm-lock.yaml | 8 +++---- 18 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 .changeset/pretty-lizards-attend.md create mode 100644 packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte create mode 100644 packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts create mode 100644 packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map create mode 100644 packages/package/test/fixtures/typescript-declaration-map/expected/index.d.ts create mode 100644 packages/package/test/fixtures/typescript-declaration-map/expected/index.d.ts.map create mode 100644 packages/package/test/fixtures/typescript-declaration-map/expected/index.js create mode 100644 packages/package/test/fixtures/typescript-declaration-map/expected/package.json create mode 100644 packages/package/test/fixtures/typescript-declaration-map/package.json create mode 100644 packages/package/test/fixtures/typescript-declaration-map/src/lib/Test.svelte create mode 100644 packages/package/test/fixtures/typescript-declaration-map/src/lib/index.ts create mode 100644 packages/package/test/fixtures/typescript-declaration-map/svelte.config.js create mode 100644 packages/package/test/fixtures/typescript-declaration-map/tsconfig.json diff --git a/.changeset/pretty-lizards-attend.md b/.changeset/pretty-lizards-attend.md new file mode 100644 index 000000000000..51d8dbc4bc7a --- /dev/null +++ b/.changeset/pretty-lizards-attend.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/package': patch +--- + +fix: adjust declaration map paths diff --git a/documentation/docs/30-advanced/70-packaging.md b/documentation/docs/30-advanced/70-packaging.md index 38d17a9c32b0..df16d885f8fa 100644 --- a/documentation/docs/30-advanced/70-packaging.md +++ b/documentation/docs/30-advanced/70-packaging.md @@ -40,6 +40,10 @@ import Foo from 'your-library/Foo.svelte'; > You should avoid using [SvelteKit-specific modules](modules) like `$app` in your packages unless you intend for them to only be consumable by other SvelteKit projects. E.g. rather than using `import { browser } from '$app/environment'` you could use [`import.meta.env.SSR`](https://vitejs.dev/guide/env-and-mode.html#env-variables) to make the library available to all Vite-based projects or better yet use [Node conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to make it work for all bundlers. You may also wish to pass in things like the current URL or a navigation action as a prop rather than relying directly on `$app/stores`, `$app/navigation`, etc. Writing your app in this more generic fashion will also make it easier to setup tools for testing, UI demos and so on. +## Source maps + +You can create so-called declaration maps (`d.ts.map` files) by setting `"declarationMap": true` in your `tsconfig.json`. This will allow editors such as VS Code to go to the original `.ts` or `.svelte` file when using features like _Go to Definition_. This means you also need to publish your source files alongside your dist folder in a way that the relative path inside the declaration files leads to a file on disk. + ## Options `svelte-package` accepts the following options: diff --git a/packages/package/package.json b/packages/package/package.json index 1e0335b32545..056f7676bb7b 100644 --- a/packages/package/package.json +++ b/packages/package/package.json @@ -13,7 +13,7 @@ "chokidar": "^3.5.3", "kleur": "^4.1.5", "sade": "^1.8.1", - "svelte2tsx": "~0.6.0" + "svelte2tsx": "~0.6.1" }, "devDependencies": { "@types/node": "^16.18.6", diff --git a/packages/package/src/typescript.js b/packages/package/src/typescript.js index fa75d51c73d6..5ae41e791b71 100644 --- a/packages/package/src/typescript.js +++ b/packages/package/src/typescript.js @@ -53,8 +53,14 @@ export async function emit_dts(config, cwd, files) { // don't overwrite hand-written .d.ts files if (excluded.has(normalized)) continue; - const source = fs.readFileSync(path.join(tmp, normalized), 'utf8'); - write(path.join(config.package.dir, normalized), resolve_lib_alias(normalized, source, config)); + let source = fs.readFileSync(path.join(tmp, normalized), 'utf8'); + if (file.endsWith('.d.ts.map')) { + // Because we put the .d.ts files in a temporary directory, the path upwards is one level too much + source = source.replace(/"sources":\["\.\.\//, '"sources":["'); + } else { + source = resolve_lib_alias(normalized, source, config); + } + write(path.join(config.package.dir, normalized), source); } rimraf(tmp); diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte new file mode 100644 index 000000000000..661b1b8276b0 --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte @@ -0,0 +1,8 @@ + + + diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts new file mode 100644 index 000000000000..c03f9457a7af --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts @@ -0,0 +1,24 @@ +import { SvelteComponentTyped } from 'svelte'; +declare const __propDef: { + props: { + astring?: string; + }; + events: { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: { + astring: string; + }; + }; +}; +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +export default class Test extends SvelteComponentTyped { + get astring(): string; +} +export {}; +//# sourceMappingURL=Test.svelte.d.ts.map \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map new file mode 100644 index 000000000000..66a994255202 --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Test.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Test.svelte"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAa7C,QAAA,MAAM,SAAS;;kBADkC,MAAM;;;;;;;;;;;;CACA,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AACjD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAE/C,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,oBAAoB,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC;IACpF,IAAI,OAAO,WAA+D;CAC7E"} \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/index.d.ts b/packages/package/test/fixtures/typescript-declaration-map/expected/index.d.ts new file mode 100644 index 000000000000..3a13848c9369 --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/index.d.ts @@ -0,0 +1,2 @@ +export { default as Test } from './Test.svelte'; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/index.d.ts.map b/packages/package/test/fixtures/typescript-declaration-map/expected/index.d.ts.map new file mode 100644 index 000000000000..d62430ee3b6c --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC"} \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/index.js b/packages/package/test/fixtures/typescript-declaration-map/expected/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/package.json b/packages/package/test/fixtures/typescript-declaration-map/expected/package.json new file mode 100644 index 000000000000..7373cf455a97 --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/package.json @@ -0,0 +1,13 @@ +{ + "name": "typescript-declaration-map", + "private": true, + "version": "1.0.0", + "description": "standard typescript package with declarationMap:true", + "type": "module", + "exports": { + "./package.json": "./package.json", + "./Test.svelte": "./Test.svelte", + ".": "./index.js" + }, + "svelte": "./index.js" +} \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-declaration-map/package.json b/packages/package/test/fixtures/typescript-declaration-map/package.json new file mode 100644 index 000000000000..eac17090eabe --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/package.json @@ -0,0 +1,7 @@ +{ + "name": "typescript-declaration-map", + "private": true, + "version": "1.0.0", + "description": "standard typescript package with declarationMap:true", + "type": "module" +} diff --git a/packages/package/test/fixtures/typescript-declaration-map/src/lib/Test.svelte b/packages/package/test/fixtures/typescript-declaration-map/src/lib/Test.svelte new file mode 100644 index 000000000000..9ad736f2323d --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/src/lib/Test.svelte @@ -0,0 +1,9 @@ + + + diff --git a/packages/package/test/fixtures/typescript-declaration-map/src/lib/index.ts b/packages/package/test/fixtures/typescript-declaration-map/src/lib/index.ts new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/src/lib/index.ts @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/package/test/fixtures/typescript-declaration-map/svelte.config.js b/packages/package/test/fixtures/typescript-declaration-map/svelte.config.js new file mode 100644 index 000000000000..6bd253bdf27d --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/svelte.config.js @@ -0,0 +1,5 @@ +import preprocess from 'svelte-preprocess'; + +export default { + preprocess: preprocess() +}; diff --git a/packages/package/test/fixtures/typescript-declaration-map/tsconfig.json b/packages/package/test/fixtures/typescript-declaration-map/tsconfig.json new file mode 100644 index 000000000000..cd86fcfd945f --- /dev/null +++ b/packages/package/test/fixtures/typescript-declaration-map/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "declaration": true, + "declarationMap": true + } +} diff --git a/packages/package/test/index.js b/packages/package/test/index.js index 6a06e24bb1f5..8ab30fcf5e32 100644 --- a/packages/package/test/index.js +++ b/packages/package/test/index.js @@ -31,7 +31,7 @@ async function test_make_package(path) { assert.equal(actual_files, expected_files); - const extensions = ['.json', '.svelte', '.ts', 'js']; + const extensions = ['.json', '.svelte', '.ts', 'js', '.map']; for (const file of actual_files) { const pathname = join(pwd, file); if (fs.statSync(pathname).isDirectory()) continue; @@ -60,6 +60,9 @@ async function test_make_package(path) { * @param {string} content */ function format(file, content) { + if (file.endsWith('.map')) { + return content; + } if (file.endsWith('package.json')) { // For some reason these are ordered differently in different test environments const json = JSON.parse(content); @@ -150,6 +153,10 @@ test('SvelteKit interop', async () => { await test_make_package('svelte-kit'); }); +test('create package with declaration map', async () => { + await test_make_package('typescript-declaration-map'); +}); + // chokidar doesn't fire events in github actions :shrug: if (!process.env.CI) { test('watches for changes', async () => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 66efa48cb9dd..d860aadd27be 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -667,14 +667,14 @@ importers: sade: ^1.8.1 svelte: ^3.55.1 svelte-preprocess: ^5.0.0 - svelte2tsx: ~0.6.0 + svelte2tsx: ~0.6.1 typescript: ^4.9.4 uvu: ^0.5.6 dependencies: chokidar: 3.5.3 kleur: 4.1.5 sade: 1.8.1 - svelte2tsx: 0.6.0_atrrhq7vg4ekua4nnyrpuardle + svelte2tsx: 0.6.1_atrrhq7vg4ekua4nnyrpuardle devDependencies: '@types/node': 16.18.6 svelte: 3.55.1 @@ -4626,8 +4626,8 @@ packages: resolution: {integrity: sha512-S+87/P0Ve67HxKkEV23iCdAh/SX1xiSfjF1HOglno/YTbSTW7RniICMCofWGdJJbdjw3S+0PfFb1JtGfTXE0oQ==} engines: {node: '>= 8'} - /svelte2tsx/0.6.0_atrrhq7vg4ekua4nnyrpuardle: - resolution: {integrity: sha512-TrxfQkO7CKi8Pu2eC/FyteDCdk3OOeQV5u6z7OjYAsOhsd0ClzAKqxJdvp6xxNQLrbFzf/XvCi9Fy8MQ1MleFA==} + /svelte2tsx/0.6.1_atrrhq7vg4ekua4nnyrpuardle: + resolution: {integrity: sha512-O/1+5UyChfmhp1/GUv8b8iveTrn6eZwHxEXc+rw7LMKRidr9KHk5w/EiliLjDUwHa2VA6CoEty+CQylROVU4Sw==} peerDependencies: svelte: ^3.55 typescript: ^4.9.4 From 8d4e28fe95a29468b2d0a16d2a690071f8f450ec Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Fri, 11 Aug 2023 13:00:05 +0200 Subject: [PATCH 2/7] adjust --- packages/package/src/index.js | 4 ++-- packages/package/src/typescript.js | 18 +++++++++++++++--- .../expected/Test.svelte.d.ts.map | 2 +- .../expected/package.json | 13 ------------- .../typescript-declaration-map/package.json | 8 +++++++- 5 files changed, 25 insertions(+), 20 deletions(-) delete mode 100644 packages/package/test/fixtures/typescript-declaration-map/expected/package.json diff --git a/packages/package/src/index.js b/packages/package/src/index.js index 8e1398577247..ffb551560389 100644 --- a/packages/package/src/index.js +++ b/packages/package/src/index.js @@ -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, output, options.cwd, alias, files); } for (const file of files) { @@ -122,7 +122,7 @@ export async function watch(options) { } if (options.types) { - await emit_dts(input, output, options.cwd, alias, files); + await emit_dts(input, output, output, options.cwd, alias, files); console.log('Updated .d.ts files'); } diff --git a/packages/package/src/typescript.js b/packages/package/src/typescript.js index ff50c597039e..62d2caadab8d 100644 --- a/packages/package/src/typescript.js +++ b/packages/package/src/typescript.js @@ -14,11 +14,12 @@ import { load_pkg_json } from './config.js'; * * @param {string} input * @param {string} output + * @param {string} final_output * @param {string} cwd * @param {Record} alias * @param {import('./types').File[]} files */ -export async function emit_dts(input, output, cwd, alias, files) { +export async function emit_dts(input, output, final_output, cwd, alias, files) { const tmp = `${output}/__package_types_tmp__`; rimraf(tmp); mkdirp(tmp); @@ -54,8 +55,19 @@ export async function emit_dts(input, output, cwd, alias, files) { let source = fs.readFileSync(path.join(tmp, normalized), 'utf8'); if (file.endsWith('.d.ts.map')) { - // Because we put the .d.ts files in a temporary directory, the path upwards is one level too much - source = source.replace(/"sources":\["\.\.\//, '"sources":["'); + // Because we put the .d.ts files in a temporary directory, the relative path needs to be adjusted + source = source.replace(/("sources":\[")(.+?)("\])/, (_, prefix, source_path, suffix) => { + const new_sourcepath = posixify( + path.join( + path.relative( + path.dirname(path.join(final_output, normalized)), + path.dirname(path.join(input, normalized)) + ), + path.basename(source_path) + ) + ); + return prefix + new_sourcepath + suffix; + }); } else { source = resolve_aliases(input, normalized, source, alias); } diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map index 66a994255202..95495fc03366 100644 --- a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Test.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Test.svelte"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAA;AAa7C,QAAA,MAAM,SAAS;;kBADkC,MAAM;;;;;;;;;;;;CACA,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AACjD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAE/C,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,oBAAoB,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC;IACpF,IAAI,OAAO,WAA+D;CAC7E"} \ No newline at end of file +{"version":3,"file":"Test.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Test.svelte"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAE5C;AAeD,QAAA,MAAM,SAAS;;kBADkC,MAAM;;;;;;;;;;;;CACA,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AACjD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAE/C,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,oBAAoB,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC;IACpF,IAAI,OAAO,WAA+D;CAC7E"} \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/package.json b/packages/package/test/fixtures/typescript-declaration-map/expected/package.json deleted file mode 100644 index 7373cf455a97..000000000000 --- a/packages/package/test/fixtures/typescript-declaration-map/expected/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "typescript-declaration-map", - "private": true, - "version": "1.0.0", - "description": "standard typescript package with declarationMap:true", - "type": "module", - "exports": { - "./package.json": "./package.json", - "./Test.svelte": "./Test.svelte", - ".": "./index.js" - }, - "svelte": "./index.js" -} \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-declaration-map/package.json b/packages/package/test/fixtures/typescript-declaration-map/package.json index eac17090eabe..63a39c721f17 100644 --- a/packages/package/test/fixtures/typescript-declaration-map/package.json +++ b/packages/package/test/fixtures/typescript-declaration-map/package.json @@ -3,5 +3,11 @@ "private": true, "version": "1.0.0", "description": "standard typescript package with declarationMap:true", - "type": "module" + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "svelte": "./dist/index.js" + } + } } From a68768c3bfdff93be85cf007c9bea667df9a7a2d Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Mon, 18 Mar 2024 23:37:16 +0800 Subject: [PATCH 3/7] prettier --- packages/package/test/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/package/test/index.js b/packages/package/test/index.js index c384592180bb..b62b0e5baf65 100644 --- a/packages/package/test/index.js +++ b/packages/package/test/index.js @@ -67,7 +67,7 @@ async function test_make_package(path, options) { * @param {string} content */ async function format(file, content) { - if (file.endsWith('.map')) { + if (file.endsWith('.map')) { return content; } From 397df6e0c65830a2fec3cc7d9058679dbd93c1e0 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:59:46 +0100 Subject: [PATCH 4/7] Update packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte --- .../fixtures/typescript-declaration-map/expected/Test.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte index 661b1b8276b0..7613c3ebf28b 100644 --- a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte @@ -1,4 +1,4 @@ - - +{foo} diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts index c03f9457a7af..a085b329fba8 100644 --- a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts @@ -1,24 +1,7 @@ -import { SvelteComponentTyped } from 'svelte'; -declare const __propDef: { - props: { - astring?: string; - }; - events: { - event: CustomEvent; - } & { - [evt: string]: CustomEvent; - }; - slots: { - default: { - astring: string; - }; - }; +type $$ComponentProps = { + foo: string; }; -export type TestProps = typeof __propDef.props; -export type TestEvents = typeof __propDef.events; -export type TestSlots = typeof __propDef.slots; -export default class Test extends SvelteComponentTyped { - get astring(): string; -} -export {}; +declare const Test: import("svelte").Component<$$ComponentProps, {}, "">; +type Test = ReturnType; +export default Test //# sourceMappingURL=Test.svelte.d.ts.map \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map index 95495fc03366..fd94dc2b8f55 100644 --- a/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map +++ b/packages/package/test/fixtures/typescript-declaration-map/expected/Test.svelte.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"Test.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Test.svelte"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAE5C;AAeD,QAAA,MAAM,SAAS;;kBADkC,MAAM;;;;;;;;;;;;CACA,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,OAAO,SAAS,CAAC,MAAM,CAAC;AACjD,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,KAAK,CAAC;AAE/C,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,oBAAoB,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC;IACpF,IAAI,OAAO,WAA+D;CAC7E"} \ No newline at end of file +{"version":3,"file":"Test.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Test.svelte.ts"],"names":[],"mappings":"AAGC,KAAK,gBAAgB,GAAI;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAS1C,QAAA,MAAM,IAAI,sDAAsC,CAAC;AACjD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"} \ No newline at end of file diff --git a/packages/package/test/fixtures/typescript-declaration-map/package.json b/packages/package/test/fixtures/typescript-declaration-map/package.json index 63a39c721f17..0f71eb5defeb 100644 --- a/packages/package/test/fixtures/typescript-declaration-map/package.json +++ b/packages/package/test/fixtures/typescript-declaration-map/package.json @@ -4,6 +4,9 @@ "version": "1.0.0", "description": "standard typescript package with declarationMap:true", "type": "module", + "peerDependencies": { + "svelte": "^5.0.0" + }, "exports": { ".": { "types": "./dist/index.d.ts", diff --git a/packages/package/test/fixtures/typescript-declaration-map/src/lib/Test.svelte b/packages/package/test/fixtures/typescript-declaration-map/src/lib/Test.svelte index 9ad736f2323d..50483b0ec942 100644 --- a/packages/package/test/fixtures/typescript-declaration-map/src/lib/Test.svelte +++ b/packages/package/test/fixtures/typescript-declaration-map/src/lib/Test.svelte @@ -1,9 +1,5 @@ - +{foo} From 3e1548b972e603136082751cde1ff21668ef0965 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Fri, 10 Jan 2025 16:48:47 +0100 Subject: [PATCH 6/7] bump svelte2tsx --- .changeset/dirty-doors-hide.md | 5 +++++ packages/package/package.json | 2 +- pnpm-lock.yaml | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/dirty-doors-hide.md diff --git a/.changeset/dirty-doors-hide.md b/.changeset/dirty-doors-hide.md new file mode 100644 index 000000000000..da40c8d476a1 --- /dev/null +++ b/.changeset/dirty-doors-hide.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/package': patch +--- + +chore: bump `svelte2tsx` dependency for more up-to-date `d.ts` output diff --git a/packages/package/package.json b/packages/package/package.json index 1ab629b29654..2d8a3d1a7e19 100644 --- a/packages/package/package.json +++ b/packages/package/package.json @@ -24,7 +24,7 @@ "kleur": "^4.1.5", "sade": "^1.8.1", "semver": "^7.5.4", - "svelte2tsx": "~0.7.16" + "svelte2tsx": "~0.7.33" }, "devDependencies": { "@sveltejs/vite-plugin-svelte": "^5.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee44a84c946c..028964dd1324 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1067,8 +1067,8 @@ importers: specifier: ^7.5.4 version: 7.6.3 svelte2tsx: - specifier: ~0.7.16 - version: 0.7.18(svelte@5.2.9)(typescript@5.6.3) + specifier: ~0.7.33 + version: 0.7.33(svelte@5.2.9)(typescript@5.6.3) devDependencies: '@sveltejs/vite-plugin-svelte': specifier: ^5.0.1 @@ -3383,8 +3383,8 @@ packages: typescript: optional: true - svelte2tsx@0.7.18: - resolution: {integrity: sha512-PCOhH7uQaV472ZvNAcnkvShjFRMMkKUc/eNJImQMH9T4CyHeQpdatedFrEjaMCsweFb/oo3a6bv4qtdfaCPw8g==} + svelte2tsx@0.7.33: + resolution: {integrity: sha512-geogGkzfciwteiKvlbaDBnKOitWuh6e1n2f5KLBBXEfZgui9gy5yRlOBYtNEkdwciO4MC9fTM/EyltsiQrOPNQ==} peerDependencies: svelte: ^3.55 || ^4.0.0-next.0 || ^4.0 || ^5.0.0-next.0 typescript: ^4.9.4 || ^5.0.0 @@ -5794,7 +5794,7 @@ snapshots: postcss-load-config: 3.1.4(postcss@8.4.49) typescript: 5.6.3 - svelte2tsx@0.7.18(svelte@5.2.9)(typescript@5.6.3): + svelte2tsx@0.7.33(svelte@5.2.9)(typescript@5.6.3): dependencies: dedent-js: 1.0.1 pascal-case: 3.1.2 From 27534fcdaff490cd4fa7cb5b1c5d49a7c9f1cfec Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 21 Jan 2025 15:05:10 +0100 Subject: [PATCH 7/7] Update documentation/docs/30-advanced/70-packaging.md --- documentation/docs/30-advanced/70-packaging.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/documentation/docs/30-advanced/70-packaging.md b/documentation/docs/30-advanced/70-packaging.md index 3a27604e372d..93294e3f2616 100644 --- a/documentation/docs/30-advanced/70-packaging.md +++ b/documentation/docs/30-advanced/70-packaging.md @@ -220,7 +220,20 @@ You should think carefully about whether or not the changes you make to your pac ## Source maps -You can create so-called declaration maps (`d.ts.map` files) by setting `"declarationMap": true` in your `tsconfig.json`. This will allow editors such as VS Code to go to the original `.ts` or `.svelte` file when using features like _Go to Definition_. This means you also need to publish your source files alongside your dist folder in a way that the relative path inside the declaration files leads to a file on disk. +You can create so-called declaration maps (`d.ts.map` files) by setting `"declarationMap": true` in your `tsconfig.json`. This will allow editors such as VS Code to go to the original `.ts` or `.svelte` file when using features like _Go to Definition_. This means you also need to publish your source files alongside your dist folder in a way that the relative path inside the declaration files leads to a file on disk. Assuming that you have all your library code inside `src/lib` as suggested by Svelte's CLI, this is as simple as adding `src/lib` to `files` in your `package.json`: + +```json +{ + "files": [ + "dist", + "!dist/**/*.test.*", + "!dist/**/*.spec.*", + +++"src/lib", + "!src/lib/**/*.test.*", + "!src/lib/**/*.spec.*"+++ + ] +} +``` ## Options