Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite to typescript with puppeteer-cluster + additional options and hooks. #554

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
933c8d9
networkidle0 -> networkidle2
jan-rycko Oct 25, 2021
bc56629
Added exclude option.
jan-rycko Oct 26, 2021
10b8b80
Unnecessary glob-to-regexp.
jan-rycko Oct 26, 2021
d843ff7
Base path in options.
jan-rycko Oct 27, 2021
6aa4f68
console.log
jan-rycko Oct 27, 2021
558504e
Using calculated basePath, not only on localhost
jan-rycko Oct 27, 2021
ca63d63
Fix for null base path.
jan-rycko Mar 7, 2022
098f362
Default base path and wait for response option.
jan-rycko Mar 11, 2022
51257ba
Customizable logging with handling in afterFetch.
jan-rycko Mar 16, 2022
ca8d3b3
More optimizations.
jan-rycko Mar 17, 2022
1be88eb
Minor style processing improvements.
jan-rycko Mar 18, 2022
109e5f3
No-port mode.
jan-rycko Mar 25, 2022
eabd0c8
Fixed tests
jan-rycko Mar 28, 2022
38ce0b3
Rewrite to typescript, puppeteer upgrade, with ts-jest.
jan-rycko Mar 28, 2022
756a6ce
Rewrite to puppeteer-cluster.
jan-rycko Mar 28, 2022
d548690
Finished rewrite to puppeteer cluster.
jan-rycko Mar 30, 2022
b60ad49
dist in files
jan-rycko Apr 2, 2022
45c9672
More logs for pageerror
jan-rycko Apr 2, 2022
771895f
concurrencyType from puppeteer-cluster added to options.
jan-rycko Apr 4, 2022
60692e5
Build
jan-rycko Apr 4, 2022
4f641b2
Package json for react-snap-typed
jan-rycko Apr 5, 2022
fd3b6bd
pageerror message and cancelable wait for idle.
jan-rycko Apr 11, 2022
474733b
Build 1.26.0
jan-rycko Apr 11, 2022
e57b353
Fix.
jan-rycko Apr 11, 2022
1de2258
1.26.2
jan-rycko Apr 11, 2022
a01276b
1.26.3
jan-rycko Apr 11, 2022
2c9c303
Rebuild 1.26.4
jan-rycko Apr 11, 2022
6ae68c3
Ignore canceled promise error.
jan-rycko Apr 11, 2022
01e4753
Typo 1.26.6
jan-rycko Apr 11, 2022
ed63af9
1.26.7
jan-rycko Apr 11, 2022
de87ffe
1.26.8
jan-rycko Apr 11, 2022
b517b39
1.26.9
jan-rycko Apr 11, 2022
7bd2c84
1.26.10
jan-rycko Apr 11, 2022
d402690
page/browser close strategy
jan-rycko Apr 11, 2022
c1d04fc
Logs 1.26.12
jan-rycko Apr 11, 2022
6542cb2
Logs 1.26.13
jan-rycko Apr 11, 2022
7d44b74
Version
jan-rycko Apr 11, 2022
e49883e
Logs 1.26.15
jan-rycko Apr 11, 2022
ea3aa21
Logs 1.26.16
jan-rycko Apr 11, 2022
ce40e9b
cleanup hook 1.26.17
jan-rycko Apr 11, 2022
0e6cefd
cleanupBrowser
jan-rycko Jun 6, 2022
a7400db
1.26.18
jan-rycko Jun 6, 2022
dfa8e13
Disabled websocket connections in puppeteer_utils.
jan-rycko Jul 13, 2022
77744bd
Rollback for now.
jan-rycko Jul 13, 2022
3f7401c
Basic auth.
jan-rycko Nov 7, 2022
3f8e922
Use timeout option.
jan-rycko Nov 7, 2022
3cd2709
Version
jan-rycko Nov 7, 2022
736c4d8
Version.
jan-rycko Nov 7, 2022
7bd7be2
Version.
jan-rycko Nov 7, 2022
e053573
Retries on errors.
jan-rycko Nov 7, 2022
d7c8b54
Version.
jan-rycko Nov 8, 2022
17f8746
Disable check for unique url when requesting for second snapshot.
jan-rycko Nov 8, 2022
866b132
Disabled browser.close()
jan-rycko Nov 9, 2022
22e32bb
1.26.30: Audit fixes.
jan-rycko Feb 9, 2023
54e82f0
preinstall -> force-resolutions
jan-rycko Mar 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*]
charset = utf-8
indent_size = 2
indent_style = space
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
yarn-error.log
.idea
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ If you need to pass some options for `react-snap`, you can do this in your `pack
}
```

Not all options are documented yet, but you can check `defaultOptions` in `index.js`.
Not all options are documented yet, but you can check `defaultOptions` in `index.ts`.

### inlineCss

