Skip to content

Commit

Permalink
chore: fix broken build
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Apr 13, 2024
1 parent e119fd9 commit e44bad6
Show file tree
Hide file tree
Showing 9 changed files with 807 additions and 843 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"nuxt-icon": "^0.6.10",
"nuxt-lego": "^0.0.14",
"nuxt-lodash": "^2.5.3",
"three": "0.163.0",
"three": "0.138.3",
"troisjs": "^0.3.4",
"typescript": "^5.4.5"
}
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default antfu({
'no-use-before-define': 'off',
'node/prefer-global/process': 'off',
'ts/no-use-before-define': 'off',
'ts/prefer-ts-expect-error': 'off',
},
// exclude examples dir
ignores: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@antfu/eslint-config": "2.13.3",
"bumpp": "^9.4.0",
"eslint": "^9.0.0",
"typescript": "^5.4.5",
"typescript": "5.3.3",
"unbuild": "^2.0.0",
"vite": "^5.2.8",
"vitest": "^1.5.0"
Expand Down
60 changes: 55 additions & 5 deletions packages/core/cluster.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
import { EventEmitter } from 'node:events'
import type { LaunchOptions, Page } from 'puppeteer-core'
import type { LaunchOptions, Page, PuppeteerNodeLaunchOptions } from 'puppeteer-core'

export interface ResourceData {
page: Page
[key: string]: any
}

export interface JobInstance {
resources: ResourceData
/**
* Called to close the related resources
*/
close: () => Promise<void>
}

export interface WorkerInstance {
jobInstance: () => Promise<JobInstance>
/**
* Closes the worker (called when the cluster is about to shut down)
*/
close: () => Promise<void>
/**
* Repair is called when there is a problem with the worker (like call or close throwing
* an error)
*/
repair: () => Promise<void>
}

export type ConcurrencyImplementationClassType = new (options: LaunchOptions, puppeteer: any) => ConcurrencyImplementation

export default abstract class ConcurrencyImplementation {
protected options: LaunchOptions
protected puppeteer: any
/**
* @param options Options that should be provided to puppeteer.launch
* @param puppeteer puppeteer object (like puppeteer or puppeteer-core)
*/
constructor(options: LaunchOptions, puppeteer: any)
/**
* Initializes the manager
*/
abstract init(): Promise<void>
/**
* Closes the manager (called when cluster is about to shut down)
*/
abstract close(): Promise<void>
/**
* Creates a worker and returns it
*/
abstract workerInstance(perBrowserOptions: LaunchOptions | undefined): Promise<WorkerInstance>
}

interface ClusterOptions {
concurrency: number | unknown
concurrency: number | ConcurrencyImplementationClassType
maxConcurrency: number
workerCreationDelay: number
puppeteerOptions: LaunchOptions
perBrowserOptions: LaunchOptions[] | undefined
puppeteerOptions: PuppeteerNodeLaunchOptions
perBrowserOptions: PuppeteerNodeLaunchOptions[] | undefined
monitor: boolean
timeout: number
retryLimit: number
Expand All @@ -18,7 +68,7 @@ interface ClusterOptions {
declare type Partial<T> = {
[P in keyof T]?: T[P];
}
declare type ClusterOptionsArgument = Partial<ClusterOptions>
export type ClusterOptionsArgument = Partial<ClusterOptions>
interface TaskFunctionArguments<JobData> {
page: Page
data: JobData
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,6 +1,6 @@
import { join } from 'node:path'
import fs from 'fs-extra'
import type { LH } from 'lighthouse'
import type { Result } from 'lighthouse'
import { map, pick, sumBy } from 'lodash-es'
import { computeMedianRun } from 'lighthouse/core/lib/median-run.js'
import chalk from 'chalk'
Expand All @@ -12,7 +12,7 @@ import { useLogger } from '../../logger'
import { ReportArtifacts, base64ToBuffer } from '../../util'
import { setupPage } from '../util'

export function normaliseLighthouseResult(route: UnlighthouseRouteReport, result: LH.Result): LighthouseReport {
export function normaliseLighthouseResult(route: UnlighthouseRouteReport, result: Result): LighthouseReport {
const { resolvedConfig, runtimeSettings } = useUnlighthouse()

const measuredCategories = Object.values(result.categories)
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const resolveUserConfig: (userConfig: UserConfig) => Promise<ResolvedUser
const siteUrl = normaliseHost(config.site)
if (siteUrl.pathname !== '/' && siteUrl.pathname !== '') {
logger.warn('You are providing a site with a path, disabling sitemap, robots and dynamic sampling.')
config.scanner = config.scanner || {}
config.scanner.sitemap = false
config.scanner.robotsTxt = false
config.scanner.dynamicSampling = false
Expand All @@ -62,8 +63,8 @@ export const resolveUserConfig: (userConfig: UserConfig) => Promise<ResolvedUser
else {
const hasPwa = config.lighthouseOptions.onlyCategories.includes('pwa')
// restrict categories values and copy order of columns from the default config
config.lighthouseOptions.onlyCategories = defaultConfig.lighthouseOptions.onlyCategories
.filter(column => config.lighthouseOptions.onlyCategories.includes(column))
config.lighthouseOptions.onlyCategories = defaultConfig.lighthouseOptions!.onlyCategories!
.filter(column => config.lighthouseOptions!.onlyCategories!.includes(column))
// allow PWA
if (hasPwa)
config.lighthouseOptions.onlyCategories.push('pwa')
Expand Down
19 changes: 3 additions & 16 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type http from 'node:http'
import type https from 'node:https'
import type { QueryObject } from 'ufo'
import type LH from 'lighthouse/types/lh'
import type { LaunchOptions, Page, PuppeteerNodeLaunchOptions } from 'puppeteer-core'
import type { Page, PuppeteerNodeLaunchOptions } from 'puppeteer-core'
import type { Hookable, NestedHooks } from 'hookable'
import type { Cluster, TaskFunction } from '../cluster'
import type { Cluster, ClusterOptionsArgument, TaskFunction } from '../cluster'
import type { WS } from './router'

/**
Expand Down Expand Up @@ -464,20 +464,7 @@ export interface ResolvedUserConfig {
/**
* Change the behaviour of puppeteer-cluster.
*/
puppeteerClusterOptions: Partial<{
concurrency: number | unknown
maxConcurrency: number
workerCreationDelay: number
puppeteerOptions: LaunchOptions
perBrowserOptions: LaunchOptions[] | undefined
monitor: boolean
timeout: number
retryLimit: number
retryDelay: number
skipDuplicateUrls: boolean
sameDomainDelay: number
puppeteer: any
}>
puppeteerClusterOptions: Partial<ClusterOptionsArgument>

chrome: {
/**
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/unlighthouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function createUnlighthouse(userConfig: UserConfig, provider?: Prov
configFile = configDefinition.sources[0]
// @ts-expect-error fixes issue with default being returned for mjs loads
const config = configDefinition.config?.default || configDefinition.config
// @ts-expect-error untyped
// @ts-ignore broken types
userConfig = defu(config, userConfig)
}
const runtimeSettings: { moduleWorkingDir: string, lighthouseProcessPath: string } & Partial<RuntimeSettings> = {
Expand Down Expand Up @@ -139,7 +139,6 @@ export async function createUnlighthouse(userConfig: UserConfig, provider?: Prov
runLighthouseTask,
}

// @ts-expect-error untyped
const worker = await createUnlighthouseWorker(tasks)

if (resolvedConfig.hooks?.authenticate) {
Expand Down
Loading

0 comments on commit e44bad6

Please sign in to comment.