@agent-scope/cli 1.17.0 → 1.17.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.
package/dist/index.js CHANGED
@@ -7,8 +7,8 @@ import { Command } from 'commander';
7
7
  import * as esbuild from 'esbuild';
8
8
  import { createRequire } from 'module';
9
9
  import * as readline from 'readline';
10
- import { chromium } from 'playwright';
11
10
  import { loadTrace, generateTest, getBrowserEntryScript } from '@agent-scope/playwright';
11
+ import { chromium } from 'playwright';
12
12
  import { createServer } from 'http';
13
13
  import { buildSite } from '@agent-scope/site';
14
14
 
@@ -1683,6 +1683,7 @@ async function runHooksProfiling(componentName, filePath, props) {
1683
1683
  try {
1684
1684
  const context = await browser.newContext();
1685
1685
  const page = await context.newPage();
1686
+ await page.addInitScript({ content: getBrowserEntryScript() });
1686
1687
  const htmlHarness = await buildComponentHarness(filePath, componentName, props, 1280);
1687
1688
  await page.setContent(htmlHarness, { waitUntil: "load" });
1688
1689
  await page.waitForFunction(
@@ -2066,24 +2067,6 @@ Available: ${available}`
2066
2067
  var MANIFEST_PATH4 = ".reactscope/manifest.json";
2067
2068
  var DEFAULT_VIEWPORT_WIDTH = 375;
2068
2069
  var DEFAULT_VIEWPORT_HEIGHT = 812;
2069
- var _pool2 = null;
2070
- async function getPool2() {
2071
- if (_pool2 === null) {
2072
- _pool2 = new BrowserPool({
2073
- size: { browsers: 1, pagesPerBrowser: 1 },
2074
- viewportWidth: DEFAULT_VIEWPORT_WIDTH,
2075
- viewportHeight: DEFAULT_VIEWPORT_HEIGHT
2076
- });
2077
- await _pool2.init();
2078
- }
2079
- return _pool2;
2080
- }
2081
- async function shutdownPool2() {
2082
- if (_pool2 !== null) {
2083
- await _pool2.close();
2084
- _pool2 = null;
2085
- }
2086
- }
2087
2070
  function mapNodeType(node) {
2088
2071
  if (node.type === "forward_ref") return "forwardRef";
2089
2072
  if (node.type === "host") return "host";
@@ -2293,10 +2276,12 @@ function formatInstrumentTree(root, showProviderDepth = false) {
2293
2276
  }
2294
2277
  async function runInstrumentTree(options) {
2295
2278
  const { componentName, filePath } = options;
2296
- const pool = await getPool2();
2297
- const slot = await pool.acquire();
2298
- const { page } = slot;
2279
+ const browser = await chromium.launch({ headless: true });
2299
2280
  try {
2281
+ const context = await browser.newContext({
2282
+ viewport: { width: DEFAULT_VIEWPORT_WIDTH, height: DEFAULT_VIEWPORT_HEIGHT }
2283
+ });
2284
+ const page = await context.newPage();
2300
2285
  await page.addInitScript({ content: getBrowserEntryScript() });
2301
2286
  const htmlHarness = await buildComponentHarness(
2302
2287
  filePath,
@@ -2350,7 +2335,7 @@ async function runInstrumentTree(options) {
2350
2335
  }
2351
2336
  return instrumentRoot;
2352
2337
  } finally {
2353
- pool.release(slot);
2338
+ await browser.close();
2354
2339
  }
2355
2340
  }
2356
2341
  function createInstrumentTreeCommand() {
@@ -2390,7 +2375,6 @@ Available: ${available}`
2390
2375
  providerDepth: opts.providerDepth,
2391
2376
  wastedRenders: opts.wastedRenders
2392
2377
  });
2393
- await shutdownPool2();
2394
2378
  const fmt2 = resolveFormat2(opts.format);
2395
2379
  if (fmt2 === "json") {
2396
2380
  process.stdout.write(`${JSON.stringify(instrumentRoot, null, 2)}
@@ -2401,7 +2385,6 @@ Available: ${available}`
2401
2385
  `);
2402
2386
  }
2403
2387
  } catch (err) {
2404
- await shutdownPool2();
2405
2388
  process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
2406
2389
  `);
2407
2390
  process.exit(1);
@@ -2719,22 +2702,22 @@ async function replayInteraction2(page, steps) {
2719
2702
  }
2720
2703
  }
2721
2704
  }
