diff --git a/.changeset/humble-paths-fly.md b/.changeset/humble-paths-fly.md new file mode 100644 index 0000000000..a33d0ea32b --- /dev/null +++ b/.changeset/humble-paths-fly.md @@ -0,0 +1,5 @@ +--- +'@fuzdev/gro': minor +--- + +feat: rewrite `.ts` to `.js` in dist files diff --git a/CLAUDE.md b/CLAUDE.md index 85ed11ac60..605ee2b05d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -275,7 +275,8 @@ Builtin plugins: - `gro_plugin_sveltekit_app` - runs `vite dev` or `vite build` for SvelteKit frontends ([docs](src/docs/gro_plugin_sveltekit_app.md)) - `gro_plugin_sveltekit_library` - runs `svelte-package` to publish from - `src/lib/` ([docs](src/docs/gro_plugin_sveltekit_library.md)) + `src/lib/`, then rewrites relative `.ts`→`.js` import specifiers in the + emitted `.d.ts`/`.svelte` ([docs](src/docs/gro_plugin_sveltekit_library.md)) - `gro_plugin_server` - runs Node servers with auto-restart on changes ### Configuration diff --git a/src/docs/gro_plugin_sveltekit_library.md b/src/docs/gro_plugin_sveltekit_library.md index dd0e98e745..d6a461c15e 100644 --- a/src/docs/gro_plugin_sveltekit_library.md +++ b/src/docs/gro_plugin_sveltekit_library.md @@ -22,7 +22,14 @@ npm i -D @sveltejs/package ## behavior In production (`gro build`), runs `svelte-package` during `setup` -to compile `src/lib/` into `dist/`. +to compile `src/lib/` into `dist/`, then rewrites relative `.ts` import +specifiers to `.js` (and `.svelte.ts` to `.svelte.js`) in the emitted `.d.ts` +declarations and `.svelte` ` + +{icon_link} +`; + const expected = ` + +{icon_link} +`; + assert.equal(rewrite_svelte_ts_imports(input), expected); + }); + + test('rewrites both module and instance ` + +`; + const expected = ` + +`; + assert.equal(rewrite_svelte_ts_imports(input), expected); + }); + + test('preserves `$`-sequences ($$props, $:) while rewriting specifiers', () => { + const input = ` +`; + const expected = ` +`; + assert.equal(rewrite_svelte_ts_imports(input), expected); + }); + + test('leaves a `.svelte` with no rewritable specifiers untouched', () => { + const input = ` +