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a,EAAA;AAAA,MACb,aAAA,EAAe,EAAA;AAAA,MACf,aAAA,EAAe,EAAA;AAAA,MACf,GAAA,EAAK,EAAA;AAAA,MACL,GAAA,EAAK,IAAA;AAAA;AAAA,MACL,GAAA,EAAK,IAAA;AAAA,MACL,GAAA,EAAK,GAAA;AAAA,MACL,GAAA,EAAK;AAAA,KACP;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,WAAA,EAAa,EAAA;AAAA,IACb,aAAA,EAAe,EAAA;AAAA,IACf,aAAA,EAAe,EAAA;AAAA,IACf,GAAA,EAAK,EAAA;AAAA,IACL,GAAA,EAAK,GAAA;AAAA;AAAA,IACL,GAAA,EAAK,GAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,GAAA,EAAK;AAAA,GACP;AACF","file":"index.cjs","sourcesContent":["/**\n * @silverassist/performance-toolkit\n *\n * Lighthouse CI runner - wrapper for @lhci/cli with fluent API.\n *\n * @module lighthouse\n * @author Miguel Colmenares <me@miguelcolmenares.com>\n * @license PolyForm-Noncommercial-1.0.0\n */\n\nimport type {\n  LHCIAssertions,\n  LHCIConfig,\n  LHCIOptions,\n  PerformanceThresholds,\n} from \"../types\";\n\n/**\n * Lighthouse CI Runner for programmatic execution\n */\nexport class LighthouseRunner {\n  private config: LHCIConfig;\n\n  /**\n   * Creates a new Lighthouse runner\n   * @param options - Runner options\n   */\n  constructor(options: LHCIOptions) {\n    this.config = this.buildConfig(options);\n  }\n\n  /**\n   * Builds LHCI configuration from options\n   */\n  private buildConfig(options: LHCIOptions): LHCIConfig {\n    const {\n      urls,\n      method = \"node\",\n      numberOfRuns = 3,\n      psiApiKey,\n      psiStrategy = \"mobile\",\n      chromeFlags = [\"--headless\", \"--no-sandbox\"],\n      outputDir,\n    } = options;\n\n    const config: LHCIConfig = {\n      ci: {\n        collect: {\n          url: urls,\n          method,\n          numberOfRuns,\n          ...(method === \"psi\" && psiApiKey ? { psiApiKey, psiStrategy } : {}),\n          settings: {\n            chromeFlags: method === \"node\" ? chromeFlags : undefined,\n            preset: psiStrategy === \"desktop\" ? \"desktop\" : \"mobile\",\n          },\n        },\n      },\n    };\n\n    if (outputDir) {\n      config.ci.upload = {\n        target: \"filesystem\",\n        outputDir,\n      };\n    }\n\n    return config;\n  }\n\n  /**\n   * Gets the generated configuration\n   * @returns LHCI configuration object\n   */\n  getConfig(): LHCIConfig {\n    return this.config;\n  }\n\n  /**\n   * Adds assertion thresholds to the configuration\n   * @param thresholds - Performance thresholds to assert\n   * @returns This runner instance for chaining\n   */\n  withAssertions(thresholds: PerformanceThresholds): this {\n    const assertions: LHCIAssertions = {};\n\n    if (thresholds.performance !== undefined) {\n      assertions[\"categories:performance\"] = [\n        \"error\",\n        { minScore: thresholds.performance / 100 },\n      ];\n    }\n    if (thresholds.accessibility !== undefined) {\n      assertions[\"categories:accessibility\"] = [\n        \"error\",\n        { minScore: thresholds.accessibility / 100 },\n      ];\n    }\n    if (thresholds.bestPractices !== undefined) {\n      assertions[\"categories:best-practices\"] = [\n        \"error\",\n        { minScore: thresholds.bestPractices / 100 },\n      ];\n    }\n    if (thresholds.seo !== undefined) {\n      assertions[\"categories:seo\"] = [\n        \"error\",\n        { minScore: thresholds.seo / 100 },\n      ];\n    }\n    if (thresholds.lcp !== undefined) {\n      assertions[\"largest-contentful-paint\"] = [\n        \"error\",\n        { maxNumericValue: thresholds.lcp },\n      ];\n    }\n    if (thresholds.fcp !== undefined) {\n      assertions[\"first-contentful-paint\"] = [\n        \"error\",\n        { maxNumericValue: thresholds.fcp },\n      ];\n    }\n    if (thresholds.cls !== undefined) {\n      assertions[\"cumulative-layout-shift\"] = [\n        \"error\",\n        { maxNumericValue: thresholds.cls },\n      ];\n    }\n    if (thresholds.tbt !== undefined) {\n      assertions[\"total-blocking-time\"] = [\n        \"error\",\n        { maxNumericValue: thresholds.tbt },\n      ];\n    }\n\n    this.config.ci.assert = { assertions };\n    return this;\n  }\n\n  /**\n   * Configures upload to temporary public storage\n   * @returns This runner instance for chaining\n   */\n  withTemporaryStorage(): this {\n    this.config.ci.upload = {\n      target: \"temporary-public-storage\",\n    };\n    return this;\n  }\n\n  /**\n   * Configures upload to LHCI server\n   * @param serverBaseUrl - LHCI server URL\n   * @param token - Build token\n   * @returns This runner instance for chaining\n   */\n  withLHCIServer(serverBaseUrl: string, token: string): this {\n    this.config.ci.upload = {\n      target: \"lhci\",\n      serverBaseUrl,\n      token,\n    };\n    return this;\n  }\n\n  /**\n   * Runs Lighthouse CI with the configured options\n   * @returns Promise resolving to exit code (0 for success)\n   */\n  async run(): Promise<number> {\n    // Dynamic import to avoid requiring @lhci/cli at module load time\n    try {\n      const { autorun } = await import(\"@lhci/cli\");\n\n      // Run with the ci config\n      const result = await autorun(this.config.ci);\n      return result.success ? 0 : 1;\n    } catch (error) {\n      if ((error as NodeJS.ErrnoException).code === \"MODULE_NOT_FOUND\") {\n        throw new Error(\n          \"Lighthouse CI (@lhci/cli) is not installed. \" +\n            \"Install it with: npm install -D @lhci/cli\",\n        );\n      }\n      throw error;\n    }\n  }\n\n  /**\n   * Generates a lighthouserc.js configuration file content\n   * @returns Configuration file content as string\n   */\n  generateConfigFile(): string {\n    const configContent = `/** @type {import('@lhci/cli').LighthouseConfig} */\nmodule.exports = ${JSON.stringify(this.config, null, 2)};\n`;\n    return configContent;\n  }\n}\n\n/**\n * Creates a Lighthouse runner for staging/internal URLs (uses local Chrome)\n * @param urls - URLs to analyze\n * @param options - Additional options\n * @returns Configured LighthouseRunner\n */\nexport function createNodeRunner(\n  urls: string[],\n  options: Partial<Omit<LHCIOptions, \"urls\" | \"method\">> = {},\n): LighthouseRunner {\n  return new LighthouseRunner({\n    urls,\n    method: \"node\",\n    ...options,\n  });\n}\n\n/**\n * Creates a Lighthouse runner for production URLs (uses PageSpeed API)\n * @param urls - URLs to analyze\n * @param psiApiKey - PageSpeed Insights API key\n * @param options - Additional options\n * @returns Configured LighthouseRunner\n */\nexport function createPSIRunner(\n  urls: string[],\n  psiApiKey: string,\n  options: Partial<Omit<LHCIOptions, \"urls\" | \"method\" | \"psiApiKey\">> = {},\n): LighthouseRunner {\n  return new LighthouseRunner({\n    urls,\n    method: \"psi\",\n    psiApiKey,\n    ...options,\n  });\n}\n\n/**\n * Creates a hybrid runner that uses node for staging and PSI for production\n * @param config - Configuration with staging and production URLs\n * @returns Object with staging and production runners\n */\nexport function createHybridRunners(config: {\n  stagingUrls: string[];\n  productionUrls: string[];\n  psiApiKey: string;\n  thresholds?: PerformanceThresholds;\n}): {\n  staging: LighthouseRunner;\n  production: LighthouseRunner;\n} {\n  const { stagingUrls, productionUrls, psiApiKey, thresholds } = config;\n\n  const staging = createNodeRunner(stagingUrls);\n  const production = createPSIRunner(productionUrls, psiApiKey);\n\n  if (thresholds) {\n    staging.withAssertions(thresholds);\n    production.withAssertions(thresholds);\n  }\n\n  return { staging, production };\n}\n\n/**\n * Generates default performance thresholds based on Core Web Vitals\n * @param strict - Whether to use stricter thresholds\n * @returns Performance thresholds object\n */\nexport function getDefaultThresholds(strict = false): PerformanceThresholds {\n  if (strict) {\n    return {\n      performance: 90,\n      accessibility: 90,\n      bestPractices: 90,\n      seo: 90,\n      lcp: 2500, // Good: < 2.5s\n      fcp: 1800,\n      cls: 0.1,\n      tbt: 200,\n    };\n  }\n\n  return {\n    performance: 50,\n    accessibility: 80,\n    bestPractices: 80,\n    seo: 80,\n    lcp: 4000, // Needs improvement: < 4s\n    fcp: 3000,\n    cls: 0.25,\n    tbt: 600,\n  };\n}\n"]}