@cleartrip/frontguard 0.2.4 → 0.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleartrip/frontguard",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Org-wide frontend PR guardrails: linting, hygiene, any-delta, cycles, dead code, bundle/CWV hints, custom rules, optional LLM brief",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,17 +1,12 @@
1
- # FrontGuard + PR comment (Bitbucket Cloud) FreeKit.dev report URL
1
+ # FrontGuard PR comment: checks screenshot (inline) + FreeKit full report
2
2
  #
3
- # HTML report is uploaded to https://freekit.dev via their public API (no API key for POST /sites).
4
- # Docs: https://freekit.dev/docs
3
+ # FrontGuard renders the checks table to HTML, then to PNG using Playwright (`npx`, no apt Chromium).
4
+ # The PNG is embedded in the PR comment as a small base64 image (no Bitbucket Downloads / extra tokens).
5
+ # • Full HTML report is uploaded to FreeKit; the comment links to that URL for details.
5
6
  #
6
- # Per-repo setup:
7
- # 1. Repository variable (secured): BITBUCKET_ACCESS_TOKEN — permission to comment on pull requests.
8
- # 2. Add @cleartrip/frontguard as a devDependency and use this file (or merge the step).
7
+ # Secured variable: BITBUCKET_ACCESS_TOKEN — must be allowed to post pull request comments.
9
8
  #
10
- # API hostname for comments MUST be api.bitbucket.org (Bitbucket Cloud).
11
- #
12
- # The PR comment body is the hosted https://freekit.dev/s/... URL (one line).
13
- #
14
- # Caveats (see templates/freekit-ci-setup.md): public URL, third-party service, size/rate limits.
9
+ # Optional: FREEKIT_BASE_URL override FreeKit API host (default https://freekit.dev).
15
10
 
16
11
  image: node:20
17
12
 
@@ -19,28 +14,35 @@ pipelines:
19
14
  pull-requests:
20
15
  '**':
21
16
  - step:
22
- name: FrontGuard FreeKit report + PR comment
17
+ name: FrontGuard report + PR comment
23
18
  caches:
24
19
  - node
25
20
  artifacts:
26
21
  - frontguard-report.html
27
22
  - frontguard-report.md
23
+ - frontguard-checks.html
24
+ - frontguard-checks.png
28
25
  script:
29
26
  - corepack enable
30
27
  - yarn install --immutable || yarn install
31
28
  - |
32
29
  yarn frontguard run --markdown \
33
30
  --htmlOut frontguard-report.html \
31
+ --checksSnapshotOut frontguard-checks.html \
32
+ --checksPngOut frontguard-checks.png \
34
33
  > frontguard-report.md
35
34
  - |
36
35
  python3 << 'PY'
36
+ import base64
37
37
  import json
38
38
  import os
39
39
  from urllib.error import HTTPError
40
40
  from urllib.request import Request, urlopen
41
41
 
42
- base = os.environ.get("FREEKIT_BASE_URL", "https://freekit.dev").rstrip("/")
42
+ DETAILED = "For detailed check analysis, please open the full interactive report:"
43
+ MAX_B64 = 290_000
43
44
 
45
+ base = os.environ.get("FREEKIT_BASE_URL", "https://freekit.dev").rstrip("/")
44
46
  with open("frontguard-report.html", encoding="utf-8") as f:
45
47
  html = f.read()
46
48
 
@@ -62,15 +64,25 @@ pipelines:
62
64
  raise SystemExit(f"FreeKit error: {json.dumps(parsed)[:4000]}")
63
65
 
64
66
  data = parsed.get("data") or {}
65
- url = (data.get("url") or "").strip()
66
- if not url:
67
+ report_url = (data.get("url") or "").strip()
68
+ if not report_url:
67
69
  raise SystemExit(f"FreeKit: missing data.url in {json.dumps(parsed)[:2000]}")
68
70
 
69
- with open("frontguard-pr-comment.md", "w", encoding="utf-8") as out:
70
- out.write(url + "\n")
71
+ with open("frontguard-checks.png", "rb") as f:
72
+ raw = f.read()
73
+ b64 = base64.standard_b64encode(raw).decode("ascii")
74
+ img_line = f"![FrontGuard — checks summary](data:image/png;base64,{b64})"
75
+ if len(img_line) > MAX_B64:
76
+ raise SystemExit(
77
+ f"Checks PNG too large for inline comment ({len(raw)} bytes). "
78
+ "Shrink the table or raise MAX_B64 after verifying Bitbucket limits."
79
+ )
71
80
 
81
+ body = f"{img_line}\n\n{DETAILED}\n{report_url}\n"
82
+ with open("frontguard-pr-comment.md", "w", encoding="utf-8") as out:
83
+ out.write(body)
72
84
  with open("frontguard-payload.json", "w", encoding="utf-8") as out:
73
- json.dump({"content": {"raw": url}}, out, ensure_ascii=False)
85
+ json.dump({"content": {"raw": body}}, out, ensure_ascii=False)
74
86
  PY
75
87
  - |
76
88
  test -n "${BITBUCKET_ACCESS_TOKEN:-}" || { echo "Missing secured var BITBUCKET_ACCESS_TOKEN"; exit 1; }
