[astro-purgecss] Add __unsafeContent option for custom content sources#1288
Conversation
🦋 Changeset detectedLatest commit: e00f544 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
📝 WalkthroughWalkthroughAdds a new Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
commit: |
There was a problem hiding this comment.
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 | 🟠 MajorEmpty
__unsafeContentarray would purge all CSS.If a user passes
__unsafeContent: [], the nullish coalescing operator treats it as a valid value (it's notnull/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 dropscontentfrompurgecssOptionswhen__unsafeContentis set — intentional but implicit.When
__unsafeContentis provided, thecontentkey that may also be present inpurgecssOptionsis silently ignored (overridden on line 114). This is consistent with the docs but could surprise users who set both. A runtime warning vialoggerwhen both are supplied would be a nice safeguard.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
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.
Summary by CodeRabbit
New Features
__unsafeContentoption to override default PurgeCSS content sources with custom arrays or raw content entries.Documentation
__unsafeContent, including usage examples and prominent warnings about overriding defaults and potential over‑purging.