Skip to content

Commit

Permalink
feat(core)!: default preflights to preflights layer (#1190)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
CanRau and antfu committed Jun 30, 2022
1 parent bc3f293 commit 103a6de
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
12 changes: 5 additions & 7 deletions packages/core/src/generator/index.ts
Expand Up @@ -175,20 +175,18 @@ export class UnoGenerator {
theme: this.config.theme,
}

const preflightLayerSet = new Set<string>(['default'])
this.config.preflights.forEach(({ layer }) => {
if (layer) {
layerSet.add(layer)
preflightLayerSet.add(layer)
}
const preflightLayerSet = new Set<string>([])
this.config.preflights.forEach(({ layer = 'preflights' }) => {
layerSet.add(layer)
preflightLayerSet.add(layer)
})

preflightsMap = Object.fromEntries(
await Promise.all(Array.from(preflightLayerSet).map(
async (layer) => {
const preflights = await Promise.all(
this.config.preflights
.filter(i => (i.layer || 'default') === layer)
.filter(i => (i.layer || 'preflights') === layer)
.map(async i => await i.getCSS(preflightContext)),
)
const css = preflights
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/preflights.test.ts.snap
@@ -1,8 +1,8 @@
// Vitest Snapshot v1

exports[`preflights > basic 1`] = `
"/* layer: default */
"/* layer: preflights */
.default-preflight {}
/* layer: preflight */
/* layer: custom */
.hello { text: red }"
`;
2 changes: 1 addition & 1 deletion test/preflights.test.ts
Expand Up @@ -9,7 +9,7 @@ describe('preflights', () => {
getCSS() {
return '.hello { text: red }'
},
layer: 'preflight',
layer: 'custom',
},
{
getCSS() { return undefined },
Expand Down

0 comments on commit 103a6de

Please sign in to comment.