@absolutejs/absolute 0.2.3 → 0.2.5

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}';
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};
2
+ var _t=60,O=1000,h=60000,mt=60,It=24,Nt=86400000,w=2,b=3000;import{rm as j,mkdir as A,writeFile as Z}from"fs/promises";import{join as e,basename as tt}from"path";import{cwd as ot,exit as rt}from"process";var{$:y,build:st,Glob:B}=globalThis.Bun;import{readFile as Q,writeFile as V}from"fs/promises";var{Glob:X}=globalThis.Bun;var v=async(o,s)=>{let r=new X("*.html"),t=[];for await(let i of r.scan({cwd:s,absolute:!0}))t.push(i);for(let i of t){let a=await Q(i,"utf8");for(let[m,p]of Object.entries(o)){let I=m.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=new RegExp(`(<script[^>]+src=["'])(/?(?:.*\\/)?${I})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`,"g");a=a.replace(l,(c,E,N,x,S)=>{return`${E}${p}${S}`})}await V(i,a,"utf8")}};var $t=async({buildDir:o="build",assetsDir:s,reactIndexDir:r,javascriptDir:t,typeScriptDir:i,reactPagesDir:a,htmlDir:m,htmxDir:p})=>{let I=performance.now(),l=ot(),c=e(l,o),E=s&&e(l,s),N=r&&e(l,r),x=t&&e(l,t),S=i&&e(l,i),C=a&&e(l,a),f=m&&e(l,m),T=p&&e(l,p);await j(c,{force:!0,recursive:!0}),await A(c),C&&N&&await nt(C,N);let W=N&&await L(N,"*.tsx"),q=x&&await L(x,"*.js"),z=S&&await L(S,"*.ts"),P=[...W??[],...q??[],...z??[]];if(P.length===0)return console.warn("No entry points found, skipping build"),null;let{logs:G,outputs:J}=await st({entrypoints:P,format:"esm",naming:"[dir]/[name].[hash].[ext]",outdir:c,target:"bun"}).catch((n)=>{console.error("Build failed:",n),rt(1)});if(G.forEach((n)=>{if(n.level==="error")console.error(n);else if(n.level==="warning")console.warn(n);else if(n.level==="info"||n.level==="debug")console.info(n)}),E&&await y`cp -R ${E} ${c}`,f)await A(e(c,"html")),await y`cp -R ${f} ${e(c)}`;if(T)await A(e(c,"htmx")),await y`cp -R ${T} ${e(c)}`;let R=J.reduce((n,U)=>{let _=U.path;if(_.startsWith(c))_=_.slice(c.length);_=_.replace(/^\/+/,"");let d=_.split("/").pop();if(!d)return n;let $=`.${U.hash}.`;if(!d.includes($))throw new Error(`Expected hash delimiter ${$} in ${d}`);let[K]=d.split($);return n[K]="/"+_,n},{});f&&await v(R,f);let u=performance.now()-I,g;if(u<O)g=`${u.toFixed(w)}ms`;else if(u<h)g=`${(u/O).toFixed(w)}s`;else g=`${(u/h).toFixed(w)}m`;return console.log(`Build completed in ${g}`),R},nt=async(o,s)=>{await j(s,{force:!0,recursive:!0}),await A(s);let r=new B("*.*"),t=[];for await(let a of r.scan({cwd:o}))t.push(a);let i=t.map(async(a)=>{let m=tt(a),[p]=m.split("."),I=["import { hydrateRoot } from 'react-dom/client';",`import { ${p} } from '../pages/${p}';
3
+ `,`hydrateRoot(document, <${p} />);`].join(`
4
+ `);return Z(e(s,`${p}Index.tsx`),I)});await Promise.all(i)},L=async(o,s)=>{let r=[],t=new B(s);for await(let i of t.scan({absolute:!0,cwd:o}))r.push(i);return r};import{createElement as et}from"react";import{renderToReadableStream as it}from"react-dom/server.browser";var Mt=async(o,s)=>{let r=et(o),t=await it(r,{bootstrapModules:[s]});return new Response(t,{headers:{"Content-Type":"text/html"}})},Ct=(o)=>Bun.file(o);import{argv as at}from"process";var{env:k}=globalThis.Bun;import ct from"os";var H=()=>{let o=ct.networkInterfaces(),r=Object.values(o).flat().filter((t)=>t!==void 0).find((t)=>t.family==="IPv4"&&!t.internal);if(r)return r.address;return console.warn("No IP address found, falling back to localhost"),"localhost"};var M=k.HOST??"localhost",D=k.PORT??b,F,lt=at,Y=lt.includes("--host");if(Y)F=H(),M="0.0.0.0";var Ft=(o)=>o.listen({hostname:M,port:D},()=>{if(Y)console.log(`Server started on http://localhost:${D}`),console.log(`Server started on network: http://${F}:${D}`);else console.log(`Server started on http://${M}:${D}`)});export{v as updateScriptTags,Ft as networkingPlugin,Mt as handleReactPageRequest,Ct as handleHTMLPageRequest,H as getLocalIPAddress,$t as build,w as TIME_PRECISION,_t as SECONDS_IN_A_MINUTE,mt as MINUTES_IN_AN_HOUR,O as MILLISECONDS_IN_A_SECOND,h as MILLISECONDS_IN_A_MINUTE,Nt as MILLISECONDS_IN_A_DAY,It 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.5",
4
4
  "description": "A fullstack meta-framework for building web applications with TypeScript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,8 @@
1
+ import tailwindcss from "tailwindcss";
2
+ import autoprefixer from "autoprefixer";
3
+
4
+ const config = {
5
+ plugins: [tailwindcss, autoprefixer]
6
+ };
7
+
8
+ export default config;
package/src/core/build.ts CHANGED
@@ -32,17 +32,6 @@ export const build = async ({
32
32
  }: BuildConfig) => {
33
33
  const start = performance.now();
34
34
 
35
- console.log("Build Config", {
36
- buildDir,
37
- assetsDir,
38
- reactIndexDir,
39
- javascriptDir,
40
- typeScriptDir,
41
- reactPagesDir,
42
- htmlDir,
43
- htmxDir
44
- });
45
-
46
35
  const projectRoot = cwd();
47
36
  const buildDirAbsolute = join(projectRoot, buildDir);
48
37
  const assetsDirAbsolute = assetsDir && join(projectRoot, assetsDir);
@@ -67,35 +56,21 @@ export const build = async ({
67
56
  reactIndexDirAbsolute
68
57
  ));
69
58
 
70
- const reactEntryGlob = new Glob("*.{tsx,jsx}");
71
- const reactEntryPaths: string[] = [];
72
- for await (const file of reactEntryGlob.scan({
73
- absolute: true,
74
- cwd: reactIndexDirAbsolute
75
- })) {
76
- reactEntryPaths.push(file);
77
- }
78
-
79
- const javascriptEntryGlob = new Glob("*.js");
80
- const javascriptEntryPaths: string[] = [];
81
- for await (const file of javascriptEntryGlob.scan({
82
- absolute: true,
83
- cwd: javascriptDirAbsolute
84
- })) {
85
- javascriptEntryPaths.push(file);
86
- }
87
-
88
- const typeScriptEntryGlob = new Glob("*.ts");
89
- const typeScriptEntryPaths: string[] = [];
90
- for await (const file of typeScriptEntryGlob.scan({
91
- absolute: true,
92
- cwd: typeScriptDirAbsolute
93
- })) {
94
- typeScriptEntryPaths.push(file);
95
- }
96
- const entryPaths = reactEntryPaths
97
- .concat(javascriptEntryPaths)
98
- .concat(typeScriptEntryPaths);
59
+ const reactEntryPaths =
60
+ reactIndexDirAbsolute &&
61
+ (await scanEntryPoints(reactIndexDirAbsolute, "*.tsx"));
62
+ const javascriptEntryPaths =
63
+ javascriptDirAbsolute &&
64
+ (await scanEntryPoints(javascriptDirAbsolute, "*.js"));
65
+ const typeScriptEntryPaths =
66
+ typeScriptDirAbsolute &&
67
+ (await scanEntryPoints(typeScriptDirAbsolute, "*.ts"));
68
+
69
+ const entryPaths = [
70
+ ...(reactEntryPaths ?? []),
71
+ ...(javascriptEntryPaths ?? []),
72
+ ...(typeScriptEntryPaths ?? [])
73
+ ];
99
74
 
100
75
  if (entryPaths.length === 0) {
101
76
  console.warn("No entry points found, skipping build");
@@ -202,3 +177,12 @@ const generateReactIndexFiles = async (
202
177
  });
203
178
  await Promise.all(promises);
204
179
  };
180
+
181
+ const scanEntryPoints = async (dir: string, pattern: string) => {
182
+ const entryPaths: string[] = [];
183
+ const glob = new Glob(pattern);
184
+ for await (const file of glob.scan({ absolute: true, cwd: dir })) {
185
+ entryPaths.push(file);
186
+ }
187
+ return entryPaths;
188
+ };
@@ -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
- };
@@ -0,0 +1,10 @@
1
+ import type { Config } from "tailwindcss";
2
+ import flowbite from "flowbite/plugin";
3
+ import tailwindForms from "@tailwindcss/forms";
4
+
5
+ const config: Config = {
6
+ content: ["./src/frontend/**/*.{js,ts,jsx,tsx,mdx}"],
7
+ plugins: [flowbite, tailwindForms]
8
+ };
9
+
10
+ export default config;