Skip to content

Commit

Permalink
chore(deps): bump cheerio from 1.0.0-rc.12 to 1.0.0 (mdn#11626)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] authored Aug 18, 2024
1 parent 6a82a08 commit 856405f
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 68 deletions.
5 changes: 3 additions & 2 deletions build/check-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Document, FileAttachment } from "../content/index.js";
import { FLAW_LEVELS } from "../libs/constants/index.js";
import { findMatchesInText, findMatchesInMarkdown } from "./matches.js";
import * as cheerio from "cheerio";
import { Element } from "domhandler";
import { Doc } from "../libs/types/document.js";

const { default: sizeOf } = imagesize;
Expand All @@ -33,7 +34,7 @@ export function checkImageReferences(
const checked = new Map<string, number>();

function addImageFlaw(
$img: cheerio.Cheerio<cheerio.Element>,
$img: cheerio.Cheerio<Element>,
src: string,
{
explanation,
Expand Down Expand Up @@ -235,7 +236,7 @@ export function checkImageWidths(
const checked = new Map();

function addStyleFlaw(
$img: cheerio.Cheerio<cheerio.Element>,
$img: cheerio.Cheerio<Element>,
style: string,
suggestion: string
) {
Expand Down
35 changes: 14 additions & 21 deletions build/extract-sections.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as cheerio from "cheerio";
import { Element, ParentNode } from "domhandler";
import { ProseSection, Section } from "../libs/types/document.js";
import { extractSpecifications } from "./extract-specifications.js";

Expand All @@ -9,20 +10,17 @@ export async function extractSections(
): Promise<[Section[], string[]]> {
const flaws: string[] = [];
const sections: Section[] = [];
const section = cheerio
.load("<div></div>", {
// decodeEntities: false
})("div")
.eq(0);
const section = cheerio.load("<div></div>")("div").eq(0);

const body = $("body")[0] as cheerio.ParentNode;
const iterable = [...(body.childNodes as cheerio.Element[])];
const bodies = $("body");
const body = bodies[0] as ParentNode;
const iterable = [...(body.childNodes as Element[])];

let c = 0;
for (const child of iterable) {
if (
(child as cheerio.Element).tagName === "h2" ||
(child as cheerio.Element).tagName === "h3"
(child as Element).tagName === "h2" ||
(child as Element).tagName === "h3"
) {
if (c) {
const [subSections, subFlaws] = await addSections(section.clone());
Expand Down Expand Up @@ -164,7 +162,7 @@ export async function extractSections(
* }]
*/
async function addSections(
$: cheerio.Cheerio<cheerio.Element>
$: cheerio.Cheerio<Element>
): Promise<SectionsAndFlaws> {
const flaws: string[] = [];

Expand Down Expand Up @@ -207,17 +205,14 @@ async function addSections(
*/
if (countPotentialSpecialDivs > 1) {
const subSections: Section[] = [];
const section = cheerio
.load("<div></div>", {
// decodeEntities: false
})("div")
.eq(0);
const section = cheerio.load("<div></div>")("div").eq(0);

// Loop over each and every "root element" in the node and keep piling
// them up in a buffer, until you encounter a `div.bc-data` or `div.bc-specs` then
// add that to the stack, clear and repeat.
const div = $[0] as cheerio.ParentNode;
const iterable = [...(div.childNodes as cheerio.Element[])];
const div = $[0] as ParentNode;
console.log({ div });
const iterable = [...(div.childNodes as Element[])];
let c = 0;
let countSpecialDivsFound = 0;
for (const child of iterable) {
Expand Down Expand Up @@ -290,7 +285,7 @@ async function addSections(
}

async function _addSingleSpecialSection(
$: cheerio.Cheerio<cheerio.Element>
$: cheerio.Cheerio<Element>
): Promise<Section[]> {
let id: string | null = null;
let title: string | null = null;
Expand Down Expand Up @@ -373,9 +368,7 @@ async function _addSingleSpecialSection(
throw new Error(`Unrecognized special section type '${specialSectionType}'`);
}

function _addSectionProse(
$: cheerio.Cheerio<cheerio.Element>
): SectionsAndFlaws {
function _addSectionProse($: cheerio.Cheerio<Element>): SectionsAndFlaws {
let id: string | null = null;
let title: string | null = null;
let isH3 = false;
Expand Down
11 changes: 4 additions & 7 deletions build/flaws/broken-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "../../libs/constants/index.js";
import { isValidLocale } from "../../libs/locale-utils/index.js";
import * as cheerio from "cheerio";
import { Element } from "domhandler";
import { Doc } from "../../libs/types/document.js";
import { Flaw } from "./index.js";
import { ONLY_AVAILABLE_IN_ENGLISH } from "../../libs/l10n/l10n.js";
Expand Down Expand Up @@ -43,7 +44,7 @@ function isHomepageURL(url) {
}

function mutateLink(
$element: cheerio.Cheerio<cheerio.Element>,
$element: cheerio.Cheerio<Element>,
suggestion: string = null,
enUSFallback: string = null,
isSelfLink = false
Expand Down Expand Up @@ -93,7 +94,7 @@ export function getBrokenLinksFlaws(

// A closure function to help making it easier to append flaws
function addBrokenLink(
$element: cheerio.Cheerio<cheerio.Element>,
$element: cheerio.Cheerio<Element>,
index: number,
href: string,
suggestion: string = null,
Expand Down Expand Up @@ -137,11 +138,7 @@ export function getBrokenLinksFlaws(
});
}

function checkHash(
hash: string,
a: cheerio.Cheerio<cheerio.Element>,
href: string
) {
function checkHash(hash: string, a: cheerio.Cheerio<Element>, href: string) {
if (hash.startsWith(":~:")) {
// Ignore fragment directives.
return;
Expand Down
3 changes: 2 additions & 1 deletion build/flaws/pre-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Flaw } from "./index.js";

import { getFirstMatchInText } from "../matches.js";
import * as cheerio from "cheerio";
import { Element } from "domhandler";
import { Doc } from "../../libs/types/document.js";
const escapeHTML = (s: string) =>
s
Expand Down Expand Up @@ -36,7 +37,7 @@ export function getPreTagFlaws(
//
// This makes it easier to edit the code in raw form. It also makes it less
// heavy because any HTML will be replaced with Prism HTML anyway.
function addCodeTagFlaw($pre: cheerio.Cheerio<cheerio.Element>) {
function addCodeTagFlaw($pre: cheerio.Cheerio<Element>) {
const id = `bad_pre_tags${flaws.length + 1}`;
const type = "pre_with_html";
const explanation = `<pre><code>CODE can be just <pre>CODE`;
Expand Down
3 changes: 2 additions & 1 deletion build/flaws/unsafe-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "../../libs/env/index.js";
import { findMatchesInText } from "../matches.js";
import * as cheerio from "cheerio";
import { Element } from "domhandler";
import { Doc } from "../../libs/types/document.js";

const safeIFrameSrcs = [
Expand All @@ -32,7 +33,7 @@ function getAndMarkupUnsafeHTMLFlaws(
) {
const flaws: Flaw[] = [];

function addFlaw(element: cheerio.Element, explanation: string) {
function addFlaw(element: Element, explanation: string) {
const id = `unsafe_html${flaws.length + 1}`;
let html = $.html($(element));
$(element).replaceWith($("<code>").addClass("unsafe-html").text(html));
Expand Down
7 changes: 3 additions & 4 deletions build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from "node:path";
import { cwd } from "node:process";

import * as cheerio from "cheerio";
import { Element } from "domhandler";
import got from "got";
import { fileTypeFromBuffer } from "file-type";
import imagemin from "imagemin";
Expand Down Expand Up @@ -153,11 +154,9 @@ export function splitSections(rawHTML) {
const blocks = [];
const toc = [];

const section = cheerio
.load("<div></div>", { decodeEntities: false })("div")
.eq(0);
const section = cheerio.load("<div></div>")("div").eq(0);

const iterable = [...($("#_body")[0] as cheerio.Element).childNodes];
const iterable = [...($("#_body")[0] as Element).childNodes];
let c = 0;
iterable.forEach((child) => {
if ("tagName" in child && child.tagName === "h2") {
Expand Down
2 changes: 1 addition & 1 deletion client/scripts/postprocess-client-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import fs from "node:fs";
import path from "node:path";

import cheerio from "cheerio";
import * as cheerio from "cheerio";
import md5File from "md5-file";

export async function hashSomeStaticFilesForClientBuild(buildRoot) {
Expand Down
8 changes: 3 additions & 5 deletions kumascript/src/api/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import sanitizeFilename from "sanitize-filename";
import * as cheerio from "cheerio";
import { Element } from "domhandler";

const H1_TO_H6_TAGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
const HEADING_TAGS = new Set([...H1_TO_H6_TAGS, "hgroup"]);
Expand Down Expand Up @@ -142,10 +143,7 @@ export class HTMLTool {
private $: cheerio.CheerioAPI;

constructor(html, pathDescription?: any) {
this.$ =
typeof html == "string"
? cheerio.load(html, { decodeEntities: true })
: html;
this.$ = typeof html == "string" ? cheerio.load(html) : html;
this.pathDescription = pathDescription;
}

Expand Down Expand Up @@ -177,7 +175,7 @@ export class HTMLTool {
// And we ensure all IDs that get added are completely lowercase.
$([...INJECT_SECTION_ID_TAGS].join(",")).each((i, element) => {
const $element = $(element);
const $first = $element[0] as cheerio.Element;
const $first = $element[0] as Element;
const isDt = $first.name === "dt";
// Default is the existing one. Let's see if we need to change it.
let id = $element.attr("id");
Expand Down
2 changes: 1 addition & 1 deletion kumascript/src/info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cheerio from "cheerio";
import * as cheerio from "cheerio";

import * as Parser from "./parser.js";
import { Document, Redirect } from "../../content/index.js";
Expand Down
2 changes: 1 addition & 1 deletion kumascript/src/live-sample.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cheerio from "cheerio";
import * as cheerio from "cheerio";
import ejs from "ejs";
import path from "node:path";

Expand Down
2 changes: 1 addition & 1 deletion kumascript/tests/macros/svginfo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "node:fs";
import path from "node:path";
import cheerio from "cheerio";
import * as cheerio from "cheerio";
import { jest } from "@jest/globals";

import { itMacro, describeMacro, beforeEachMacro } from "./utils.js";
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"accept-language-parser": "^1.5.0",
"async": "^3.2.5",
"chalk": "^5.3.0",
"cheerio": "^1.0.0-rc.12",
"cheerio": "^1.0.0",
"cli-progress": "^3.12.0",
"codemirror": "^6.0.1",
"compression": "^1.7.4",
Expand All @@ -92,6 +92,7 @@
"css-tree": "^2.3.1",
"dayjs": "^1.11.12",
"dexie": "^4.0.8",
"domhandler": "^5.0.3",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"express": "^4.19.2",
Expand Down
2 changes: 1 addition & 1 deletion testing/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import path from "node:path";

import cheerio from "cheerio";
import * as cheerio from "cheerio";
import imagesize from "image-size";

const { default: sizeOf } = imagesize;
Expand Down
Loading

0 comments on commit 856405f

Please sign in to comment.