@solidjs/start 2.0.4 → 2.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @solidjs/start
2
2
 
3
+ ## 2.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - eca4cc4: Only strip a whole `index` segment when mapping route files to paths. Route files whose names merely end in "index", such as `routes/reindex.tsx`, were previously served at `/re` instead of `/reindex`.
8
+
3
9
  ## 2.0.4
4
10
 
5
11
  ### Patch Changes
@@ -1,20 +1,29 @@
1
1
  import { analyzeModule, BaseFileSystemRouter, cleanPath, } from "./fs-routes/router.js";
2
+ /**
3
+ * Maps a route file to its router path: strips the routes directory and extension,
4
+ * drops a trailing `index` segment (`blog/index` -> `/blog/`, `index` -> `/`) and
5
+ * converts `[param]`, `[[optional]]` and `[...rest]` segments to router syntax.
6
+ */
7
+ function toRoutePath(src, config) {
8
+ const routePath = cleanPath(src, config)
9
+ // remove the initial slash
10
+ .slice(1)
11
+ // only strip a whole `index` segment, not a name that merely ends in "index" (e.g. `reindex`)
12
+ .replace(/(^|\/)index$/, "$1")
13
+ .replace(/\[([^/]+)\]/g, (_, m) => {
14
+ if (m.length > 3 && m.startsWith("...")) {
15
+ return `*${m.slice(3)}`;
16
+ }
17
+ if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
18
+ return `:${m.slice(1, -1)}?`;
19
+ }
20
+ return `:${m}`;
21
+ });
22
+ return routePath.length > 0 ? `/${routePath}` : "/";
23
+ }
2
24
  export class SolidStartClientFileRouter extends BaseFileSystemRouter {
3
25
  toPath(src) {
4
- const routePath = cleanPath(src, this.config)
5
- // remove the initial slash
6
- .slice(1)
7
- .replace(/index$/, "")
8
- .replace(/\[([^/]+)\]/g, (_, m) => {
9
- if (m.length > 3 && m.startsWith("...")) {
10
- return `*${m.slice(3)}`;
11
- }
12
- if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
13
- return `:${m.slice(1, -1)}?`;
14
- }
15
- return `:${m}`;
16
- });
17
- return routePath?.length > 0 ? `/${routePath}` : "/";
26
+ return toRoutePath(src, this.config);
18
27
  }
19
28
  toRoute(src) {
20
29
  const path = this.toPath(src);
@@ -87,20 +96,7 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
87
96
  super(config);
88
97
  }
89
98
  toPath(src) {
90
- const routePath = cleanPath(src, this.config)
91
- // remove the initial slash
92
- .slice(1)
93
- .replace(/index$/, "")
94
- .replace(/\[([^/]+)\]/g, (_, m) => {
95
- if (m.length > 3 && m.startsWith("...")) {
96
- return `*${m.slice(3)}`;
97
- }
98
- if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
99
- return `:${m.slice(1, -1)}?`;
100
- }
101
- return `:${m}`;
102
- });
103
- return routePath?.length > 0 ? `/${routePath}` : "/";
99
+ return toRoutePath(src, this.config);
104
100
  }
105
101
  toRoute(src) {
106
102
  const path = this.toPath(src);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/start",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/solidjs/solid-start.git",