Skip to content

Commit

Permalink
chore(deps): upgrade to gts v2.0.0 (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Apr 10, 2020
1 parent 9c26c5a commit 2bb0246
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 91 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/node_modules
build/
test/fixtures
samples/
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts"
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/*
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json')
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@
"@types/server-destroy": "^1.0.0",
"@types/sinon": "^9.0.0",
"@types/update-notifier": "^4.0.0",
"assert-rejects": "^1.0.0",
"c8": "^7.0.0",
"chai": "^4.2.0",
"codecov": "^3.6.1",
"execa": "^4.0.0",
"gts": "^1.1.0",
"gts": "^2.0.0",
"mocha": "^7.0.0",
"nock": "^12.0.0",
"semantic-release": "^17.0.0",
Expand Down
3 changes: 1 addition & 2 deletions samples/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const link = require('linkinator');
*/
async function simple() {
const results = await link.check({
path: 'http://example.com'
path: 'http://example.com',
});

// To see if all the links passed, you can check `passed`
Expand Down Expand Up @@ -47,7 +47,6 @@ async function complex() {

// After a page is scanned, check out the results!
checker.on('link', result => {

// check the specific url that was scanned
console.log(` ${result.url}`);

Expand Down
26 changes: 15 additions & 11 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import * as meow from 'meow';
import * as updateNotifier from 'update-notifier';
import chalk = require('chalk');
import { LinkChecker, LinkState, LinkResult, CheckOptions } from './index';
import { promisify } from 'util';
import { Flags, getConfig } from './config';
import {LinkChecker, LinkState, LinkResult, CheckOptions} from './index';
import {promisify} from 'util';
import {Flags, getConfig} from './config';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const toCSV = promisify(require('jsonexport'));

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../../package.json');
updateNotifier({ pkg }).notify();
updateNotifier({pkg}).notify();

const cli = meow(
`
Expand Down Expand Up @@ -52,12 +55,12 @@ const cli = meow(
`,
{
flags: {
config: { type: 'string' },
concurrency: { type: 'string' },
recurse: { type: 'boolean', alias: 'r' },
skip: { type: 'string', alias: 's' },
format: { type: 'string', alias: 'f' },
silent: { type: 'boolean' },
config: {type: 'string'},
concurrency: {type: 'string'},
recurse: {type: 'boolean', alias: 'r'},
skip: {type: 'string', alias: 's'},
format: {type: 'string', alias: 'f'},
silent: {type: 'boolean'},
},
booleanDefault: undefined,
}
Expand Down Expand Up @@ -137,7 +140,7 @@ async function main() {
acc[parent].push(curr);
}
return acc;
}, {} as { [index: string]: LinkResult[] });
}, {} as {[index: string]: LinkResult[]});

Object.keys(parents).forEach(parent => {
const links = parents[parent];
Expand Down Expand Up @@ -178,6 +181,7 @@ async function main() {
)} links in ${chalk.cyan(total.toString())} seconds.`
)
);
// eslint-disable-next-line no-process-exit
process.exit(1);
}

Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import { promisify } from 'util';
import {promisify} from 'util';

const readFile = promisify(fs.readFile);

Expand All @@ -17,7 +17,7 @@ export async function getConfig(flags: Flags) {
const configPath = flags.config || 'linkinator.config.json';
let configData: string | undefined;
try {
configData = await readFile(configPath, { encoding: 'utf8' });
configData = await readFile(configPath, {encoding: 'utf8'});
} catch (e) {
if (flags.config) {
console.error(`Unable to find config file ${flags.config}`);
Expand All @@ -35,7 +35,7 @@ export async function getConfig(flags: Flags) {
const strippedFlags = Object.assign({}, flags);
Object.entries(strippedFlags).forEach(([key, value]) => {
if (typeof value === 'undefined') {
delete (strippedFlags as { [index: string]: {} })[key];
delete (strippedFlags as {[index: string]: {}})[key];
}
});

Expand Down
21 changes: 13 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { EventEmitter } from 'events';
import {EventEmitter} from 'events';
import * as gaxios from 'gaxios';
import * as http from 'http';
import enableDestroy = require('server-destroy');
import PQueue, { DefaultAddOptions } from 'p-queue';
import PQueue, {DefaultAddOptions} from 'p-queue';

import { getLinks } from './links';
import { URL } from 'url';
import {getLinks} from './links';
import {URL} from 'url';
import PriorityQueue from 'p-queue/dist/priority-queue';

const finalhandler = require('finalhandler');
const serveStatic = require('serve-static');
import finalhandler = require('finalhandler');
import serveStatic = require('serve-static');

export interface CheckOptions {
concurrency?: number;
Expand Down Expand Up @@ -107,7 +107,10 @@ export class LinkChecker extends EventEmitter {
return new Promise((resolve, reject) => {
const serve = serveStatic(root);
const server = http
.createServer((req, res) => serve(req, res, finalhandler(req, res)))
.createServer((req, res) =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
serve(req as any, res as any, finalhandler(req, res))
)
.listen(port, () => resolve(server))
.on('error', reject);
});
Expand Down Expand Up @@ -263,7 +266,9 @@ export class LinkChecker extends EventEmitter {
try {
const pathUrl = new URL(opts.checkOptions.path);
crawl = result.url!.host === pathUrl.host;
} catch {}
} catch {
// ignore errors
}
}

// Ensure the url hasn't already been touched, largely to avoid a
Expand Down
10 changes: 5 additions & 5 deletions src/links.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as cheerio from 'cheerio';
import { URL } from 'url';
import {URL} from 'url';

const linksAttr = {
background: ['body'],
Expand All @@ -25,7 +25,7 @@ const linksAttr = {
'video',
],
srcset: ['img', 'source'],
} as { [index: string]: string[] };
} as {[index: string]: string[]};

export interface ParsedUrl {
link: string;
Expand Down Expand Up @@ -57,7 +57,7 @@ export function getLinks(source: string, baseUrl: string): ParsedUrl[] {
return;
}
for (const v of values) {
if (!!v) {
if (v) {
const link = parseLink(v, realBaseUrl);
links.push(link);
}
Expand Down Expand Up @@ -102,8 +102,8 @@ function parseLink(link: string, baseUrl: string): ParsedUrl {
try {
const url = new URL(link, baseUrl);
url.hash = '';
return { link, url };
return {link, url};
} catch (error) {
return { link, error };
return {link, error};
}
}
2 changes: 1 addition & 1 deletion test/fixtures/scripts/script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const foo = {
bar: "<a href=\"uhoh.html\">Wot<a>",
bar: '<a href="uhoh.html">Wot<a>',
};
10 changes: 6 additions & 4 deletions test/test.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import * as path from 'path';
import { getConfig, Flags } from '../src/config';
const assertRejects = require('assert-rejects');
import {describe, it} from 'mocha';
import {getConfig, Flags} from '../src/config';

describe('config', () => {
it('should allow passing no config', async () => {
Expand All @@ -20,15 +20,16 @@ describe('config', () => {
const cfg = {
config: '/path/does/not/exist',
};
await assertRejects(getConfig(cfg), /ENOENT: no such file or directory/);
await assert.rejects(getConfig(cfg), /ENOENT: no such file or directory/);
});

it('should allow reading from a config file', async () => {
const configPath = path.resolve(
'test/fixtures/config/linkinator.config.json'
);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const expected = require(configPath);
const config = await getConfig({ config: configPath });
const config = await getConfig({config: configPath});
delete config.config;
assert.deepStrictEqual(config, expected);
});
Expand All @@ -37,6 +38,7 @@ describe('config', () => {
const configPath = path.resolve(
'test/fixtures/config/linkinator.config.json'
);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const expected = require(configPath);
expected.skip = 'loo';
const config = await getConfig({
Expand Down
Loading

0 comments on commit 2bb0246

Please sign in to comment.