Skip to content

Commit

Permalink
fix(postprocess): with in import utility repeat
Browse files Browse the repository at this point in the history
close #6
  • Loading branch information
zyyv committed Oct 18, 2023
1 parent 735cfdb commit 2e97098
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/core/postprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export function postprocessWithUnColor(unColor: string): Postprocessor {

export function importantProcess(): Postprocessor {
return (util) => {
util.entries.forEach(i => i[1] += ' !important')
util.entries.forEach(i => {

Check failure on line 25 in packages/core/src/core/postprocess.ts

View workflow job for this annotation

GitHub Actions / lint

Expected parentheses around arrow function argument having a body with curly braces
if(i[1] != null && !String(i[1]).includes('!important')){

Check failure on line 26 in packages/core/src/core/postprocess.ts

View workflow job for this annotation

GitHub Actions / lint

Expected space(s) after "if"

Check failure on line 26 in packages/core/src/core/postprocess.ts

View workflow job for this annotation

GitHub Actions / lint

Unnecessary { after 'if' condition

Check failure on line 26 in packages/core/src/core/postprocess.ts

View workflow job for this annotation

GitHub Actions / lint

Missing space before opening brace
i[1] += ' !important'
}
})
}
}
// IN-README-END
13 changes: 10 additions & 3 deletions test/postprocess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,26 @@ describe('presetUseful postprocess with unColor', () => {
})

describe('presetUseful postprocess with important', () => {
const code = 'bg-red text-blue'
const withOutImport = ['bg-red', 'text-blue']
const withInImport = ['!text-xl', 'sm:text-sm!', 'important-ma']


Check failure on line 43 in test/postprocess.test.ts

View workflow job for this annotation

GitHub Actions / lint

More than 1 blank line not allowed
it('base', async () => {
const uno = generateUno({
important: true,
})

const { css } = await uno.generate(code, { preflights: false })
const { css } = await uno.generate([...withInImport, ...withOutImport], { preflights: false })

expect(css).toMatchInlineSnapshot(`
"/* layer: default */
.important-ma{margin:auto !important;}
.bg-red{--un-bg-opacity:1 !important;background-color:rgba(248,113,113,var(--un-bg-opacity)) !important;}
.text-blue{--un-text-opacity:1 !important;color:rgba(96,165,250,var(--un-text-opacity)) !important;}"
.\\\\!text-xl{font-size:1.25rem !important;line-height:1.75rem !important;}
.text-blue{--un-text-opacity:1 !important;color:rgba(96,165,250,var(--un-text-opacity)) !important;}
@media (min-width: 640px){
.sm\\\\:text-sm\\\\!{font-size:0.875rem !important;line-height:1.25rem !important;}
}"
`)
})
})

0 comments on commit 2e97098

Please sign in to comment.