@solidjs/start 2.0.0-beta.0 → 2.0.0-beta.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.
Files changed (154) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +5 -4
  3. package/src/config/dev-server.ts +5 -1
  4. package/dist/client/StartClient.d.ts +0 -7
  5. package/dist/client/StartClient.jsx +0 -26
  6. package/dist/client/index.d.ts +0 -2
  7. package/dist/client/index.jsx +0 -2
  8. package/dist/client/mount.d.ts +0 -1
  9. package/dist/client/mount.js +0 -1
  10. package/dist/client/spa/index.d.ts +0 -4
  11. package/dist/client/spa/index.jsx +0 -5
  12. package/dist/config/constants.d.ts +0 -16
  13. package/dist/config/constants.js +0 -16
  14. package/dist/config/dev-server.d.ts +0 -2
  15. package/dist/config/dev-server.js +0 -126
  16. package/dist/config/env.d.ts +0 -19
  17. package/dist/config/env.js +0 -81
  18. package/dist/config/fs-router.d.ts +0 -37
  19. package/dist/config/fs-router.js +0 -141
  20. package/dist/config/fs-routes/fs-watcher.d.ts +0 -3
  21. package/dist/config/fs-routes/fs-watcher.js +0 -53
  22. package/dist/config/fs-routes/index.d.ts +0 -7
  23. package/dist/config/fs-routes/index.js +0 -107
  24. package/dist/config/fs-routes/router.d.ts +0 -42
  25. package/dist/config/fs-routes/router.js +0 -148
  26. package/dist/config/fs-routes/tree-shake.d.ts +0 -2
  27. package/dist/config/fs-routes/tree-shake.js +0 -305
  28. package/dist/config/index.d.ts +0 -25
  29. package/dist/config/index.js +0 -217
  30. package/dist/config/lazy.d.ts +0 -3
  31. package/dist/config/lazy.js +0 -114
  32. package/dist/config/manifest.d.ts +0 -3
  33. package/dist/config/manifest.js +0 -109
  34. package/dist/config/utils.d.ts +0 -4
  35. package/dist/config/utils.js +0 -6
  36. package/dist/config/vite-utils.d.ts +0 -21
  37. package/dist/config/vite-utils.js +0 -85
  38. package/dist/directives/bubble-function-declaration.d.ts +0 -3
  39. package/dist/directives/bubble-function-declaration.js +0 -23
  40. package/dist/directives/compile.d.ts +0 -9
  41. package/dist/directives/compile.js +0 -40
  42. package/dist/directives/generate-unique-name.d.ts +0 -3
  43. package/dist/directives/generate-unique-name.js +0 -16
  44. package/dist/directives/get-descriptive-name.d.ts +0 -2
  45. package/dist/directives/get-descriptive-name.js +0 -37
  46. package/dist/directives/get-import-identifier.d.ts +0 -4
  47. package/dist/directives/get-import-identifier.js +0 -19
  48. package/dist/directives/get-root-statement-path.d.ts +0 -2
  49. package/dist/directives/get-root-statement-path.js +0 -12
  50. package/dist/directives/index.d.ts +0 -14
  51. package/dist/directives/index.js +0 -170
  52. package/dist/directives/is-statement-top-level.d.ts +0 -3
  53. package/dist/directives/is-statement-top-level.js +0 -9
  54. package/dist/directives/paths.d.ts +0 -9
  55. package/dist/directives/paths.js +0 -36
  56. package/dist/directives/plugin.d.ts +0 -21
  57. package/dist/directives/plugin.js +0 -302
  58. package/dist/directives/remove-unused-variables.d.ts +0 -3
  59. package/dist/directives/remove-unused-variables.js +0 -66
  60. package/dist/directives/types.d.ts +0 -10
  61. package/dist/directives/types.js +0 -1
  62. package/dist/directives/xxhash32.d.ts +0 -6
  63. package/dist/directives/xxhash32.js +0 -193
  64. package/dist/fns/client.d.ts +0 -3
  65. package/dist/fns/client.js +0 -106
  66. package/dist/fns/handler.d.ts +0 -5
  67. package/dist/fns/handler.js +0 -269
  68. package/dist/fns/registration.d.ts +0 -2
  69. package/dist/fns/registration.js +0 -12
  70. package/dist/fns/serialization.d.ts +0 -6
  71. package/dist/fns/serialization.js +0 -208
  72. package/dist/fns/server.d.ts +0 -7
  73. package/dist/fns/server.js +0 -38
  74. package/dist/fns/shared.d.ts +0 -17
  75. package/dist/fns/shared.js +0 -105
  76. package/dist/http/index.d.ts +0 -81
  77. package/dist/http/index.js +0 -129
  78. package/dist/index.d.ts +0 -5
  79. package/dist/index.jsx +0 -6
  80. package/dist/middleware/index.d.ts +0 -38
  81. package/dist/middleware/index.js +0 -59
  82. package/dist/router.d.ts +0 -6
  83. package/dist/router.jsx +0 -29
  84. package/dist/server/StartServer.d.ts +0 -9
  85. package/dist/server/StartServer.jsx +0 -34
  86. package/dist/server/assets/PatchVirtualDevStyles.d.ts +0 -4
  87. package/dist/server/assets/PatchVirtualDevStyles.jsx +0 -28
  88. package/dist/server/assets/index.d.ts +0 -2
  89. package/dist/server/assets/index.js +0 -52
  90. package/dist/server/assets/render.d.ts +0 -19
  91. package/dist/server/assets/render.jsx +0 -14
  92. package/dist/server/collect-styles.d.ts +0 -3
  93. package/dist/server/collect-styles.js +0 -57
  94. package/dist/server/fetchEvent.d.ts +0 -7
  95. package/dist/server/fetchEvent.js +0 -26
  96. package/dist/server/handler.d.ts +0 -64
  97. package/dist/server/handler.js +0 -222
  98. package/dist/server/index.d.ts +0 -9
  99. package/dist/server/index.jsx +0 -14
  100. package/dist/server/manifest/client-manifest.d.ts +0 -9
  101. package/dist/server/manifest/client-manifest.js +0 -6
  102. package/dist/server/manifest/dev-client-manifest.d.ts +0 -4
  103. package/dist/server/manifest/dev-client-manifest.js +0 -24
  104. package/dist/server/manifest/dev-ssr-manifest.d.ts +0 -5
  105. package/dist/server/manifest/dev-ssr-manifest.js +0 -23
  106. package/dist/server/manifest/prod-client-manifest.d.ts +0 -5
  107. package/dist/server/manifest/prod-client-manifest.js +0 -26
  108. package/dist/server/manifest/prod-ssr-manifest.d.ts +0 -6
  109. package/dist/server/manifest/prod-ssr-manifest.js +0 -85
  110. package/dist/server/manifest/ssr-manifest.d.ts +0 -4
  111. package/dist/server/manifest/ssr-manifest.js +0 -6
  112. package/dist/server/routes.d.ts +0 -23
  113. package/dist/server/routes.js +0 -74
  114. package/dist/server/spa/StartServer.d.ts +0 -9
  115. package/dist/server/spa/StartServer.jsx +0 -25
  116. package/dist/server/spa/handler.d.ts +0 -36
  117. package/dist/server/spa/handler.js +0 -20
  118. package/dist/server/spa/index.d.ts +0 -4
  119. package/dist/server/spa/index.jsx +0 -5
  120. package/dist/server/types.d.ts +0 -75
  121. package/dist/server/types.js +0 -1
  122. package/dist/server/util.d.ts +0 -2
  123. package/dist/server/util.js +0 -8
  124. package/dist/shared/ErrorBoundary.d.ts +0 -3
  125. package/dist/shared/ErrorBoundary.jsx +0 -36
  126. package/dist/shared/GET.d.ts +0 -5
  127. package/dist/shared/GET.js +0 -8
  128. package/dist/shared/HttpHeader.d.ts +0 -10
  129. package/dist/shared/HttpHeader.jsx +0 -38
  130. package/dist/shared/HttpStatusCode.d.ts +0 -9
  131. package/dist/shared/HttpStatusCode.js +0 -18
  132. package/dist/shared/clientOnly.d.ts +0 -12
  133. package/dist/shared/clientOnly.js +0 -27
  134. package/dist/shared/dev-overlay/CodeView.d.ts +0 -7
  135. package/dist/shared/dev-overlay/CodeView.jsx +0 -62
  136. package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +0 -9
  137. package/dist/shared/dev-overlay/DevOverlayDialog.jsx +0 -226
  138. package/dist/shared/dev-overlay/createStackFrame.d.ts +0 -9
  139. package/dist/shared/dev-overlay/createStackFrame.js +0 -56
  140. package/dist/shared/dev-overlay/download.d.ts +0 -1
  141. package/dist/shared/dev-overlay/download.js +0 -6
  142. package/dist/shared/dev-overlay/get-source-map.d.ts +0 -2
  143. package/dist/shared/dev-overlay/get-source-map.js +0 -25
  144. package/dist/shared/dev-overlay/icons.d.ts +0 -28
  145. package/dist/shared/dev-overlay/icons.jsx +0 -150
  146. package/dist/shared/dev-overlay/index.d.ts +0 -5
  147. package/dist/shared/dev-overlay/index.jsx +0 -39
  148. package/dist/shared/dev-overlay/styles.css +0 -292
  149. package/dist/shared/lazy.d.ts +0 -3
  150. package/dist/shared/lazy.js +0 -42
  151. package/dist/shared/serverFunction.d.ts +0 -6
  152. package/dist/shared/serverFunction.js +0 -8
  153. package/dist/utils/debounce.d.ts +0 -4
  154. package/dist/utils/debounce.js +0 -10
