11import { Glob , fileURLToPath , pathToFileURL } from "bun" ;
2- import { unlink } from "node:fs/promises" ;
32import { basename , join , relative } from "node:path" ;
43
54function escapeRegExp ( string : string ) {
65 return string . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ; // $& means the whole matched string
76}
87
9- function glob (
10- path : string ,
11- pattern = "**/*.{ts,tsx,js,jsx}"
12- ) : AsyncIterableIterator < string > {
13- const glob = new Glob ( pattern ) ;
14- return glob . scan ( { cwd : path , onlyFiles : true , absolute : true } ) ;
15- }
16-
178export async function build ( {
189 baseDir,
1910 buildDir = ".build" ,
@@ -35,7 +26,12 @@ export async function build({
3526} ) {
3627 const entrypoints = [ join ( baseDir , hydrate ) ] ;
3728 const absPageDir = join ( baseDir , pageDir ) ;
38- for await ( const path of glob ( absPageDir ) ) {
29+ const entrypointGlob = new Glob ( "**/*.{ts,tsx,js,jsx}" ) ;
30+ for await ( const path of entrypointGlob . scan ( {
31+ cwd : absPageDir ,
32+ onlyFiles : true ,
33+ absolute : true ,
34+ } ) ) {
3935 entrypoints . push ( path ) ;
4036 }
4137 const outdir = join ( baseDir , buildDir ) ;
@@ -95,11 +91,6 @@ export async function build({
9591 ] ,
9692 } ) ;
9793 if ( result . success ) {
98- for await ( const path of glob ( join ( baseDir , buildDir ) ) ) {
99- if ( result . outputs . every ( ( x ) => x . path !== path ) ) {
100- await unlink ( path ) ;
101- }
102- }
10394 const hashed : Record < string , string > = { } ;
10495 for ( const output of result . outputs ) {
10596 if ( output . kind === "entry-point" && output . hash ) {
0 commit comments