@absolutejs/absolute 0.2.4 → 0.3.0
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/core/build.d.ts +5 -1
- package/package.json +5 -2
- package/postcss.config.ts +8 -0
- package/src/core/build.ts +34 -41
- package/src/plugins/networkingPlugin.ts +1 -0
- package/tailwind.config.ts +7 -0
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
`,`hydrateRoot(document, <${
|
|
4
|
-
`);return
|
|
2
|
+
var pt=60,C=1000,O=60000,It=60,mt=24,Et=86400000,x=2,h=3000;import{rm as P,mkdir as A,writeFile as tt}from"fs/promises";import{join as n,basename as ot}from"path";import{cwd as rt,exit as nt}from"process";var{$:D,build:st,Glob:v}=globalThis.Bun;import{readFile as Z,writeFile as k}from"fs/promises";var{Glob:F}=globalThis.Bun;var H=async(o,s)=>{let r=new F("*.html"),t=[];for await(let c of r.scan({cwd:s,absolute:!0}))t.push(c);for(let c of t){let a=await Z(c,"utf8");for(let[I,_]of Object.entries(o)){let N=I.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),d=new RegExp(`(<script[^>]+src=["'])(/?(?:.*\\/)?${N})(?:\\.[^."'/]+)?(\\.js)(["'][^>]*>)`,"g");a=a.replace(d,(u,i,g,m,S)=>{return`${i}${_}${S}`})}await k(c,a,"utf8")}};var Mt=async({buildDir:o="build",assetsDir:s,reactIndexDir:r,javascriptDir:t,typeScriptDir:c,reactPagesDir:a,htmlDir:I,htmxDir:_,tailwind:N})=>{let d=performance.now(),u=rt(),i=n(u,o),g=s&&n(u,s),m=r&&n(u,r),S=t&&n(u,t),b=c&&n(u,c),U=a&&n(u,a),l=I&&n(u,I),R=_&&n(u,_);await P(i,{force:!0,recursive:!0}),await A(i),U&&m&&await it(U,m);let G=m&&await y(m,"*.tsx"),J=S&&await y(S,"*.js"),K=b&&await y(b,"*.ts"),T=[...G??[],...J??[],...K??[]];if(T.length===0)return console.warn("No entry points found, skipping build"),null;let{logs:Q,outputs:V}=await st({entrypoints:T,format:"esm",naming:"[dir]/[name].[hash].[ext]",outdir:i,target:"bun"}).catch((e)=>{console.error("Build failed:",e),nt(1)});if(Q.forEach((e)=>{if(e.level==="error")console.error(e);else if(e.level==="warning")console.warn(e);else if(e.level==="info"||e.level==="debug")console.info(e)}),g&&await D`cp -R ${g} ${i}`,l)await A(n(i,"html")),await D`cp -R ${l} ${n(i)}`;if(R)await A(n(i,"htmx")),await D`cp -R ${R} ${n(i)}`;if(N)await D`tailwindcss -i ${N.input} -o ${n(i,N.output)}`;let j=V.reduce((e,B)=>{let p=B.path;if(p.startsWith(i))p=p.slice(i.length);p=p.replace(/^\/+/,"");let w=p.split("/").pop();if(!w)return e;let M=`.${B.hash}.`;if(!w.includes(M))throw new Error(`Expected hash delimiter ${M} in ${w}`);let[X]=w.split(M);return e[X]="/"+p,e},{});l&&await H(j,l);let E=performance.now()-d,f;if(E<C)f=`${E.toFixed(x)}ms`;else if(E<O)f=`${(E/C).toFixed(x)}s`;else f=`${(E/O).toFixed(x)}m`;return console.log(`Build completed in ${f}`),j},it=async(o,s)=>{await P(s,{force:!0,recursive:!0}),await A(s);let r=new v("*.*"),t=[];for await(let a of r.scan({cwd:o}))t.push(a);let c=t.map(async(a)=>{let I=ot(a),[_]=I.split("."),N=["import { hydrateRoot } from 'react-dom/client';",`import { ${_} } from '../pages/${_}';
|
|
3
|
+
`,`hydrateRoot(document, <${_} />);`].join(`
|
|
4
|
+
`);return tt(n(s,`${_}Index.tsx`),N)});await Promise.all(c)},y=async(o,s)=>{let r=[],t=new v(s);for await(let c of t.scan({absolute:!0,cwd:o}))r.push(c);return r};import{createElement as et}from"react";import{renderToReadableStream as ct}from"react-dom/server.browser";var bt=async(o,s)=>{let r=et(o),t=await ct(r,{bootstrapModules:[s]});return new Response(t,{headers:{"Content-Type":"text/html"}})},Ut=(o)=>Bun.file(o);import{argv as _t}from"process";var{env:W}=globalThis.Bun;import at from"os";var Y=()=>{let o=at.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 L=W.HOST??"localhost",$=W.PORT??h,q,ut=_t,z=ut.includes("--host");if(z)q=Y(),L="0.0.0.0";var qt=(o)=>o.listen({hostname:L,port:$},()=>{if(z)console.log(`Server started on http://localhost:${$}`),console.log(`Server started on network: http://${q}:${$}`);else console.log(`Server started on http://${L}:${$}`)});export{H as updateScriptTags,qt as networkingPlugin,bt as handleReactPageRequest,Ut as handleHTMLPageRequest,Y as getLocalIPAddress,Mt as build,x as TIME_PRECISION,pt as SECONDS_IN_A_MINUTE,It as MINUTES_IN_AN_HOUR,C as MILLISECONDS_IN_A_SECOND,O as MILLISECONDS_IN_A_MINUTE,Et as MILLISECONDS_IN_A_DAY,mt as HOURS_IN_A_DAY,h as DEFAULT_PORT};
|
package/dist/src/core/build.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ type BuildConfig = {
|
|
|
7
7
|
reactPagesDir?: string;
|
|
8
8
|
htmlDir?: string;
|
|
9
9
|
htmxDir?: string;
|
|
10
|
+
tailwind?: {
|
|
11
|
+
input: string;
|
|
12
|
+
output: string;
|
|
13
|
+
};
|
|
10
14
|
};
|
|
11
|
-
export declare const build: ({ buildDir, assetsDir, reactIndexDir, javascriptDir, typeScriptDir, reactPagesDir, htmlDir, htmxDir }: BuildConfig) => Promise<Record<string, string> | null>;
|
|
15
|
+
export declare const build: ({ buildDir, assetsDir, reactIndexDir, javascriptDir, typeScriptDir, reactPagesDir, htmlDir, htmxDir, tailwind }: BuildConfig) => Promise<Record<string, string> | null>;
|
|
12
16
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absolutejs/absolute",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A fullstack meta-framework for building web applications with TypeScript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
"typescript": "5.7.2",
|
|
32
32
|
"react": "19.1.0",
|
|
33
33
|
"svelte": "4.2.15",
|
|
34
|
-
"vue": "3.4.26"
|
|
34
|
+
"vue": "3.4.26",
|
|
35
|
+
"postcss": "8.4.49",
|
|
36
|
+
"autoprefixer": "10.4.20",
|
|
37
|
+
"tailwindcss": "3.4.17"
|
|
35
38
|
}
|
|
36
39
|
}
|
package/src/core/build.ts
CHANGED
|
@@ -18,6 +18,10 @@ type BuildConfig = {
|
|
|
18
18
|
reactPagesDir?: string;
|
|
19
19
|
htmlDir?: string;
|
|
20
20
|
htmxDir?: string;
|
|
21
|
+
tailwind?: {
|
|
22
|
+
input: string;
|
|
23
|
+
output: string;
|
|
24
|
+
};
|
|
21
25
|
};
|
|
22
26
|
|
|
23
27
|
export const build = async ({
|
|
@@ -28,21 +32,11 @@ export const build = async ({
|
|
|
28
32
|
typeScriptDir,
|
|
29
33
|
reactPagesDir,
|
|
30
34
|
htmlDir,
|
|
31
|
-
htmxDir
|
|
35
|
+
htmxDir,
|
|
36
|
+
tailwind
|
|
32
37
|
}: BuildConfig) => {
|
|
33
38
|
const start = performance.now();
|
|
34
39
|
|
|
35
|
-
console.log("Build Config", {
|
|
36
|
-
buildDir,
|
|
37
|
-
assetsDir,
|
|
38
|
-
reactIndexDir,
|
|
39
|
-
javascriptDir,
|
|
40
|
-
typeScriptDir,
|
|
41
|
-
reactPagesDir,
|
|
42
|
-
htmlDir,
|
|
43
|
-
htmxDir
|
|
44
|
-
});
|
|
45
|
-
|
|
46
40
|
const projectRoot = cwd();
|
|
47
41
|
const buildDirAbsolute = join(projectRoot, buildDir);
|
|
48
42
|
const assetsDirAbsolute = assetsDir && join(projectRoot, assetsDir);
|
|
@@ -67,35 +61,21 @@ export const build = async ({
|
|
|
67
61
|
reactIndexDirAbsolute
|
|
68
62
|
));
|
|
69
63
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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);
|
|
64
|
+
const reactEntryPaths =
|
|
65
|
+
reactIndexDirAbsolute &&
|
|
66
|
+
(await scanEntryPoints(reactIndexDirAbsolute, "*.tsx"));
|
|
67
|
+
const javascriptEntryPaths =
|
|
68
|
+
javascriptDirAbsolute &&
|
|
69
|
+
(await scanEntryPoints(javascriptDirAbsolute, "*.js"));
|
|
70
|
+
const typeScriptEntryPaths =
|
|
71
|
+
typeScriptDirAbsolute &&
|
|
72
|
+
(await scanEntryPoints(typeScriptDirAbsolute, "*.ts"));
|
|
73
|
+
|
|
74
|
+
const entryPaths = [
|
|
75
|
+
...(reactEntryPaths ?? []),
|
|
76
|
+
...(javascriptEntryPaths ?? []),
|
|
77
|
+
...(typeScriptEntryPaths ?? [])
|
|
78
|
+
];
|
|
99
79
|
|
|
100
80
|
if (entryPaths.length === 0) {
|
|
101
81
|
console.warn("No entry points found, skipping build");
|
|
@@ -133,6 +113,10 @@ export const build = async ({
|
|
|
133
113
|
await $`cp -R ${htmxDirAbsolute} ${join(buildDirAbsolute)}`;
|
|
134
114
|
}
|
|
135
115
|
|
|
116
|
+
if (tailwind) {
|
|
117
|
+
await $`tailwindcss -i ${tailwind.input} -o ${join(buildDirAbsolute, tailwind.output)}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
136
120
|
const manifest = outputs.reduce<Record<string, string>>((acc, artifact) => {
|
|
137
121
|
let relativePath = artifact.path;
|
|
138
122
|
|
|
@@ -202,3 +186,12 @@ const generateReactIndexFiles = async (
|
|
|
202
186
|
});
|
|
203
187
|
await Promise.all(promises);
|
|
204
188
|
};
|
|
189
|
+
|
|
190
|
+
const scanEntryPoints = async (dir: string, pattern: string) => {
|
|
191
|
+
const entryPaths: string[] = [];
|
|
192
|
+
const glob = new Glob(pattern);
|
|
193
|
+
for await (const file of glob.scan({ absolute: true, cwd: dir })) {
|
|
194
|
+
entryPaths.push(file);
|
|
195
|
+
}
|
|
196
|
+
return entryPaths;
|
|
197
|
+
};
|