svelte-router-file 0.1.0 → 0.1.2

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.
package/README.md CHANGED
@@ -9,7 +9,8 @@ Initialize the library in `main.js` or similar, before any FileRouter is mounted
9
9
  ```js
10
10
  import { init } from "svelte-router-file";
11
11
 
12
- init(/* opts */);
12
+ /* basePath is set to ./routes if not specified */
13
+ init({ basePath: "./myroutes" });
13
14
  ```
14
15
 
15
16
  Initializing this library means that you should not call the usual `init()` function of `@svelte-router/core`.
@@ -27,7 +28,7 @@ In the root component, like `App.svelte` or similar:
27
28
  <script lang="ts">
28
29
  import { FileRouter } from "svelte-router-file";
29
30
 
30
- let files = import.meta.glob("routes/**/*.ts");
31
+ let files = import.meta.glob("routes/**/*.svelte", { eager: true });
31
32
  </script>
32
33
 
33
34
  <FileRouter files />
package/dist/init.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { type InitOptions, type Hash } from "@svelte-router/core";
2
2
  export declare let initialized: boolean;
3
+ export declare let basePath: string;
3
4
  export declare function init(options?: Omit<InitOptions, "defaultHash"> & {
4
5
  defaultHash?: Exclude<Hash, true | string>;
6
+ basePath?: string;
5
7
  }): () => void;
package/dist/init.js CHANGED
@@ -1,10 +1,12 @@
1
- import { initCore, location } from "@svelte-router/core";
1
+ import { initCore, LocationLite, StockHistoryApi } from "@svelte-router/core";
2
2
  export let initialized = false;
3
+ export let basePath = "./routes";
3
4
  export function init(options) {
4
5
  if (options?.defaultHash !== false && options?.defaultHash !== undefined) {
5
6
  throw new Error("svelte-router-file requires path mode. Setting defaultHash to anything but false is not allowed.");
6
7
  }
7
- const core = initCore(location, {
8
+ basePath = options?.basePath ?? "./routes";
9
+ const core = initCore(new LocationLite(new StockHistoryApi()), {
8
10
  defaultHash: false,
9
11
  disallowHashRouting: true,
10
12
  ...options
package/dist/router.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { RouterEngine } from "@svelte-router/core";
2
2
  import { basename, dirname } from "path-browserify";
3
+ import { basePath as baseRoutesPath } from "./init.js";
3
4
  function getParamsFromRoute(route) {
4
5
  const params = [];
5
6
  const regex = /\/:([a-zA-Z_][a-zA-Z0-9_]*)/g;
@@ -10,7 +11,6 @@ function getParamsFromRoute(route) {
10
11
  return params;
11
12
  }
12
13
  function getRouteFromPath(path) {
13
- const baseRoutesPath = "./routes";
14
14
  let basePath = path.startsWith(baseRoutesPath) ?
15
15
  path.substring(baseRoutesPath.length) :
16
16
  path;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-router-file",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "license": "AGPLv3",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -9,7 +9,8 @@
9
9
  "prepare": "svelte-kit sync || echo ''",
10
10
  "prepack": "svelte-kit sync && svelte-package && publint",
11
11
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
12
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
12
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
13
+ "test": "vitest"
13
14
  },
14
15
  "files": [
15
16
  "dist",
@@ -50,7 +51,8 @@
50
51
  "svelte-check": "^4.4.2",
51
52
  "typescript": "^5.9.3",
52
53
  "typescript-eslint": "^8.58.0",
53
- "vite": "^7.3.1"
54
+ "vite": "^7.3.1",
55
+ "vitest": "^4.1.3"
54
56
  },
55
57
  "keywords": [
56
58
  "svelte",