@cleartrip/frontguard 0.3.0 → 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 +41 -8
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5130,11 +5130,12 @@ function tokenizeCommand(cmd) {
|
|
|
5130
5130
|
}
|
|
5131
5131
|
function npmScriptFromBuildCommand(cmd) {
|
|
5132
5132
|
const t3 = cmd.trim();
|
|
5133
|
-
if (/^yarn\s+build\b/i.test(t3)) return "build";
|
|
5134
5133
|
const np = /^(?:npm|pnpm)\s+run\s+(\S+)/i.exec(t3);
|
|
5135
5134
|
if (np?.[1]) return np[1];
|
|
5136
5135
|
const yr = /^yarn\s+run\s+(\S+)/i.exec(t3);
|
|
5137
5136
|
if (yr?.[1]) return yr[1];
|
|
5137
|
+
const yPlain = /^yarn\s+(?!run\b)(\S+)/i.exec(t3);
|
|
5138
|
+
if (yPlain?.[1]) return yPlain[1];
|
|
5138
5139
|
return null;
|
|
5139
5140
|
}
|
|
5140
5141
|
async function bundleBuildPrecheck(cwd, buildCommand) {
|
|
@@ -5148,15 +5149,29 @@ async function bundleBuildPrecheck(cwd, buildCommand) {
|
|
|
5148
5149
|
} catch {
|
|
5149
5150
|
return {
|
|
5150
5151
|
run: false,
|
|
5151
|
-
message: "
|
|
5152
|
-
detail:
|
|
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")
|
|
5153
5159
|
};
|
|
5154
5160
|
}
|
|
5155
5161
|
if (!scripts?.[script]) {
|
|
5162
|
+
const keys = scripts ? Object.keys(scripts).sort().join(", ") : "(none)";
|
|
5156
5163
|
return {
|
|
5157
5164
|
run: false,
|
|
5158
|
-
message: `
|
|
5159
|
-
detail:
|
|
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")
|
|
5160
5175
|
};
|
|
5161
5176
|
}
|
|
5162
5177
|
return { run: true };
|
|
@@ -5183,6 +5198,7 @@ async function runBundle(cwd, config, stack) {
|
|
|
5183
5198
|
const strategy = resolveStrategy(cfg.bundleSizeStrategy, stack);
|
|
5184
5199
|
const preFindings = [];
|
|
5185
5200
|
let buildStdout = "";
|
|
5201
|
+
let buildExecuted = false;
|
|
5186
5202
|
if (cfg.runBuild) {
|
|
5187
5203
|
const parts = tokenizeCommand(cfg.buildCommand);
|
|
5188
5204
|
if (parts.length === 0) {
|
|
@@ -5224,6 +5240,7 @@ async function runBundle(cwd, config, stack) {
|
|
|
5224
5240
|
};
|
|
5225
5241
|
}
|
|
5226
5242
|
buildStdout = (res.stdout ?? "") + "\n" + (res.stderr ?? "");
|
|
5243
|
+
buildExecuted = true;
|
|
5227
5244
|
}
|
|
5228
5245
|
}
|
|
5229
5246
|
let sizeResult = null;
|
|
@@ -5274,6 +5291,23 @@ async function runBundle(cwd, config, stack) {
|
|
|
5274
5291
|
const total = sizeResult?.bytes ?? 0;
|
|
5275
5292
|
const sizeLabel = sizeResult?.label ?? `(no bundle output detected for strategy "${strategy}")`;
|
|
5276
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");
|
|
5277
5311
|
return {
|
|
5278
5312
|
checkId: "bundle",
|
|
5279
5313
|
findings: [
|
|
@@ -5281,9 +5315,8 @@ async function runBundle(cwd, config, stack) {
|
|
|
5281
5315
|
{
|
|
5282
5316
|
id: "bundle-empty",
|
|
5283
5317
|
severity: "info",
|
|
5284
|
-
message: `No bundle size detected (strategy: ${strategy})`,
|
|
5285
|
-
detail:
|
|
5286
|
-
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
|
|
5287
5320
|
}
|
|
5288
5321
|
],
|
|
5289
5322
|
durationMs: Math.round(performance.now() - t0)
|