@absolutejs/absolute 0.1.25 → 0.1.27
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/dist/index.js +3 -3
- package/dist/src/plugins/index.d.ts +0 -1
- package/dist/src/utils/networking.d.ts +5 -0
- package/package.json +2 -2
- package/src/plugins/index.ts +0 -1
- package/src/utils/networking.ts +27 -0
- package/dist/src/plugins/networkingPlugin.d.ts +0 -21
- package/src/plugins/networkingPlugin.ts +0 -35
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
`,`hydrateRoot(document, <${
|
|
4
|
-
`);return
|
|
2
|
+
var pt=60,g=1000,y=60000,ut=60,_t=24,Nt=86400000,d=2,h=3000;import{rm as v,mkdir as x,writeFile as X}from"fs/promises";import{join as e,basename as Z}from"path";import{cwd as F,exit as tt}from"process";var{$:C,build:ot,Glob:A}=globalThis.Bun;import{readFile as K,writeFile as Q}from"fs/promises";var{Glob:V}=globalThis.Bun;var H=async(r,o)=>{let s=new V("*.html"),n=[];for await(let i of s.scan({cwd:o,absolute:!0}))n.push(i);for(let i of n){let c=await K(i,"utf8");for(let[_,p]of Object.entries(r)){let l=_.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),u=new RegExp(`(<script[^>]+src=["'])(/?(?:.*\\/)?${l})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`,"g");c=c.replace(u,(a,f,m,M,O)=>{return`${f}${p}${O}`})}await Q(i,c,"utf8")}};var G=async({buildDir:r="build",assetsDir:o,reactIndexDir:s,javascriptDir:n,typeScriptDir:i,reactPagesDir:c,htmlDir:_,htmxDir:p})=>{let l=performance.now();console.log("Build Config",{buildDir:r,assetsDir:o,reactIndexDir:s,javascriptDir:n,typeScriptDir:i,reactPagesDir:c,htmlDir:_,htmxDir:p});let u=F(),a=e(u,r),f=o&&e(u,o),m=s&&e(u,s),M=n&&e(u,n),O=i&&e(u,i),b=c&&e(u,c),E=_&&e(u,_),D=p&&e(u,p);await v(a,{force:!0,recursive:!0}),await x(a),b&&m&&await nt(b,m);let k=new A("*.{tsx,jsx}"),L=[];for await(let t of k.scan({absolute:!0,cwd:m}))L.push(t);let P=new A("*.js"),U=[];for await(let t of P.scan({absolute:!0,cwd:M}))U.push(t);let W=new A("*.ts"),R=[];for await(let t of W.scan({absolute:!0,cwd:O}))R.push(t);let T=L.concat(U).concat(R);if(T.length===0)return console.warn("No entry points found, skipping build"),null;let{logs:q,outputs:z}=await ot({entrypoints:T,format:"esm",naming:"[dir]/[name].[hash].[ext]",outdir:a}).catch((t)=>{console.error("Build failed:",t),tt(1)});if(q.forEach((t)=>{if(t.level==="error")console.error(t);else if(t.level==="warning")console.warn(t);else if(t.level==="info"||t.level==="debug")console.info(t)}),f&&await C`cp -R ${f} ${a}`,E)await x(e(a,"html")),await C`cp -R ${E} ${e(a)}`;if(D)await x(e(a,"htmx")),await C`cp -R ${D} ${e(a)}`;let j=z.reduce((t,B)=>{let N=B.path;if(N.startsWith(a))N=N.slice(a.length);N=N.replace(/^\/+/,"");let w=N.split("/").pop();if(!w)return t;let $=`.${B.hash}.`;if(!w.includes($))throw new Error(`Expected hash delimiter ${$} in ${w}`);let[J]=w.split($);return t[J]="/"+N,t},{});E&&await H(j,E);let I=performance.now()-l,S;if(I<g)S=`${I.toFixed(d)}ms`;else if(I<y)S=`${(I/g).toFixed(d)}s`;else S=`${(I/y).toFixed(d)}m`;return console.log(`Build completed in ${S}`),j},nt=async(r,o)=>{await v(o,{force:!0,recursive:!0}),await x(o);let s=new A("*.*"),n=[];for await(let c of s.scan({cwd:r}))n.push(c);let i=n.map(async(c)=>{let _=Z(c),[p]=_.split("."),l=["import { hydrateRoot } from 'react-dom/client';",`import { ${p} } from '../pages/${p}';
|
|
3
|
+
`,`hydrateRoot(document, <${p} />);`].join(`
|
|
4
|
+
`);return X(e(o,`${p}Index.tsx`),l)});await Promise.all(i)};import{createElement as rt}from"react";import{renderToReadableStream as st}from"react-dom/server.browser";var Ct=async(r,o)=>{let s=rt(r),n=await st(s,{bootstrapModules:[o]});return new Response(n,{headers:{"Content-Type":"text/html"}})},Mt=(r)=>Bun.file(r);var Tt=await G({});import it from"os";var{argv:et,env:Y}=globalThis.Bun;var ct=()=>{let r=it.networkInterfaces(),s=Object.values(r).flat().filter((n)=>n!==void 0).find((n)=>n.family==="IPv4"&&!n.internal);if(s)return s.address;return console.warn("No IP address found, falling back to localhost"),"localhost"},vt=()=>{let r=Y.HOST??"localhost",o=Y.PORT??h,s,i=et.includes("--host");if(i)s=ct(),r="0.0.0.0";return{host:r,port:o,listenCallback:()=>{if(i)console.log(`Server started on http://localhost:${o}`),console.log(`Server started on network: http://${s}:${o}`);else console.log(`Server started on http://${r}:${o}`)}}};export{H as updateScriptTags,Ct as handleReactPageRequest,Mt as handleHTMLPageRequest,vt as getNetworkSettings,ct as getLocalIPAddress,G as build,d as TIME_PRECISION,pt as SECONDS_IN_A_MINUTE,ut as MINUTES_IN_AN_HOUR,g as MILLISECONDS_IN_A_SECOND,y as MILLISECONDS_IN_A_MINUTE,Nt as MILLISECONDS_IN_A_DAY,_t as HOURS_IN_A_DAY,h as DEFAULT_PORT};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absolutejs/absolute",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"description": "A fullstack meta-framework for building web applications with TypeScript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"release": "bun run format && bun run build && bun publish"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"elysia": "1.
|
|
21
|
+
"elysia": "1.2.25",
|
|
22
22
|
"react": "19.1.0",
|
|
23
23
|
"react-dom": "19.1.0"
|
|
24
24
|
},
|
package/src/plugins/index.ts
CHANGED
package/src/utils/networking.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import os from "os";
|
|
2
|
+
import { argv, env } from "bun";
|
|
3
|
+
import { DEFAULT_PORT } from "../constants";
|
|
2
4
|
|
|
3
5
|
export const getLocalIPAddress = () => {
|
|
4
6
|
const interfaces = os.networkInterfaces();
|
|
@@ -17,3 +19,28 @@ export const getLocalIPAddress = () => {
|
|
|
17
19
|
|
|
18
20
|
return "localhost"; // Fallback to localhost if no IP found
|
|
19
21
|
};
|
|
22
|
+
|
|
23
|
+
export const getNetworkSettings = () => {
|
|
24
|
+
let host = env.HOST ?? "localhost";
|
|
25
|
+
const port = env.PORT ?? DEFAULT_PORT;
|
|
26
|
+
let localIP: string | undefined;
|
|
27
|
+
|
|
28
|
+
const args = argv;
|
|
29
|
+
const hostFlag = args.includes("--host");
|
|
30
|
+
|
|
31
|
+
if (hostFlag) {
|
|
32
|
+
localIP = getLocalIPAddress();
|
|
33
|
+
host = "0.0.0.0";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const listenCallback = () => {
|
|
37
|
+
if (hostFlag) {
|
|
38
|
+
console.log(`Server started on http://localhost:${port}`);
|
|
39
|
+
console.log(`Server started on network: http://${localIP}:${port}`);
|
|
40
|
+
} else {
|
|
41
|
+
console.log(`Server started on http://${host}:${port}`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return { host, port, listenCallback };
|
|
46
|
+
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Elysia } from "elysia";
|
|
2
|
-
export declare const networkingPlugin: (app: Elysia) => Elysia<"", false, {
|
|
3
|
-
decorator: {};
|
|
4
|
-
store: {};
|
|
5
|
-
derive: {};
|
|
6
|
-
resolve: {};
|
|
7
|
-
}, {
|
|
8
|
-
type: {};
|
|
9
|
-
error: {};
|
|
10
|
-
}, {
|
|
11
|
-
schema: {};
|
|
12
|
-
macro: {};
|
|
13
|
-
}, {}, {
|
|
14
|
-
derive: {};
|
|
15
|
-
resolve: {};
|
|
16
|
-
schema: {};
|
|
17
|
-
}, {
|
|
18
|
-
derive: {};
|
|
19
|
-
resolve: {};
|
|
20
|
-
schema: {};
|
|
21
|
-
}>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { argv } from "node:process";
|
|
2
|
-
import { env } from "bun";
|
|
3
|
-
import { Elysia } from "elysia";
|
|
4
|
-
import { getLocalIPAddress } from "../utils/networking";
|
|
5
|
-
import { DEFAULT_PORT } from "../constants";
|
|
6
|
-
|
|
7
|
-
let host = env.HOST ?? "localhost";
|
|
8
|
-
const port = env.PORT ?? DEFAULT_PORT;
|
|
9
|
-
let localIP: string | undefined;
|
|
10
|
-
|
|
11
|
-
const args = argv;
|
|
12
|
-
const hostFlag = args.includes("--host");
|
|
13
|
-
|
|
14
|
-
if (hostFlag) {
|
|
15
|
-
localIP = getLocalIPAddress();
|
|
16
|
-
host = "0.0.0.0";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const networkingPlugin = (app: Elysia) =>
|
|
20
|
-
app.listen(
|
|
21
|
-
{
|
|
22
|
-
hostname: host,
|
|
23
|
-
port: port
|
|
24
|
-
},
|
|
25
|
-
() => {
|
|
26
|
-
if (hostFlag) {
|
|
27
|
-
console.log(`Server started on http://localhost:${port}`);
|
|
28
|
-
console.log(
|
|
29
|
-
`Server started on network: http://${localIP}:${port}`
|
|
30
|
-
);
|
|
31
|
-
} else {
|
|
32
|
-
console.log(`Server started on http://${host}:${port}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
);
|