1
1
const puppeteer = require ( "puppeteer" ) ;
2
2
const _ = require ( "highland" ) ;
3
3
const url = require ( "url" ) ;
4
+ const glob = require ( "glob-to-regexp" ) ;
5
+ // @ts -ignore
4
6
const mapStackTrace = require ( "sourcemapped-stacktrace-node" ) . default ;
5
7
const path = require ( "path" ) ;
6
8
const fs = require ( "fs" ) ;
@@ -140,6 +142,7 @@ const crawl = async opt => {
140
142
publicPath,
141
143
sourceDir
142
144
} = opt ;
145
+ const exclude = options . exclude . map ( g => glob ( g , { extended : true , globstar : true } ) ) ;
143
146
let shuttingDown = false ;
144
147
let streamClosed = false ;
145
148
@@ -173,7 +176,7 @@ const crawl = async opt => {
173
176
* @returns {void }
174
177
*/
175
178
const addToQueue = newUrl => {
176
- const { hostname, search, hash, port } = url . parse ( newUrl ) ;
179
+ const { hostname, search, hash, port, pathname } = url . parse ( newUrl ) ;
177
180
newUrl = newUrl . replace ( `${ search || "" } ${ hash || "" } ` , "" ) ;
178
181
179
182
// Ensures that only link on the same port are crawled
@@ -184,6 +187,7 @@ const crawl = async opt => {
184
187
// Port can be null, therefore we need the null check
185
188
const isOnAppPort = port && port . toString ( ) === options . port . toString ( ) ;
186
189
190
+ if ( exclude . filter ( regex => regex . test ( pathname ) ) . length > 0 ) return ;
187
191
if ( hostname === "localhost" && isOnAppPort && ! uniqueUrls . has ( newUrl ) && ! streamClosed ) {
188
192
uniqueUrls . add ( newUrl ) ;
189
193
enqued ++ ;
0 commit comments