Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JustinBeckwith/linkinator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.12.2
Choose a base ref
...
head repository: JustinBeckwith/linkinator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.13.0
Choose a head ref
  • 2 commits
  • 13 files changed
  • 1 contributor

Commits on Jan 3, 2021

  1. feat: introduce retry-after detection (#221)

    This introduces a --retry flag, which when passed will automatically retry requests that comes back with a HTTP 429, and a retry-after header. I tested this against GitHub , and it appears to work as expected.
    JustinBeckwith authored Jan 3, 2021
    Copy the full SHA
    cebea21 View commit details

Commits on Jan 4, 2021

  1. Copy the full SHA
    1850490 View commit details
Showing with 588 additions and 154 deletions.
  1. +3 −2 .mocharc.json
  2. +5 −0 README.md
  3. +16 −1 src/cli.ts
  4. +1 −0 src/config.ts
  5. +106 −139 src/index.ts
  6. +137 −0 src/options.ts
  7. +52 −0 src/queue.ts
  8. +7 −0 test/fixtures/retry/index.html
  9. +5 −0 test/fixtures/retry/subpage.html
  10. +5 −0 test/fixtures/retryCLI/index.html
  11. +49 −12 test/{zcli.ts → test.cli.ts}
  12. 0 test/{test.ts → test.index.ts}
  13. +202 −0 test/test.retry.ts
5 changes: 3 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"check-leaks": true,
"timeout": 60000,
"timeout": 2000,
"throw-deprecation": true,
"enable-source-maps": true
"enable-source-maps": true,
"exit": true
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -64,6 +64,10 @@ $ linkinator LOCATIONS [ --arguments ]
--recurse, -r
Recursively follow links on the same root domain.
--retry,
Automatically retry requests that return HTTP 429 responses and include
a 'retry-after' header. Defaults to false.
--server-root
When scanning a locally directory, customize the location on disk
where the server is started. Defaults to the path passed in [LOCATION].
@@ -183,6 +187,7 @@ Asynchronous method that runs a site wide scan. Options come in the form of an o
- `concurrency` (number) - The number of connections to make simultaneously. Defaults to 100.
- `port` (number) - When the `path` is provided as a local path on disk, the `port` on which to start the temporary web server. Defaults to a random high range order port.
- `recurse` (boolean) - By default, all scans are shallow. Only the top level links on the requested page will be scanned. By setting `recurse` to `true`, the crawler will follow all links on the page, and continue scanning links **on the same domain** for as long as it can go. Results are cached, so no worries about loops.
- `retry` (boolean|RetryConfig) - Automatically retry requests that respond with an HTTP 429, and include a `retry-after` header. The `RetryConfig` option is a placeholder for fine-grained controls to be implemented at a later time, and is only included here to signal forward-compatibility.
- `serverRoot` (string) - When scanning a locally directory, customize the location on disk
where the server is started. Defaults to the path passed in `path`.
- `timeout` (number) - By default, requests made by linkinator do not time out (or follow the settings of the OS). This option (in milliseconds) will fail requests after the configured amount of time.
17 changes: 16 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,13 @@
import * as meow from 'meow';
import * as updateNotifier from 'update-notifier';
import chalk = require('chalk');
import {LinkChecker, LinkState, LinkResult, CheckOptions} from './index';
import {
LinkChecker,
LinkState,
LinkResult,
CheckOptions,
RetryInfo,
} from './index';
import {promisify} from 'util';
import {Flags, getConfig} from './config';
import {Format, Logger, LogLevel} from './logger';
@@ -51,6 +57,10 @@ const cli = meow(
--recurse, -r
Recursively follow links on the same root domain.
--retry,
Automatically retry requests that return HTTP 429 responses and include
a 'retry-after' header. Defaults to false.
--server-root
When scanning a locally directory, customize the location on disk
where the server is started. Defaults to the path passed in [LOCATION].
@@ -85,6 +95,7 @@ const cli = meow(
serverRoot: {type: 'string'},
verbosity: {type: 'string'},
directoryListing: {type: 'boolean'},
retry: {type: 'boolean'},
},
booleanDefault: undefined,
}
@@ -107,6 +118,9 @@ async function main() {
logger.error(`🏊‍♂️ crawling ${cli.input}`);

const checker = new LinkChecker();
checker.on('retry', (info: RetryInfo) => {
logger.warn(`Retrying: ${info.url} in ${info.secondsUntilRetry} seconds.`);
});
checker.on('link', (link: LinkResult) => {
let state = '';
switch (link.state) {
@@ -132,6 +146,7 @@ async function main() {
concurrency: Number(flags.concurrency),
serverRoot: flags.serverRoot,
directoryListing: flags.directoryListing,
retry: flags.retry,
};
if (flags.skip) {
if (typeof flags.skip === 'string') {
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ export interface Flags {
markdown?: boolean;
serverRoot?: string;
directoryListing?: boolean;
retry?: boolean;
}

export async function getConfig(flags: Flags) {
Loading