apex-auditor 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,57 @@
1
1
  import lighthouse from "lighthouse";
2
+ import chromeLauncher from "chrome-launcher";
3
+ async function createChromeSession(chromePort) {
4
+ if (typeof chromePort === "number") {
5
+ return { port: chromePort };
6
+ }
7
+ const chrome = await chromeLauncher.launch({
8
+ chromeFlags: [
9
+ "--headless=new",
10
+ "--disable-gpu",
11
+ "--no-sandbox",
12
+ "--disable-dev-shm-usage",
13
+ "--disable-extensions",
14
+ "--disable-default-apps",
15
+ "--no-first-run",
16
+ "--no-default-browser-check",
17
+ ],
18
+ });
19
+ return {
20
+ port: chrome.port,
21
+ close: async () => {
22
+ await chrome.kill();
23
+ },
24
+ };
25
+ }
2
26
  /**
3
27
  * Run audits for all pages defined in the config and return a structured summary.
4
28
  */
5
29
  export async function runAuditsForConfig({ config, configPath, }) {
6
- const port = config.chromePort ?? 9222;
7
30
  const runs = config.runs ?? 1;
8
31
  const results = [];
9
- for (const page of config.pages) {
10
- for (const device of page.devices) {
11
- const url = buildUrl({ baseUrl: config.baseUrl, path: page.path, query: config.query });
12
- const summaries = [];
13
- for (let i = 0; i < runs; i += 1) {
14
- const summary = await runSingleAudit({
15
- url,
16
- path: page.path,
17
- label: page.label,
18
- device,
19
- port,
20
- });
21
- summaries.push(summary);
32
+ const session = await createChromeSession(config.chromePort);
33
+ try {
34
+ for (const page of config.pages) {
35
+ for (const device of page.devices) {
36
+ const url = buildUrl({ baseUrl: config.baseUrl, path: page.path, query: config.query });
37
+ const summaries = [];
38
+ for (let index = 0; index < runs; index += 1) {
39
+ const summary = await runSingleAudit({
40
+ url,
41
+ path: page.path,
42
+ label: page.label,
43
+ device,
44
+ port: session.port,
45
+ });
46
+ summaries.push(summary);
47
+ }
48
+ results.push(aggregateSummaries(summaries));
22
49
  }
23
- results.push(aggregateSummaries(summaries));
50
+ }
51
+ }
52
+ finally {
53
+ if (session.close) {
54
+ await session.close();
24
55
  }
25
56
  }
26
57
  return { configPath, results };
@@ -11,9 +11,8 @@ const PROFILE_TO_DETECTOR = {
11
11
  custom: undefined,
12
12
  };
13
13
  const DEFAULT_BASE_URL = "http://localhost:3000";
14
- const DEFAULT_CHROME_PORT = 9222;
15
14
  const DEFAULT_RUNS = 1;
16
- const DEFAULT_PROJECT_ROOT = "..";
15
+ const DEFAULT_PROJECT_ROOT = ".";
17
16
  const DEFAULT_PRESELECT_COUNT = 5;
18
17
  const DEFAULT_DEVICES = ["mobile", "desktop"];
19
18
  const PROMPT_OPTIONS = { onCancel: handleCancel };
@@ -49,13 +48,6 @@ const baseQuestions = [
49
48
  message: "Query string appended to every route (optional)",
50
49
  initial: "",
51
50
  },
52
- {
53
- type: "number",
54
- name: "chromePort",
55
- message: "Chrome remote debugging port",
56
- initial: DEFAULT_CHROME_PORT,
57
- min: 1,
58
- },
59
51
  {
60
52
  type: "number",
61
53
  name: "runs",
@@ -168,7 +160,6 @@ async function collectBaseAnswers() {
168
160
  return {
169
161
  baseUrl: answers.baseUrl.trim(),
170
162
  query: answers.query && answers.query.length > 0 ? answers.query : undefined,
171
- chromePort: answers.chromePort,
172
163
  runs: answers.runs,
173
164
  };
174
165
  }
@@ -261,7 +252,6 @@ async function buildConfig() {
261
252
  return {
262
253
  baseUrl: baseAnswers.baseUrl,
263
254
  query: baseAnswers.query,
264
- chromePort: baseAnswers.chromePort,
265
255
  runs: baseAnswers.runs,
266
256
  pages,
267
257
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apex-auditor",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "description": "CLI to run structured Lighthouse audits (Performance, Accessibility, Best Practices, SEO) across routes.",
6
6
  "type": "module",
@@ -18,6 +18,7 @@
18
18
  "test": "vitest run"
19
19
  },
20
20
  "dependencies": {
21
+ "chrome-launcher": "^0.15.2",
21
22
  "lighthouse": "^12.6.1",
22
23
  "prompts": "^2.4.2"
23
24
  },