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.14.3
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.14.4
Choose a head ref
  • 4 commits
  • 7 files changed
  • 3 contributors

Commits on Oct 5, 2021

  1. build: update CI config (#338)

    * make use of `actions/setup-node@v2` `cache` option
    * update CodeQL workflow to the latest recommended one
    
    Co-authored-by: Justin Beckwith <beckwith@google.com>
    XhmikosR and JustinBeckwith authored Oct 5, 2021
    Copy the full SHA
    5a36c06 View commit details
  2. Copy the full SHA
    43db808 View commit details
  3. test: increase timeout (#340)

    Co-authored-by: Justin Beckwith <beckwith@google.com>
    XhmikosR and JustinBeckwith authored Oct 5, 2021
    Copy the full SHA
    02f9af6 View commit details
  4. fix: allow system to generate random port when desired (#319) (#328)

    Co-authored-by: Justin Beckwith <beckwith@google.com>
    rrthomas and JustinBeckwith authored Oct 5, 2021
    Copy the full SHA
    7b9d493 View commit details
Showing with 30 additions and 51 deletions.
  1. +5 −39 .github/workflows/ci.yaml
  2. +5 −4 .github/workflows/codeql.yml
  3. +2 −1 renovate.json
  4. +6 −1 src/index.ts
  5. +7 −2 src/server.ts
  6. +1 −1 test/test.cli.ts
  7. +4 −3 test/test.server.ts
44 changes: 5 additions & 39 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -19,13 +19,7 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Set up npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-v${{ matrix.node }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-v${{ matrix.node }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
cache: npm
- run: npm ci
- run: npm test
- run: npm run codecov
@@ -37,17 +31,7 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE }}
- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- name: Set up npm cache
uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-v${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-v${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
cache: npm
- run: npm ci
- run: npm test
lint:
@@ -57,13 +41,7 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE }}
- name: Set up npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-v${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-v${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
cache: npm
- run: npm ci
- run: npm run lint
docs:
@@ -73,13 +51,7 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE }}
- name: Set up npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-v${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-v${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
cache: npm
- run: npm ci
- run: npm run docs-test
release:
@@ -91,13 +63,7 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE }}
- name: Set up npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-v${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-v${{ env.NODE }}-${{ hashFiles('package.json') }}-${{ hashFiles('package-lock.json') }}
cache: npm
- run: npm ci
- run: npm run compile
- run: npm run build-binaries
9 changes: 5 additions & 4 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -9,26 +9,27 @@ on:
# The branches below must be a subset of the branches above
branches:
- main
- "!renovate/**"
schedule:
- cron: "0 0 * * 0"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: "javascript"

- name: Autobuild
uses: github/codeql-action/autobuild@v1

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
3 changes: 2 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": [
"config:base"
"config:base",
":disableDependencyDashboard"
],
"pinVersions": false,
"rebaseStalePrs": true
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {EventEmitter} from 'events';
import {URL} from 'url';
import {AddressInfo} from 'net';
import * as http from 'http';
import * as path from 'path';
import {Readable} from 'stream';
@@ -81,13 +82,17 @@ export class LinkChecker extends EventEmitter {
let server: http.Server | undefined;
const hasHttpPaths = options.path.find(x => x.startsWith('http'));
if (!hasHttpPaths) {
const port = options.port || 5000 + Math.round(Math.random() * 1000);
let port = options.port;
server = await startWebServer({
root: options.serverRoot!,
port,
markdown: options.markdown,
directoryListing: options.directoryListing,
});
if (port === undefined) {
const addr = server.address() as AddressInfo;
port = addr.port;
}
for (let i = 0; i < options.path.length; i++) {
if (options.path[i].startsWith('/')) {
options.path[i] = options.path[i].slice(1);
9 changes: 7 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {AddressInfo} from 'net';
import * as http from 'http';
import * as path from 'path';
import * as fs from 'fs';
@@ -16,7 +17,7 @@ export interface WebServerOptions {
// The local path that should be mounted as a static web server
root: string;
// The port on which to start the local web server
port: number;
port?: number;
// If markdown should be automatically compiled and served
markdown?: boolean;
// Should directories automatically serve an inde page
@@ -33,8 +34,12 @@ export async function startWebServer(options: WebServerOptions) {
return new Promise<http.Server>((resolve, reject) => {
const server = http
.createServer((req, res) => handleRequest(req, res, root, options))
.listen(options.port, () => resolve(server))
.listen(options.port || 0, () => resolve(server))
.on('error', reject);
if (!options.port) {
const addr = server.address() as AddressInfo;
options.port = addr.port;
}
enableDestroy(server);
});
}
2 changes: 1 addition & 1 deletion test/test.cli.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import {LinkResult, LinkState} from '../src/index';
// eslint-disable-next-line prefer-arrow-callback
describe('cli', function () {
let server: http.Server;
this.timeout(10_000);
this.timeout(20_000);

const pkg = require('../../package.json');
const linkinator = pkg.bin.linkinator;
7 changes: 4 additions & 3 deletions test/test.server.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import * as assert from 'assert';
import {describe, it, before, after} from 'mocha';
import {startWebServer} from '../src/server';
import {AddressInfo} from 'net';
import {Server} from 'http';
import {request} from 'gaxios';
import * as fs from 'fs';

describe('server', () => {
let server: Server;
const port = 5000 + Math.round(Math.random() * 1000);
const rootUrl = `http://localhost:${port}`;
let rootUrl: string;
const contents = fs.readFileSync('test/fixtures/server/index.html', 'utf-8');
before(async () => {
server = await startWebServer({
port,
directoryListing: true,
markdown: true,
root: 'test/fixtures/server',
});
const addr = server.address() as AddressInfo;
rootUrl = `http://localhost:${addr.port}`;
});
after(() => server.destroy());