litestar-vite-plugin 0.6.0 → 0.6.1

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.
@@ -4,4 +4,4 @@ declare global {
4
4
  [key: string]: string;
5
5
  };
6
6
  }
7
- export declare function route(routeName: string, ...args: any[]): string;
7
+ export declare function route(routeName: string, ...args: any[]): string | null;
@@ -1,11 +1,11 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  export async function resolvePageComponent(path, pages) {
3
- for (const p of (Array.isArray(path) ? path : [path])) {
3
+ for (const p of Array.isArray(path) ? path : [path]) {
4
4
  const page = pages[p];
5
- if (typeof page === 'undefined') {
5
+ if (typeof page === "undefined") {
6
6
  continue;
7
7
  }
8
- return typeof page === 'function' ? page() : page;
8
+ return typeof page === "function" ? page() : page;
9
9
  }
10
10
  throw new Error(`Page not found: ${path}`);
11
11
  }
@@ -13,38 +13,44 @@ globalThis.routes = globalThis.routes || {};
13
13
  export function route(routeName, ...args) {
14
14
  let url = globalThis.routes[routeName];
15
15
  if (!url) {
16
- throw new Error("URL " + routeName + " was not found.");
16
+ console.error(`URL '${routeName}' not found in routes.`);
17
+ return null; // Return null to indicate failure
17
18
  }
18
19
  const argTokens = url.match(/<(\w+:?)?\w+>/g);
19
20
  if (!argTokens && args.length > 0) {
20
- throw new Error("Invalid URL lookup: URL " + routeName + " does not expect any arguments.");
21
+ console.error(`Invalid URL lookup: URL '${routeName}' does not expect arguments.`);
22
+ return null;
21
23
  }
22
- if (typeof args[0] === "object" && !Array.isArray(args[0])) {
23
- argTokens?.forEach((token) => {
24
- let argName = token.slice(1, -1);
25
- if (argName.includes(":")) {
26
- argName = argName.split(":")[1];
27
- }
28
- const argValue = args[0][argName];
29
- if (argValue === undefined) {
30
- throw new Error("Invalid URL lookup: Argument " + argName + " was not provided.");
24
+ try {
25
+ if (typeof args[0] === "object" && !Array.isArray(args[0])) {
26
+ argTokens?.forEach((token) => {
27
+ let argName = token.slice(1, -1);
28
+ if (argName.includes(":")) {
29
+ argName = argName.split(":")[1];
30
+ }
31
+ const argValue = args[0][argName];
32
+ if (argValue === undefined) {
33
+ throw new Error(`Invalid URL lookup: Argument '${argName}' was not provided.`);
34
+ }
35
+ url = url.replace(token, argValue.toString());
36
+ });
37
+ }
38
+ else {
39
+ const argsArray = Array.isArray(args[0])
40
+ ? args[0]
41
+ : Array.prototype.slice.call(args);
42
+ if (argTokens && argTokens.length !== argsArray.length) {
43
+ throw new Error(`Invalid URL lookup: Wrong number of arguments; expected ${argTokens.length.toString()} arguments.`);
31
44
  }
32
- url = url.replace(token, argValue.toString());
33
- });
34
- }
35
- else {
36
- const argsArray = Array.isArray(args[0])
37
- ? args[0]
38
- : Array.prototype.slice.call(args);
39
- if (argTokens && argTokens.length !== argsArray.length) {
40
- throw new Error("Invalid URL lookup: Wrong number of arguments; expected " +
41
- argTokens.length.toString() +
42
- " arguments.");
45
+ argTokens?.forEach((token, i) => {
46
+ const argValue = argsArray[i];
47
+ url = url.replace(token, argValue.toString());
48
+ });
43
49
  }
44
- argTokens?.forEach((token, i) => {
45
- const argValue = argsArray[i];
46
- url = url.replace(token, argValue.toString());
47
- });
50
+ }
51
+ catch (error) {
52
+ console.error(error.message);
53
+ return null; // Return null to indicate failure
48
54
  }
49
55
  return url;
50
56
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "litestar-vite-plugin",
3
- "version": "0.6.0",
4
- "type":"module",
3
+ "version": "0.6.1",
4
+ "type": "module",
5
5
  "description": "Litestar plugin for Vite.",
6
6
  "keywords": [
7
7
  "litestar",
@@ -11,7 +11,7 @@
11
11
  "homepage": "https://github.com/litestar-org/vite-plugin",
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/litestar-org/vite-plugin"
14
+ "url": "git+https://github.com/litestar-org/vite-plugin.git"
15
15
  },
16
16
  "license": "MIT",
17
17
  "author": "Litestar",
@@ -29,7 +29,8 @@
29
29
  "files": [
30
30
  "/dist",
31
31
  "/inertia-helpers"
32
- ],"bin": {
32
+ ],
33
+ "bin": {
33
34
  "clean-orphaned-assets": "bin/clean.js"
34
35
  },
35
36
  "scripts": {