@@ -1,30 +1 @@
1
- # Optional fragment: PNG of the Checks table in the PR comment (Bitbucket Cloud)
2
- #
3
- # Merge into pull-requests after `frontguard run` produces:
4
- # - frontguard-checks.html (--checksSnapshotOut)
5
- # - frontguard-report.html (--htmlOut)
6
- #
7
- # Flow:
8
- # 1. Screenshot the minimal HTML with Playwright (Chromium).
9
- # 2. Upload the PNG somewhere HTTPS-public (examples below).
10
- # 3. export FRONTGUARD_CHECKS_IMAGE_URL='https://.../frontguard-checks.png'
11
- # 4. Run frontguard again with --prCommentOut (or only export + re-run snippet step) so the comment includes ![...](url).
12
- #
13
- # The PR body is Markdown: Bitbucket renders ![](https://...) images when the URL is reachable.
14
-
15
- # --- Example: screenshot + upload to Bitbucket Downloads (public file URL for repo viewers) ---
16
- # - npx playwright@1.49.0 install chromium
17
- # - |
18
- # FILE_URL="$(node --input-type=module -e "import { pathToFileURL } from 'node:url'; console.log(pathToFileURL('frontguard-checks.html').href)")"
19
- # npx playwright@1.49.0 screenshot "$FILE_URL" frontguard-checks.png --viewport-size=920,2000
20
- # - |
21
- # curl --silent --show-error --fail --request POST \
22
- # --url "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_FULL_NAME}/downloads" \
23
- # --header "Authorization: Bearer ${BITBUCKET_ACCESS_TOKEN}" \
24
- # --form "files=@frontguard-checks.png"
25
- # # Then set FRONTGUARD_CHECKS_IMAGE_URL to the href Bitbucket returns for that file (see API response),
26
- # # or construct the known downloads URL pattern for your workspace.
27
- #
28
- # --- Example: same image hosted on your CDN / object storage ---
29
- # - aws s3 cp frontguard-checks.png s3://my-bucket/ci/frontguard-checks-${BITBUCKET_BUILD_NUMBER}.png --acl public-read
30
- # - export FRONTGUARD_CHECKS_IMAGE_URL="https://my-bucket.s3.amazonaws.com/ci/frontguard-checks-${BITBUCKET_BUILD_NUMBER}.png"
1
+ # Deprecated: use `templates/bitbucket-pipelines.yml` it now uses `--checksPngOut` + inline PNG.
@@ -1,10 +1,12 @@
1
1
  # FreeKit.dev + FrontGuard (Bitbucket Pipelines)
2
2
 
3
- The Bitbucket template uploads `frontguard-report.html` with **no signup or API key**, using FreeKit’s public API:
3
+ The Bitbucket template (`templates/bitbucket-pipelines.yml`) runs FrontGuard with **`--checksPngOut`** (Playwright via `npx`), uploads the full HTML to **FreeKit**, and posts a PR comment that **inlines** the checks PNG as `data:image/png;base64,...` plus the FreeKit URL. You only need **`BITBUCKET_ACCESS_TOKEN`** with permission to **comment on pull requests** — no Repository Downloads or `repository:write`.
4
+
5
+ The same step uploads `frontguard-report.html` to FreeKit’s public API:
4
6
 
5
7
  - **Docs:** [FreeKit API](https://freekit.dev/docs)
6
8
  - **Endpoint:** `POST https://freekit.dev/api/v1/sites` with JSON `{"html": "<full report html>"}`
7
- - **Response:** `data.url` like `https://freekit.dev/s/<siteId>` — this URL is posted as the PR comment.
9
+ - **Response:** `data.url` like `https://freekit.dev/s/<siteId>` — this URL is included in the PR comment below the checks screenshot caption.
8
10
 
9
11
  Optional env (advanced): **`FREEKIT_BASE_URL`** — override the API host (e.g. self‑hosted instance per FreeKit docs).
10
12
 
@@ -24,24 +26,7 @@ On **Bitbucket Pipelines** pull-request builds, FrontGuard reads **`BITBUCKET_PR
24
26
 
25
27
  ## Checks table image in PR comments
26
28
 
27
- Bitbucket renders **`![](https://.../checks.png)`** in PR comments when the URL is public HTTPS. FrontGuard can emit a **minimal HTML** file that contains only the Checks table (same styling as the full report):
28
-
29
- ```bash
30
- yarn frontguard run --markdown \
31
- --htmlOut frontguard-report.html \
32
- --checksSnapshotOut frontguard-checks.html \
33
- > frontguard-report.md
34
- ```
35
-
36
- Then:
37
-
38
- 1. **Screenshot** `frontguard-checks.html` with headless Chromium (e.g. `npx playwright screenshot "<file://...>" frontguard-checks.png`).
39
- 2. **Upload** the PNG to a reachable URL (Bitbucket Downloads API, S3, CDN, etc.).
40
- 3. Set **`FRONTGUARD_CHECKS_IMAGE_URL`** to that URL **before** writing the PR comment (e.g. before `formatBitbucketPrSnippet` / `--prCommentOut`).
41
-
42
- The snippet places the image at the **top** of the comment and keeps the **full interactive report** link below (with a short line explaining that details are in the HTML).
43
-
44
- See **`templates/checks-snapshot-bitbucket-snippet.yml`** for merge-ready pipeline examples.
29
+ The default pipeline uses **`--checksPngOut`** so FrontGuard runs **Playwright via `npx`** and writes `frontguard-checks.png`. A short Python step base64-embeds that image in the PR comment (no extra hosting). If the PNG is too large for Bitbucket, raise the limit in the pipeline script cautiously or host the image and set **`FRONTGUARD_CHECKS_IMAGE_URL`** with **`--prCommentOut`** instead.
45
30
 
46
31
  ## Compared to Surge
47
32