@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 CHANGED
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- var ft=60,h=1000,y=60000,It=60,Nt=24,Et=86400000,g=2,B=3000;import{rm as k,mkdir as w,writeFile as rt}from"fs/promises";import{join as s,basename as st}from"path";import{cwd as nt,exit as et}from"process";var{$:b,build:it,Glob:A}=globalThis.Bun;import{readFile as Z,writeFile as tt}from"fs/promises";var{Glob:ot}=globalThis.Bun;var H=async(r,n)=>{let e=new ot("*.html"),o=[];for await(let a of e.scan({cwd:n,absolute:!0}))o.push(a);for(let a of o){let i=await Z(a,"utf8");for(let[u,l]of Object.entries(r)){let m=u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),p=new RegExp(`(<script[^>]+src=["'])(/?(?:.*\\/)?${m})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`,"g");i=i.replace(p,(c,I,N,L,x)=>{return`${I}${l}${x}`})}await tt(a,i,"utf8")}};var F=async({buildDir:r="build",assetsDir:n,reactIndexDir:e,javascriptDir:o,typeScriptDir:a,reactPagesDir:i,htmlDir:u,htmxDir:l})=>{let m=performance.now();console.log("Build Config",{buildDir:r,assetsDir:n,reactIndexDir:e,javascriptDir:o,typeScriptDir:a,reactPagesDir:i,htmlDir:u,htmxDir:l});let p=nt(),c=s(p,r),I=n&&s(p,n),N=e&&s(p,e),L=o&&s(p,o),x=a&&s(p,a),M=i&&s(p,i),E=u&&s(p,u),D=l&&s(p,l);await k(c,{force:!0,recursive:!0}),await w(c),M&&N&&await ct(M,N);let z=new A("*.{tsx,jsx}"),T=[];for await(let t of z.scan({absolute:!0,cwd:N}))T.push(t);let J=new A("*.js"),R=[];for await(let t of J.scan({absolute:!0,cwd:L}))R.push(t);let K=new A("*.ts"),U=[];for await(let t of K.scan({absolute:!0,cwd:x}))U.push(t);let v=T.concat(R).concat(U);if(v.length===0)return console.warn("No entry points found, skipping build"),null;let{logs:Q,outputs:V}=await it({entrypoints:v,format:"esm",naming:"[dir]/[name].[hash].[ext]",outdir:c}).catch((t)=>{console.error("Build failed:",t),et(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)}),I&&await b`cp -R ${I} ${c}`,E)await w(s(c,"html")),await b`cp -R ${E} ${s(c)}`;if(D)await w(s(c,"htmx")),await b`cp -R ${D} ${s(c)}`;let P=V.reduce((t,j)=>{let _=j.path;if(_.startsWith(c))_=_.slice(c.length);_=_.replace(/^\/+/,"");let d=_.split("/").pop();if(!d)return t;let O=`.${j.hash}.`;if(!d.includes(O))throw new Error(`Expected hash delimiter ${O} in ${d}`);let[X]=d.split(O);return t[X]="/"+_,t},{});E&&await H(P,E);let f=performance.now()-m,S;if(f<h)S=`${f.toFixed(g)}ms`;else if(f<y)S=`${(f/h).toFixed(g)}s`;else S=`${(f/y).toFixed(g)}m`;return console.log(`Build completed in ${S}`),P},ct=async(r,n)=>{await k(n,{force:!0,recursive:!0}),await w(n);let e=new A("*.*"),o=[];for await(let i of e.scan({cwd:r}))o.push(i);let a=o.map(async(i)=>{let u=st(i),[l]=u.split("."),m=["import { hydrateRoot } from 'react-dom/client';",`import { ${l} } from '../pages/${l}';
3
- `,`hydrateRoot(document, <${l} />);`].join(`
4
- `);return rt(s(n,`${l}Index.tsx`),m)});await Promise.all(a)};import{createElement as at}from"react";import{renderToReadableStream as lt}from"react-dom/server.browser";var Dt=async(r,n)=>{let e=at(r),o=await lt(e,{bootstrapModules:[n]});return new Response(o,{headers:{"Content-Type":"text/html"}})},Tt=(r)=>Bun.file(r);import{argv as ut}from"process";var{env:Y}=globalThis.Bun;import pt from"os";var G=()=>{let r=pt.networkInterfaces(),e=Object.values(r).flat().filter((o)=>o!==void 0).find((o)=>o.family==="IPv4"&&!o.internal);if(e)return e.address;return console.warn("No IP address found, falling back to localhost"),"localhost"};var C=Y.HOST??"localhost",$=Y.PORT??B,W,_t=ut,q=_t.includes("--host");if(q)W=G(),C="0.0.0.0";var Yt=(r)=>r.listen({hostname:C,port:$},()=>{if(q)console.log(`Server started on http://localhost:${$}`),console.log(`Server started on network: http://${W}:${$}`);else console.log(`Server started on http://${C}:${$}`)});var zt=await F({});export{H as updateScriptTags,Yt as networkingPlugin,Dt as handleReactPageRequest,Tt as handleHTMLPageRequest,G as getLocalIPAddress,F as build,g as TIME_PRECISION,ft as SECONDS_IN_A_MINUTE,It as MINUTES_IN_AN_HOUR,h as MILLISECONDS_IN_A_SECOND,y as MILLISECONDS_IN_A_MINUTE,Et as MILLISECONDS_IN_A_DAY,Nt as HOURS_IN_A_DAY,B as DEFAULT_PORT};
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};
@@ -1,2 +1 @@
1
- export * from "./networkingPlugin";
2
1
  export * from "./pageRouterPlugin";
@@ -1 +1,6 @@
1
1
  export declare const getLocalIPAddress: () => string;
2
+ export declare const getNetworkSettings: () => {
3
+ host: string;
4
+ port: string | number;
5
+ listenCallback: () => void;
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/absolute",
3
- "version": "0.1.25",
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.0.13",
21
+ "elysia": "1.2.25",
22
22
  "react": "19.1.0",
23
23
  "react-dom": "19.1.0"
24
24
  },
@@ -1,2 +1 @@
1
- export * from "./networkingPlugin";
2
1
  export * from "./pageRouterPlugin";
@@ -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
- );