@@ -104,11 +104,10 @@ function copyRuntimeBlocklist() {
104104 path . join ( CUSTOM_DIR , "v8s-policies.json" ) ,
105105 path . join ( CUSTOM_DIR , "v8s-blocklist.json" )
106106 ) ;
107- const base = readJsonFile ( defaultPath ) ;
108- const custom = readJsonFile ( customPath ) ;
109- const merged = mergeRuntimeBlocklist ( base , custom ) ;
107+ const policyPath = fs . existsSync ( customPath ) ? customPath : defaultPath ;
108+ const policy = readJsonFile ( policyPath ) ;
110109
111- fs . writeFileSync ( RUNTIME_BLOCKLIST_PATH , `${ JSON . stringify ( merged , null , 2 ) } \n` ) ;
110+ fs . writeFileSync ( RUNTIME_BLOCKLIST_PATH , `${ JSON . stringify ( policy , null , 2 ) } \n` ) ;
112111}
113112
114113function readJsonFile ( filePath ) {
@@ -120,57 +119,6 @@ function firstExistingPath(...paths) {
120119 return paths . find ( ( filePath ) => fs . existsSync ( filePath ) ) || paths [ 0 ] ;
121120}
122121
123- function mergeRuntimeBlocklist ( base , custom ) {
124- return {
125- ...base ,
126- ...custom ,
127- defaults : {
128- ...( base . defaults || { } ) ,
129- ...( custom . defaults || { } ) ,
130- allowed_protocols : mergeArray (
131- base . defaults ?. allowed_protocols ,
132- custom . defaults ?. allowed_protocols
133- ) ,
134- blocked_file_extensions : mergeArray (
135- base . defaults ?. blocked_file_extensions ,
136- custom . defaults ?. blocked_file_extensions
137- )
138- } ,
139- generated_sources : {
140- ...( base . generated_sources || { } ) ,
141- ...( custom . generated_sources || { } )
142- } ,
143- allow_domains : mergeEntries ( base . allow_domains , custom . allow_domains , "domain" ) ,
144- blocked_keywords : mergeEntries ( base . blocked_keywords , custom . blocked_keywords , "keyword" ) ,
145- block_domains : mergeEntries ( base . block_domains , custom . block_domains , "domain" )
146- } ;
147- }
148-
149- function mergeArray ( first = [ ] , second = [ ] ) {
150- return [ ...new Set ( [ ...asArray ( first ) , ...asArray ( second ) ] ) ] ;
151- }
152-
153- function mergeEntries ( first = [ ] , second = [ ] , key ) {
154- const merged = new Map ( ) ;
155-
156- for ( const entry of [ ...asArray ( first ) , ...asArray ( second ) ] ) {
157- if ( ! entry || typeof entry !== "object" ) continue ;
158- const value = String ( entry [ key ] || "" ) . trim ( ) . toLowerCase ( ) ;
159- if ( ! value ) continue ;
160-
161- merged . set ( value , {
162- ...entry ,
163- [ key ] : value
164- } ) ;
165- }
166-
167- return [ ...merged . values ( ) ] ;
168- }
169-
170- function asArray ( value ) {
171- return Array . isArray ( value ) ? value : [ ] ;
172- }
173-
174122function buildRedirectTargets ( ) {
175123 log ( "Building v8s.json" ) ;
176124
0 commit comments