Skip to content

Commit

Permalink
fix: bump jss from 10.0.4 to 10.1.1 (#380)
Browse files Browse the repository at this point in the history
* fix: bump jss from 10.0.4 to 10.1.1

Bumps [jss](https://github.com/cssinjs/jss) from 10.0.4 to 10.1.1.
- [Release notes](https://github.com/cssinjs/jss/releases)
- [Changelog](https://github.com/cssinjs/jss/blob/master/changelog.md)
- [Commits](cssinjs/jss@v10.0.4...v10.1.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

* Update dependencies.

* Remove cheerio in favor of jsdom.

* Update dependencies.

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Golo Roden <[email protected]>
Co-authored-by: Matthias Wagler <[email protected]>
  • Loading branch information
3 people authored Mar 18, 2020
1 parent 4abaaf1 commit 466894e
Show file tree
Hide file tree
Showing 27 changed files with 1,454 additions and 2,019 deletions.
6 changes: 4 additions & 2 deletions lib/cli/getBrokenUrls.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BrokenUrl } from './BrokenUrl';
import { cloneDeep } from 'lodash';
import { getExternalUrlsFromPage } from './getExternalUrlsFromPage';
import { getPage } from './getPage';
import { noop } from './noop';
import { getPage, Page } from './getPage';

const getBrokenUrls = async function ({
urls,
Expand Down Expand Up @@ -35,7 +35,7 @@ const getBrokenUrls = async function ({

verifiedUrls.push(currentUrl);

let page;
let page: Page;

try {
page = await getPage({ url: currentUrl });
Expand Down Expand Up @@ -71,6 +71,8 @@ const getBrokenUrls = async function ({
urlsToVerify.push(externalUrl);
}
}

page.destroy();
}

return brokenUrls;
Expand Down
11 changes: 7 additions & 4 deletions lib/cli/getExternalUrlsFromPage.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Page } from './getPage';
import { toArray } from '../utils/toArray';

const getExternalUrlsFromPage = function ({ page, baseUrl }: {
page: CheerioStatic;
page: Page;
baseUrl: string;
}): string[] {
const urls: string[] = [];

const linkElements = page('a[href]').toArray();
const linkElements = toArray(page.document.querySelectorAll<HTMLAnchorElement>('a[href]'));

for (const linkElement of linkElements) {
let url = page(linkElement).attr('href');
let url = linkElement.getAttribute('href');

if (!url) {
continue;
Expand All @@ -23,7 +26,7 @@ const getExternalUrlsFromPage = function ({ page, baseUrl }: {
urls.push(url);
}

const metaRedirectContent = page('head meta[http-equiv="refresh"]').attr('content');
const metaRedirectContent = page.document.querySelector<HTMLMetaElement>('head meta[http-equiv="refresh"]')?.getAttribute('content');

if (metaRedirectContent) {
const results = /url=(?<url>.*)$/u.exec(metaRedirectContent);
Expand Down
20 changes: 17 additions & 3 deletions lib/cli/getPage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import axios from 'axios';
import cheerio from 'cheerio';
import { JSDOM, VirtualConsole } from 'jsdom';

export interface Page {
document: Document;
destroy: () => void;
}

const getPage = async ({ url }: {
url: string;
}): Promise<CheerioStatic> => {
}): Promise<Page> => {
const { data } = await axios({
method: 'get',
url,
Expand All @@ -16,7 +21,16 @@ const getPage = async ({ url }: {
}
});

const page = cheerio.load(data);
const { window } = new JSDOM(data, {
virtualConsole: new VirtualConsole().sendTo(console, { omitJSDOMErrors: true })
});

const page = {
document: window.document,
destroy (): void {
window.close();
}
};

return page;
};
Expand Down
File renamed without changes.
Loading

0 comments on commit 466894e

Please sign in to comment.