Skip to content

feat: copy fonts and nested assets from public/ to build - #3412

Merged
lemagnetic merged 2 commits into
devfrom
feat/copy-public-files-fonts-filter
Jul 20, 2026
Merged

lemagnetic merged 2 commits into
devfrom
feat/copy-public-files-fonts-filter

Conversation

@lemagnetic

@lemagnetic lemagnetic commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

Stores couldn't self-host fonts: .woff/.woff2 files placed in public/ were dropped during @faststore/cli's generate step and returned 404 in production. This blocks GDPR-sensitive (EU) stores and hurts Core Web Vitals, forcing merchants to inline fonts as base64.

How it works?

copyPublicFiles in packages/cli/src/utils/generate.ts used a fragile filter that matched extensions as a substring (endsWith) and cut whole subdirectories. It now:

  • Always allows directories, so nested assets (e.g. public/fonts/) are traversed instead of being skipped.
  • Matches the real file extension via path.extname().toLowerCase(), fixing false matches (e.g. basico matching ico).
  • Expands the allowlist with font formats: .woff, .woff2, .ttf, .otf, .eot.

The decision logic was extracted into a pure, exported isPublicFileAllowed(src, isDirectory) and covered by unit tests.

How to test it?

  • Add a font under public/fonts/ (e.g. public/fonts/inter.woff2) in a store.
  • Run the generate step and confirm the file is copied to .faststore/public/fonts/.
  • Confirm the font resolves (no 404) in the built store.
  • Unit tests: pnpm turbo run test --filter=@faststore/cli.

References

Summary by CodeRabbit

  • Bug Fixes

    • Improved build copying for the public assets directory using an explicit, case-insensitive extension allowlist (including self-hosted font files).
    • Prevented unsupported or misleading filenames/extensions from being copied.
    • Ensured directories are always included, and the copy process skips entries that can’t be inspected instead of failing.
  • Tests

    • Expanded coverage for public asset filtering and copying behavior, including nested font assets and scenarios like dangling/unstat’able entries.

@lemagnetic
lemagnetic requested a review from a team as a code owner July 15, 2026 00:03
@lemagnetic lemagnetic added the enhancement New feature or request label Jul 15, 2026
@lemagnetic
lemagnetic requested review from eduardoformiga and lucasfp13 and removed request for a team July 15, 2026 00:03
@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 495e8f19-10f0-475b-9231-f27a3f7f9f6c

📥 Commits

Reviewing files that changed from the base of the PR and between 142ac5a and feb46c1.

📒 Files selected for processing (2)
  • packages/cli/src/utils/generate.test.ts
  • packages/cli/src/utils/generate.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/cli/src/utils/generate.ts

Walkthrough

The CLI public-file copy filter now uses an exported extension allowlist and directory-aware predicate. Tests cover allowed extensions, self-hosted fonts, case-insensitive matching, rejected filenames, nested copies, and stat failure handling.

Changes

Public file filtering

Layer / File(s) Summary
Allowlist and copy filter
packages/cli/src/utils/generate.ts
copyPublicFiles uses statSync and isPublicFileAllowed, allowing directories and dot-prefixed extensions matched case-insensitively against the exported allowlist while skipping entries that cannot be stat’d.
Public file filter tests
packages/cli/src/utils/generate.test.ts
Tests validate allowed fonts and legacy extensions, rejected filename heuristics, nested asset copying, and continuation after a dangling symlink.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Suggested reviewers: lucasfp13, eduardoformiga

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: copying fonts and nested public assets into the build output.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/copy-public-files-fonts-filter

Comment @coderabbitai help to get the list of available commands.

@codesandbox-ci

codesandbox-ci Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/cli/src/utils/generate.ts`:
- Around line 230-239: Update the filter callback in copyPublicFiles so statSync
failures for individual entries are caught locally and cause only that entry to
be rejected. Preserve isPublicFileAllowed for successfully statted entries,
while ensuring copySync continues processing the remaining public files instead
of propagating the per-entry exception to the outer try/catch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8f261528-04aa-4a7a-bbb7-4dca9d641e17

📥 Commits

Reviewing files that changed from the base of the PR and between e0e8188 and 142ac5a.

📒 Files selected for processing (2)
  • packages/cli/src/utils/generate.test.ts
  • packages/cli/src/utils/generate.ts

Comment thread packages/cli/src/utils/generate.ts Resolved
@pkg-pr-new

pkg-pr-new Bot commented Jul 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

npm i https://pkg.pr.new/vtex/faststore/@faststore/api@feb46c1

@faststore/cli

npm i https://pkg.pr.new/vtex/faststore/@faststore/cli@feb46c1

@faststore/components

npm i https://pkg.pr.new/vtex/faststore/@faststore/components@feb46c1

@faststore/core

npm i https://pkg.pr.new/vtex/faststore/@faststore/core@feb46c1

@faststore/diagnostics

npm i https://pkg.pr.new/vtex/faststore/@faststore/diagnostics@feb46c1

@faststore/lighthouse

npm i https://pkg.pr.new/vtex/faststore/@faststore/lighthouse@feb46c1

@faststore/sdk

npm i https://pkg.pr.new/vtex/faststore/@faststore/sdk@feb46c1

@faststore/ui

npm i https://pkg.pr.new/vtex/faststore/@faststore/ui@feb46c1

commit: feb46c1

@sonar-workflows

Copy link
Copy Markdown

Failed Quality Gate failed

  • 13.80% Coverage on New Code (is less than 75.00%)
  • 16.11% Duplicated Lines (%) on New Code (is greater than 10.00%)

Project ID: vtex_faststore_f0a862d5-9557-49f9-8d09-de40caa76622

View in SonarQube

@lemagnetic
lemagnetic merged commit ce07376 into dev Jul 20, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants