Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Sep 20, 2024
1 parent f02ad53 commit bb692bb
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/core/cluster.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter } from 'node:events'
import type { LaunchOptions, Page, PuppeteerNodeLaunchOptions } from 'puppeteer-core'
import { EventEmitter } from 'node:events'

export interface ResourceData {
page: Page
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { dirname, join, resolve } from 'node:path'
import fs from 'fs-extra'
import { pick } from 'lodash-es'
import { withLeadingSlash, withTrailingSlash } from 'ufo'
import { createScanMeta } from './data'
import { useLogger, useUnlighthouse } from './unlighthouse'
import type {
ClientOptionsPayload,
GenerateClientOptions,
ScanMeta,
UnlighthouseContext,
UnlighthouseRouteReport,
} from './types'
import { dirname, join, resolve } from 'node:path'
import fs from 'fs-extra'
import { pick } from 'lodash-es'
import { withLeadingSlash, withTrailingSlash } from 'ufo'
import { createScanMeta } from './data'
import { useLogger, useUnlighthouse } from './unlighthouse'

/**
* Copies the file contents of the @unlighthouse/client package and does transformation based on the provided configuration.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnlighthouseColumn, UnlighthouseTabs, UserConfig } from './types'
import os from 'node:os'
import { Cluster } from 'puppeteer-cluster'
import type { UnlighthouseColumn, UnlighthouseTabs, UserConfig } from './types'

export const AppName = 'Unlighthouse'
export const ClientPkg = '@unlighthouse/client'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/data/scanMeta.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useUnlighthouse } from '../unlighthouse'
import type { ScanMeta } from '../types'
import { useUnlighthouse } from '../unlighthouse'

export function createScanMeta(): ScanMeta {
const { worker } = useUnlighthouse()
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/discovery/robotsTxt.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ResolvedUserConfig } from '../types'
import type { RobotsGroupResolved } from '../util/robotsTxtParser'
import { $URL } from 'ufo'
import { useLogger } from '../logger'
import { useUnlighthouse } from '../unlighthouse'
import { fetchUrlRaw } from '../util'
import type { ResolvedUserConfig } from '../types'
import type { RobotsGroupResolved } from '../util/robotsTxtParser'

export interface RobotsTxtParsed {
sitemaps: string[]
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/discovery/routeDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { RouteDefinition } from '../types'
import { join } from 'node:path'
import { useLogger } from '../logger'
import { useUnlighthouse } from '../unlighthouse'
import { createRoutes } from '../util/createRoutes'
import type { RouteDefinition } from '../types'

/**
* Using the configuration discovery details will try and resolve the route definitions using the file system.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/discovery/routes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { NormalisedRoute } from '../types'
import { groupBy, map, sampleSize } from 'lodash-es'
import { useLogger } from '../logger'
import { isScanOrigin, normaliseRoute } from '../router'
import { useUnlighthouse } from '../unlighthouse'
import { parseRobotsTxt } from '../util/robotsTxtParser'
import { fetchRobotsTxt, mergeRobotsTxtConfig } from './robotsTxt'
import { extractSitemapRoutes } from './sitemap'
import type { NormalisedRoute } from '../types'

let warnedAboutSampling = false

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ConsolaInstance } from 'consola'
import { createConsola } from 'consola'
import { createContext } from 'unctx'
import type { ConsolaInstance } from 'consola'
import { AppName } from './constants'

const loggerCtx = createContext<ConsolaInstance>()
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/process/lighthouse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Flags } from 'lighthouse'
import type { UnlighthouseRouteReport } from '../types'
import { setMaxListeners } from 'node:events'
import fs from 'node:fs'
import { join } from 'node:path'
import lighthouse from 'lighthouse/core/index.cjs'
import minimist from 'minimist'
import type { Flags } from 'lighthouse'
import type { UnlighthouseRouteReport } from '../types'

setMaxListeners(0);

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/puppeteer/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnlighthousePuppeteerCluster } from '../types'
import { Cluster } from 'puppeteer-cluster'
import { useUnlighthouse } from '../unlighthouse'
import type { UnlighthousePuppeteerCluster } from '../types'

/**
* Create an instance of puppeteer-cluster
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/puppeteer/tasks/html.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { CheerioAPI } from 'cheerio'
import type { Page } from 'puppeteer-core'
import type { HTMLExtractPayload, PuppeteerTask } from '../../types'
import { join } from 'node:path'
import { load as cheerio } from 'cheerio'
import fs from 'fs-extra'
import { withoutTrailingSlash } from 'ufo'
import type { CheerioAPI } from 'cheerio'
import type { Page } from 'puppeteer-core'
import { useLogger } from '../../logger'
import { normaliseRoute } from '../../router'
import { useUnlighthouse } from '../../unlighthouse'
import { fetchUrlRaw, ReportArtifacts, trimSlashes } from '../../util'
import { setupPage } from '../util'
import type { HTMLExtractPayload, PuppeteerTask } from '../../types'

export const extractHtmlPayload: (page: Page, route: string) => Promise<{ success: boolean, redirected?: false | string, message?: string, payload?: string }> = async (page, route) => {
const { worker, resolvedConfig } = useUnlighthouse()
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/puppeteer/tasks/lighthouse.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Result } from 'lighthouse'
import type { LighthouseReport, PuppeteerTask, UnlighthouseRouteReport } from '../../types'
import { join } from 'node:path'
import fs from 'fs-extra'
import { computeMedianRun } from 'lighthouse/core/lib/median-run.js'
import { map, pick, sumBy } from 'lodash-es'
import { relative } from 'pathe'
import { withQuery } from 'ufo'
import type { Result } from 'lighthouse'
import { useLogger } from '../../logger'
import { useUnlighthouse } from '../../unlighthouse'
import { base64ToBuffer, ReportArtifacts } from '../../util'
import { setupPage } from '../util'
import type { LighthouseReport, PuppeteerTask, UnlighthouseRouteReport } from '../../types'

export function normaliseLighthouseResult(route: UnlighthouseRouteReport, result: Result): LighthouseReport {
const { resolvedConfig, runtimeSettings } = useUnlighthouse()
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/puppeteer/worker.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import type { TaskFunction } from 'puppeteer-cluster/dist/Cluster'
import type {
NormalisedRoute,
PuppeteerTaskArgs,
PuppeteerTaskReturn,
UnlighthouseRouteReport,
UnlighthouseTask,
UnlighthouseWorker,
UnlighthouseWorkerStats,
} from '../types'
import fs from 'node:fs'
import { join } from 'node:path'
import chalk from 'chalk'
import { get, sortBy, uniqBy } from 'lodash-es'
import type { TaskFunction } from 'puppeteer-cluster/dist/Cluster'
import { useLogger } from '../logger'
import { useUnlighthouse } from '../unlighthouse'
import { createTaskReportFromRoute, formatBytes, ReportArtifacts } from '../util'
import { createFilter } from '../util/filter'
import {
launchPuppeteerCluster,
} from './cluster'
import type {
NormalisedRoute,
PuppeteerTaskArgs,
PuppeteerTaskReturn,
UnlighthouseRouteReport,
UnlighthouseTask,
UnlighthouseWorker,
UnlighthouseWorkerStats,
} from '../types'

let warnedMaxRoutesExceeded = false

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/resolveConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { InstallOptions } from '@puppeteer/browsers'
import type { ResolvedUserConfig, UnlighthouseTabs, UserConfig } from './types'
import { Buffer } from 'node:buffer'
import { existsSync } from 'node:fs'
import { homedir } from 'node:os'
Expand All @@ -10,11 +12,9 @@ import { pick } from 'lodash-es'
import { resolve as resolveModule } from 'mlly'
import puppeteer from 'puppeteer-core'
import { PUPPETEER_REVISIONS } from 'puppeteer-core/lib/cjs/puppeteer/revisions.js'
import type { InstallOptions } from '@puppeteer/browsers'
import { defaultConfig } from './constants'
import { useLogger } from './logger'
import { normaliseHost, withSlashes } from './util'
import type { ResolvedUserConfig, UnlighthouseTabs, UserConfig } from './types'

/**
* A provided configuration from the user may require runtime transformations to avoid breaking app functionality.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/router/broadcasting.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Buffer } from 'node:buffer'
import { WebSocketServer } from 'ws'
import type { IncomingMessage } from 'node:http'
import type { Socket } from 'node:net'
import { Buffer } from 'node:buffer'
import { WebSocketServer } from 'ws'
import { useUnlighthouse } from '../unlighthouse'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/router/mockRouter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MockRouter, RouteDefinition } from '../types'
import { parse } from 'regexparam'
import { useLogger } from '../logger'
import type { MockRouter, RouteDefinition } from '../types'

/**
* The default mock router using regexparam as the matcher
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/router/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { NormalisedRoute } from '../types'
import { basename } from 'node:path'
import { hasProtocol, isRelative, withBase, withLeadingSlash } from 'ufo'
import { useUnlighthouse } from '../unlighthouse'
import { hashPathName, trimSlashes } from '../util'
import type { NormalisedRoute } from '../types'

export function isScanOrigin(url: string): boolean {
if (isRelative(url) || (url.startsWith('/') && !url.startsWith('//')))
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/unlighthouse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import type { IncomingMessage } from 'node:http'
import type { Socket } from 'node:net'
import type {
Provider,
ResolvedUserConfig,
RuntimeSettings,
UnlighthouseContext,
UnlighthouseHooks,
UserConfig,
} from './types'
import { existsSync } from 'node:fs'
import { isAbsolute, join } from 'node:path'
import chalk from 'chalk'
Expand All @@ -10,8 +20,6 @@ import { $fetch } from 'ofetch'
import { $URL, joinURL } from 'ufo'
import { loadConfig } from 'unconfig'
import { createContext } from 'unctx'
import type { IncomingMessage } from 'node:http'
import type { Socket } from 'node:net'
import { version } from '../package.json'
import { generateClient } from './build'
import { AppName, ClientPkg } from './constants'
Expand All @@ -22,14 +30,6 @@ import { resolveUserConfig } from './resolveConfig'
import { createApi, createBroadcastingEvents, createMockRouter, WS } from './router'
import { normaliseHost } from './util'
import { successBox } from './util/cliFormatting'
import type {
Provider,
ResolvedUserConfig,
RuntimeSettings,
UnlighthouseContext,
UnlighthouseHooks,
UserConfig,
} from './types'

const engineContext = createContext<UnlighthouseContext>()

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
import type { NormalisedRoute, ResolvedUserConfig, UnlighthouseRouteReport } from './types'
import { Buffer } from 'node:buffer'
import { createHash } from 'node:crypto'
import dns from 'node:dns'
Expand All @@ -9,9 +11,7 @@ import { ensureDirSync } from 'fs-extra'
import sanitize from 'sanitize-filename'
import slugify from 'slugify'
import { joinURL, withLeadingSlash, withoutLeadingSlash, withoutTrailingSlash, withTrailingSlash } from 'ufo'
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
import { useLogger, useUnlighthouse } from './unlighthouse'
import type { NormalisedRoute, ResolvedUserConfig, UnlighthouseRouteReport } from './types'

export const ReportArtifacts = {
html: 'payload.html',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/util/createRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RouteDefinition } from '../types'
import { resolve } from 'pathe'
import { normalizeURL, withoutTrailingSlash, withTrailingSlash } from 'ufo'
import type { RouteDefinition } from '../types'

/**
* From https://github.com/nuxt/nuxt.js/blob/dev/packages/utils/src/route.js
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/robots.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ResolvedUserConfig } from '../src'
import { describe, expect, it } from 'vitest'
import { mergeRobotsTxtConfig } from '../src/discovery'
import { asRegExp } from '../src/util'
import { parseRobotsTxt } from '../src/util/robotsTxtParser'
import type { ResolvedUserConfig } from '../src'

describe('robots', () => {
it ('parses example #1', () => {
Expand Down

0 comments on commit bb692bb

Please sign in to comment.