@@ -13,7 +13,7 @@ const BASE_URL = "http://localhost:4321"
1313const TEMP_DIR = `${ cwd ( ) } /temp`
1414const LOG_FILE = `${ TEMP_DIR } /link-checker.log`
1515
16- const LINK_CHUNK_SIZE = 300
16+ const LINK_CHUNK_SIZE = 150
1717
1818// ================================
1919// HELPER FUNCTIONS
@@ -42,14 +42,36 @@ function displayLogFile() {
4242
4343/**
4444 * Wait for the dev server to be "ready" by checking for a 2xx status on BASE_URL.
45+ * Uses multiple checks to ensure server stability.
4546 */
4647async function waitForServerReadiness ( url : string , attempts = 20 ) {
4748 for ( let i = 1 ; i <= attempts ; i ++ ) {
4849 try {
4950 const response = await fetch ( url )
5051 if ( response . ok ) {
51- console . log ( `Server is ready at ${ url } ` )
52- return
52+ // Server responded, but few more checks to ensure stability
53+ console . log ( `Server responded on attempt ${ i } , verifying stability...` )
54+
55+ let stableChecks = 0
56+ for ( let j = 0 ; j < 3 ; j ++ ) {
57+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) )
58+ try {
59+ const checkResponse = await fetch ( url )
60+ if ( checkResponse . ok ) {
61+ stableChecks ++
62+ }
63+ } catch {
64+ // Stability check failed
65+ break
66+ }
67+ }
68+
69+ if ( stableChecks === 3 ) {
70+ console . log ( `Server is ready and stable at ${ url } ` )
71+ return
72+ } else {
73+ console . log ( `Server not yet stable, continuing checks...` )
74+ }
5375 }
5476 } catch {
5577 // Connection error or not ready yet
@@ -247,22 +269,29 @@ async function main() {
247269 const chunkFiles = await processSiteMap ( mode )
248270 console . log ( `Created ${ chunkFiles . length } chunk files.` )
249271
250- // 6) Run link check on each chunk in parallel, collecting any failures
251- const checkPromises = chunkFiles . map ( ( chunkFile , index ) => {
272+ // 6) Run link check on each chunk sequentially to reduce CI resource pressure
273+ const results : { chunkNumber : number ; failed : boolean } [ ] = [ ]
274+
275+ for ( let index = 0 ; index < chunkFiles . length ; index ++ ) {
276+ const chunkFile = chunkFiles [ index ]
252277 const chunkNumber = index + 1
253278 console . log ( `\n>>> Checking chunk ${ chunkNumber } of ${ chunkFiles . length } : ${ chunkFile } \n` )
254279
255- return checkChunkFile ( chunkFile , mode ) . then ( ( code ) => {
256- if ( code !== 0 ) {
257- console . error ( `Link checker failed on chunk ${ chunkNumber } (exit code: ${ code } )` )
258- // We'll store chunkNumber with the failure
259- return { chunkNumber, failed : true }
260- }
261- return { chunkNumber, failed : false }
262- } )
263- } )
280+ const code = await checkChunkFile ( chunkFile , mode )
281+ if ( code !== 0 ) {
282+ console . error ( `Link checker failed on chunk ${ chunkNumber } (exit code: ${ code } )` )
283+ results . push ( { chunkNumber, failed : true } )
284+ } else {
285+ results . push ( { chunkNumber, failed : false } )
286+ }
287+
288+ // Add a small delay between chunks to reduce server pressure
289+ if ( index < chunkFiles . length - 1 ) {
290+ console . log ( "Waiting 2 seconds before next chunk..." )
291+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) )
292+ }
293+ }
264294
265- const results = await Promise . all ( checkPromises )
266295 const failedChunks = results . filter ( ( r ) => r . failed ) . map ( ( r ) => r . chunkNumber )
267296
268297 // 7) If any chunks failed, exit with error after we've checked them all
0 commit comments