@agent-scope/cli 1.20.1 → 1.20.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
@@ -464,6 +464,11 @@ var STYLE_ENTRY_CANDIDATES = [
464
464
  "index.css"
465
465
  ];
466
466
  var TAILWIND_IMPORT = /@import\s+["']tailwindcss["']\s*;?/;
467
+ function getElementClassNames(el) {
468
+ const className = el.className;
469
+ const raw = typeof className === "string" ? className : typeof className?.baseVal === "string" ? className.baseVal : el.getAttribute("class") ?? "";
470
+ return raw.split(/\s+/).filter(Boolean);
471
+ }
467
472
  var compilerCache = null;
468
473
  function getCachedBuild(cwd) {
469
474
  if (compilerCache !== null && path.resolve(compilerCache.cwd) === path.resolve(cwd)) {
@@ -684,8 +689,8 @@ async function renderComponent(filePath, componentName, props, viewportWidth, vi
684
689
  const classes = await page.evaluate(() => {
685
690
  const set = /* @__PURE__ */ new Set();
686
691
  document.querySelectorAll("[class]").forEach((el) => {
687
- for (const c of el.className.split(/\s+/)) {
688
- if (c) set.add(c);
692
+ for (const c of getElementClassNames(el)) {
693
+ set.add(c);
689
694
  }
690
695
  });
691
696
  return [...set];
@@ -4078,6 +4083,39 @@ function formatAggregateRenderFailureJson(componentName, failures, scenarioCount
4078
4083
  }
4079
4084
  var MANIFEST_PATH6 = ".reactscope/manifest.json";
4080
4085
  var DEFAULT_OUTPUT_DIR = ".reactscope/renders";
4086
+ function renderArtifactBaseName(componentName, scenarioName) {
4087
+ return scenarioName === void 0 ? componentName : `${componentName}-${scenarioName}`;
4088
+ }
4089
+ function removeStaleRenderError(outputDir, componentName, scenarioName) {
4090
+ const errorPath = path.resolve(
4091
+ outputDir,
4092
+ `${renderArtifactBaseName(componentName, scenarioName)}.error.json`
4093
+ );
4094
+ if (fs.existsSync(errorPath)) {
4095
+ fs.rmSync(errorPath, { force: true });
4096
+ }
4097
+ }
4098
+ function writeRenderErrorArtifact(outputDir, failure) {
4099
+ const errPath = path.resolve(
4100
+ outputDir,
4101
+ `${renderArtifactBaseName(failure.component, failure.scenario)}.error.json`
4102
+ );
4103
+ fs.writeFileSync(
4104
+ errPath,
4105
+ JSON.stringify(
4106
+ {
4107
+ component: failure.component,
4108
+ scenario: failure.scenario,
4109
+ errorMessage: failure.errorMessage,
4110
+ heuristicFlags: failure.heuristicFlags,
4111
+ propsAtCrash: failure.propsAtCrash
4112
+ },
4113
+ null,
4114
+ 2
4115
+ )
4116
+ );
4117
+ return errPath;
4118
+ }
4081
4119
  var _pool3 = null;
4082
4120
  async function getPool3(viewportWidth, viewportHeight) {
4083
4121
  if (_pool3 === null) {
@@ -4137,8 +4175,8 @@ function buildRenderer(filePath, componentName, viewportWidth, viewportHeight, g
4137
4175
  const classes = await page.evaluate(() => {
4138
4176
  const set = /* @__PURE__ */ new Set();
4139
4177
  document.querySelectorAll("[class]").forEach((el) => {
4140
- for (const c of el.className.split(/\s+/)) {
4141
- if (c) set.add(c);
4178
+ for (const c of getElementClassNames(el)) {
4179
+ set.add(c);
4142
4180
  }
4143
4181
  });
4144
4182
  return [...set];
@@ -4762,20 +4800,12 @@ function registerRenderAll(renderCmd) {
4762
4800
  success: false,
4763
4801
  errorMessage: outcome.error.message
4764
4802
  });
4765
- const errPath = path.resolve(outputDir, `${name}.error.json`);
4766
- fs.writeFileSync(
4767
- errPath,
4768
- JSON.stringify(
4769
- {
4770
- component: name,
4771
- errorMessage: outcome.error.message,
4772
- heuristicFlags: outcome.error.heuristicFlags,
4773
- propsAtCrash: outcome.error.propsAtCrash
4774
- },
4775
- null,
4776
- 2
4777
- )
4778
- );
4803
+ const errPath = writeRenderErrorArtifact(outputDir, {
4804
+ component: name,
4805
+ errorMessage: outcome.error.message,
4806
+ heuristicFlags: outcome.error.heuristicFlags,
4807
+ propsAtCrash: outcome.error.propsAtCrash
4808
+ });
4779
4809
  failures.push({
4780
4810
  component: name,
4781
4811
  stage: "render",
@@ -4788,13 +4818,14 @@ function registerRenderAll(renderCmd) {
4788
4818
  }
4789
4819
  const result = outcome.result;
4790
4820
  results.push({ name, renderTimeMs: result.renderTimeMs, success: true });
4821
+ removeStaleRenderError(outputDir, name);
4791
4822
  if (!isIcon) {
4792
4823
  const pngPath = path.resolve(outputDir, `${name}.png`);
4793
4824
  fs.writeFileSync(pngPath, result.screenshot);
4794
4825
  outputPaths.push(pngPath);
4795
4826
  }
4796
4827
  const jsonPath = path.resolve(outputDir, `${name}.json`);
4797
- const renderJson = formatRenderJson(name, {}, result);
4828
+ const renderJson = formatRenderJson(name, renderProps, result);
4798
4829
  const extResult = result;
4799
4830
  if (isIcon && extResult.svgContent) {
4800
4831
  renderJson.svgContent = extResult.svgContent;
@@ -4855,13 +4886,34 @@ function registerRenderAll(renderCmd) {
4855
4886
  concurrency: 2
4856
4887
  });
4857
4888
  const matrixResult = await matrix.render();
4858
- const matrixCells = matrixResult.cells.map((cell) => ({
4859
- axisValues: [scenarioEntries2[cell.axisIndices[0] ?? 0]?.[0] ?? ""],
4860
- screenshot: cell.result.screenshot.toString("base64"),
4861
- width: cell.result.width,
4862
- height: cell.result.height,
4863
- renderTimeMs: cell.result.renderTimeMs
4864
- }));
4889
+ const matrixCells = matrixResult.cells.map((cell) => {
4890
+ const scenarioName = scenarioEntries2[cell.axisIndices[0] ?? 0]?.[0] ?? "";
4891
+ const artifactBaseName = renderArtifactBaseName(name, scenarioName);
4892
+ const scenarioPngPath = path.resolve(outputDir, `${artifactBaseName}.png`);
4893
+ const scenarioJsonPath = path.resolve(outputDir, `${artifactBaseName}.json`);
4894
+ if (!isIcon) {
4895
+ fs.writeFileSync(scenarioPngPath, cell.result.screenshot);
4896
+ outputPaths.push(scenarioPngPath);
4897
+ }
4898
+ const scenarioJson = formatRenderJson(
4899
+ `${name}:${scenarioName}`,
4900
+ scenarioPropsMap[scenarioName] ?? {},
4901
+ cell.result
4902
+ );
4903
+ fs.writeFileSync(scenarioJsonPath, JSON.stringify(scenarioJson, null, 2));
4904
+ outputPaths.push(scenarioJsonPath);
4905
+ removeStaleRenderError(outputDir, name, scenarioName);
4906
+ return {
4907
+ axisValues: [scenarioName],
4908
+ scenario: scenarioName,
4909
+ outputPath: scenarioJsonPath,
4910
+ screenshotPath: isIcon ? void 0 : scenarioPngPath,
4911
+ screenshot: cell.result.screenshot.toString("base64"),
4912
+ width: cell.result.width,
4913
+ height: cell.result.height,
4914
+ renderTimeMs: cell.result.renderTimeMs
4915
+ };
4916
+ });
4865
4917
  const existingJson = JSON.parse(fs.readFileSync(jsonPath, "utf-8"));
4866
4918
  existingJson.cells = matrixCells;
4867
4919
  existingJson.axisLabels = [scenarioAxis.values];
@@ -5018,8 +5070,8 @@ async function renderComponent2(filePath, componentName, props, viewportWidth, v
5018
5070
  const classes = await page.evaluate(() => {
5019
5071
  const set = /* @__PURE__ */ new Set();
5020
5072
  document.querySelectorAll("[class]").forEach((el) => {
5021
- for (const c of el.className.split(/\s+/)) {
5022
- if (c) set.add(c);
5073
+ for (const c of getElementClassNames(el)) {
5074
+ set.add(c);
5023
5075
  }
5024
5076
  });
5025
5077
  return [...set];
@@ -5356,8 +5408,8 @@ async function renderComponent3(filePath, componentName, props, viewportWidth, v
5356
5408
  const classes = await page.evaluate(() => {
5357
5409
  const set = /* @__PURE__ */ new Set();
5358
5410
  document.querySelectorAll("[class]").forEach((el) => {
5359
- for (const c of el.className.split(/\s+/)) {
5360
- if (c) set.add(c);
5411
+ for (const c of getElementClassNames(el)) {
5412
+ set.add(c);
5361
5413
  }
5362
5414
  });
5363
5415
  return [...set];