Skip to content

Commit a0d3e05

Browse files
zelphirpaulRbr
authored andcommitted
Add exclude option
1 parent b741d41 commit a0d3e05

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const defaultOptions = {
1919
destination: null,
2020
concurrency: 4,
2121
include: ["/"],
22+
exclude: [],
2223
userAgent: "ReactSnap",
2324
// 4 params below will be refactored to one: `puppeteer: {}`
2425
// https://github.com/stereobooster/react-snap/issues/120

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"clean-css": "4.2.1",
1414
"express": "4.16.4",
1515
"express-history-api-fallback": "2.2.1",
16+
"glob-to-regexp": "^0.4.0",
1617
"highland": "2.13.4",
1718
"html-minifier": "4.0.0",
1819
"minimalcss": "0.8.2",

src/puppeteer_utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const puppeteer = require("puppeteer");
22
const _ = require("highland");
33
const url = require("url");
4+
const glob = require("glob-to-regexp");
5+
// @ts-ignore
46
const mapStackTrace = require("sourcemapped-stacktrace-node").default;
57
const path = require("path");
68
const 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,8 +176,9 @@ const crawl = async opt => {
173176
* @returns {void}
174177
*/
175178
const addToQueue = newUrl => {
176-
const { hostname, search, hash } = url.parse(newUrl);
179+
const { hostname, search, hash, pathname } = url.parse(newUrl);
177180
newUrl = newUrl.replace(`${search || ""}${hash || ""}`, "");
181+
if (exclude.filter(regex => regex.test(pathname)).length > 0) return;
178182
if (hostname === "localhost" && !uniqueUrls.has(newUrl) && !streamClosed) {
179183
uniqueUrls.add(newUrl);
180184
enqued++;

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,11 @@ getpass@^0.1.1:
14251425
dependencies:
14261426
assert-plus "^1.0.0"
14271427

1428+
glob-to-regexp@^0.4.0:
1429+
version "0.4.1"
1430+
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e"
1431+
integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==
1432+
14281433
glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:
14291434
version "7.1.2"
14301435
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"

0 commit comments

Comments
 (0)