@agent-scope/cli 1.17.1 → 1.17.3

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
@@ -13,9 +13,9 @@ import { createServer } from 'http';
13
13
  import { buildSite } from '@agent-scope/site';
14
14
 
15
15
  // src/ci/commands.ts
16
- async function buildComponentHarness(filePath, componentName, props, viewportWidth, projectCss) {
16
+ async function buildComponentHarness(filePath, componentName, props, viewportWidth, projectCss, preScript) {
17
17
  const bundledScript = await bundleComponentToIIFE(filePath, componentName, props);
18
- return wrapInHtml(bundledScript, viewportWidth, projectCss);
18
+ return wrapInHtml(bundledScript, viewportWidth, projectCss, preScript);
19
19
  }
20
20
  async function bundleComponentToIIFE(filePath, componentName, props) {
21
21
  const propsJson = JSON.stringify(props).replace(/<\/script>/gi, "<\\/script>");
@@ -101,10 +101,12 @@ ${msg}`);
101
101
  }
102
102
  return outputFile.text;
103
103
  }
104
- function wrapInHtml(bundledScript, viewportWidth, projectCss) {
104
+ function wrapInHtml(bundledScript, viewportWidth, projectCss, preScript) {
105
105
  const projectStyleBlock = projectCss != null && projectCss.length > 0 ? `<style id="scope-project-css">
106
106
  ${projectCss.replace(/<\/style>/gi, "<\\/style>")}
107
107
  </style>` : "";
108
+ const preScriptBlock = preScript != null && preScript.length > 0 ? `<script>${preScript}</script>
109
+ ` : "";
108
110
  return `<!DOCTYPE html>
109
111
  <html lang="en">
110
112
  <head>
@@ -119,7 +121,7 @@ ${projectCss.replace(/<\/style>/gi, "<\\/style>")}
119
121
  </head>
120
122
  <body>
121
123
  <div id="scope-root" data-reactscope-root></div>
122
- <script>${bundledScript}</script>
124
+ ${preScriptBlock}<script>${bundledScript}</script>
123
125
  </body>
124
126
  </html>`;
125
127
  }
@@ -1683,8 +1685,15 @@ async function runHooksProfiling(componentName, filePath, props) {
1683
1685
  try {
1684
1686
  const context = await browser.newContext();
1685
1687
  const page = await context.newPage();
1686
- await page.addInitScript({ content: getBrowserEntryScript() });
1687
- const htmlHarness = await buildComponentHarness(filePath, componentName, props, 1280);
1688
+ const scopeRuntime = getBrowserEntryScript();
1689
+ const htmlHarness = await buildComponentHarness(
1690
+ filePath,
1691
+ componentName,
1692
+ props,
1693
+ 1280,
1694
+ void 0,
1695
+ scopeRuntime
1696
+ );
1688
1697
  await page.setContent(htmlHarness, { waitUntil: "load" });
1689
1698
  await page.waitForFunction(
1690
1699
  () => {
@@ -1943,7 +1952,15 @@ async function runInteractionProfile(componentName, filePath, props, interaction
1943
1952
  try {
1944
1953
  const context = await browser.newContext();
1945
1954
  const page = await context.newPage();
1946
- const htmlHarness = await buildComponentHarness(filePath, componentName, props, 1280);
1955
+ const scopeRuntime = getBrowserEntryScript();
1956
+ const htmlHarness = await buildComponentHarness(
1957
+ filePath,
1958
+ componentName,
1959
+ props,
1960
+ 1280,
1961
+ void 0,
1962
+ scopeRuntime
1963
+ );
1947
1964
  await page.setContent(htmlHarness, { waitUntil: "load" });
1948
1965
  await page.waitForFunction(
1949
1966
  () => {
@@ -2282,12 +2299,14 @@ async function runInstrumentTree(options) {
2282
2299
  viewport: { width: DEFAULT_VIEWPORT_WIDTH, height: DEFAULT_VIEWPORT_HEIGHT }
2283
2300
  });
2284
2301
  const page = await context.newPage();
2285
- await page.addInitScript({ content: getBrowserEntryScript() });
2302
+ const scopeRuntime = getBrowserEntryScript();
2286
2303
  const htmlHarness = await buildComponentHarness(
2287
2304
  filePath,
2288
2305
  componentName,
2289
2306
  {},
2290
- DEFAULT_VIEWPORT_WIDTH
2307
+ DEFAULT_VIEWPORT_WIDTH,
2308
+ void 0,
2309
+ scopeRuntime
2291
2310
  );
2292
2311
  await page.setContent(htmlHarness, { waitUntil: "load" });
2293
2312
  await page.waitForFunction(
@@ -2733,13 +2752,20 @@ Available: ${available}`
2733
2752
  }
2734
2753
  const rootDir = process.cwd();
2735
2754
  const filePath = resolve(rootDir, descriptor.filePath);
2736
- const htmlHarness = await buildComponentHarness(filePath, options.componentName, {}, 1280);
2755
+ const preScript = getBrowserEntryScript() + "\n" + buildInstrumentationScript();
2756
+ const htmlHarness = await buildComponentHarness(
2757
+ filePath,
2758
+ options.componentName,
2759
+ {},
2760
+ 1280,
2761
+ void 0,
2762
+ preScript
2763
+ );
2737
2764
  const pool = await getPool2();
2738
2765
  const slot = await pool.acquire();
2739
2766
  const { page } = slot;
2740
2767
  const startMs = performance.now();
2741
2768
  try {
2742
- await page.addInitScript(buildInstrumentationScript());
2743
2769
  await page.setContent(htmlHarness, { waitUntil: "load" });
2744
2770
  await page.waitForFunction(
2745
2771
  () => window.__SCOPE_RENDER_COMPLETE__ === true,