Skip to content

fix: applying plugin on an empty css file #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ module.exports = (options) => {
STATE.mapped = new Set()
STATE.mapped_dark = new Set()

STATE.target_rule = new Rule({ selector: target_selector, source: node.first.source })
STATE.target_rule_dark = new Rule({ selector: target_selector_dark, source: node.first.source })
STATE.target_media_dark = new AtRule({ name: 'media', params: '(prefers-color-scheme: dark)', source: node.first.source })
if (node.first) {
STATE.target_rule = new Rule({ selector: target_selector, source: node.first.source })
STATE.target_rule_dark = new Rule({ selector: target_selector_dark, source: node.first.source })
STATE.target_media_dark = new AtRule({ name: 'media', params: '(prefers-color-scheme: dark)', source: node.first.source })
}

if (layer) {
if (layer && node.first) {
STATE.target_layer = new AtRule({ name: 'layer', params: layer, source: node.first.source })
node.root().prepend(STATE.target_layer)
STATE.target_ss = STATE.target_layer
Expand Down
15 changes: 15 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,18 @@ it('Supports parallel runners when reading from a file', async () => {
expect(resultE.css).toEqual('a { color: green; }')
expect(resultE.warnings()).toHaveLength(0)
})

// situation encountered when using postcs-jit-props for Open Props
// together with having @nuxt/fonts module with no global font definition
// it still creates an empty .nuxt/nuxt-fonts-global.css file
// and postcs-jit-props started to fail trying to parse it
// --
// fixed by adding "node.first" null check into parsing method
// (lines 130 and 136 in index.js)

it('Parses an empty file and rule', async () => {
const pluginInstance = plugin({ files: ['./props.test.empty.css'] });
let result = await postcss([pluginInstance]).process('');
expect(result.css).toEqual("");
expect(result.warnings()).toHaveLength(0);
})
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added props.test.empty.css
Empty file.