@solidjs/start 2.0.0-beta.4 → 2.0.0-beta.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
package/dist/config/fs-router.js
CHANGED
|
@@ -30,19 +30,17 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
|
30
30
|
// filePath: src
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
33
|
+
const exports = analyzeModule(src);
|
|
34
|
+
const exportNames = exports.map(getExportName);
|
|
35
|
+
const localExportNames = exports.map(getLocalExportName).filter(name => name !== undefined);
|
|
36
|
+
const hasDefault = exportNames.includes("default");
|
|
37
|
+
const hasRouteConfig = exportNames.includes("route");
|
|
36
38
|
if (hasDefault) {
|
|
37
39
|
return {
|
|
38
40
|
page: true,
|
|
39
41
|
$component: {
|
|
40
42
|
src: src,
|
|
41
|
-
pick: [
|
|
42
|
-
...exports.filter(e => e.n === e.ln && e.n !== "route").map(e => e.n),
|
|
43
|
-
"default",
|
|
44
|
-
"$css",
|
|
45
|
-
],
|
|
43
|
+
pick: [...localExportNames.filter(name => name !== "route"), "default", "$css"],
|
|
46
44
|
},
|
|
47
45
|
$$route: hasRouteConfig
|
|
48
46
|
? {
|
|
@@ -57,18 +55,27 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
const HTTP_METHODS = ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
|
|
58
|
+
function getExportName(entry) {
|
|
59
|
+
return entry.exportName.name ?? "default";
|
|
60
|
+
}
|
|
61
|
+
function getLocalExportName(entry) {
|
|
62
|
+
const name = getExportName(entry);
|
|
63
|
+
if (name === "default")
|
|
64
|
+
return;
|
|
65
|
+
return name === (entry.localName.name ?? entry.importName.name ?? name) ? name : undefined;
|
|
66
|
+
}
|
|
60
67
|
function createHTTPHandlers(src, exports) {
|
|
61
68
|
const handlers = {};
|
|
62
69
|
for (const exp of exports) {
|
|
63
|
-
if (HTTP_METHODS.includes(exp
|
|
64
|
-
handlers[`$${exp
|
|
70
|
+
if (HTTP_METHODS.includes(exp)) {
|
|
71
|
+
handlers[`$${exp}`] = {
|
|
65
72
|
src: src,
|
|
66
|
-
pick: [exp
|
|
73
|
+
pick: [exp],
|
|
67
74
|
};
|
|
68
|
-
if (exp
|
|
75
|
+
if (exp === "GET" && !exports.includes("HEAD")) {
|
|
69
76
|
handlers.$HEAD = {
|
|
70
77
|
src: src,
|
|
71
|
-
pick: [exp
|
|
78
|
+
pick: [exp],
|
|
72
79
|
};
|
|
73
80
|
}
|
|
74
81
|
}
|
|
@@ -108,10 +115,12 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
|
108
115
|
path,
|
|
109
116
|
};
|
|
110
117
|
}
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
118
|
+
const exports = analyzeModule(src);
|
|
119
|
+
const exportNames = exports.map(getExportName);
|
|
120
|
+
const localExportNames = exports.map(getLocalExportName).filter(name => name !== undefined);
|
|
121
|
+
const hasRouteConfig = exportNames.includes("route");
|
|
122
|
+
const hasDefault = exportNames.includes("default");
|
|
123
|
+
const hasAPIRoutes = exportNames.some(name => HTTP_METHODS.includes(name));
|
|
115
124
|
if (hasDefault || hasAPIRoutes) {
|
|
116
125
|
return {
|
|
117
126
|
page: hasDefault,
|
|
@@ -119,9 +128,7 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
|
119
128
|
? {
|
|
120
129
|
src: src,
|
|
121
130
|
pick: [
|
|
122
|
-
...
|
|
123
|
-
.filter(e => e.n === e.ln && e.n !== "route" && !HTTP_METHODS.includes(e.n))
|
|
124
|
-
.map(e => e.n),
|
|
131
|
+
...localExportNames.filter(name => name !== "route" && !HTTP_METHODS.includes(name)),
|
|
125
132
|
"default",
|
|
126
133
|
"$css",
|
|
127
134
|
],
|
|
@@ -133,7 +140,7 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
|
133
140
|
pick: ["route"],
|
|
134
141
|
}
|
|
135
142
|
: undefined,
|
|
136
|
-
...createHTTPHandlers(src,
|
|
143
|
+
...createHTTPHandlers(src, exportNames),
|
|
137
144
|
path,
|
|
138
145
|
};
|
|
139
146
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StaticExportEntry } from "oxc-parser";
|
|
1
2
|
import { pathToRegexp } from "path-to-regexp";
|
|
2
3
|
export { pathToRegexp };
|
|
3
4
|
export declare const glob: (path: string) => string[];
|
|
@@ -9,7 +10,7 @@ type Route = {
|
|
|
9
10
|
path: string;
|
|
10
11
|
} & Record<string, any>;
|
|
11
12
|
export declare function cleanPath(src: string, config: FileSystemRouterConfig): string;
|
|
12
|
-
export declare function analyzeModule(src: string):
|
|
13
|
+
export declare function analyzeModule(src: string): StaticExportEntry[];
|
|
13
14
|
type RouterEvent = CustomEvent<{
|
|
14
15
|
route: string;
|
|
15
16
|
type: "update" | "remove" | "add";
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { init, parse } from "es-module-lexer";
|
|
2
|
-
import esbuild from "esbuild";
|
|
3
1
|
import fg from "fast-glob";
|
|
4
2
|
import fs from "node:fs";
|
|
5
3
|
import micromatch from "micromatch";
|
|
6
4
|
import { posix } from "node:path";
|
|
5
|
+
import { parseSync } from "oxc-parser";
|
|
7
6
|
import { pathToRegexp } from "path-to-regexp";
|
|
8
7
|
import { normalizePath } from "vite";
|
|
9
8
|
export { pathToRegexp };
|
|
@@ -14,11 +13,11 @@ export function cleanPath(src, config) {
|
|
|
14
13
|
.replace(new RegExp(`\.(${(config.extensions ?? []).join("|")})$`), "");
|
|
15
14
|
}
|
|
16
15
|
export function analyzeModule(src) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}).
|
|
16
|
+
const result = parseSync(src, fs.readFileSync(src, "utf-8"), { lang: "tsx" });
|
|
17
|
+
const error = result.errors[0];
|
|
18
|
+
if (error)
|
|
19
|
+
throw new SyntaxError(`Failed to parse ${src}:\n${error.codeframe || error.message}`);
|
|
20
|
+
return result.module.staticExports.flatMap(({ entries }) => entries.filter(entry => !entry.isType && entry.exportName.kind !== "None"));
|
|
22
21
|
}
|
|
23
22
|
export class BaseFileSystemRouter extends EventTarget {
|
|
24
23
|
routes;
|
|
@@ -37,7 +36,6 @@ export class BaseFileSystemRouter extends EventTarget {
|
|
|
37
36
|
`.{${this.config.extensions.join(",")}}`);
|
|
38
37
|
}
|
|
39
38
|
async buildRoutes() {
|
|
40
|
-
await init;
|
|
41
39
|
for (var src of glob(this.glob())) {
|
|
42
40
|
await this.addRoute(src);
|
|
43
41
|
}
|
|
@@ -53,8 +51,8 @@ export class BaseFileSystemRouter extends EventTarget {
|
|
|
53
51
|
let path = this.toPath(src);
|
|
54
52
|
if (path === undefined)
|
|
55
53
|
return;
|
|
56
|
-
const
|
|
57
|
-
if (!exports.find(
|
|
54
|
+
const exports = analyzeModule(src);
|
|
55
|
+
if (!exports.find(entry => entry.exportName.kind === "Default")) {
|
|
58
56
|
console.warn("No default export", src);
|
|
59
57
|
}
|
|
60
58
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/start",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -39,12 +39,11 @@
|
|
|
39
39
|
"cookie-es": "^2.0.0",
|
|
40
40
|
"defu": "^6.1.4",
|
|
41
41
|
"error-stack-parser": "^2.1.4",
|
|
42
|
-
"es-module-lexer": "^2.0.0",
|
|
43
|
-
"esbuild": "^0.27.4",
|
|
44
42
|
"fast-glob": "^3.3.3",
|
|
45
43
|
"h3": "^2.0.1-rc.25",
|
|
46
44
|
"html-to-image": "^1.11.13",
|
|
47
45
|
"micromatch": "^4.0.8",
|
|
46
|
+
"oxc-parser": "^0.139.0",
|
|
48
47
|
"path-to-regexp": "^8.3.0",
|
|
49
48
|
"pathe": "^2.0.3",
|
|
50
49
|
"radix3": "^1.1.2",
|