jeasx 2.6.0 → 2.6.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/cli.js +0 -6
- package/esbuild.config.js +0 -4
- package/package.json +3 -3
- package/serverless.js.map +1 -0
- package/tsconfig.json +1 -1
package/cli.js
CHANGED
|
@@ -37,12 +37,6 @@ async function build() {
|
|
|
37
37
|
|
|
38
38
|
async function dev() {
|
|
39
39
|
process.env.NODE_ENV = "development";
|
|
40
|
-
process.setSourceMapsEnabled(true);
|
|
41
|
-
// Bun: https://bun.sh/docs/runtime/nodejs-apis#process
|
|
42
|
-
if (process.sourceMapsEnabled === undefined) {
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
process.sourceMapsEnabled = true;
|
|
45
|
-
}
|
|
46
40
|
await build();
|
|
47
41
|
await start();
|
|
48
42
|
}
|
package/esbuild.config.js
CHANGED
|
@@ -24,8 +24,6 @@ const buildOptions = [
|
|
|
24
24
|
logLevel: "info",
|
|
25
25
|
color: true,
|
|
26
26
|
bundle: true,
|
|
27
|
-
sourcemap: process.sourceMapsEnabled,
|
|
28
|
-
sourcesContent: false,
|
|
29
27
|
outdir: "dist",
|
|
30
28
|
publicPath: "/",
|
|
31
29
|
assetNames: "[dir]/[name]-[hash]",
|
|
@@ -41,8 +39,6 @@ const buildOptions = [
|
|
|
41
39
|
logLevel: "info",
|
|
42
40
|
color: true,
|
|
43
41
|
bundle: true,
|
|
44
|
-
sourcemap: process.sourceMapsEnabled,
|
|
45
|
-
sourcesContent: true,
|
|
46
42
|
outdir: "dist",
|
|
47
43
|
publicPath: "/",
|
|
48
44
|
assetNames: "[dir]/[name]-[hash]",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jeasx",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "Jeasx - the ease of JSX with the power of SSR",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"async",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"type": "module",
|
|
27
27
|
"main": "server.js",
|
|
28
28
|
"scripts": {
|
|
29
|
-
"build": "esbuild --platform=node --format=esm --sourcemap=linked --
|
|
29
|
+
"build": "esbuild --platform=node --format=esm --sourcemap=linked --outdir=. serverless.ts"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@fastify/cookie": "11.0.2",
|
|
33
33
|
"@fastify/formbody": "8.0.2",
|
|
34
34
|
"@fastify/multipart": "10.0.0",
|
|
35
35
|
"@fastify/static": "9.1.3",
|
|
36
|
-
"@types/node": "25.
|
|
36
|
+
"@types/node": "25.7.0",
|
|
37
37
|
"esbuild": "0.28.0",
|
|
38
38
|
"fastify": "5.8.5",
|
|
39
39
|
"jsx-async-runtime": "2.1.2"
|
package/serverless.js.map
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["serverless.ts"],
|
|
4
|
+
"sourcesContent": ["import fastifyCookie, { FastifyCookieOptions } from \"@fastify/cookie\";\nimport fastifyFormbody, { FastifyFormbodyOptions } from \"@fastify/formbody\";\nimport fastifyMultipart, { FastifyMultipartOptions } from \"@fastify/multipart\";\nimport fastifyStatic, { FastifyStaticOptions } from \"@fastify/static\";\nimport fastify, {\n FastifyInstance,\n FastifyReply,\n FastifyRequest,\n FastifyServerOptions,\n} from \"fastify\";\nimport { jsxToString } from \"jsx-async-runtime\";\nimport { stat } from \"node:fs/promises\";\nimport { freemem } from \"node:os\";\nimport { join } from \"node:path\";\nimport env from \"./env.js\";\n\nconst ENV = await env();\n\nconst CWD = process.cwd();\nconst NODE_ENV_IS_DEVELOPMENT = process.env.NODE_ENV === \"development\";\nconst ROUTE_CACHE_LIMIT = Math.floor(freemem() / 1024 / 1024);\n\ndeclare module \"fastify\" {\n interface FastifyRequest {\n path: string; // Path without query parameters\n route: string; // Path to resolved route handler\n }\n}\n\n// Enhance Fastify server from userland\nconst FASTIFY_SERVER = (ENV.FASTIFY_SERVER ?? ((fastify) => fastify)) as (\n fastify: FastifyInstance,\n) => FastifyInstance;\n\n// Create and export a Fastify instance\nexport default FASTIFY_SERVER(\n fastify({\n ...(ENV.FASTIFY_SERVER_OPTIONS?.() as FastifyServerOptions),\n }),\n)\n // Create encapsulation context\n .register((fastify) => {\n fastify\n .register(fastifyCookie, {\n ...(ENV.FASTIFY_COOKIE_OPTIONS?.() as FastifyCookieOptions),\n })\n .register(fastifyFormbody, {\n ...(ENV.FASTIFY_FORMBODY_OPTIONS?.() as FastifyFormbodyOptions),\n })\n .register(fastifyMultipart, {\n ...(ENV.FASTIFY_MULTIPART_OPTIONS?.() as FastifyMultipartOptions),\n })\n .register(fastifyStatic, {\n root: [\"public\", \"dist\"].map((dir) => join(CWD, dir)),\n wildcard: false,\n globIgnore: [\"/**/\\\\[*\\\\].js?(.map)\"], // ignore server routes\n ...(ENV.FASTIFY_STATIC_OPTIONS?.() as FastifyStaticOptions),\n })\n .decorateRequest(\"route\", \"\")\n .decorateRequest(\"path\", \"\")\n .addHook(\"onRequest\", async (request) => {\n // Extract path from url\n const index = request.url.indexOf(\"?\");\n request.path = index === -1 ? request.url : request.url.slice(0, index);\n })\n .all(\"*\", async (request: FastifyRequest, reply: FastifyReply) => {\n try {\n const payload = await handler(request, reply);\n if (\n reply.getHeader(\"content-type\") === undefined &&\n (typeof payload === \"string\" || Buffer.isBuffer(payload))\n ) {\n reply.type(\"text/html; charset=utf-8\");\n }\n return payload;\n } catch (error) {\n request.log.error(error);\n throw error;\n }\n });\n });\n\n// Cache for resolved route modules, 'null' means no module exists.\nconst modules = new Map<string, { default: Function }>();\n\n/**\n * Resolves route module based on the request path and execute it.\n */\nasync function handler(request: FastifyRequest, reply: FastifyReply) {\n let response: unknown;\n\n // Global context object for route handlers\n const context = {};\n\n // Default props for route handlers\n const props = { request, reply };\n\n try {\n // Execute route handlers for current request\n for (const route of generateRoutes(request.path)) {\n // Resolve module via cache\n let module = modules.get(route);\n\n // Module was cached as not found?\n if (module === null) {\n continue;\n }\n\n // Module was not loaded yet?\n if (module === undefined) {\n try {\n const modulePath = join(CWD, \"dist\", `${route}.js`);\n if (NODE_ENV_IS_DEVELOPMENT) {\n if (typeof require === \"function\") {\n // Bun: Remove module from cache before importing\n // as query parameter for import is ignored (see Node).\n if (require.cache[modulePath]) {\n delete require.cache[modulePath];\n }\n module = await import(`file://${modulePath}`);\n } else {\n // Node: Use timestamp as query parameter to update modules.\n const mtime = (await stat(modulePath)).mtime.getTime();\n module = await import(`file://${modulePath}?${mtime}`);\n }\n } else {\n // Load and cache module for non-development\n module = await import(`file://${modulePath}`);\n modules.set(route, module);\n }\n } catch (e) {\n switch (e.code) {\n case \"ENOENT\":\n case \"ENOTDIR\":\n case \"ERR_MODULE_NOT_FOUND\":\n if (!NODE_ENV_IS_DEVELOPMENT) {\n // Cache module as not found\n modules.set(route, null);\n }\n continue;\n default:\n // Module exists, but fails to load.\n throw e;\n }\n } finally {\n // Remove oldest entry from cache if limit is reached\n if (modules.size > ROUTE_CACHE_LIMIT) {\n modules.delete(modules.keys().next().value);\n }\n }\n }\n\n // Store current route in request\n request.route = route;\n\n response =\n // Call functions with 'this' context and props as parameters\n typeof module.default === \"function\"\n ? await module.default.call(context, props)\n : module.default; // otherwise return default export\n\n if (reply.sent) {\n return;\n } else if (route.endsWith(\"/[404]\")) {\n // Preserve existing status if a 404 page is requested directly.\n // If no status is defined, set status to 404 automatically.\n if (reply.statusCode === 200 && !request.path.endsWith(\"/404\")) {\n reply.status(404);\n }\n break;\n } else if (typeof response === \"string\" || Buffer.isBuffer(response) || isJSX(response)) {\n break;\n } else if (\n route.endsWith(\"/[...guard]\") &&\n (response === undefined || typeof response === \"object\")\n ) {\n // Add object entries from guard to props\n Object.assign(props, response);\n continue;\n } else if (reply.statusCode === 404) {\n continue;\n } else {\n break;\n }\n }\n return await renderJSX(context, response);\n } catch (error) {\n const errorHandler = context[\"errorHandler\"];\n if (typeof errorHandler === \"function\") {\n reply.status(500);\n response = await errorHandler.call(context, error);\n return await renderJSX(context, response);\n } else {\n throw error;\n }\n }\n}\n\n/**\n * Generates all possible routes based on the given input path.\n */\nfunction generateRoutes(path: string): string[] {\n // \"/a/b/c\" => [\"/a/b/c\", \"/a/b\", \"/a\", \"\"]\n const segments = generateSegments(path);\n\n // \"/a/b/c\" => [\"/a/b/[c]\", \"/a/b/c/[index]\"]\n const edges = generateEdges(segments[0]);\n\n return [\n ...segments\n .toReversed() // [...guard]s are evaluated from top to bottom\n .map((segment) => `${segment}/[...guard]`),\n ...edges.map((edge) => `${edge}`),\n ...segments.map((segment) => `${segment}/[...path]`),\n ...segments.map((segment) => `${segment}/[404]`),\n ];\n}\n\n/**\n * Transforms a given path into an array of all its segments.\n *\n * @example\n * generateSegments(\"/a/b/c\") => [\"/a/b/c\", \"/a/b\", \"/a\", \"\"]\n */\nfunction generateSegments(path: string): string[] {\n return path\n .split(\"/\")\n .filter((segment) => segment !== \"\")\n .reduce((acc, segment) => {\n acc.push((acc.length > 0 ? acc[acc.length - 1] : \"\") + \"/\" + segment);\n return acc;\n }, [])\n .reverse()\n .concat(\"\");\n}\n\n/**\n * Generates edge routes for the given input path.\n *\n * An edge is either a route with a named segment (e.g. \"/a/b/[c]\")\n * or a route with an \"index\" segment (e.g. \"/a/b/c/[index]\").\n */\nfunction generateEdges(path: string): string[] {\n const edges = [];\n if (path) {\n const lastSegment = path.lastIndexOf(\"/\") + 1;\n edges.push(`${path.substring(0, lastSegment)}[${path.substring(lastSegment)}]`);\n }\n edges.push(`${path}/[index]`);\n return edges;\n}\n\n/**\n * Determines if a given object is a JSX element.\n */\nfunction isJSX(obj: unknown): boolean {\n return !!obj && typeof obj === \"object\" && \"type\" in obj && \"props\" in obj;\n}\n\n/**\n * Renders JSX to string and applies optional response handler.\n */\nasync function renderJSX(context: object, response: unknown) {\n const payload = isJSX(response) ? await jsxToString.call(context, response) : response;\n\n // Post-process the payload with an optional response handler\n const responseHandler = context[\"responseHandler\"];\n return typeof responseHandler === \"function\"\n ? await responseHandler.call(context, payload)\n : payload;\n}\n"],
|
|
4
5
|
"mappings": "AAAA,OAAO,mBAA6C;AACpD,OAAO,qBAAiD;AACxD,OAAO,sBAAmD;AAC1D,OAAO,mBAA6C;AACpD,OAAO,aAKA;AACP,SAAS,mBAAmB;AAC5B,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,OAAO,SAAS;AAEhB,MAAM,MAAM,MAAM,IAAI;AAEtB,MAAM,MAAM,QAAQ,IAAI;AACxB,MAAM,0BAA0B,QAAQ,IAAI,aAAa;AACzD,MAAM,oBAAoB,KAAK,MAAM,QAAQ,IAAI,OAAO,IAAI;AAU5D,MAAM,iBAAkB,IAAI,mBAAmB,CAACA,aAAYA;AAK5D,IAAO,qBAAQ;AAAA,EACb,QAAQ;AAAA,IACN,GAAI,IAAI,yBAAyB;AAAA,EACnC,CAAC;AACH,EAEG,SAAS,CAACA,aAAY;AACrB,EAAAA,SACG,SAAS,eAAe;AAAA,IACvB,GAAI,IAAI,yBAAyB;AAAA,EACnC,CAAC,EACA,SAAS,iBAAiB;AAAA,IACzB,GAAI,IAAI,2BAA2B;AAAA,EACrC,CAAC,EACA,SAAS,kBAAkB;AAAA,IAC1B,GAAI,IAAI,4BAA4B;AAAA,EACtC,CAAC,EACA,SAAS,eAAe;AAAA,IACvB,MAAM,CAAC,UAAU,MAAM,EAAE,IAAI,CAAC,QAAQ,KAAK,KAAK,GAAG,CAAC;AAAA,IACpD,UAAU;AAAA,IACV,YAAY,CAAC,uBAAuB;AAAA;AAAA,IACpC,GAAI,IAAI,yBAAyB;AAAA,EACnC,CAAC,EACA,gBAAgB,SAAS,EAAE,EAC3B,gBAAgB,QAAQ,EAAE,EAC1B,QAAQ,aAAa,OAAO,YAAY;AAEvC,UAAM,QAAQ,QAAQ,IAAI,QAAQ,GAAG;AACrC,YAAQ,OAAO,UAAU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