@volpe/astro-svelte-spa 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +5 -29
  2. package/index.js +6 -52
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -37,32 +37,8 @@ export function plugin(options?: PluginOptions): Plugin;
37
37
 
38
38
  export default plugin;
39
39
 
40
- /**
41
- * The main App component that renders the router.
42
- * Use with `client:only="svelte"` in Astro.
43
- *
44
- * @example
45
- * ```astro
46
- * ---
47
- * import { App } from "@volpe/astro-svelte-spa"
48
- * ---
49
- * <App client:only="svelte" />
50
- * ```
51
- */
52
- export const App: Component<{}>;
53
-
54
- /**
55
- * Link component for client-side navigation.
56
- *
57
- * @example
58
- * ```svelte
59
- * <script>
60
- * import { Link } from "@volpe/astro-svelte-spa"
61
- * </script>
62
- * <Link href="/about">About</Link>
63
- * ```
64
- */
65
- export const Link: Component<{
66
- href: string;
67
- [key: string]: any;
68
- }>;
40
+ declare module "virtual:svelte-spa" {
41
+ import type { Component } from "svelte";
42
+ const App: Component<{}>;
43
+ export default App;
44
+ }
package/index.js CHANGED
@@ -4,14 +4,8 @@ import path from "node:path";
4
4
  const VIRTUAL_MODULE_ID = "virtual:svelte-routes";
5
5
  const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
6
6
 
7
- const PACKAGE_ID = "@volpe/astro-svelte-spa";
8
- const RESOLVED_PACKAGE_ID = "\0" + PACKAGE_ID;
9
-
10
- const VIRTUAL_APP_ID = "virtual:svelte-spa-app";
11
- const RESOLVED_VIRTUAL_APP_ID = "\0" + VIRTUAL_APP_ID;
12
-
13
- const VIRTUAL_LINK_ID = "virtual:svelte-spa-link";
14
- const RESOLVED_VIRTUAL_LINK_ID = "\0" + VIRTUAL_LINK_ID;
7
+ const VIRTUAL_SPA_ID = "virtual:svelte-spa";
8
+ const RESOLVED_VIRTUAL_SPA_ID = "\0" + VIRTUAL_SPA_ID;
15
9
 
16
10
  /**
17
11
  * @typedef {Object} RouteNode
@@ -226,7 +220,7 @@ function generatePageFiles(pagesDir) {
226
220
  const catchAllPath = path.resolve(pagesDir, "[...path].astro");
227
221
  if (!fs.existsSync(catchAllPath)) {
228
222
  const catchAllContent = `---
229
- import { App } from "@volpe/astro-svelte-spa"
223
+ import App from "virtual:svelte-spa"
230
224
  ---
231
225
 
232
226
  <App client:only="svelte" />
@@ -299,27 +293,6 @@ function generateAppComponent() {
299
293
  `;
300
294
  }
301
295
 
302
- /**
303
- * Generates the virtual Link component code
304
- * @returns {string}
305
- */
306
- function generateLinkComponent() {
307
- return `<script>
308
- import { route, goto } from "@mateothegreat/svelte5-router"
309
-
310
- let { href, children, ...rest } = $props()
311
-
312
- const handleClick = (e) => {
313
- e.preventDefault()
314
- goto(href)
315
- }
316
- </script>
317
-
318
- <a {href} onclick={handleClick} class:active={$route.path === href} {...rest}>
319
- {@render children?.()}
320
- </a>
321
- `;
322
- }
323
296
 
324
297
  /**
325
298
  * Vite plugin for file-based routing with svelte5-router in Astro
@@ -380,16 +353,8 @@ export function plugin(options = {}) {
380
353
  if (id === VIRTUAL_MODULE_ID) {
381
354
  return RESOLVED_VIRTUAL_MODULE_ID;
382
355
  }
383
- // Intercept main package import (but not /plugin subpath)
384
- if (id === PACKAGE_ID) {
385
- return RESOLVED_PACKAGE_ID;
386
- }
387
- // Handle virtual component IDs
388
- if (id === VIRTUAL_APP_ID) {
389
- return RESOLVED_VIRTUAL_APP_ID;
390
- }
391
- if (id === VIRTUAL_LINK_ID) {
392
- return RESOLVED_VIRTUAL_LINK_ID;
356
+ if (id === VIRTUAL_SPA_ID) {
357
+ return RESOLVED_VIRTUAL_SPA_ID;
393
358
  }
394
359
  },
395
360
 
@@ -397,20 +362,9 @@ export function plugin(options = {}) {
397
362
  if (id === RESOLVED_VIRTUAL_MODULE_ID) {
398
363
  return generateRoutesModule(pagesDir, basePath);
399
364
  }
400
- // Virtual package module - exports App, Link, and re-exports plugin
401
- if (id === RESOLVED_PACKAGE_ID) {
402
- return `
403
- export { default as App } from "${VIRTUAL_APP_ID}";
404
- export { default as Link } from "${VIRTUAL_LINK_ID}";
405
- export { plugin, default } from "@volpe/astro-svelte-spa/plugin";
406
- `;
407
- }
408
- if (id === RESOLVED_VIRTUAL_APP_ID) {
365
+ if (id === RESOLVED_VIRTUAL_SPA_ID) {
409
366
  return generateAppComponent();
410
367
  }
411
- if (id === RESOLVED_VIRTUAL_LINK_ID) {
412
- return generateLinkComponent();
413
- }
414
368
  },
415
369
 
416
370
  handleHotUpdate() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volpe/astro-svelte-spa",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Vite plugin for file-based routing with svelte5-router in Astro",
5
5
  "type": "module",
6
6
  "main": "index.js",