@volpe/astro-svelte-spa 0.1.3 → 0.1.5

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 +5 -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,7 @@ 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";
15
8
 
16
9
  /**
17
10
  * @typedef {Object} RouteNode
@@ -226,7 +219,7 @@ function generatePageFiles(pagesDir) {
226
219
  const catchAllPath = path.resolve(pagesDir, "[...path].astro");
227
220
  if (!fs.existsSync(catchAllPath)) {
228
221
  const catchAllContent = `---
229
- import { App } from "@volpe/astro-svelte-spa"
222
+ import App from "virtual:svelte-spa"
230
223
  ---
231
224
 
232
225
  <App client:only="svelte" />
@@ -299,27 +292,6 @@ function generateAppComponent() {
299
292
  `;
300
293
  }
301
294
 
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
295
 
324
296
  /**
325
297
  * Vite plugin for file-based routing with svelte5-router in Astro
@@ -380,16 +352,8 @@ export function plugin(options = {}) {
380
352
  if (id === VIRTUAL_MODULE_ID) {
381
353
  return RESOLVED_VIRTUAL_MODULE_ID;
382
354
  }
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;
355
+ if (id === VIRTUAL_SPA_ID) {
356
+ return VIRTUAL_SPA_ID;
393
357
  }
394
358
  },
395
359
 
@@ -397,20 +361,9 @@ export function plugin(options = {}) {
397
361
  if (id === RESOLVED_VIRTUAL_MODULE_ID) {
398
362
  return generateRoutesModule(pagesDir, basePath);
399
363
  }
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) {
364
+ if (id === VIRTUAL_SPA_ID) {
409
365
  return generateAppComponent();
410
366
  }
411
- if (id === RESOLVED_VIRTUAL_LINK_ID) {
412
- return generateLinkComponent();
413
- }
414
367
  },
415
368
 
416
369
  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.5",
4
4
  "description": "Vite plugin for file-based routing with svelte5-router in Astro",
5
5
  "type": "module",
6
6
  "main": "index.js",