@@ -1,107 +0,0 @@
1
- import { relative } from "node:path";
2
- import { fileSystemWatcher } from "./fs-watcher.js";
3
- import { treeShake } from "./tree-shake.js";
4
- export const moduleId = "solid-start:routes";
5
- export function fsRoutes({ routers }) {
6
- globalThis.ROUTERS = routers;
7
- return [
8
- {
9
- name: "solid-start-fs-routes",
10
- enforce: "pre",
11
- resolveId(id) {
12
- if (id === moduleId)
13
- return id;
14
- },
15
- async load(id) {
16
- const root = this.environment.config.root;
17
- const isBuild = this.environment.mode === "build";
18
- if (id !== moduleId)
19
- return;
20
- const js = jsCode();
21
- const router = globalThis.ROUTERS[this.environment.name];
22
- const routes = await router.getRoutes();
23
- let routesCode = JSON.stringify(routes ?? [], (k, v) => {
24
- if (v === undefined)
25
- return undefined;
26
- if (k.startsWith("$$")) {
27
- const buildId = `${v.src}?${v.pick.map((p) => `pick=${p}`).join("&")}`;
28
- /**
29
- * @type {{ [key: string]: string }}
30
- */
31
- const refs = {};
32
- for (var pick of v.pick) {
33
- refs[pick] = js.addNamedImport(pick, buildId);
34
- }
35
- return {
36
- require: `_$() => ({ ${Object.entries(refs)
37
- .map(([pick, namedImport]) => `'${pick}': ${namedImport}`)
38
- .join(", ")} })$_`,
39
- // src: isBuild ? relative(root, buildId) : buildId
40
- };
41
- }
42
- else if (k.startsWith("$")) {
43
- const buildId = `${v.src}?${v.pick.map((p) => `pick=${p}`).join("&")}`;
44
- return {
45
- src: relative(root, buildId),
46
- build: isBuild ? `_$() => import('${buildId}')$_` : undefined,
47
- import: `_$() => import('${buildId}')$_`,
48
- };
49
- }
50
- return v;
51
- });
52
- routesCode = routesCode.replaceAll('"_$(', "(").replaceAll(')$_"', ")");
53
- const code = `
54
- ${js.getImportStatements()}
55
- export default ${routesCode}`;
56
- return code;
57
- },
58
- },
59
- treeShake(),
60
- fileSystemWatcher(routers),
61
- ];
62
- }
63
- function jsCode() {
64
- const imports = new Map();
65
- let vars = 0;
66
- function addImport(p) {
67
- let id = imports.get(p);
68
- if (!id) {
69
- id = {};
70
- imports.set(p, id);
71
- }
72
- const d = "routeData" + vars++;
73
- id["default"] = d;
74
- return d;
75
- }
76
- function addNamedImport(name, p) {
77
- let id = imports.get(p);
78
- if (!id) {
79
- id = {};
80
- imports.set(p, id);
81
- }
82
- const d = "routeData" + vars++;
83
- id[name] = d;
84
- return d;
85
- }
86
- const getNamedExport = (p) => {
87
- const id = imports.get(p);
88
- delete id["default"];
89
- return Object.keys(id).length > 0
90
- ? `{ ${Object.keys(id)
91
- .map(k => `${k} as ${id[k]}`)
92
- .join(", ")} }`
93
- : "";
94
- };
95
- const getImportStatements = () => {
96
- return `${[...imports.keys()]
97
- .map(i => `import ${imports.get(i).default
98
- ? `${imports.get(i).default}${Object.keys(imports.get(i)).length > 1 ? ", " : ""}`
99
- : ""} ${getNamedExport(i)} from '${i}';`)
100
- .join("\n")}`;
101
- };
102
- return {
103
- addImport,
104
- addNamedImport,
105
- getImportStatements,
106
- };
107
- }
@@ -1,42 +0,0 @@
1
- import { pathToRegexp } from "path-to-regexp";
2
- export { pathToRegexp };
3
- export declare const glob: (path: string) => string[];
4
- export type FileSystemRouterConfig = {
5
- dir: string;
6
- extensions: string[];
7
- };
8
- type Route = {
9
- path: string;
10
- } & Record<string, any>;
11
- export declare function cleanPath(src: string, config: FileSystemRouterConfig): string;
12
- export declare function analyzeModule(src: string): readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean, hasModuleSyntax: boolean];
13
- type RouterEvent = CustomEvent<{
14
- route: string;
15
- type: "update" | "remove" | "add";
16
- }>;
17
- export declare class BaseFileSystemRouter extends EventTarget {
18
- routes: Route[];
19
- config: FileSystemRouterConfig;
20
- /**
21
- *
22
- * @param {} config
23
- */
24
- constructor(config: FileSystemRouterConfig);
25
- glob(): string;
26
- buildRoutes(): Promise<any[]>;
27
- isRoute(src: string): boolean;
28
- toPath(src: string): void;
29
- toRoute(src: string): Route | undefined;
30
- /**
31
- * To be attached by vite plugin to the vite dev server
32
- */
33
- update: undefined;
34
- _addRoute(route: Route): boolean;
35
- addRoute(src: string): Promise<void>;
36
- reload(route: string, type: "update" | "remove" | "add"): void;
37
- updateRoute(src_: string): Promise<void>;
38
- removeRoute(src: string): void;
39
- on(type: string, cb: (evt: RouterEvent) => void): () => void;
40
- buildRoutesPromise?: Promise<any[]>;
41
- getRoutes(): Promise<Route[]>;
42
- }
@@ -1,148 +0,0 @@
1
- import { init, parse } from "es-module-lexer";
2
- import esbuild from "esbuild";
3
- import fg from "fast-glob";
4
- import fs from "node:fs";
5
- import micromatch from "micromatch";
6
- import { posix } from "node:path";
7
- import { pathToRegexp } from "path-to-regexp";
8
- import { normalizePath } from "vite";
9
- export { pathToRegexp };
10
- export const glob = (path) => fg.sync(path, { absolute: true });
11
- export function cleanPath(src, config) {
12
- return src
13
- .slice(config.dir.length)
14
- .replace(new RegExp(`\.(${(config.extensions ?? []).join("|")})$`), "");
15
- }
16
- export function analyzeModule(src) {
17
- return parse(esbuild.transformSync(fs.readFileSync(src, "utf-8"), {
18
- jsx: "transform",
19
- format: "esm",
20
- loader: "tsx",
21
- }).code, src);
22
- }
23
- export class BaseFileSystemRouter extends EventTarget {
24
- routes;
25
- config;
26
- /**
27
- *
28
- * @param {} config
29
- */
30
- constructor(config) {
31
- super();
32
- this.routes = [];
33
- this.config = config;
34
- }
35
- glob() {
36
- return (posix.join(fg.convertPathToPattern(this.config.dir), "**/*") +
37
- `.{${this.config.extensions.join(",")}}`);
38
- }
39
- async buildRoutes() {
40
- await init;
41
- for (var src of glob(this.glob())) {
42
- await this.addRoute(src);
43
- }
44
- return this.routes;
45
- }
46
- isRoute(src) {
47
- return Boolean(micromatch(src, this.glob())?.length);
48
- }
49
- toPath(src) {
50
- throw new Error("Not implemented");
51
- }
52
- toRoute(src) {
53
- let path = this.toPath(src);
54
- if (path === undefined)
55
- return;
56
- const [_, exports] = analyzeModule(src);
57
- if (!exports.find(e => e.n === "default")) {
58
- console.warn("No default export", src);
59
- }
60
- return {
61
- $component: {
62
- src: src,
63
- pick: ["default", "$css"],
64
- },
65
- path,
66
- // filePath: src
67
- };
68
- }
69
- /**
70
- * To be attached by vite plugin to the vite dev server
71
- */
72
- update = undefined;
73
- _addRoute(route) {
74
- const idx = this.routes.findIndex(r => r.path === route.path);
75
- if (idx >= 0)
76
- this.routes.splice(idx, 1);
77
- this.routes.push(route);
78
- return idx >= 0;
79
- }
80
- async addRoute(src) {
81
- src = normalizePath(src);
82
- if (this.isRoute(src)) {
83
- try {
84
- const route = this.toRoute(src);
85
- if (route) {
86
- this._addRoute(route);
87
- this.reload(route.path, "add");
88
- }
89
- }
90
- catch (e) {
91
- console.error(e);
92
- }
93
- }
94
- }
95
- reload(route, type) {
96
- this.dispatchEvent(new CustomEvent("reload", {
97
- detail: {
98
- route,
99
- type,
100
- },
101
- }));
102
- }
103
- async updateRoute(src_) {
104
- const src = normalizePath(src_);
105
- if (this.isRoute(src)) {
106
- try {
107
- const route = this.toRoute(src);
108
- if (route) {
109
- const updated = this._addRoute(route);
110
- this.reload(route.path, updated ? "update" : "add");
111
- }
112
- else {
113
- this.removeRoute(src_);
114
- }
115
- }
116
- catch (e) {
117
- console.error(e);
118
- }
119
- // this.update?.();
120
- }
121
- }
122
- removeRoute(src) {
123
- src = normalizePath(src);
124
- if (this.isRoute(src)) {
125
- const path = this.toPath(src);
126
- if (path === undefined) {
127
- return;
128
- }
129
- const idx = this.routes.findIndex(r => r.path === path);
130
- if (idx === -1)
131
- return;
132
- this.routes.splice(idx, 1);
133
- this.reload(path, "remove");
134
- }
135
- }
136
- on(type, cb) {
137
- this.addEventListener(type, cb);
138
- return () => this.removeEventListener(type, cb);
139
- }
140
- buildRoutesPromise;
141
- async getRoutes() {
142
- if (!this.buildRoutesPromise) {
143
- this.buildRoutesPromise = this.buildRoutes();
144
- }
145
- await this.buildRoutesPromise;
146
- return this.routes;
147
- }
148
- }
@@ -1,2 +0,0 @@
1
- import type { Plugin } from "vite";
2
- export declare function treeShake(): Plugin;
@@ -1,305 +0,0 @@
1
- // All credit for this work goes to the amazing Next.js team.
2
- // https://github.com/vercel/next.js/blob/canary/packages/next/build/babel/plugins/next-ssg-transform.ts
3
- // This is adapted to work with routeData functions. It can be run in two modes, one which preserves the routeData and the Component in the same file, and one which creates a
4
- import { basename } from "pathe";
5
- function treeShakeTransform({ types: t }) {
6
- function getIdentifier(path) {
7
- const parentPath = path.parentPath;
8
- if (parentPath.type === "VariableDeclarator") {
9
- const pp = parentPath;
10
- const name = pp.get("id");
11
- return name.node.type === "Identifier" ? name : null;
12
- }
13
- if (parentPath.type === "AssignmentExpression") {
14
- const pp = parentPath;
15
- const name = pp.get("left");
16
- return name.node.type === "Identifier" ? name : null;
17
- }
18
- if (path.node.type === "ArrowFunctionExpression") {
19
- return null;
20
- }
21
- return path.node.id && path.node.id.type === "Identifier" ? path.get("id") : null;
22
- }
23
- function isIdentifierReferenced(ident) {
24
- const b = ident.scope.getBinding(ident.node.name);
25
- if (b?.referenced) {
26
- if (b.path.type === "FunctionDeclaration") {
27
- return !b.constantViolations
28
- .concat(b.referencePaths)
29
- .every(ref => ref.findParent(p => p === b.path));
30
- }
31
- return true;
32
- }
33
- return false;
34
- }
35
- function markFunction(path, state) {
36
- const ident = getIdentifier(path);
37
- if (ident && ident.node && isIdentifierReferenced(ident)) {
38
- state.refs.add(ident);
39
- }
40
- }
41
- function markImport(path, state) {
42
- const local = path.get("local");
43
- if (isIdentifierReferenced(local)) {
44
- state.refs.add(local);
45
- }
46
- }
47
- return {
48
- visitor: {
49
- Program: {
50
- enter(path, state) {
51
- state.refs = new Set();
52
- state.done = false;
53
- path.traverse({
54
- VariableDeclarator(variablePath, variableState) {
55
- if (variablePath.node.id.type === "Identifier") {
56
- const local = variablePath.get("id");
57
- if (isIdentifierReferenced(local)) {
58
- variableState.refs.add(local);
59
- }
60
- }
61
- else if (variablePath.node.id.type === "ObjectPattern") {
62
- const pattern = variablePath.get("id");
63
- const properties = pattern.get("properties");
64
- properties.forEach(p => {
65
- const local = p.get(p.node.type === "ObjectProperty"
66
- ? "value"
67
- : p.node.type === "RestElement"
68
- ? "argument"
69
- : (() => {
70
- throw new Error("invariant");
71
- })());
72
- if (isIdentifierReferenced(local)) {
73
- variableState.refs.add(local);
74
- }
75
- });
76
- }
77
- else if (variablePath.node.id.type === "ArrayPattern") {
78
- const pattern = variablePath.get("id");
79
- const elements = pattern.get("elements");
80
- elements.forEach(e => {
81
- let local;
82
- if (e.node && e.node.type === "Identifier") {
83
- local = e;
84
- }
85
- else if (e.node && e.node.type === "RestElement") {
86
- local = e.get("argument");
87
- }
88
- else {
89
- return;
90
- }
91
- if (isIdentifierReferenced(local)) {
92
- variableState.refs.add(local);
93
- }
94
- });
95
- }
96
- },
97
- ExportDefaultDeclaration(exportNamedPath) {
98
- // if opts.keep is true, we don't remove the routeData export
99
- if (state.opts.pick && !state.opts.pick.includes("default")) {
100
- exportNamedPath.remove();
101
- }
102
- },
103
- ExportNamedDeclaration(exportNamedPath) {
104
- // if opts.keep is false, we don't remove the routeData export
105
- if (!state.opts.pick) {
106
- return;
107
- }
108
- const specifiers = exportNamedPath.get("specifiers");
109
- if (specifiers.length) {
110
- specifiers.forEach(s => {
111
- if (t.isIdentifier(s.node.exported)
112
- ? s.node.exported.name
113
- : state.opts.pick.includes(s.node.exported.value)) {
114
- s.remove();
115
- }
116
- });
117
- if (exportNamedPath.node.specifiers.length < 1) {
118
- exportNamedPath.remove();
119
- }
120
- return;
121
- }
122
- const decl = exportNamedPath.get("declaration");
123
- if (decl == null || decl.node == null) {
124
- return;
125
- }
126
- switch (decl.node.type) {
127
- case "FunctionDeclaration": {
128
- const name = decl.node.id?.name;
129
- if (name && state.opts.pick && !state.opts.pick.includes(name)) {
130
- exportNamedPath.remove();
131
- }
132
- break;
133
- }
134
- case "VariableDeclaration": {
135
- const inner = decl.get("declarations");
136
- inner.forEach(d => {
137
- if (d.node.id.type !== "Identifier") {
138
- return;
139
- }
140
- const name = d.node.id.name;
141
- if (state.opts.pick && !state.opts.pick.includes(name)) {
142
- d.remove();
143
- }
144
- });
145
- break;
146
- }
147
- default: {
148
- break;
149
- }
150
- }
151
- },
152
- FunctionDeclaration: markFunction,
153
- FunctionExpression: markFunction,
154
- ArrowFunctionExpression: markFunction,
155
- ImportSpecifier: markImport,
156
- ImportDefaultSpecifier: markImport,
157
- ImportNamespaceSpecifier: markImport,
158
- ImportDeclaration: (path, state) => {
159
- if (path.node.source.value.endsWith(".css") &&
160
- state.opts.pick &&
161
- !state.opts.pick.includes("$css")) {
162
- path.remove();
163
- }
164
- },
165
- }, state);
166
- const refs = state.refs;
167
- let count = 0;
168
- const sweepFunction = (sweepPath) => {
169
- const ident = getIdentifier(sweepPath);
170
- if (ident && ident.node && refs.has(ident) && !isIdentifierReferenced(ident)) {
171
- ++count;
172
- if (t.isAssignmentExpression(sweepPath.parentPath) ||
173
- t.isVariableDeclarator(sweepPath.parentPath)) {
174
- sweepPath.parentPath.remove();
175
- }
176
- else {
177
- sweepPath.remove();
178
- }
179
- }
180
- };
181
- function sweepImport(sweepPath) {
182
- const local = sweepPath.get("local");
183
- if (refs.has(local) && !isIdentifierReferenced(local)) {
184
- ++count;
185
- sweepPath.remove();
186
- if (sweepPath.parent.specifiers.length === 0) {
187
- sweepPath.parentPath.remove();
188
- }
189
- }
190
- }
191
- do {
192
- path.scope.crawl();
193
- count = 0;
194
- path.traverse({
195
- VariableDeclarator(variablePath) {
196
- if (variablePath.node.id.type === "Identifier") {
197
- const local = variablePath.get("id");
198
- if (refs.has(local) && !isIdentifierReferenced(local)) {
199
- ++count;
200
- variablePath.remove();
201
- }
202
- }
203
- else if (variablePath.node.id.type === "ObjectPattern") {
204
- const pattern = variablePath.get("id");
205
- const beforeCount = count;
206
- const properties = pattern.get("properties");
207
- properties.forEach(p => {
208
- const local = p.get(p.node.type === "ObjectProperty"
209
- ? "value"
210
- : p.node.type === "RestElement"
211
- ? "argument"
212
- : (() => {
213
- throw new Error("invariant");
214
- })());
215
- if (refs.has(local) && !isIdentifierReferenced(local)) {
216
- ++count;
217
- p.remove();
218
- }
219
- });
220
- if (beforeCount !== count && pattern.get("properties").length < 1) {
221
- variablePath.remove();
222
- }
223
- }
224
- else if (variablePath.node.id.type === "ArrayPattern") {
225
- const pattern = variablePath.get("id");
226
- const beforeCount = count;
227
- const elements = pattern.get("elements");
228
- elements.forEach(e => {
229
- let local;
230
- if (e.node && e.node.type === "Identifier") {
231
- local = e;
232
- }
233
- else if (e.node && e.node.type === "RestElement") {
234
- local = e.get("argument");
235
- }
236
- else {
237
- return;
238
- }
239
- if (refs.has(local) && !isIdentifierReferenced(local)) {
240
- ++count;
241
- e.remove();
242
- }
243
- });
244
- if (beforeCount !== count && pattern.get("elements").length < 1) {
245
- variablePath.remove();
246
- }
247
- }
248
- },
249
- FunctionDeclaration: sweepFunction,
250
- FunctionExpression: sweepFunction,
251
- ArrowFunctionExpression: sweepFunction,
252
- ImportSpecifier: sweepImport,
253
- ImportDefaultSpecifier: sweepImport,
254
- ImportNamespaceSpecifier: sweepImport,
255
- });
256
- } while (count);
257
- },
258
- },
259
- },
260
- };
261
- }
262
- export function treeShake() {
263
- async function transform(id, code) {
264
- const [path, queryString] = id.split("?");
265
- const query = new URLSearchParams(queryString);
266
- if (query.has("pick")) {
267
- const babel = await import("@babel/core");
268
- const transformed = await babel.transformAsync(code, {
269
- plugins: [[treeShakeTransform, { pick: query.getAll("pick") }]],
270
- parserOpts: {
271
- plugins: ["jsx", "typescript"],
272
- },
273
- filename: basename(id),
274
- ast: false,
275
- sourceMaps: true,
276
- configFile: false,
277
- babelrc: false,
278
- sourceFileName: id,
279
- });
280
- return transformed;
281
- }
282
- }
283
- return {
284
- name: "tree-shake",
285
- enforce: "pre",
286
- async transform(code, id) {
287
- const [path, queryString] = id.split("?");
288
- if (!path)
289
- return;
290
- const query = new URLSearchParams(queryString);
291
- const ext = path.split(".").pop();
292
- if (!ext)
293
- return;
294
- if (query.has("pick") && ["js", "jsx", "ts", "tsx"].includes(ext)) {
295
- const transformed = await transform(id, code);
296
- if (!transformed?.code)
297
- return;
298
- return {
299
- code: transformed.code,
300
- map: transformed.map,
301
- };
302
- }
303
- },
304
- };
305
- }
@@ -1,25 +0,0 @@
1
- import type { PluginOption } from "vite";
2
- import { type Options as SolidOptions } from "vite-plugin-solid";
3
- import { type ServerFunctionsOptions } from "../directives/index.ts";
4
- import { type EnvPluginOptions } from "./env.ts";
5
- export interface SolidStartOptions {
6
- solid?: Partial<SolidOptions>;
7
- ssr?: boolean;
8
- routeDir?: string;
9
- extensions?: string[];
10
- middleware?: string;
11
- serialization?: {
12
- /**
13
- * The serialization mode to use for server functions/actions.
14
- * The "js" mode uses a custom binary format that is more efficient than JSON, but requires a custom deserializer (with `eval()`) on the client.
15
- * A strong CSP should block `eval()` executions, which would prevent the "js" mode from working.
16
- * The "json" mode uses JSON for serialization, which is less efficient but can be deserialized with `JSON.parse` on the client.
17
- *
18
- * @default "json"
19
- */
20
- mode?: "js" | "json";
21
- };
22
- env?: EnvPluginOptions;
23
- serverFunctions?: Pick<ServerFunctionsOptions, "filter">;
24
- }
25
- export declare function solidStart(options?: SolidStartOptions): Array<PluginOption>;