@cleartrip/frontguard 0.3.1 → 0.3.2

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/cli.js CHANGED
@@ -5149,15 +5149,29 @@ async function bundleBuildPrecheck(cwd, buildCommand) {
5149
5149
  } catch {
5150
5150
  return {
5151
5151
  run: false,
5152
- message: "Skipped bundle build \u2014 no readable package.json",
5153
- detail: "Set checks.bundle.buildCommand to your real build (e.g. `vite build`), set checks.bundle.runBuild to false, or add a package.json with the matching script."
5152
+ message: "Bundle check: build not run (unreadable package.json)",
5153
+ detail: [
5154
+ "Front Guard did not start the build because package.json could not be read next to the project root.",
5155
+ "No bundle size was measured.",
5156
+ "",
5157
+ "Fix: ensure package.json exists, or set checks.bundle.runBuild to false to only measure files already on disk."
5158
+ ].join("\n")
5154
5159
  };
5155
5160
  }
5156
5161
  if (!scripts?.[script]) {
5162
+ const keys = scripts ? Object.keys(scripts).sort().join(", ") : "(none)";
5157
5163
  return {
5158
5164
  run: false,
5159
- message: `Skipped bundle build \u2014 no scripts.${script} in package.json`,
5160
- detail: "The bundle check runs a production build, then measures the output. Libraries and non-web repos often have no `build` script \u2014 set checks.bundle.runBuild to false, or set checks.bundle.buildCommand to whatever produces your artifacts."
5165
+ message: `Bundle check: build not run (missing scripts["${script}"])`,
5166
+ detail: [
5167
+ `Configured checks.bundle.buildCommand is: \`${buildCommand}\``,
5168
+ `That maps to package.json scripts["${script}"], which is not defined.`,
5169
+ `Existing script names: ${keys}`,
5170
+ "",
5171
+ "Front Guard did not run a production build, so no bundle size was measured (nothing to compare to a baseline).",
5172
+ "",
5173
+ "Fix: set buildCommand to an existing script (e.g. `npm run build:prod` / `yarn run prod:build`), add the missing script, or set checks.bundle.runBuild to false if artifacts are produced elsewhere."
5174
+ ].join("\n")
5161
5175
  };
5162
5176
  }
5163
5177
  return { run: true };
@@ -5184,6 +5198,7 @@ async function runBundle(cwd, config, stack) {
5184
5198
  const strategy = resolveStrategy(cfg.bundleSizeStrategy, stack);
5185
5199
  const preFindings = [];
5186
5200
  let buildStdout = "";
5201
+ let buildExecuted = false;
5187
5202
  if (cfg.runBuild) {
5188
5203
  const parts = tokenizeCommand(cfg.buildCommand);
5189
5204
  if (parts.length === 0) {
@@ -5225,6 +5240,7 @@ async function runBundle(cwd, config, stack) {
5225
5240
  };
5226
5241
  }
5227
5242
  buildStdout = (res.stdout ?? "") + "\n" + (res.stderr ?? "");
5243
+ buildExecuted = true;
5228
5244
  }
5229
5245
  }
5230
5246
  let sizeResult = null;
@@ -5275,6 +5291,23 @@ async function runBundle(cwd, config, stack) {
5275
5291
  const total = sizeResult?.bytes ?? 0;
5276
5292
  const sizeLabel = sizeResult?.label ?? `(no bundle output detected for strategy "${strategy}")`;
5277
5293
  if (total === 0) {
5294
+ const buildSkippedPrecheck = preFindings.some((f4) => f4.id === "bundle-build-skipped");
5295
+ if (buildSkippedPrecheck) {
5296
+ return {
5297
+ checkId: "bundle",
5298
+ findings: preFindings,
5299
+ durationMs: Math.round(performance.now() - t0)
5300
+ };
5301
+ }
5302
+ const emptyDetail = buildExecuted ? [
5303
+ `Strategy "${strategy}" did not find a size after the build finished.`,
5304
+ sizeLabel,
5305
+ "",
5306
+ "For Next.js, confirm `next build` still prints the line `First Load JS shared by all`, or that `.next/static/**/*.js` exists. You can try bundleSizeStrategy `glob` or `custom` if your setup differs."
5307
+ ].join("\n") : [
5308
+ sizeLabel,
5309
+ cfg.runBuild ? "No production build ran successfully before this measurement (unexpected)." : "checks.bundle.runBuild is false \u2014 only existing files on disk are measured. Run a build earlier in the pipeline, or set runBuild to true."
5310
+ ].join("\n");
5278
5311
  return {
5279
5312
  checkId: "bundle",
5280
5313
  findings: [
@@ -5282,9 +5315,8 @@ async function runBundle(cwd, config, stack) {
5282
5315
  {
5283
5316
  id: "bundle-empty",
5284
5317
  severity: "info",
5285
- message: `No bundle size detected (strategy: ${strategy})`,
5286
- detail: `${sizeLabel}
5287
- Ensure the build produces artifacts, or switch to a different bundleSizeStrategy.`
5318
+ message: buildExecuted ? `No bundle size extracted (strategy: ${strategy})` : `No bundle size detected (strategy: ${strategy})`,
5319
+ detail: emptyDetail
5288
5320
  }
5289
5321
  ],
5290
5322
  durationMs: Math.round(performance.now() - t0)