@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.cjs CHANGED
@@ -36,9 +36,9 @@ var esbuild__namespace = /*#__PURE__*/_interopNamespace(esbuild);
36
36
  var readline__namespace = /*#__PURE__*/_interopNamespace(readline);
37
37
 
38
38
  // src/ci/commands.ts
39
- async function buildComponentHarness(filePath, componentName, props, viewportWidth, projectCss) {
39
+ async function buildComponentHarness(filePath, componentName, props, viewportWidth, projectCss, preScript) {
40
40
  const bundledScript = await bundleComponentToIIFE(filePath, componentName, props);
41
- return wrapInHtml(bundledScript, viewportWidth, projectCss);
41
+ return wrapInHtml(bundledScript, viewportWidth, projectCss, preScript);
42
42
  }
43
43
  async function bundleComponentToIIFE(filePath, componentName, props) {
44
44
  const propsJson = JSON.stringify(props).replace(/<\/script>/gi, "<\\/script>");
@@ -124,10 +124,12 @@ ${msg}`);
124
124
  }
125
125
  return outputFile.text;
126
126
  }
127
- function wrapInHtml(bundledScript, viewportWidth, projectCss) {
127
+ function wrapInHtml(bundledScript, viewportWidth, projectCss, preScript) {
128
128
  const projectStyleBlock = projectCss != null && projectCss.length > 0 ? `<style id="scope-project-css">
129
129
  ${projectCss.replace(/<\/style>/gi, "<\\/style>")}
130
130
  </style>` : "";
131
+ const preScriptBlock = preScript != null && preScript.length > 0 ? `<script>${preScript}</script>
132
+ ` : "";
131
133
  return `<!DOCTYPE html>
132
134
  <html lang="en">
133
135
  <head>
@@ -142,7 +144,7 @@ ${projectCss.replace(/<\/style>/gi, "<\\/style>")}
142
144
  </head>
143
145
  <body>
144
146
  <div id="scope-root" data-reactscope-root></div>
145
- <script>${bundledScript}</script>
147
+ ${preScriptBlock}<script>${bundledScript}</script>
146
148
  </body>
147
149
  </html>`;
148
150
  }
@@ -1706,8 +1708,15 @@ async function runHooksProfiling(componentName, filePath, props) {
1706
1708
  try {
1707
1709
  const context = await browser.newContext();
1708
1710
  const page = await context.newPage();
1709
- await page.addInitScript({ content: playwright.getBrowserEntryScript() });
1710
- const htmlHarness = await buildComponentHarness(filePath, componentName, props, 1280);
1711
+ const scopeRuntime = playwright.getBrowserEntryScript();
1712
+ const htmlHarness = await buildComponentHarness(
1713
+ filePath,
1714
+ componentName,
1715
+ props,
1716
+ 1280,
1717
+ void 0,
1718
+ scopeRuntime
1719
+ );
1711
1720
  await page.setContent(htmlHarness, { waitUntil: "load" });
1712
1721
  await page.waitForFunction(
1713
1722
  () => {
@@ -1966,7 +1975,15 @@ async function runInteractionProfile(componentName, filePath, props, interaction
1966
1975
  try {
1967
1976
  const context = await browser.newContext();
1968
1977
  const page = await context.newPage();
1969
- const htmlHarness = await buildComponentHarness(filePath, componentName, props, 1280);
1978
+ const scopeRuntime = playwright.getBrowserEntryScript();
1979
+ const htmlHarness = await buildComponentHarness(
1980
+ filePath,
1981
+ componentName,
1982
+ props,
1983
+ 1280,
1984
+ void 0,
1985
+ scopeRuntime
1986
+ );
1970
1987
  await page.setContent(htmlHarness, { waitUntil: "load" });
1971
1988
  await page.waitForFunction(
1972
1989
  () => {
@@ -2305,12 +2322,14 @@ async function runInstrumentTree(options) {
2305
2322
  viewport: { width: DEFAULT_VIEWPORT_WIDTH, height: DEFAULT_VIEWPORT_HEIGHT }
2306
2323
  });
2307
2324
  const page = await context.newPage();
2308
- await page.addInitScript({ content: playwright.getBrowserEntryScript() });
2325
+ const scopeRuntime = playwright.getBrowserEntryScript();
2309
2326
  const htmlHarness = await buildComponentHarness(
2310
2327
  filePath,
2311
2328
  componentName,
2312
2329
  {},
2313
- DEFAULT_VIEWPORT_WIDTH
2330
+ DEFAULT_VIEWPORT_WIDTH,
2331
+ void 0,
2332
+ scopeRuntime
2314
2333
  );
2315
2334
  await page.setContent(htmlHarness, { waitUntil: "load" });
2316
2335
  await page.waitForFunction(
@@ -2756,13 +2775,20 @@ Available: ${available}`
2756
2775
  }
2757
2776
  const rootDir = process.cwd();
2758
2777
  const filePath = path.resolve(rootDir, descriptor.filePath);
2759
- const htmlHarness = await buildComponentHarness(filePath, options.componentName, {}, 1280);
2778
+ const preScript = playwright.getBrowserEntryScript() + "\n" + buildInstrumentationScript();
2779
+ const htmlHarness = await buildComponentHarness(
2780
+ filePath,
2781
+ options.componentName,
2782
+ {},
2783
+ 1280,
2784
+ void 0,
2785
+ preScript
2786
+ );
2760
2787
  const pool = await getPool2();
2761
2788
  const slot = await pool.acquire();
2762
2789
  const { page } = slot;
2763
2790
  const startMs = performance.now();
2764
2791
  try {
2765
- await page.addInitScript(buildInstrumentationScript());
2766
2792
  await page.setContent(htmlHarness, { waitUntil: "load" });
2767
2793
  await page.waitForFunction(
2768
2794
  () => window.__SCOPE_RENDER_COMPLETE__ === true,