@volpe/astro-svelte-spa 0.1.2 → 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 -45
  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,10 +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
- const VIRTUAL_APP_ID = "\0svelte-spa-app.svelte";
10
- const VIRTUAL_LINK_ID = "\0svelte-spa-link.svelte";
7
+ const VIRTUAL_SPA_ID = "virtual:svelte-spa";
8
+ const RESOLVED_VIRTUAL_SPA_ID = "\0" + VIRTUAL_SPA_ID;
11
9
 
12
10
  /**
13
11
  * @typedef {Object} RouteNode
@@ -222,7 +220,7 @@ function generatePageFiles(pagesDir) {
222
220
  const catchAllPath = path.resolve(pagesDir, "[...path].astro");
223
221
  if (!fs.existsSync(catchAllPath)) {
224
222
  const catchAllContent = `---
225
- import { App } from "@volpe/astro-svelte-spa"
223
+ import App from "virtual:svelte-spa"
226
224
  ---
227
225
 
228
226
  <App client:only="svelte" />
@@ -295,27 +293,6 @@ function generateAppComponent() {
295
293
  `;
296
294
  }
297
295
 
298
- /**
299
- * Generates the virtual Link component code
300
- * @returns {string}
301
- */
302
- function generateLinkComponent() {
303
- return `<script>
304
- import { route, goto } from "@mateothegreat/svelte5-router"
305
-
306
- let { href, children, ...rest } = $props()
307
-
308
- const handleClick = (e) => {
309
- e.preventDefault()
310
- goto(href)
311
- }
312
- </script>
313
-
314
- <a {href} onclick={handleClick} class:active={$route.path === href} {...rest}>
315
- {@render children?.()}
316
- </a>
317
- `;
318
- }
319
296
 
320
297
  /**
321
298
  * Vite plugin for file-based routing with svelte5-router in Astro
@@ -376,13 +353,8 @@ export function plugin(options = {}) {
376
353
  if (id === VIRTUAL_MODULE_ID) {
377
354
  return RESOLVED_VIRTUAL_MODULE_ID;
378
355
  }
379
- // Intercept main package import (but not /plugin subpath)
380
- if (id === PACKAGE_ID) {
381
- return RESOLVED_PACKAGE_ID;
382
- }
383
- // Handle virtual component IDs
384
- if (id === VIRTUAL_APP_ID || id === VIRTUAL_LINK_ID) {
385
- return id;
356
+ if (id === VIRTUAL_SPA_ID) {
357
+ return RESOLVED_VIRTUAL_SPA_ID;
386
358
  }
387
359
  },
388
360
 
@@ -390,20 +362,9 @@ export function plugin(options = {}) {
390
362
  if (id === RESOLVED_VIRTUAL_MODULE_ID) {
391
363
  return generateRoutesModule(pagesDir, basePath);
392
364
  }
393
- // Virtual package module - exports App, Link, and re-exports plugin
394
- if (id === RESOLVED_PACKAGE_ID) {
395
- return `
396
- export { default as App } from "${VIRTUAL_APP_ID}";
397
- export { default as Link } from "${VIRTUAL_LINK_ID}";
398
- export { plugin, default } from "@volpe/astro-svelte-spa/plugin";
399
- `;
400
- }
401
- if (id === VIRTUAL_APP_ID) {
365
+ if (id === RESOLVED_VIRTUAL_SPA_ID) {
402
366
  return generateAppComponent();
403
367
  }
404
- if (id === VIRTUAL_LINK_ID) {
405
- return generateLinkComponent();
406
- }
407
368
  },
408
369
 
409
370
  handleHotUpdate() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volpe/astro-svelte-spa",
3
- "version": "0.1.2",
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",