Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop @types/cheerio #36

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion @iconify/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"dependencies": {
"@iconify/types": "^2.0.0",
"@iconify/utils": "^2.1.10",
"@types/cheerio": "^0.22.32",
"@types/tar": "^6.1.6",
"cheerio": "^1.0.0-rc.12",
"extract-zip": "^2.0.1",
Expand Down
6 changes: 4 additions & 2 deletions @iconify/tools/src/misc/cheerio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as cheerio from 'cheerio';

/**
* Shortcuts for Cheerio elements
*/
export type CheerioElement = cheerio.TagElement;
export type WrappedCheerioElement = cheerio.Cheerio;
export type CheerioElement = cheerio.Element;
export type WrappedCheerioElement = cheerio.Cheerio<cheerio.Element>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work, throws error.

10 changes: 6 additions & 4 deletions @iconify/tools/src/optimise/figma.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as cheerio from 'cheerio';

import { SVG } from '../svg';
import { defsTag, maskTags, symbolTag } from '../svg/data/tags';

Expand All @@ -10,7 +12,7 @@ function isTinyNumber(value: string, limit: number): boolean {
}

interface CheckClipPathResult {
node: cheerio.TagElement;
node: cheerio.Element;
attribs: Record<string, string>;
}

Expand All @@ -20,7 +22,7 @@ interface CheckClipPathResult {
* Returns CheckClipPathResult on success, false on error
*/
function checkClipPathNode(
clipNode: cheerio.TagElement,
clipNode: cheerio.Element,
expectedWidth: number,
expectedHeight: number
): CheckClipPathResult | false {
Expand Down Expand Up @@ -134,7 +136,7 @@ export function removeFigmaClipPathFromSVG(svg: SVG): boolean {
const backup = svg.toString();

// Shapes
const shapesToClip: cheerio.TagElement[] = [];
const shapesToClip: cheerio.Element[] = [];

// Find expected clip path id
let clipID: string | undefined;
Expand Down Expand Up @@ -175,7 +177,7 @@ export function removeFigmaClipPathFromSVG(svg: SVG): boolean {

// Check clip path node
// Returns CheckClipPathResult on success, false on error, undefined if this is not clip path we need
const checkClipPath = (node: cheerio.TagElement) => {
const checkClipPath = (node: cheerio.Element) => {
const id = node.attribs['id'];
if (id !== clipID) {
return;
Expand Down
4 changes: 3 additions & 1 deletion @iconify/tools/src/svg/analyse/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as cheerio from 'cheerio';

/**
* Options
*/
Expand Down Expand Up @@ -75,7 +77,7 @@ interface ExtendedTagElementRelations {
* Extended tag
*/
export interface ExtendedTagElement
extends cheerio.TagElement,
extends cheerio.Element,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? And it doesn't work.

ExtendedTagElementUses,
ExtendedTagElementRelations {
// Node index
Expand Down
4 changes: 3 additions & 1 deletion @iconify/tools/src/svg/cleanup/root-svg.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as cheerio from 'cheerio';

import type { SVG } from '../../svg';
import {
badAttributes,
Expand All @@ -17,7 +19,7 @@ import { maskTags, reusableElementsWithPalette } from '../data/tags';
export function cleanupSVGRoot(svg: SVG) {
const cheerio = svg.$svg;
const $root = svg.$svg(':root');
const root = $root.get(0) as cheerio.TagElement;
const root = $root.get(0) as cheerio.Element;
const tagName = 'svg';
if (root.tagName !== tagName) {
throw new Error(`Unexpected root tag <${root.tagName}>`);
Expand Down
4 changes: 2 additions & 2 deletions @iconify/tools/src/svg/index.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 type { IconifyIcon } from '@iconify/types';
import { trimSVG, iconToSVG } from '@iconify/utils';
import type { CommonIconProps } from '../icon-set/types';
Expand All @@ -20,7 +20,7 @@ export type { IconifyIconCustomisations, IconifyIcon };
*/
export class SVG {
// Cheerio tree, initialized in load()
public $svg!: cheerio.Root;
public $svg!: cheerio.CheerioAPI;

// Dimensions, initialized in load()
public viewBox!: ViewBox;
Expand Down
3 changes: 2 additions & 1 deletion @iconify/tools/src/svg/parse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as cheerio from 'cheerio';

import type { CheerioElement, WrappedCheerioElement } from '../misc/cheerio';
import type { SVG } from './';

/**
* Item in callback
*/
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.