@absolutejs/absolute 0.2.3 → 0.2.4

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