1
1
import { Glob , fileURLToPath , pathToFileURL } from "bun" ;
2
- import { unlink } from "node:fs/promises" ;
3
2
import { basename , join , relative } from "node:path" ;
4
3
5
4
function escapeRegExp ( string : string ) {
6
5
return string . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ; // $& means the whole matched string
7
6
}
8
7
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
-
17
8
export async function build ( {
18
9
baseDir,
19
10
buildDir = ".build" ,
@@ -35,7 +26,12 @@ export async function build({
35
26
} ) {
36
27
const entrypoints = [ join ( baseDir , hydrate ) ] ;
37
28
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
+ } ) ) {
39
35
entrypoints . push ( path ) ;
40
36
}
41
37
const outdir = join ( baseDir , buildDir ) ;
@@ -95,11 +91,6 @@ export async function build({
95
91
] ,
96
92
} ) ;
97
93
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
- }
103
94
const hashed : Record < string , string > = { } ;
104
95
for ( const output of result . outputs ) {
105
96
if ( output . kind === "entry-point" && output . hash ) {
0 commit comments