11const puppeteer = require ( "puppeteer" ) ;
22const _ = require ( "highland" ) ;
33const url = require ( "url" ) ;
4+ const glob = require ( "glob-to-regexp" ) ;
5+ // @ts -ignore
46const mapStackTrace = require ( "sourcemapped-stacktrace-node" ) . default ;
57const path = require ( "path" ) ;
68const fs = require ( "fs" ) ;
@@ -140,6 +142,7 @@ const crawl = async opt => {
140142 publicPath,
141143 sourceDir
142144 } = opt ;
145+ const exclude = options . exclude . map ( g => glob ( g , { extended : true , globstar : true } ) ) ;
143146 let shuttingDown = false ;
144147 let streamClosed = false ;
145148
@@ -173,7 +176,7 @@ const crawl = async opt => {
173176 * @returns {void }
174177 */
175178 const addToQueue = newUrl => {
176- const { hostname, search, hash, port } = url . parse ( newUrl ) ;
179+ const { hostname, search, hash, port, pathname } = url . parse ( newUrl ) ;
177180 newUrl = newUrl . replace ( `${ search || "" } ${ hash || "" } ` , "" ) ;
178181
179182 // Ensures that only link on the same port are crawled
@@ -184,6 +187,7 @@ const crawl = async opt => {
184187 // Port can be null, therefore we need the null check
185188 const isOnAppPort = port && port . toString ( ) === options . port . toString ( ) ;
186189
190+ if ( exclude . filter ( regex => regex . test ( pathname ) ) . length > 0 ) return ;
187191 if ( hostname === "localhost" && isOnAppPort && ! uniqueUrls . has ( newUrl ) && ! streamClosed ) {
188192 uniqueUrls . add ( newUrl ) ;
189193 enqued ++ ;
0 commit comments