Skip to content

Commit

Permalink
chore: update eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernankez committed Aug 12, 2024
1 parent f4b11ed commit a65febf
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
5 changes: 4 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import bernankez from "@bernankez/eslint-config";

export default bernankez();
export default bernankez({
ignores: ["playground"],
type: "lib",
});
3 changes: 3 additions & 0 deletions playground/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import bernankez from "@bernankez/eslint-config";

export default bernankez();
2 changes: 1 addition & 1 deletion src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface CompressOptions {
input: string;
}

export function compress(buffer: Buffer | string, options: CompressOptions) {
export function compress(buffer: Buffer | string, options: CompressOptions): Buffer {
const { type, input } = options;

try {
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const FontCarrier: (options: FontCarrierOptions) => Plugin = (options) => {
let nodeModulesDir: string;
let tempDir: string;

function resolveFontAssets() {
function resolveFontAssets(): FontAsset[] {
const assets: FontAsset[] = [];
for (const font of fonts) {
let underPublicDir = false;
Expand Down Expand Up @@ -66,7 +66,7 @@ const FontCarrier: (options: FontCarrierOptions) => Plugin = (options) => {
return assets;
}

function extractFontUrls(code: string) {
function extractFontUrls(code: string): string[] {
// Get font url from source code
const fontFaces = matchFontFace(code);
if (!fontFaces) {
Expand All @@ -77,7 +77,7 @@ const FontCarrier: (options: FontCarrierOptions) => Plugin = (options) => {
return fontFaces.map(fc => matchUrl(fc)).flat().filter(url => url).filter((url, index, arr) => arr.indexOf(url) === index) as string[] || [];
}

function compressFont(font: FontAsset, write: boolean) {
function compressFont(font: FontAsset, write: boolean): FontAsset {
const source = readFileSync(font.path);
const compressed = compress(source, font);
const { source: compressedSource, ext } = compressed;
Expand Down
4 changes: 2 additions & 2 deletions src/match.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FONT_FACE_REG, FONT_FACE_URL_REG } from "./const";

export function matchFontFace(code: string) {
export function matchFontFace(code: string): string[] | undefined {
if (code.includes("@font-face")) {
const matches = code.matchAll(FONT_FACE_REG);
const fontFaces = [...matches].map(([match]) => match);
Expand All @@ -9,7 +9,7 @@ export function matchFontFace(code: string) {
return undefined;
}

export function matchUrl(fontFace: string) {
export function matchUrl(fontFace: string): string[] | undefined {
if (fontFace.includes("url")) {
const matches = fontFace.matchAll(FONT_FACE_URL_REG);
const urls = [...matches].map(([, , url]) => url?.replaceAll("\"", "")).filter(url => url);
Expand Down
7 changes: 5 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function assert(condition: unknown, msg?: string): asserts condition {
}
}

export function getFileHash(path: string | BinaryLike) {
export function getFileHash(path: string | BinaryLike): string | undefined {
if (typeof path === "string") {
try {
const buffer = readFileSync(path);
Expand All @@ -36,7 +36,10 @@ export interface ResolvePathOptions {
ssr?: boolean;
}

export async function resolvePath(options: ResolvePathOptions) {
export async function resolvePath(options: ResolvePathOptions): Promise<{
underPublicDir: boolean;
path: string;
}> {
const { id, importer, publicDir, root, resolver, ssr } = options;
let underPublicDir = false;
let path = await resolver(id, importer, false, ssr);
Expand Down

0 comments on commit a65febf

Please sign in to comment.