Skip to content

[astro-purgecss] Add __unsafeContent option for custom content sources#1288

Merged
mhdcodes merged 3 commits into
mainfrom
astro-purgecss-allow-overriding-content
Feb 13, 2026
Merged

[astro-purgecss] Add __unsafeContent option for custom content sources#1288
mhdcodes merged 3 commits into
mainfrom
astro-purgecss-allow-overriding-content

Conversation

@mhdcodes

@mhdcodes mhdcodes commented Feb 13, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added __unsafeContent option to override default PurgeCSS content sources with custom arrays or raw content entries.
  • Documentation

    • Updated README with an advanced configuration section for __unsafeContent, including usage examples and prominent warnings about overriding defaults and potential over‑purging.

@changeset-bot

changeset-bot Bot commented Feb 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e00f544

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro-purgecss Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Feb 13, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a new __unsafeContent option to astro-purgecss to let callers completely override PurgeCSS content sources; documents the option in README and wires the option into the package's index implementation with appropriate typing.

Changes

Cohort / File(s) Summary
Changelog
\.changeset/dry-owls-bake.md
Adds a changeset marking a minor release and describing the new __unsafeContent option.
Documentation
packages/astro-purgecss/README.md
Adds an "Advanced: Overriding Content Sources (__unsafeContent)" section with example and two warnings; section appears duplicated.
Core Implementation
packages/astro-purgecss/src/index.ts
Imports type RawContent from purgecss, extends PurgeCSSOptions with `__unsafeContent?: Array<string

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐇 I nibble lines of code and cheer,
A toggle born to change the gear.
__unsafeContent opens the door,
But hop with care on that wild floor.
Happy purging — with a cautious paw! 🥕

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: adding a new __unsafeContent option for custom content sources in the astro-purgecss package.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch astro-purgecss-allow-overriding-content

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@pkg-pr-new

pkg-pr-new Bot commented Feb 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/codiume/orbit/astro-gtm@1288
npm i https://pkg.pr.new/codiume/orbit/astro-purgecss@1288
npm i https://pkg.pr.new/codiume/orbit/astro-seo-meta@1288
npm i https://pkg.pr.new/codiume/orbit/astro-seo-schema@1288

commit: e00f544

@mhdcodes mhdcodes added the astro-purgecss Issues related to astro-purgecss package label Feb 13, 2026

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/astro-purgecss/src/index.ts (1)

114-118: ⚠️ Potential issue | 🟠 Major

Empty __unsafeContent array would purge all CSS.

If a user passes __unsafeContent: [], the nullish coalescing operator treats it as a valid value (it's not null/undefined), so PurgeCSS runs with zero content sources and strips every class from every CSS file. Consider adding a guard that falls back to defaults when the array is empty:

Proposed fix
-          content: __unsafeContent ?? [
+          content: __unsafeContent?.length ? __unsafeContent : [
             `${outDir}/**/*.html`.replace(/\\/g, '/'),
             `${outDir}/**/*.js`.replace(/\\/g, '/'),
             ...(purgecssOptions.content || [])
           ]
🤖 Fix all issues with AI agents
In `@packages/astro-purgecss/README.md`:
- Line 267: The Markdown link to the issue is missing the '#' prefix in its link
text; update the reference text from
`[1001](https://github.com/codiume/orbit/issues/1001)` to
`[`#1001`](https://github.com/codiume/orbit/issues/1001)` in the README (the line
mentioning "Maximum call stack size exceeded" for very large sites) so it
matches the other issue references' style.
🧹 Nitpick comments (1)
packages/astro-purgecss/src/index.ts (1)

60-62: Destructuring drops content from purgecssOptions when __unsafeContent is set — intentional but implicit.

When __unsafeContent is provided, the content key that may also be present in purgecssOptions is silently ignored (overridden on line 114). This is consistent with the docs but could surprise users who set both. A runtime warning via logger when both are supplied would be a nice safeguard.

Comment thread packages/astro-purgecss/README.md Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@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

🤖 Fix all issues with AI agents
In `@packages/astro-purgecss/README.md`:
- Around line 256-296: Add the new __unsafeContent option to the "Available
Options" / PurgeCSSOptions list in the README so docs match the new section:
document the option name __unsafeContent, its type (array of globs), that it
completely overrides the default content globs, and include the same short
warning about risk of over-purging and only using it for very large sites;
update any examples or parameter tables referencing PurgeCSSOptions to include
this entry and ensure the wording matches the advanced section for consistency.

Comment thread packages/astro-purgecss/README.md
@mhdcodes mhdcodes merged commit 74403e2 into main Feb 13, 2026
8 checks passed
@mhdcodes mhdcodes deleted the astro-purgecss-allow-overriding-content branch February 13, 2026 19:33
@github-actions github-actions Bot mentioned this pull request Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

astro-purgecss Issues related to astro-purgecss package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[astro-purgecss] Option to override default content globs passed to PurgeCSS

1 participant