File tree 2 files changed +19
-6
lines changed
2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ onExit();
6
6
async function checkList ( list ) {
7
7
return await Promise . all (
8
8
// for each redirect
9
- list . map ( async ( { to } ) => {
9
+ list . map ( async ( { to, file , index } ) => {
10
10
try {
11
11
// do simple request to target url
12
12
const response = await fetch ( to ) ;
@@ -19,10 +19,12 @@ async function checkList(list) {
19
19
)
20
20
throw Error ( response . status ) ;
21
21
} catch ( error ) {
22
- addError ( `"to: ${ to } " may be a broken link\n(${ error } )` ) ;
22
+ addError (
23
+ `${ file } entry ${ index } "to: ${ to } " may be a broken link\n (${ error } )`
24
+ ) ;
23
25
}
24
26
} )
25
27
) ;
26
28
}
27
29
28
- await checkList ( getList ( ) ) ;
30
+ await checkList ( getList ( true ) ) ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import { parse } from "yaml";
7
7
export const verbose = ! ! process . env . RUNNER_DEBUG ;
8
8
9
9
// get full list of redirects
10
- export function getList ( ) {
10
+ export function getList ( meta ) {
11
11
// get yaml files that match glob pattern
12
12
const files = globSync ( "*.y?(a)ml" , { cwd : __dirname } ) ;
13
13
@@ -63,12 +63,16 @@ export function getList() {
63
63
// normalize "from" field. lower case, remove leading slashes.
64
64
entry . from = entry . from . toLowerCase ( ) . replace ( / ^ ( \/ + ) / , "" ) ;
65
65
66
+ // record meta for logging
67
+ entry . file = file ;
68
+ entry . index = index ;
69
+
66
70
// add to combined list
67
71
list . push ( entry ) ;
68
72
69
- // add to duplicate list. record source file and entry number for logging.
73
+ // add to duplicate list
70
74
duplicates [ entry . from ] ??= [ ] ;
71
- duplicates [ entry . from ] . push ( { ... entry , file , index } ) ;
75
+ duplicates [ entry . from ] . push ( entry ) ;
72
76
}
73
77
}
74
78
@@ -87,6 +91,13 @@ export function getList() {
87
91
addError ( `"from: ${ from } " appears ${ count } time(s): ${ duplicates } ` ) ;
88
92
}
89
93
94
+ // if meta not requested, clean up
95
+ if ( ! meta )
96
+ list . forEach ( ( entry ) => {
97
+ delete entry . file ;
98
+ delete entry . index ;
99
+ } ) ;
100
+
90
101
return list ;
91
102
}
92
103
You can’t perform that action at this time.
0 commit comments