2722
- var _pool3 = null;
2723
- async function getPool3() {
2724
- if (_pool3 === null) {
2725
- _pool3 = new BrowserPool({
2705
+ var _pool2 = null;
2706
+ async function getPool2() {
2707
+ if (_pool2 === null) {
2708
+ _pool2 = new BrowserPool({
2726
2709
  size: { browsers: 1, pagesPerBrowser: 2 },
2727
2710
  viewportWidth: 1280,
2728
2711
  viewportHeight: 800
2729
2712
  });
2730
- await _pool3.init();
2713
+ await _pool2.init();
2731
2714
  }
2732
- return _pool3;
2715
+ return _pool2;
2733
2716
  }
2734
- async function shutdownPool3() {
2735
- if (_pool3 !== null) {
2736
- await _pool3.close();
2737
- _pool3 = null;
2717
+ async function shutdownPool2() {
2718
+ if (_pool2 !== null) {
2719
+ await _pool2.close();
2720
+ _pool2 = null;
2738
2721
  }
2739
2722
  }
2740
2723
  async function analyzeRenders(options) {
@@ -2751,7 +2734,7 @@ Available: ${available}`
2751
2734
  const rootDir = process.cwd();
2752
2735
  const filePath = resolve(rootDir, descriptor.filePath);
2753
2736
  const htmlHarness = await buildComponentHarness(filePath, options.componentName, {}, 1280);
2754
- const pool = await getPool3();
2737
+ const pool = await getPool2();
2755
2738
  const slot = await pool.acquire();
2756
2739
  const { page } = slot;
2757
2740
  const startMs = performance.now();
@@ -2859,7 +2842,7 @@ function createInstrumentRendersCommand() {
2859
2842
  interaction,
2860
2843
  manifestPath: opts.manifest
2861
2844
  });
2862
- await shutdownPool3();
2845
+ await shutdownPool2();
2863
2846
  if (opts.json || !isTTY()) {
2864
2847
  process.stdout.write(`${JSON.stringify(result, null, 2)}
2865
2848
  `);
@@ -2868,7 +2851,7 @@ function createInstrumentRendersCommand() {
2868
2851
  `);
2869
2852
  }
2870
2853
  } catch (err) {
2871
- await shutdownPool3();
2854
+ await shutdownPool2();
2872
2855
  process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
2873
2856
  `);
2874
2857
  process.exit(1);
@@ -2928,22 +2911,22 @@ function writeReportToFile(report, outputPath, pretty) {
2928
2911
  }
2929
2912
  var MANIFEST_PATH6 = ".reactscope/manifest.json";
2930
2913
  var DEFAULT_OUTPUT_DIR = ".reactscope/renders";
2931
- var _pool4 = null;
2932
- async function getPool4(viewportWidth, viewportHeight) {
2933
- if (_pool4 === null) {
2934
- _pool4 = new BrowserPool({
2914
+ var _pool3 = null;
2915
+ async function getPool3(viewportWidth, viewportHeight) {
2916
+ if (_pool3 === null) {
2917
+ _pool3 = new BrowserPool({
2935
2918
  size: { browsers: 1, pagesPerBrowser: 4 },
2936
2919
  viewportWidth,
2937
2920
  viewportHeight
2938
2921
  });
2939
- await _pool4.init();
2922
+ await _pool3.init();
2940
2923
  }
2941
- return _pool4;
2924
+ return _pool3;
2942
2925
  }
2943
- async function shutdownPool4() {
2944
- if (_pool4 !== null) {
2945
- await _pool4.close();
2946
- _pool4 = null;
2926
+ async function shutdownPool3() {
2927
+ if (_pool3 !== null) {
2928
+ await _pool3.close();
2929
+ _pool3 = null;
2947
2930
  }
2948
2931
  }
2949
2932
  function buildRenderer(filePath, componentName, viewportWidth, viewportHeight) {
@@ -2954,7 +2937,7 @@ function buildRenderer(filePath, componentName, viewportWidth, viewportHeight) {
2954
2937
  _satori: satori,
2955
2938
  async renderCell(props, _complexityClass) {
2956
2939
  const startMs = performance.now();
2957
- const pool = await getPool4(viewportWidth, viewportHeight);
2940
+ const pool = await getPool3(viewportWidth, viewportHeight);
2958
2941
  const htmlHarness = await buildComponentHarness(
2959
2942
  filePath,
2960
2943
  componentName,
@@ -3090,7 +3073,7 @@ Available: ${available}`
3090
3073
  }
3091
3074
  }
3092
3075
  );
3093
- await shutdownPool4();
3076
+ await shutdownPool3();
3094
3077
  if (outcome.crashed) {
3095
3078
  process.stderr.write(`\u2717 Render failed: ${outcome.error.message}
3096
3079
  `);
@@ -3138,7 +3121,7 @@ Available: ${available}`
3138
3121
  );
3139
3122
  }
3140
3123
  } catch (err) {
3141
- await shutdownPool4();
3124
+ await shutdownPool3();
3142
3125
  process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
3143
3126
  `);
3144
3127
  process.exit(1);
@@ -3223,7 +3206,7 @@ Available: ${available}`
3223
3206
  concurrency
3224
3207
  });
3225
3208
  const result = await matrix.render();
3226
- await shutdownPool4();
3209
+ await shutdownPool3();
3227
3210
  process.stderr.write(
3228
3211
  `Done. ${result.stats.totalCells} cells, avg ${result.stats.avgRenderTimeMs.toFixed(1)}ms
3229
3212
  `
@@ -3268,7 +3251,7 @@ Available: ${available}`
3268
3251
  process.stdout.write(formatMatrixCsv(componentName, result));
3269
3252
  }
3270
3253
  } catch (err) {
3271
- await shutdownPool4();
3254
+ await shutdownPool3();
3272
3255
  process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
3273
3256
  `);
3274
3257
  process.exit(1);
@@ -3365,13 +3348,13 @@ function registerRenderAll(renderCmd) {
3365
3348
  workers.push(worker());
3366
3349
  }
3367
3350
  await Promise.all(workers);
3368
- await shutdownPool4();
3351
+ await shutdownPool3();
3369
3352
  process.stderr.write("\n");
3370
3353
  const summary = formatSummaryText(results, outputDir);
3371
3354
  process.stderr.write(`${summary}
3372
3355
  `);
3373
3356
  } catch (err) {
3374
- await shutdownPool4();
3357
+ await shutdownPool3();
3375
3358
  process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}
3376
3359
  `);
