@solidjs/start 2.0.0-beta.0 → 2.0.0-beta.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 +14 -0
- package/dist/config/dev-server.js +3 -1
- package/dist/config/fs-router.d.ts +1 -1
- package/dist/http/index.d.ts +4 -4
- package/package.json +11 -5
- package/scripts/build.js +0 -15
- package/scripts/validate-imports.js +0 -316
- package/src/client/StartClient.tsx +0 -34
- package/src/client/index.tsx +0 -2
- package/src/client/mount.ts +0 -1
- package/src/client/spa/index.tsx +0 -9
- package/src/config/constants.ts +0 -19
- package/src/config/dev-server.ts +0 -157
- package/src/config/env.ts +0 -105
- package/src/config/fs-router.ts +0 -162
- package/src/config/fs-routes/fs-watcher.ts +0 -66
- package/src/config/fs-routes/index.ts +0 -136
- package/src/config/fs-routes/router.ts +0 -184
- package/src/config/fs-routes/tree-shake.ts +0 -324
- package/src/config/index.ts +0 -239
- package/src/config/lazy.ts +0 -132
- package/src/config/manifest.ts +0 -120
- package/src/config/utils.ts +0 -5
- package/src/config/vite-utils.ts +0 -113
- package/src/directives/bubble-function-declaration.ts +0 -33
- package/src/directives/compile.ts +0 -54
- package/src/directives/generate-unique-name.ts +0 -22
- package/src/directives/get-descriptive-name.ts +0 -39
- package/src/directives/get-import-identifier.ts +0 -34
- package/src/directives/get-root-statement-path.ts +0 -14
- package/src/directives/index.ts +0 -233
- package/src/directives/is-statement-top-level.ts +0 -13
- package/src/directives/paths.ts +0 -63
- package/src/directives/plugin.ts +0 -389
- package/src/directives/remove-unused-variables.ts +0 -70
- package/src/directives/types.ts +0 -12
- package/src/directives/xxhash32.ts +0 -214
- package/src/env.d.ts +0 -17
- package/src/fns/client.ts +0 -141
- package/src/fns/handler.spec.ts +0 -85
- package/src/fns/handler.ts +0 -287
- package/src/fns/registration.ts +0 -19
- package/src/fns/serialization.ts +0 -250
- package/src/fns/server.ts +0 -46
- package/src/fns/shared.ts +0 -116
- package/src/http/index.ts +0 -216
- package/src/index.tsx +0 -7
- package/src/internal.d.ts +0 -14
- package/src/middleware/index.ts +0 -92
- package/src/router.tsx +0 -37
- package/src/server/StartServer.tsx +0 -58
- package/src/server/assets/PatchVirtualDevStyles.tsx +0 -31
- package/src/server/assets/index.ts +0 -70
- package/src/server/assets/render.tsx +0 -46
- package/src/server/collect-styles.ts +0 -70
- package/src/server/fetchEvent.spec.ts +0 -85
- package/src/server/fetchEvent.ts +0 -36
- package/src/server/handler.ts +0 -261
- package/src/server/index.tsx +0 -29
- package/src/server/manifest/client-manifest.ts +0 -8
- package/src/server/manifest/dev-client-manifest.ts +0 -21
- package/src/server/manifest/dev-ssr-manifest.ts +0 -23
- package/src/server/manifest/prod-client-manifest.ts +0 -21
- package/src/server/manifest/prod-ssr-manifest.ts +0 -109
- package/src/server/manifest/ssr-manifest.ts +0 -10
- package/src/server/routes.ts +0 -126
- package/src/server/spa/StartServer.tsx +0 -42
- package/src/server/spa/handler.ts +0 -29
- package/src/server/spa/index.tsx +0 -5
- package/src/server/types.ts +0 -82
- package/src/server/util.ts +0 -12
- package/src/shared/ErrorBoundary.tsx +0 -52
- package/src/shared/GET.ts +0 -8
- package/src/shared/HttpHeader.tsx +0 -42
- package/src/shared/HttpStatusCode.ts +0 -27
- package/src/shared/clientOnly.ts +0 -44
- package/src/shared/dev-overlay/CodeView.tsx +0 -90
- package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
- package/src/shared/dev-overlay/createStackFrame.ts +0 -74
- package/src/shared/dev-overlay/download.ts +0 -6
- package/src/shared/dev-overlay/env.d.ts +0 -4
- package/src/shared/dev-overlay/get-source-map.ts +0 -33
- package/src/shared/dev-overlay/icons.tsx +0 -456
- package/src/shared/dev-overlay/index.tsx +0 -63
- package/src/shared/dev-overlay/styles.css +0 -292
- package/src/shared/lazy.ts +0 -52
- package/src/shared/serverFunction.ts +0 -10
- package/src/utils/debounce.ts +0 -10
- package/src/virtual.d.ts +0 -27
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -9
package/src/config/manifest.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { type PluginOption, type ViteDevServer, version as viteVersion } from "vite";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
|
|
6
|
-
import { findStylesInModuleGraph } from "../server/collect-styles.ts";
|
|
7
|
-
import { VIRTUAL_MODULES } from "./constants.ts";
|
|
8
|
-
import { type SolidStartOptions } from "./index.ts";
|
|
9
|
-
import { wrapId } from "./vite-utils.ts";
|
|
10
|
-
|
|
11
|
-
export function manifest(start: SolidStartOptions): PluginOption {
|
|
12
|
-
let devServer: ViteDevServer = undefined!;
|
|
13
|
-
return {
|
|
14
|
-
name: "solid-start:manifest-plugin",
|
|
15
|
-
enforce: "pre",
|
|
16
|
-
configureServer(server) {
|
|
17
|
-
devServer = server;
|
|
18
|
-
},
|
|
19
|
-
async resolveId(id) {
|
|
20
|
-
if (id === VIRTUAL_MODULES.clientViteManifest)
|
|
21
|
-
return `\0${VIRTUAL_MODULES.clientViteManifest}`;
|
|
22
|
-
if (id === VIRTUAL_MODULES.getClientManifest)
|
|
23
|
-
return this.resolve(
|
|
24
|
-
fileURLToPath(new URL("../server/manifest/client-manifest", import.meta.url)),
|
|
25
|
-
);
|
|
26
|
-
if (id === VIRTUAL_MODULES.getManifest) {
|
|
27
|
-
return this.environment.config.consumer === "client"
|
|
28
|
-
? this.resolve(
|
|
29
|
-
fileURLToPath(new URL("../server/manifest/client-manifest", import.meta.url)),
|
|
30
|
-
)
|
|
31
|
-
: this.resolve(
|
|
32
|
-
fileURLToPath(new URL("../server/manifest/ssr-manifest", import.meta.url)),
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
if (id === VIRTUAL_MODULES.middleware) {
|
|
36
|
-
if (start.middleware) return await this.resolve(start.middleware);
|
|
37
|
-
return `\0${VIRTUAL_MODULES.middleware}`;
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
async load(id) {
|
|
41
|
-
if (id === `\0${VIRTUAL_MODULES.clientViteManifest}`) {
|
|
42
|
-
let clientViteManifest: Record<string, Record<string, any>>;
|
|
43
|
-
if (this.environment.config.command === "serve") {
|
|
44
|
-
clientViteManifest = {};
|
|
45
|
-
} else {
|
|
46
|
-
const entry = Object.values(globalThis.START_CLIENT_BUNDLE).find(
|
|
47
|
-
v => "isEntry" in v && v.isEntry,
|
|
48
|
-
);
|
|
49
|
-
if (!entry) throw new Error("No client entry found");
|
|
50
|
-
let rawManifest: string | undefined;
|
|
51
|
-
|
|
52
|
-
const viteMajor = parseInt(viteVersion.split('.')[0]!, 10);
|
|
53
|
-
|
|
54
|
-
const manifestKey = Object.keys(globalThis.START_CLIENT_BUNDLE).find(k => k.endsWith("manifest.json"));
|
|
55
|
-
if (manifestKey && viteMajor < 8) {
|
|
56
|
-
const manifestAsset = globalThis.START_CLIENT_BUNDLE[manifestKey] as any;
|
|
57
|
-
rawManifest = manifestAsset.source as string;
|
|
58
|
-
} else {
|
|
59
|
-
try {
|
|
60
|
-
const appRoot = (start as any).appRoot || "./src";
|
|
61
|
-
let outDir = ".solid-start/client";
|
|
62
|
-
if (devServer?.environments?.client?.config?.build?.outDir) {
|
|
63
|
-
outDir = devServer.environments.client.config.build.outDir;
|
|
64
|
-
} else if (this.environment?.config?.build?.outDir && this.environment?.config?.consumer === "client") {
|
|
65
|
-
outDir = this.environment.config.build.outDir;
|
|
66
|
-
} else if ((globalThis as any).START_CLIENT_OUT_DIR) {
|
|
67
|
-
outDir = (globalThis as any).START_CLIENT_OUT_DIR;
|
|
68
|
-
}
|
|
69
|
-
const manifestPath = path.resolve(appRoot, "..", outDir, ".vite/manifest.json");
|
|
70
|
-
rawManifest = fs.readFileSync(manifestPath, "utf-8");
|
|
71
|
-
} catch (e) {
|
|
72
|
-
throw new Error(`Manifest asset not found in bundle and could not be read from disk. Keys: ${Object.keys(globalThis.START_CLIENT_BUNDLE).join(", ")}. Error: ${e}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!rawManifest) {
|
|
77
|
-
throw new Error("Failed to extract or read raw manifest.");
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
clientViteManifest = JSON.parse(rawManifest);
|
|
81
|
-
}
|
|
82
|
-
return `export const clientViteManifest = ${JSON.stringify(clientViteManifest)};`;
|
|
83
|
-
} else if (id === `\0${VIRTUAL_MODULES.middleware}`) return "export default {};";
|
|
84
|
-
else if (id.startsWith("/@manifest")) {
|
|
85
|
-
if (this.environment.mode !== "dev")
|
|
86
|
-
throw new Error("@manifest queries are only allowed in dev");
|
|
87
|
-
|
|
88
|
-
const [urlPath, query] = id.split("?");
|
|
89
|
-
const target = id.split("/")[2]!;
|
|
90
|
-
const params = new URLSearchParams(query);
|
|
91
|
-
if (!urlPath || !query) return;
|
|
92
|
-
if (urlPath.endsWith("assets")) {
|
|
93
|
-
const id = params.get("id");
|
|
94
|
-
if (!id) {
|
|
95
|
-
throw new Error("Missing id to get assets.");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Client env does not have css dependencies in mod.transformResult
|
|
99
|
-
// Aalways use ssr env instead, to prevent hydration mismatches
|
|
100
|
-
const env = devServer.environments["ssr"];
|
|
101
|
-
const styles = await findStylesInModuleGraph(env, id);
|
|
102
|
-
|
|
103
|
-
const cssAssets = Object.entries(styles).map(
|
|
104
|
-
([key, value]) => `{
|
|
105
|
-
tag: "style",
|
|
106
|
-
attrs: {
|
|
107
|
-
type: "text/css",
|
|
108
|
-
"data-vite-dev-id": "${wrapId(key)}",
|
|
109
|
-
"data-vite-ref": "0",
|
|
110
|
-
},
|
|
111
|
-
children: () => import("${wrapId(value)}?inline").then(mod => mod.default),
|
|
112
|
-
}`,
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
return `export default [${cssAssets.join(",")}]`;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
}
|
package/src/config/utils.ts
DELETED
package/src/config/vite-utils.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { DevEnvironment, Rollup } from "vite";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
const postfixRE = /[?#].*$/;
|
|
6
|
-
export function cleanUrl(url: string): string {
|
|
7
|
-
return url.replace(postfixRE, "");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const FS_PREFIX = `/@fs/`;
|
|
11
|
-
|
|
12
|
-
export const VALID_ID_PREFIX = `/@id/`;
|
|
13
|
-
|
|
14
|
-
export const NULL_BYTE_PLACEHOLDER = `__x00__`;
|
|
15
|
-
const NULL_BYTE_REGEX = /^\0/;
|
|
16
|
-
|
|
17
|
-
export function normalizeResolvedIdToUrl(
|
|
18
|
-
environment: DevEnvironment,
|
|
19
|
-
url: string,
|
|
20
|
-
resolved: Rollup.PartialResolvedId,
|
|
21
|
-
): string {
|
|
22
|
-
const root = environment.config.root;
|
|
23
|
-
const depsOptimizer = environment.depsOptimizer;
|
|
24
|
-
|
|
25
|
-
// normalize all imports into resolved URLs
|
|
26
|
-
// e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
|
|
27
|
-
if (resolved.id.startsWith(withTrailingSlash(root))) {
|
|
28
|
-
// in root: infer short absolute path from root
|
|
29
|
-
url = resolved.id.slice(root.length);
|
|
30
|
-
} else if (
|
|
31
|
-
depsOptimizer?.isOptimizedDepFile(resolved.id) ||
|
|
32
|
-
// vite-plugin-react isn't following the leading \0 virtual module convention.
|
|
33
|
-
// This is a temporary hack to avoid expensive fs checks for React apps.
|
|
34
|
-
// We'll remove this as soon we're able to fix the react plugins.
|
|
35
|
-
(resolved.id !== "/@react-refresh" &&
|
|
36
|
-
path.isAbsolute(resolved.id) &&
|
|
37
|
-
fs.existsSync(cleanUrl(resolved.id)))
|
|
38
|
-
) {
|
|
39
|
-
// an optimized deps may not yet exists in the filesystem, or
|
|
40
|
-
// a regular file exists but is out of root: rewrite to absolute /@fs/ paths
|
|
41
|
-
url = path.posix.join(FS_PREFIX, resolved.id);
|
|
42
|
-
} else {
|
|
43
|
-
url = resolved.id;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// if the resolved id is not a valid browser import specifier,
|
|
47
|
-
// prefix it to make it valid. We will strip this before feeding it
|
|
48
|
-
// back into the transform pipeline
|
|
49
|
-
if (url[0] !== "." && url[0] !== "/") {
|
|
50
|
-
url = wrapId(resolved.id);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return url;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Inspired by:
|
|
58
|
-
* https://github.com/withastro/astro/blob/fddde5fad81007795eb263c7fd0cea096b8e2cba/packages/astro/src/core/util.ts#L115
|
|
59
|
-
* https://github.com/vitejs/vite/blob/130e7181a55c524383c63bbfb1749d0ff7185cad/packages/vite/src/shared/utils.ts#L11
|
|
60
|
-
*/
|
|
61
|
-
export function wrapId(id: string): string {
|
|
62
|
-
return id.replace(NULL_BYTE_REGEX, `${VALID_ID_PREFIX}${NULL_BYTE_PLACEHOLDER}`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function unwrapId(id: string): string {
|
|
66
|
-
return id.startsWith(VALID_ID_PREFIX)
|
|
67
|
-
? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0")
|
|
68
|
-
: id;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function normalizeViteImportAnalysisUrl(environment: DevEnvironment, id: string): string {
|
|
72
|
-
let url = normalizeResolvedIdToUrl(environment, id, { id });
|
|
73
|
-
|
|
74
|
-
// https://github.com/vitejs/vite/blob/c18ce868c4d70873406e9f7d1b2d0a03264d2168/packages/vite/src/node/plugins/importAnalysis.ts#L416
|
|
75
|
-
if (environment.config.consumer === "client") {
|
|
76
|
-
const mod = environment.moduleGraph.getModuleById(id);
|
|
77
|
-
if (mod && mod.lastHMRTimestamp > 0) {
|
|
78
|
-
url = injectQuery(url, `t=${mod.lastHMRTimestamp}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return url;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function withTrailingSlash(path: string): string {
|
|
86
|
-
if (path[path.length - 1] !== "/") {
|
|
87
|
-
return `${path}/`;
|
|
88
|
-
}
|
|
89
|
-
return path;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function splitFileAndPostfix(path: string): {
|
|
93
|
-
file: string;
|
|
94
|
-
postfix: string;
|
|
95
|
-
} {
|
|
96
|
-
const file = cleanUrl(path);
|
|
97
|
-
return { file, postfix: path.slice(file.length) };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const windowsSlashRE = /\\/g;
|
|
101
|
-
export function slash(p: string): string {
|
|
102
|
-
return p.replace(windowsSlashRE, "/");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const isWindows = typeof process !== "undefined" && process.platform === "win32";
|
|
106
|
-
|
|
107
|
-
export function injectQuery(url: string, queryToInject: string): string {
|
|
108
|
-
const { file, postfix } = splitFileAndPostfix(url);
|
|
109
|
-
const normalizedFile = isWindows ? slash(file) : file;
|
|
110
|
-
return `${normalizedFile}?${queryToInject}${
|
|
111
|
-
postfix[0] === "?" ? `&${postfix.slice(1)}` : /* hash only */ postfix
|
|
112
|
-
}`;
|
|
113
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type * as babel from "@babel/core";
|
|
2
|
-
import * as t from "@babel/types";
|
|
3
|
-
|
|
4
|
-
export function bubbleFunctionDeclaration(path: babel.NodePath<t.FunctionDeclaration>): void {
|
|
5
|
-
const decl = path.node;
|
|
6
|
-
// Check if declaration is FunctionDeclaration
|
|
7
|
-
if (decl.id) {
|
|
8
|
-
const block = (path.findParent(current => current.isBlockStatement()) ||
|
|
9
|
-
path.scope.getProgramParent().path) as babel.NodePath<t.BlockStatement>;
|
|
10
|
-
|
|
11
|
-
if (path.parentPath.isExportNamedDeclaration()) {
|
|
12
|
-
path.parentPath.replaceWith(
|
|
13
|
-
t.exportNamedDeclaration(undefined, [t.exportSpecifier(decl.id, decl.id)]),
|
|
14
|
-
);
|
|
15
|
-
} else if (path.parentPath.isExportDefaultDeclaration()) {
|
|
16
|
-
path.replaceWith(decl.id);
|
|
17
|
-
} else {
|
|
18
|
-
path.remove();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const [tmp] = block.unshiftContainer(
|
|
22
|
-
"body",
|
|
23
|
-
t.variableDeclaration("const", [
|
|
24
|
-
t.variableDeclarator(
|
|
25
|
-
decl.id,
|
|
26
|
-
t.functionExpression(decl.id, decl.params, decl.body, decl.generator, decl.async),
|
|
27
|
-
),
|
|
28
|
-
]),
|
|
29
|
-
);
|
|
30
|
-
block.scope.registerDeclaration(tmp);
|
|
31
|
-
tmp.skip();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import * as babel from "@babel/core";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { directivesPlugin, type StateContext } from "./plugin.ts";
|
|
4
|
-
import xxHash32 from "./xxhash32.ts";
|
|
5
|
-
|
|
6
|
-
export interface CompileResult {
|
|
7
|
-
valid: boolean;
|
|
8
|
-
code: string;
|
|
9
|
-
map: babel.BabelFileResult["map"];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type CompileOptions = Omit<StateContext, "count" | "hash" | "imports" | "valid">;
|
|
13
|
-
|
|
14
|
-
export async function compile(
|
|
15
|
-
id: string,
|
|
16
|
-
code: string,
|
|
17
|
-
options: CompileOptions,
|
|
18
|
-
): Promise<CompileResult> {
|
|
19
|
-
const context: StateContext = {
|
|
20
|
-
...options,
|
|
21
|
-
valid: false,
|
|
22
|
-
hash: xxHash32(id).toString(16),
|
|
23
|
-
count: 0,
|
|
24
|
-
imports: new Map(),
|
|
25
|
-
};
|
|
26
|
-
const pluginOption = [directivesPlugin, context];
|
|
27
|
-
const plugins: NonNullable<NonNullable<babel.TransformOptions["parserOpts"]>["plugins"]> = [
|
|
28
|
-
"jsx",
|
|
29
|
-
];
|
|
30
|
-
if (/\.[mc]?tsx?$/i.test(id)) {
|
|
31
|
-
plugins.push("typescript");
|
|
32
|
-
}
|
|
33
|
-
const result = await babel.transformAsync(code, {
|
|
34
|
-
plugins: [pluginOption],
|
|
35
|
-
parserOpts: {
|
|
36
|
-
plugins,
|
|
37
|
-
},
|
|
38
|
-
filename: path.basename(id),
|
|
39
|
-
ast: false,
|
|
40
|
-
sourceMaps: true,
|
|
41
|
-
configFile: false,
|
|
42
|
-
babelrc: false,
|
|
43
|
-
sourceFileName: id,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
if (result) {
|
|
47
|
-
return {
|
|
48
|
-
valid: context.valid,
|
|
49
|
-
code: result.code || "",
|
|
50
|
-
map: result.map,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
throw new Error("invariant");
|
|
54
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type * as babel from "@babel/core";
|
|
2
|
-
import * as t from "@babel/types";
|
|
3
|
-
|
|
4
|
-
export function generateUniqueName(path: babel.NodePath, name: string): t.Identifier {
|
|
5
|
-
let uid: string;
|
|
6
|
-
let i = 1;
|
|
7
|
-
do {
|
|
8
|
-
uid = name + "_" + i;
|
|
9
|
-
i++;
|
|
10
|
-
} while (
|
|
11
|
-
path.scope.hasLabel(uid) ||
|
|
12
|
-
path.scope.hasBinding(uid) ||
|
|
13
|
-
path.scope.hasGlobal(uid) ||
|
|
14
|
-
path.scope.hasReference(uid)
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
const program = path.scope.getProgramParent();
|
|
18
|
-
program.references[uid] = true;
|
|
19
|
-
program.uids[uid] = true;
|
|
20
|
-
|
|
21
|
-
return t.identifier(uid);
|
|
22
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { NodePath } from "@babel/core";
|
|
2
|
-
|
|
3
|
-
export function getDescriptiveName(path: NodePath, defaultName: string): string {
|
|
4
|
-
let current: NodePath | null = path;
|
|
5
|
-
while (current) {
|
|
6
|
-
switch (current.node.type) {
|
|
7
|
-
case "FunctionDeclaration":
|
|
8
|
-
case "FunctionExpression": {
|
|
9
|
-
if (current.node.id) {
|
|
10
|
-
return current.node.id.name;
|
|
11
|
-
}
|
|
12
|
-
break;
|
|
13
|
-
}
|
|
14
|
-
case "VariableDeclarator": {
|
|
15
|
-
if (current.node.id.type === "Identifier") {
|
|
16
|
-
return current.node.id.name;
|
|
17
|
-
}
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
case "ClassPrivateMethod":
|
|
21
|
-
case "ClassMethod":
|
|
22
|
-
case "ObjectMethod": {
|
|
23
|
-
switch (current.node.key.type) {
|
|
24
|
-
case "Identifier":
|
|
25
|
-
return current.node.key.name;
|
|
26
|
-
case "PrivateName":
|
|
27
|
-
return current.node.key.id.name;
|
|
28
|
-
default:
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
default:
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
current = current.parentPath;
|
|
37
|
-
}
|
|
38
|
-
return defaultName;
|
|
39
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type * as babel from "@babel/core";
|
|
2
|
-
import * as t from "@babel/types";
|
|
3
|
-
import { generateUniqueName } from "./generate-unique-name.ts";
|
|
4
|
-
import type { ImportDefinition } from "./types.ts";
|
|
5
|
-
|
|
6
|
-
export function getImportIdentifier(
|
|
7
|
-
imports: Map<string, t.Identifier>,
|
|
8
|
-
path: babel.NodePath,
|
|
9
|
-
registration: ImportDefinition,
|
|
10
|
-
): t.Identifier {
|
|
11
|
-
const name = registration.kind === "named" ? registration.name : "default";
|
|
12
|
-
const target = `${registration.source}[${name}]`;
|
|
13
|
-
const current = imports.get(target);
|
|
14
|
-
if (current) {
|
|
15
|
-
return current;
|
|
16
|
-
}
|
|
17
|
-
const programParent = path.scope.getProgramParent();
|
|
18
|
-
const uid = generateUniqueName(programParent.path, name);
|
|
19
|
-
programParent.registerDeclaration(
|
|
20
|
-
(programParent.path as babel.NodePath<t.Program>).unshiftContainer(
|
|
21
|
-
"body",
|
|
22
|
-
t.importDeclaration(
|
|
23
|
-
[
|
|
24
|
-
registration.kind === "named"
|
|
25
|
-
? t.importSpecifier(uid, t.identifier(registration.name))
|
|
26
|
-
: t.importDefaultSpecifier(uid),
|
|
27
|
-
],
|
|
28
|
-
t.stringLiteral(registration.source),
|
|
29
|
-
),
|
|
30
|
-
)[0],
|
|
31
|
-
);
|
|
32
|
-
imports.set(target, uid);
|
|
33
|
-
return uid;
|
|
34
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type * as babel from "@babel/core";
|
|
2
|
-
import * as t from "@babel/types";
|
|
3
|
-
|
|
4
|
-
export function getRootStatementPath(path: babel.NodePath): babel.NodePath {
|
|
5
|
-
let current = path.parentPath;
|
|
6
|
-
while (current) {
|
|
7
|
-
const next = current.parentPath;
|
|
8
|
-
if (next && t.isProgram(next.node)) {
|
|
9
|
-
return current;
|
|
10
|
-
}
|
|
11
|
-
current = next;
|
|
12
|
-
}
|
|
13
|
-
return path;
|
|
14
|
-
}
|
package/src/directives/index.ts
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createFilter,
|
|
3
|
-
type EnvironmentModuleGraph,
|
|
4
|
-
type FilterPattern,
|
|
5
|
-
type Plugin,
|
|
6
|
-
type ViteDevServer,
|
|
7
|
-
} from "vite";
|
|
8
|
-
import { compile, type CompileOptions } from "./compile.ts";
|
|
9
|
-
|
|
10
|
-
export interface ServerFunctionsFilter {
|
|
11
|
-
include?: FilterPattern;
|
|
12
|
-
exclude?: FilterPattern;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface ServerFunctionsOptions {
|
|
16
|
-
manifest: string;
|
|
17
|
-
runtime: {
|
|
18
|
-
server: string;
|
|
19
|
-
client: string;
|
|
20
|
-
};
|
|
21
|
-
filter?: ServerFunctionsFilter;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const DEFAULT_INCLUDE = "src/**/*.{jsx,tsx,ts,js,mjs,cjs}";
|
|
25
|
-
const DEFAULT_EXCLUDE = "node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}";
|
|
26
|
-
const DIRECTIVE = "use server";
|
|
27
|
-
|
|
28
|
-
type Manifest = Record<CompileOptions["mode"], Set<string>>;
|
|
29
|
-
|
|
30
|
-
function createManifest(): Manifest {
|
|
31
|
-
return {
|
|
32
|
-
server: new Set(),
|
|
33
|
-
client: new Set(),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface DeferredPromise<T> {
|
|
38
|
-
reference: Promise<T>;
|
|
39
|
-
resolve: (value: T) => void;
|
|
40
|
-
reject: (value: any) => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function createDeferredPromise<T>(): DeferredPromise<T> {
|
|
44
|
-
let resolve: DeferredPromise<T>["resolve"];
|
|
45
|
-
let reject: DeferredPromise<T>["reject"];
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
reference: new Promise((res, rej) => {
|
|
49
|
-
resolve = res;
|
|
50
|
-
reject = rej;
|
|
51
|
-
}),
|
|
52
|
-
resolve(value) {
|
|
53
|
-
resolve(value);
|
|
54
|
-
},
|
|
55
|
-
reject(value) {
|
|
56
|
-
reject(value);
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
class Debouncer<T> {
|
|
62
|
-
promise: DeferredPromise<T>;
|
|
63
|
-
|
|
64
|
-
private timeout: ReturnType<typeof setTimeout> | undefined;
|
|
65
|
-
|
|
66
|
-
constructor(private source: () => T) {
|
|
67
|
-
this.promise = createDeferredPromise();
|
|
68
|
-
this.defer();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
defer(): void {
|
|
72
|
-
if (this.timeout) {
|
|
73
|
-
clearTimeout(this.timeout);
|
|
74
|
-
this.timeout = undefined;
|
|
75
|
-
}
|
|
76
|
-
this.timeout = setTimeout(() => {
|
|
77
|
-
this.promise.resolve(this.source());
|
|
78
|
-
}, 1000);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function mergeManifestRecord(
|
|
83
|
-
source: Set<string>,
|
|
84
|
-
target: Set<string>,
|
|
85
|
-
): { invalidPreload: boolean; invalidated: string[] } {
|
|
86
|
-
const current = source.size;
|
|
87
|
-
for (const entry of target) {
|
|
88
|
-
source.add(entry);
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
invalidPreload: current !== source.size,
|
|
92
|
-
invalidated: [...source],
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function invalidateModule(moduleGraph: EnvironmentModuleGraph, path: string) {
|
|
97
|
-
const target = moduleGraph.getModuleById(path);
|
|
98
|
-
if (target) {
|
|
99
|
-
moduleGraph.invalidateModule(target);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function invalidateModules(
|
|
104
|
-
server: ViteDevServer | undefined,
|
|
105
|
-
result: ReturnType<typeof mergeManifestRecord>,
|
|
106
|
-
manifest: string,
|
|
107
|
-
): void {
|
|
108
|
-
if (server) {
|
|
109
|
-
if (result.invalidPreload) {
|
|
110
|
-
invalidateModule(server.environments.client.moduleGraph, manifest);
|
|
111
|
-
invalidateModule(server.environments.ssr.moduleGraph, manifest);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
export function serverFunctionsPlugin(options: ServerFunctionsOptions): Plugin[] {
|
|
118
|
-
const filter = createFilter(
|
|
119
|
-
options.filter?.include || DEFAULT_INCLUDE,
|
|
120
|
-
options.filter?.exclude || DEFAULT_EXCLUDE,
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
let env: CompileOptions["env"];
|
|
124
|
-
|
|
125
|
-
const manifest = createManifest();
|
|
126
|
-
|
|
127
|
-
const preload: Record<CompileOptions["mode"], Debouncer<string> | undefined> = {
|
|
128
|
-
server: undefined,
|
|
129
|
-
client: undefined,
|
|
130
|
-
};
|
|
131
|
-
let currentServer: ViteDevServer;
|
|
132
|
-
|
|
133
|
-
const clientOptions: Pick<CompileOptions, "directive" | "definitions"> = {
|
|
134
|
-
directive: DIRECTIVE,
|
|
135
|
-
definitions: {
|
|
136
|
-
register: {
|
|
137
|
-
kind: "named",
|
|
138
|
-
name: "createServerReference",
|
|
139
|
-
source: options.runtime.client,
|
|
140
|
-
},
|
|
141
|
-
clone: {
|
|
142
|
-
kind: "named",
|
|
143
|
-
name: "cloneServerReference",
|
|
144
|
-
source: options.runtime.client,
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
const serverOptions: Pick<CompileOptions, "directive" | "definitions"> = {
|
|
149
|
-
directive: DIRECTIVE,
|
|
150
|
-
definitions: {
|
|
151
|
-
register: {
|
|
152
|
-
kind: "named",
|
|
153
|
-
name: "createServerReference",
|
|
154
|
-
source: options.runtime.server,
|
|
155
|
-
},
|
|
156
|
-
clone: {
|
|
157
|
-
kind: "named",
|
|
158
|
-
name: "cloneServerReference",
|
|
159
|
-
source: options.runtime.server,
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
return [
|
|
165
|
-
{
|
|
166
|
-
name: "solid-start:server-functions/setup",
|
|
167
|
-
enforce: "pre",
|
|
168
|
-
configResolved(config) {
|
|
169
|
-
env = config.mode !== "production" ? "development" : "production";
|
|
170
|
-
},
|
|
171
|
-
configureServer(server) {
|
|
172
|
-
currentServer = server;
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
name: "solid-start:server-functions/preload",
|
|
177
|
-
enforce: "pre",
|
|
178
|
-
resolveId(source) {
|
|
179
|
-
if (source === options.manifest) {
|
|
180
|
-
return { id: options.manifest, moduleSideEffects: true };
|
|
181
|
-
}
|
|
182
|
-
return null;
|
|
183
|
-
},
|
|
184
|
-
async load(id, opts) {
|
|
185
|
-
const mode = opts?.ssr ? "server" : "client";
|
|
186
|
-
if (id === options.manifest) {
|
|
187
|
-
const current = new Debouncer(() =>
|
|
188
|
-
[...manifest[mode]].map(entry => `import "${entry}";`).join("\n"),
|
|
189
|
-
);
|
|
190
|
-
preload[mode] = current;
|
|
191
|
-
const result = await current.promise.reference;
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
return null;
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
name: "solid-start:server-functions/compiler",
|
|
199
|
-
enforce: 'pre',
|
|
200
|
-
async transform(code, fileId, opts) {
|
|
201
|
-
const mode = opts?.ssr ? "server" : "client";
|
|
202
|
-
const [id] = fileId.split("?");
|
|
203
|
-
if (!filter(id)) {
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const result = await compile(id!, code, {
|
|
208
|
-
...(mode === "server" ? serverOptions : clientOptions),
|
|
209
|
-
mode,
|
|
210
|
-
env,
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
if (result.valid) {
|
|
214
|
-
const preloader = preload[mode];
|
|
215
|
-
if (preloader) {
|
|
216
|
-
preloader.defer();
|
|
217
|
-
}
|
|
218
|
-
invalidateModules(
|
|
219
|
-
currentServer,
|
|
220
|
-
mergeManifestRecord(manifest.server, new Set([id!])),
|
|
221
|
-
options.manifest,
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
return {
|
|
225
|
-
code: result.code || "",
|
|
226
|
-
map: result.map,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
return null;
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
];
|
|
233
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type * as babel from "@babel/core";
|
|
2
|
-
import type * as t from "@babel/types";
|
|
3
|
-
|
|
4
|
-
export function isStatementTopLevel(path: babel.NodePath<t.Statement>): boolean {
|
|
5
|
-
let blockParent = path.scope.getBlockParent();
|
|
6
|
-
const programParent = path.scope.getProgramParent();
|
|
7
|
-
// a FunctionDeclaration binding refers to itself as the block parent
|
|
8
|
-
if (blockParent.path === path) {
|
|
9
|
-
blockParent = blockParent.parent;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return programParent === blockParent;
|
|
13
|
-
}
|