@solidjs/start 2.0.0-alpha.0 → 2.0.0-alpha.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/CHANGELOG.md +28 -0
- package/dist/client/mount.d.ts +1 -7
- package/dist/client/mount.js +1 -99
- package/dist/config/constants.js +2 -2
- package/dist/config/dev-server.js +10 -0
- package/dist/config/fs-router.js +10 -22
- package/dist/config/fs-routes/fs-watcher.js +4 -4
- package/dist/config/fs-routes/index.js +4 -6
- package/dist/config/fs-routes/router.js +10 -11
- package/dist/config/fs-routes/tree-shake.js +12 -21
- package/dist/config/index.js +42 -42
- package/dist/config/lazy.js +42 -12
- package/dist/config/manifest.js +4 -3
- package/dist/config/vite-utils.d.ts +5 -0
- package/dist/config/vite-utils.js +7 -3
- package/dist/http/index.d.ts +1 -4
- package/dist/http/index.js +3 -5
- package/dist/index.d.ts +0 -1
- package/dist/middleware/index.d.ts +5 -2
- package/dist/middleware/index.js +6 -1
- package/dist/router.jsx +2 -2
- package/dist/server/StartServer.jsx +2 -0
- package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
- package/dist/server/assets/PatchVirtualDevStyles.jsx +28 -0
- package/dist/server/assets/index.js +1 -1
- package/dist/server/assets/render.jsx +2 -2
- package/dist/server/collect-styles.js +9 -21
- package/dist/server/fetchEvent.spec.js +1 -1
- package/dist/server/handler.js +30 -15
- package/dist/server/index.d.ts +1 -0
- package/dist/server/manifest/dev-client-manifest.js +1 -1
- package/dist/server/manifest/dev-ssr-manifest.js +1 -1
- package/dist/server/manifest/prod-ssr-manifest.js +7 -12
- package/dist/server/routes.js +3 -3
- package/dist/server/server-fns-runtime.js +2 -2
- package/dist/server/server-functions-handler.js +6 -11
- package/dist/server/server-runtime.js +8 -8
- package/dist/server/spa/StartServer.jsx +2 -0
- package/dist/shared/dev-overlay/CodeView.d.ts +1 -1
- package/dist/shared/dev-overlay/CodeView.jsx +23 -34
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +4 -4
- package/dist/shared/dev-overlay/get-source-map.d.ts +1 -1
- package/dist/shared/dev-overlay/get-source-map.js +5 -5
- package/dist/shared/dev-overlay/icons.d.ts +10 -10
- package/dist/shared/dev-overlay/icons.jsx +91 -91
- package/dist/shared/dev-overlay/index.jsx +1 -1
- package/dist/shared/lazy.js +4 -2
- package/env.d.ts +9 -0
- package/package.json +5 -4
- package/scripts/build.js +3 -3
- package/scripts/validate-imports.js +8 -8
- package/src/client/mount.ts +1 -114
- package/src/config/constants.ts +3 -3
- package/src/config/dev-server.ts +107 -99
- package/src/config/fs-router.ts +140 -155
- package/src/config/fs-routes/fs-watcher.ts +57 -61
- package/src/config/fs-routes/index.ts +117 -119
- package/src/config/fs-routes/router.ts +12 -13
- package/src/config/fs-routes/tree-shake.ts +342 -363
- package/src/config/index.ts +42 -43
- package/src/config/lazy.ts +47 -16
- package/src/config/manifest.ts +8 -7
- package/src/config/vite-utils.ts +9 -9
- package/src/env.d.ts +10 -28
- package/src/http/index.ts +105 -142
- package/src/index.tsx +0 -12
- package/src/internal.d.ts +1 -1
- package/src/middleware/index.ts +42 -49
- package/src/router.tsx +4 -3
- package/src/server/StartServer.tsx +3 -7
- package/src/server/assets/PatchVirtualDevStyles.tsx +31 -0
- package/src/server/assets/index.ts +1 -1
- package/src/server/assets/render.tsx +6 -2
- package/src/server/collect-styles.ts +49 -73
- package/src/server/fetchEvent.spec.ts +71 -75
- package/src/server/fetchEvent.ts +17 -17
- package/src/server/handler.ts +138 -129
- package/src/server/index.tsx +13 -0
- package/src/server/manifest/client-manifest.ts +1 -1
- package/src/server/manifest/dev-client-manifest.ts +7 -5
- package/src/server/manifest/dev-ssr-manifest.ts +8 -6
- package/src/server/manifest/prod-client-manifest.ts +7 -4
- package/src/server/manifest/prod-ssr-manifest.ts +78 -94
- package/src/server/manifest/ssr-manifest.ts +4 -2
- package/src/server/routes.ts +96 -108
- package/src/server/server-fns-runtime.ts +3 -3
- package/src/server/server-functions-handler.ts +294 -319
- package/src/server/server-runtime.ts +13 -13
- package/src/server/spa/StartServer.tsx +2 -0
- package/src/server/spa/handler.ts +12 -12
- package/src/server/types.ts +46 -46
- package/src/server/util.ts +4 -4
- package/src/shared/ErrorBoundary.tsx +1 -1
- package/src/shared/HttpHeader.tsx +20 -20
- package/src/shared/HttpStatusCode.ts +14 -14
- package/src/shared/clientOnly.ts +3 -3
- package/src/shared/dev-overlay/CodeView.tsx +43 -46
- package/src/shared/dev-overlay/DevOverlayDialog.tsx +4 -4
- package/src/shared/dev-overlay/createStackFrame.ts +59 -62
- package/src/shared/dev-overlay/env.d.ts +2 -2
- package/src/shared/dev-overlay/get-source-map.ts +5 -7
- package/src/shared/dev-overlay/icons.tsx +289 -121
- package/src/shared/dev-overlay/index.tsx +1 -1
- package/src/shared/lazy.ts +4 -3
- package/src/shared/serverFunction.ts +1 -1
- package/src/virtual.d.ts +10 -10
- package/tsconfig.json +2 -2
- package/vitest.config.ts +2 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @solidjs/start
|
|
2
|
+
|
|
3
|
+
## 2.0.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 10bf932: Fix path resolution on Windows
|
|
8
|
+
- 40d5a27: fix onBeforeResponse
|
|
9
|
+
- 9201e71: fix text/html missing when ssr is false
|
|
10
|
+
- a9cd2cc: add `vite preview` support
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 7077a49: Fixed CSS from shared chunks not being collected via the chunk name.
|
|
15
|
+
- a620eeb: Fixed virtual module CSS not being collected in vite dev.
|
|
16
|
+
|
|
17
|
+
## 2.0.0-alpha.1
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 8256190: Rework `@solidjs/start/env`
|
|
22
|
+
- 6cbba24: Fix multiple Set-Cookie headers being lost on redirect responses
|
|
23
|
+
- d4cc548: ## Bump Seroval
|
|
24
|
+
|
|
25
|
+
- version `1.4.1`
|
|
26
|
+
|
|
27
|
+
- dd40610: Handle base url in api routes
|
|
28
|
+
- 0c8a5e2: export server types from /server
|
package/dist/client/mount.d.ts
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { type MountableElement } from "solid-js/web";
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* Read more: https://docs.solidjs.com/solid-start/reference/client/mount
|
|
6
|
-
*/
|
|
7
|
-
export declare function mount(fn: () => JSX.Element, el: MountableElement): (() => void) | undefined;
|
|
1
|
+
export { hydrate as mount } from "solid-js/web";
|
package/dist/client/mount.js
CHANGED
|
@@ -1,99 +1 @@
|
|
|
1
|
-
|
|
2
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return path;
|
|
8
|
-
};
|
|
9
|
-
import { createStore } from "solid-js/store";
|
|
10
|
-
import { createComponent, getHydrationKey, getOwner, hydrate } from "solid-js/web";
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* Read more: https://docs.solidjs.com/solid-start/reference/client/mount
|
|
14
|
-
*/
|
|
15
|
-
export function mount(fn, el) {
|
|
16
|
-
if (import.meta.env.START_ISLANDS) {
|
|
17
|
-
const map = new WeakMap();
|
|
18
|
-
async function mountIsland(el) {
|
|
19
|
-
if (el.dataset.css) {
|
|
20
|
-
let css = JSON.parse(el.dataset.css);
|
|
21
|
-
for (let href of css) {
|
|
22
|
-
if (!document.querySelector(`link[href="${href}"]`)) {
|
|
23
|
-
let link = document.createElement("link");
|
|
24
|
-
link.rel = "stylesheet";
|
|
25
|
-
link.href = href;
|
|
26
|
-
document.head.appendChild(link);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
let mod = await import(__rewriteRelativeImportExtension(
|
|
31
|
-
/* @vite-ignore */
|
|
32
|
-
import.meta.env.MANIFEST["client"].chunks[el.dataset.id.split("#")[0]].output
|
|
33
|
-
.path, true));
|
|
34
|
-
if (!mod || !el.dataset.hk)
|
|
35
|
-
return;
|
|
36
|
-
let Component = mod[el.dataset.id.split("#")[1]];
|
|
37
|
-
let hk = el.dataset.hk;
|
|
38
|
-
// _$DEBUG("hydrating island", el.dataset.island, hk.slice(0, hk.length - 1) + `1-`, el);
|
|
39
|
-
let props = createStore({
|
|
40
|
-
...JSON.parse(el.dataset.props),
|
|
41
|
-
get children() {
|
|
42
|
-
const p = el.getElementsByTagName("solid-children");
|
|
43
|
-
getHydrationKey();
|
|
44
|
-
[...p].forEach(a => {
|
|
45
|
-
a.__$owner = getOwner();
|
|
46
|
-
});
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
map.set(el, props);
|
|
51
|
-
hydrate(() => createComponent(Component, props[0]), el, {
|
|
52
|
-
renderId: hk.slice(0, hk.length - 1) + `${1 + Number(el.dataset.offset)}-`,
|
|
53
|
-
owner: lookupOwner(el)
|
|
54
|
-
});
|
|
55
|
-
delete el.dataset.hk;
|
|
56
|
-
el.dataset.hkk = hk;
|
|
57
|
-
}
|
|
58
|
-
let queue = [];
|
|
59
|
-
let queued = false;
|
|
60
|
-
function runTaskQueue(info) {
|
|
61
|
-
while (info.timeRemaining() > 0 && queue.length) {
|
|
62
|
-
mountIsland(queue.shift());
|
|
63
|
-
}
|
|
64
|
-
if (queue.length) {
|
|
65
|
-
requestIdleCallback(runTaskQueue);
|
|
66
|
-
}
|
|
67
|
-
else
|
|
68
|
-
queued = false;
|
|
69
|
-
}
|
|
70
|
-
const hydrateIslands = () => {
|
|
71
|
-
const islands = document.querySelectorAll("solid-island[data-hk]");
|
|
72
|
-
const assets = new Set();
|
|
73
|
-
islands.forEach((el) => el.dataset.id && assets.add(el.dataset.id));
|
|
74
|
-
Promise.all([...assets].map(asset => import(
|
|
75
|
-
/* @vite-ignore */ import.meta.env.MANIFEST["client"].chunks[asset.split("#")[0]].output.path)))
|
|
76
|
-
.then(() => {
|
|
77
|
-
islands.forEach((el) => {
|
|
78
|
-
if (el.dataset.when === "idle" && "requestIdleCallback" in window) {
|
|
79
|
-
if (!queued) {
|
|
80
|
-
queued = true;
|
|
81
|
-
requestIdleCallback(runTaskQueue);
|
|
82
|
-
}
|
|
83
|
-
queue.push(el);
|
|
84
|
-
}
|
|
85
|
-
else
|
|
86
|
-
mountIsland(el);
|
|
87
|
-
});
|
|
88
|
-
})
|
|
89
|
-
.catch(e => console.error(e));
|
|
90
|
-
};
|
|
91
|
-
function lookupOwner(el) {
|
|
92
|
-
const parent = el.closest("solid-children");
|
|
93
|
-
return parent && parent.__$owner;
|
|
94
|
-
}
|
|
95
|
-
hydrateIslands();
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
return hydrate(fn, el);
|
|
99
|
-
}
|
|
1
|
+
export { hydrate as mount } from "solid-js/web";
|
package/dist/config/constants.js
CHANGED
|
@@ -8,9 +8,9 @@ export const VIRTUAL_MODULES = {
|
|
|
8
8
|
serverFnManifest: "solidstart:server-fn-manifest",
|
|
9
9
|
clientEntry: "solid-start:client-entry",
|
|
10
10
|
serverEntry: "solid-start:server-entry",
|
|
11
|
-
app: "solid-start:app"
|
|
11
|
+
app: "solid-start:app",
|
|
12
12
|
};
|
|
13
13
|
export const VITE_ENVIRONMENTS = {
|
|
14
14
|
client: "client",
|
|
15
|
-
server: "ssr"
|
|
15
|
+
server: "ssr",
|
|
16
16
|
};
|
|
@@ -5,6 +5,16 @@ export function devServer() {
|
|
|
5
5
|
return [
|
|
6
6
|
{
|
|
7
7
|
name: "solid-start-dev-server",
|
|
8
|
+
configurePreviewServer(server) {
|
|
9
|
+
return () => {
|
|
10
|
+
server.middlewares.use(async (req, res) => {
|
|
11
|
+
res.setHeader("content-encoding", "identity");
|
|
12
|
+
const webReq = new NodeRequest({ req, res });
|
|
13
|
+
const def = await import(process.cwd() + "/dist/server/entry-server.js");
|
|
14
|
+
sendNodeResponse(res, await def.default.fetch(webReq));
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
},
|
|
8
18
|
configureServer(viteDevServer) {
|
|
9
19
|
globalThis.VITE_DEV_SERVER = viteDevServer;
|
|
10
20
|
return async () => {
|
package/dist/config/fs-router.js
CHANGED
|
@@ -31,17 +31,15 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
const [_, exports] = analyzeModule(src);
|
|
34
|
-
const hasDefault = !!exports.find(
|
|
35
|
-
const hasRouteConfig = !!exports.find(
|
|
34
|
+
const hasDefault = !!exports.find(e => e.n === "default");
|
|
35
|
+
const hasRouteConfig = !!exports.find(e => e.n === "route");
|
|
36
36
|
if (hasDefault) {
|
|
37
37
|
return {
|
|
38
38
|
page: true,
|
|
39
39
|
$component: {
|
|
40
40
|
src: src,
|
|
41
41
|
pick: [
|
|
42
|
-
...exports
|
|
43
|
-
.filter((e) => e.n === e.ln && e.n !== "route")
|
|
44
|
-
.map((e) => e.n),
|
|
42
|
+
...exports.filter(e => e.n === e.ln && e.n !== "route").map(e => e.n),
|
|
45
43
|
"default",
|
|
46
44
|
"$css",
|
|
47
45
|
],
|
|
@@ -58,15 +56,7 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
|
-
const HTTP_METHODS = [
|
|
62
|
-
"HEAD",
|
|
63
|
-
"GET",
|
|
64
|
-
"POST",
|
|
65
|
-
"PUT",
|
|
66
|
-
"DELETE",
|
|
67
|
-
"PATCH",
|
|
68
|
-
"OPTIONS",
|
|
69
|
-
];
|
|
59
|
+
const HTTP_METHODS = ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
|
|
70
60
|
function createHTTPHandlers(src, exports) {
|
|
71
61
|
const handlers = {};
|
|
72
62
|
for (const exp of exports) {
|
|
@@ -75,7 +65,7 @@ function createHTTPHandlers(src, exports) {
|
|
|
75
65
|
src: src,
|
|
76
66
|
pick: [exp.n],
|
|
77
67
|
};
|
|
78
|
-
if (exp.n === "GET" && !exports.find(
|
|
68
|
+
if (exp.n === "GET" && !exports.find(exp => exp.n === "HEAD")) {
|
|
79
69
|
handlers.$HEAD = {
|
|
80
70
|
src: src,
|
|
81
71
|
pick: [exp.n],
|
|
@@ -119,9 +109,9 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
|
119
109
|
};
|
|
120
110
|
}
|
|
121
111
|
const [_, exports] = analyzeModule(src);
|
|
122
|
-
const hasRouteConfig = exports.find(
|
|
123
|
-
const hasDefault = !!exports.find(
|
|
124
|
-
const hasAPIRoutes = !!exports.find(
|
|
112
|
+
const hasRouteConfig = exports.find(e => e.n === "route");
|
|
113
|
+
const hasDefault = !!exports.find(e => e.n === "default");
|
|
114
|
+
const hasAPIRoutes = !!exports.find(exp => HTTP_METHODS.includes(exp.n));
|
|
125
115
|
if (hasDefault || hasAPIRoutes) {
|
|
126
116
|
return {
|
|
127
117
|
page: hasDefault,
|
|
@@ -130,10 +120,8 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
|
130
120
|
src: src,
|
|
131
121
|
pick: [
|
|
132
122
|
...exports
|
|
133
|
-
.filter(
|
|
134
|
-
e.n
|
|
135
|
-
!HTTP_METHODS.includes(e.n))
|
|
136
|
-
.map((e) => e.n),
|
|
123
|
+
.filter(e => e.n === e.ln && e.n !== "route" && !HTTP_METHODS.includes(e.n))
|
|
124
|
+
.map(e => e.n),
|
|
137
125
|
"default",
|
|
138
126
|
"$css",
|
|
139
127
|
],
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { moduleId } from "./index.js";
|
|
2
2
|
function setupWatcher(watcher, routes) {
|
|
3
|
-
watcher.on("unlink",
|
|
4
|
-
watcher.on("add",
|
|
5
|
-
watcher.on("change",
|
|
3
|
+
watcher.on("unlink", path => routes.removeRoute(path));
|
|
4
|
+
watcher.on("add", path => routes.addRoute(path));
|
|
5
|
+
watcher.on("change", path => routes.updateRoute(path));
|
|
6
6
|
}
|
|
7
7
|
function createRoutesReloader(server, routes, environment) {
|
|
8
8
|
routes.addEventListener("reload", handleRoutesReload);
|
|
@@ -38,7 +38,7 @@ export const fileSystemWatcher = (routers) => {
|
|
|
38
38
|
const plugin = {
|
|
39
39
|
name: "fs-watcher",
|
|
40
40
|
async configureServer(server) {
|
|
41
|
-
Object.keys(routers).forEach(
|
|
41
|
+
Object.keys(routers).forEach(environment => {
|
|
42
42
|
const router = globalThis.ROUTERS[environment];
|
|
43
43
|
setupWatcher(server.watcher, router);
|
|
44
44
|
createRoutesReloader(server, router, environment);
|
|
@@ -43,10 +43,8 @@ export function fsRoutes({ routers }) {
|
|
|
43
43
|
const buildId = `${v.src}?${v.pick.map((p) => `pick=${p}`).join("&")}`;
|
|
44
44
|
return {
|
|
45
45
|
src: relative(root, buildId),
|
|
46
|
-
build: isBuild
|
|
47
|
-
|
|
48
|
-
: undefined,
|
|
49
|
-
import: `_$() => import(/* @vite-ignore */ '${buildId}')$_`
|
|
46
|
+
build: isBuild ? `_$() => import(/* @vite-ignore */ '${buildId}')$_` : undefined,
|
|
47
|
+
import: `_$() => import(/* @vite-ignore */ '${buildId}')$_`,
|
|
50
48
|
};
|
|
51
49
|
}
|
|
52
50
|
return v;
|
|
@@ -90,13 +88,13 @@ function jsCode() {
|
|
|
90
88
|
delete id["default"];
|
|
91
89
|
return Object.keys(id).length > 0
|
|
92
90
|
? `{ ${Object.keys(id)
|
|
93
|
-
.map(
|
|
91
|
+
.map(k => `${k} as ${id[k]}`)
|
|
94
92
|
.join(", ")} }`
|
|
95
93
|
: "";
|
|
96
94
|
};
|
|
97
95
|
const getImportStatements = () => {
|
|
98
96
|
return `${[...imports.keys()]
|
|
99
|
-
.map(
|
|
97
|
+
.map(i => `import ${imports.get(i).default
|
|
100
98
|
? `${imports.get(i).default}${Object.keys(imports.get(i)).length > 1 ? ", " : ""}`
|
|
101
99
|
: ""} ${getNamedExport(i)} from '${i}';`)
|
|
102
100
|
.join("\n")}`;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { init } from "es-module-lexer";
|
|
2
|
-
import { parse } from "es-module-lexer";
|
|
1
|
+
import { init, parse } from "es-module-lexer";
|
|
3
2
|
import esbuild from "esbuild";
|
|
4
3
|
import fg from "fast-glob";
|
|
5
4
|
import fs from "fs";
|
|
6
5
|
import micromatch from "micromatch";
|
|
7
6
|
import { posix } from "path";
|
|
8
7
|
import { pathToRegexp } from "path-to-regexp";
|
|
9
|
-
import {
|
|
8
|
+
import { normalizePath } from "vite";
|
|
10
9
|
export { pathToRegexp };
|
|
11
10
|
export const glob = (path) => fg.sync(path, { absolute: true });
|
|
12
11
|
export function cleanPath(src, config) {
|
|
@@ -18,7 +17,7 @@ export function analyzeModule(src) {
|
|
|
18
17
|
return parse(esbuild.transformSync(fs.readFileSync(src, "utf-8"), {
|
|
19
18
|
jsx: "transform",
|
|
20
19
|
format: "esm",
|
|
21
|
-
loader: "tsx"
|
|
20
|
+
loader: "tsx",
|
|
22
21
|
}).code, src);
|
|
23
22
|
}
|
|
24
23
|
export class BaseFileSystemRouter extends EventTarget {
|
|
@@ -61,9 +60,9 @@ export class BaseFileSystemRouter extends EventTarget {
|
|
|
61
60
|
return {
|
|
62
61
|
$component: {
|
|
63
62
|
src: src,
|
|
64
|
-
pick: ["default", "$css"]
|
|
63
|
+
pick: ["default", "$css"],
|
|
65
64
|
},
|
|
66
|
-
path
|
|
65
|
+
path,
|
|
67
66
|
// filePath: src
|
|
68
67
|
};
|
|
69
68
|
}
|
|
@@ -76,7 +75,7 @@ export class BaseFileSystemRouter extends EventTarget {
|
|
|
76
75
|
this.routes.push(route);
|
|
77
76
|
}
|
|
78
77
|
async addRoute(src) {
|
|
79
|
-
src =
|
|
78
|
+
src = normalizePath(src);
|
|
80
79
|
if (this.isRoute(src)) {
|
|
81
80
|
try {
|
|
82
81
|
const route = this.toRoute(src);
|
|
@@ -94,12 +93,12 @@ export class BaseFileSystemRouter extends EventTarget {
|
|
|
94
93
|
this.dispatchEvent(new Event("reload", {
|
|
95
94
|
// @ts-ignore
|
|
96
95
|
detail: {
|
|
97
|
-
route
|
|
98
|
-
}
|
|
96
|
+
route,
|
|
97
|
+
},
|
|
99
98
|
}));
|
|
100
99
|
}
|
|
101
100
|
async updateRoute(src) {
|
|
102
|
-
src =
|
|
101
|
+
src = normalizePath(src);
|
|
103
102
|
if (this.isRoute(src)) {
|
|
104
103
|
try {
|
|
105
104
|
const route = this.toRoute(src);
|
|
@@ -115,7 +114,7 @@ export class BaseFileSystemRouter extends EventTarget {
|
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
removeRoute(src) {
|
|
118
|
-
src =
|
|
117
|
+
src = normalizePath(src);
|
|
119
118
|
if (this.isRoute(src)) {
|
|
120
119
|
const path = this.toPath(src);
|
|
121
120
|
if (path === undefined) {
|
|
@@ -18,9 +18,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
18
18
|
if (path.node.type === "ArrowFunctionExpression") {
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
|
-
return path.node.id && path.node.id.type === "Identifier"
|
|
22
|
-
? path.get("id")
|
|
23
|
-
: null;
|
|
21
|
+
return path.node.id && path.node.id.type === "Identifier" ? path.get("id") : null;
|
|
24
22
|
}
|
|
25
23
|
function isIdentifierReferenced(ident) {
|
|
26
24
|
const b = ident.scope.getBinding(ident.node.name);
|
|
@@ -28,7 +26,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
28
26
|
if (b.path.type === "FunctionDeclaration") {
|
|
29
27
|
return !b.constantViolations
|
|
30
28
|
.concat(b.referencePaths)
|
|
31
|
-
.every(
|
|
29
|
+
.every(ref => ref.findParent(p => p === b.path));
|
|
32
30
|
}
|
|
33
31
|
return true;
|
|
34
32
|
}
|
|
@@ -63,7 +61,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
63
61
|
else if (variablePath.node.id.type === "ObjectPattern") {
|
|
64
62
|
const pattern = variablePath.get("id");
|
|
65
63
|
const properties = pattern.get("properties");
|
|
66
|
-
properties.forEach(
|
|
64
|
+
properties.forEach(p => {
|
|
67
65
|
const local = p.get(p.node.type === "ObjectProperty"
|
|
68
66
|
? "value"
|
|
69
67
|
: p.node.type === "RestElement"
|
|
@@ -79,7 +77,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
79
77
|
else if (variablePath.node.id.type === "ArrayPattern") {
|
|
80
78
|
const pattern = variablePath.get("id");
|
|
81
79
|
const elements = pattern.get("elements");
|
|
82
|
-
elements.forEach(
|
|
80
|
+
elements.forEach(e => {
|
|
83
81
|
let local;
|
|
84
82
|
if (e.node && e.node.type === "Identifier") {
|
|
85
83
|
local = e;
|
|
@@ -109,7 +107,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
109
107
|
}
|
|
110
108
|
const specifiers = exportNamedPath.get("specifiers");
|
|
111
109
|
if (specifiers.length) {
|
|
112
|
-
specifiers.forEach(
|
|
110
|
+
specifiers.forEach(s => {
|
|
113
111
|
if (t.isIdentifier(s.node.exported)
|
|
114
112
|
? s.node.exported.name
|
|
115
113
|
: state.opts.pick.includes(s.node.exported.value)) {
|
|
@@ -128,16 +126,14 @@ function treeShakeTransform({ types: t }) {
|
|
|
128
126
|
switch (decl.node.type) {
|
|
129
127
|
case "FunctionDeclaration": {
|
|
130
128
|
const name = decl.node.id?.name;
|
|
131
|
-
if (name &&
|
|
132
|
-
state.opts.pick &&
|
|
133
|
-
!state.opts.pick.includes(name)) {
|
|
129
|
+
if (name && state.opts.pick && !state.opts.pick.includes(name)) {
|
|
134
130
|
exportNamedPath.remove();
|
|
135
131
|
}
|
|
136
132
|
break;
|
|
137
133
|
}
|
|
138
134
|
case "VariableDeclaration": {
|
|
139
135
|
const inner = decl.get("declarations");
|
|
140
|
-
inner.forEach(
|
|
136
|
+
inner.forEach(d => {
|
|
141
137
|
if (d.node.id.type !== "Identifier") {
|
|
142
138
|
return;
|
|
143
139
|
}
|
|
@@ -171,10 +167,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
171
167
|
let count = 0;
|
|
172
168
|
const sweepFunction = (sweepPath) => {
|
|
173
169
|
const ident = getIdentifier(sweepPath);
|
|
174
|
-
if (ident &&
|
|
175
|
-
ident.node &&
|
|
176
|
-
refs.has(ident) &&
|
|
177
|
-
!isIdentifierReferenced(ident)) {
|
|
170
|
+
if (ident && ident.node && refs.has(ident) && !isIdentifierReferenced(ident)) {
|
|
178
171
|
++count;
|
|
179
172
|
if (t.isAssignmentExpression(sweepPath.parentPath) ||
|
|
180
173
|
t.isVariableDeclarator(sweepPath.parentPath)) {
|
|
@@ -211,7 +204,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
211
204
|
const pattern = variablePath.get("id");
|
|
212
205
|
const beforeCount = count;
|
|
213
206
|
const properties = pattern.get("properties");
|
|
214
|
-
properties.forEach(
|
|
207
|
+
properties.forEach(p => {
|
|
215
208
|
const local = p.get(p.node.type === "ObjectProperty"
|
|
216
209
|
? "value"
|
|
217
210
|
: p.node.type === "RestElement"
|
|
@@ -224,8 +217,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
224
217
|
p.remove();
|
|
225
218
|
}
|
|
226
219
|
});
|
|
227
|
-
if (beforeCount !== count &&
|
|
228
|
-
pattern.get("properties").length < 1) {
|
|
220
|
+
if (beforeCount !== count && pattern.get("properties").length < 1) {
|
|
229
221
|
variablePath.remove();
|
|
230
222
|
}
|
|
231
223
|
}
|
|
@@ -233,7 +225,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
233
225
|
const pattern = variablePath.get("id");
|
|
234
226
|
const beforeCount = count;
|
|
235
227
|
const elements = pattern.get("elements");
|
|
236
|
-
elements.forEach(
|
|
228
|
+
elements.forEach(e => {
|
|
237
229
|
let local;
|
|
238
230
|
if (e.node && e.node.type === "Identifier") {
|
|
239
231
|
local = e;
|
|
@@ -249,8 +241,7 @@ function treeShakeTransform({ types: t }) {
|
|
|
249
241
|
e.remove();
|
|
250
242
|
}
|
|
251
243
|
});
|
|
252
|
-
if (beforeCount !== count &&
|
|
253
|
-
pattern.get("elements").length < 1) {
|
|
244
|
+
if (beforeCount !== count && pattern.get("elements").length < 1) {
|
|
254
245
|
variablePath.remove();
|
|
255
246
|
}
|
|
256
247
|
}
|