3377
3360
  process.exit(1);
@@ -3413,26 +3396,26 @@ function createRenderCommand() {
3413
3396
  return renderCmd;
3414
3397
  }
3415
3398
  var DEFAULT_BASELINE_DIR = ".reactscope/baseline";
3416
- var _pool5 = null;
3417
- async function getPool5(viewportWidth, viewportHeight) {
3418
- if (_pool5 === null) {
3419
- _pool5 = new BrowserPool({
3399
+ var _pool4 = null;
3400
+ async function getPool4(viewportWidth, viewportHeight) {
3401
+ if (_pool4 === null) {
3402
+ _pool4 = new BrowserPool({
3420
3403
  size: { browsers: 1, pagesPerBrowser: 4 },
3421
3404
  viewportWidth,
3422
3405
  viewportHeight
3423
3406
  });
3424
- await _pool5.init();
3407
+ await _pool4.init();
3425
3408
  }
3426
- return _pool5;
3409
+ return _pool4;
3427
3410
  }
3428
- async function shutdownPool5() {
3429
- if (_pool5 !== null) {
3430
- await _pool5.close();
3431
- _pool5 = null;
3411
+ async function shutdownPool4() {
3412
+ if (_pool4 !== null) {
3413
+ await _pool4.close();
3414
+ _pool4 = null;
3432
3415
  }
3433
3416
  }
3434
3417
  async function renderComponent2(filePath, componentName, props, viewportWidth, viewportHeight) {
3435
- const pool = await getPool5(viewportWidth, viewportHeight);
3418
+ const pool = await getPool4(viewportWidth, viewportHeight);
3436
3419
  const htmlHarness = await buildComponentHarness(filePath, componentName, props, viewportWidth);
3437
3420
  const slot = await pool.acquire();
3438
3421
  const { page } = slot;
@@ -3682,7 +3665,7 @@ async function runBaseline(options = {}) {
3682
3665
  workers.push(worker());
3683
3666
  }
3684
3667
  await Promise.all(workers);
3685
- await shutdownPool5();
3668
+ await shutdownPool4();
3686
3669
  if (isTTY()) {
3687
3670
  process.stderr.write("\n");
3688
3671
  }
@@ -3743,26 +3726,26 @@ function loadBaselineRenderJson2(baselineDir, componentName) {
3743
3726
  if (!existsSync(jsonPath)) return null;
3744
3727
  return JSON.parse(readFileSync(jsonPath, "utf-8"));
3745
3728
  }
3746
- var _pool6 = null;
3747
- async function getPool6(viewportWidth, viewportHeight) {
3748
- if (_pool6 === null) {
3749
- _pool6 = new BrowserPool({
3729
+ var _pool5 = null;
3730
+ async function getPool5(viewportWidth, viewportHeight) {
3731
+ if (_pool5 === null) {
3732
+ _pool5 = new BrowserPool({
3750
3733
  size: { browsers: 1, pagesPerBrowser: 4 },
3751
3734
  viewportWidth,
3752
3735
  viewportHeight
3753
3736
  });
3754
- await _pool6.init();
3737
+ await _pool5.init();
3755
3738
  }
3756
- return _pool6;
3739
+ return _pool5;
3757
3740
  }
3758
- async function shutdownPool6() {
3759
- if (_pool6 !== null) {
3760
- await _pool6.close();
3761
- _pool6 = null;
3741
+ async function shutdownPool5() {
3742
+ if (_pool5 !== null) {
3743
+ await _pool5.close();
3744
+ _pool5 = null;
3762
3745
  }
3763
3746
  }
3764
3747
  async function renderComponent3(filePath, componentName, props, viewportWidth, viewportHeight) {
3765
- const pool = await getPool6(viewportWidth, viewportHeight);
3748
+ const pool = await getPool5(viewportWidth, viewportHeight);
3766
3749
  const htmlHarness = await buildComponentHarness(filePath, componentName, props, viewportWidth);
3767
3750
  const slot = await pool.acquire();
3768
3751
  const { page } = slot;
@@ -4011,7 +3994,7 @@ async function runDiff(options = {}) {
4011
3994
  }
4012
3995
  await Promise.all(workers);
4013
3996
  }
4014
- await shutdownPool6();
3997
+ await shutdownPool5();
4015
3998
  if (isTTY() && total > 0) {
4016
3999
  process.stderr.write("\n");
4017
4000
  }