Expand Down
8 changes: 8 additions & 0 deletions dist/defaults.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { IReactSnapOptions } from "./model";
export declare const defaultOptions: IReactSnapOptions;
/**
*
* @param {{source: ?string, destination: ?string, include: ?Array<string>, sourceMaps: ?boolean, skipThirdPartyRequests: ?boolean }} userOptions
* @return {*}
*/
export declare const defaults: (userOptions: IReactSnapOptions) => IReactSnapOptions;
135 changes: 135 additions & 0 deletions dist/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaults = exports.defaultOptions = void 0;
const puppeteer_cluster_1 = require("puppeteer-cluster");
exports.defaultOptions = {
//# stable configurations
port: 45678,
basePath: "http://localhost",
source: "build",
destination: null,
concurrency: 4,
concurrencyType: puppeteer_cluster_1.Cluster.CONCURRENCY_BROWSER,
include: ["/"],
exclude: [],
userAgent: "ReactSnap",
// 4 params below will be refactored to one: `puppeteer: {}`
// https://github.com/stereobooster/react-snap/issues/120
headless: true,
puppeteer: {
cache: true
},
puppeteerArgs: [],
puppeteerExecutablePath: undefined,
puppeteerIgnoreHTTPSErrors: false,
publicPath: "/",
minifyCss: {},
minifyHtml: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
decodeEntities: true,
keepClosingSlash: true,
sortAttributes: true,
sortClassName: false
},
processHtml: undefined,
processPage: undefined,
// mobile first approach
viewport: {
width: 480,
height: 850
},
sourceMaps: true,
//# workarounds
// using CRA1 for compatibility with previous version will be changed to false in v2
fixWebpackChunksIssue: "CRA1",
removeBlobs: true,
fixInsertRule: true,
ignorePageErrors: false,
skipThirdPartyRequests: false,
cacheAjaxRequests: false,
http2PushManifest: false,
// may use some glob solution in the future, if required
// works when http2PushManifest: true
ignoreForPreload: ["service-worker.js"],
//# unstable configurations
preconnectThirdParty: true,
// Experimental. This config stands for two strategies inline and critical.
// TODO: inline strategy can contain errors, like, confuse relative urls
inlineCss: false,
warnOnInlineCssKb: 20,
processCss: undefined,
leaveLinkCss: undefined,
//# feature creeps to generate screenshots
saveAs: "html",
fileName: "index",
crawl: true,
waitFor: false,
cleanup: undefined,
externalServer: false,
//# even more workarounds
removeStyleTags: false,
preloadImages: false,
cleanPreloads: false,
// add async true to script tags
asyncScriptTags: false,
//# another feature creep
// tribute to Netflix Server Side Only React https://twitter.com/NetflixUIE/status/923374215041912833
// but this will also remove code which registers service worker
removeScriptTags: false,
};
/**
*
* @param {{source: ?string, destination: ?string, include: ?Array<string>, sourceMaps: ?boolean, skipThirdPartyRequests: ?boolean }} userOptions
* @return {*}
*/
const defaults = (userOptions) => {
const options = Object.assign(Object.assign({}, exports.defaultOptions), userOptions);
options.destination = options.destination || options.source;
options.basePath = options.basePath || exports.defaultOptions.basePath;
let exit = false;
if (!options.include || !options.include.length) {
console.log("🔥 include option should be an non-empty array");
exit = true;
}
if (options.preloadResources) {
console.log("🔥 preloadResources option deprecated. Use preloadImages or cacheAjaxRequests");
exit = true;
}
if (options.minifyOptions) {
console.log("🔥 minifyOptions option renamed to minifyHtml");
options.minifyHtml = options.minifyOptions;
}
if (options.asyncJs) {
console.log("🔥 asyncJs option renamed to asyncScriptTags");
options.asyncScriptTags = options.asyncJs;
}
if (/\.(html|jpg|jpeg|png)$/.test(options.fileName)) {
console.log("🔥 fileName should be base, appropritate extension will be added");
options.fileName = options.fileName.replace(/\.(html|jpg|jpeg|png)$/, "");
}
if (options.fixWebpackChunksIssue === true) {
console.log("🔥 fixWebpackChunksIssue - behaviour changed, valid options are CRA1, CRA2, Parcel, false");
options.fixWebpackChunksIssue = "CRA1";
}
const features = ["html", "png", "jpg", "jpeg"];
if (Array.isArray(options.saveAs) ?
!options.saveAs.every(saveAs => features.includes(saveAs))
:
!features.includes(options.saveAs)) {
console.log("🔥 saveAs supported values are html, png, and jpeg");
exit = true;
}
if (exit)
throw new Error();
if (options.minifyHtml && !options.minifyHtml.minifyCSS) {
options.minifyHtml.minifyCSS = options.minifyCss || {};
}
if (!options.publicPath.startsWith("/")) {
options.publicPath = `/${options.publicPath}`;
}
options.publicPath = options.publicPath.replace(/\/$/, "");
options.include = options.include.map(include => options.publicPath + include);
return options;
};
exports.defaults = defaults;
Empty file added dist/global.d.ts
Empty file.
Empty file added dist/global.js
Empty file.
7 changes: 7 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="node" />
import nativeFs from "fs";
import { IReactSnapOptions, ReactSnapRunInfo } from "./model";
export declare const run: (userOptions: IReactSnapOptions, { fs }?: {
fs: typeof nativeFs;
}) => Promise<ReactSnapRunInfo>;
export { IReactSnapOptions, ReactSnapRunInfo };
Loading