-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
50 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,64 @@ | ||
const postcss = require('postcss'); | ||
const postcssrc = require('postcss-load-config'); | ||
|
||
module.exports = function (plugins, options, filterType) { | ||
if (arguments.length === 0) { | ||
const rc = postcssrc.sync(); | ||
plugins = rc.plugins; | ||
options = rc.options; | ||
import postcss from 'postcss' | ||
import postcssConfig from 'postcss-load-config' | ||
|
||
const plugin = (plugins = null, options = null, filterType = null) => { | ||
if (plugins === null && options === null && filterType === null) { | ||
const rc = postcssConfig.sync() | ||
plugins = rc.plugins | ||
options = rc.options | ||
} | ||
|
||
plugins = [].concat(plugins).filter(Boolean); | ||
options = options || {}; | ||
plugins = [].concat(plugins).filter(Boolean) | ||
options = options || {} | ||
|
||
const css = postcss(plugins); | ||
const css = postcss(plugins) | ||
|
||
return function (tree) { | ||
const promises = []; | ||
const promises = [] | ||
|
||
tree.walk(node => { | ||
let promise; | ||
let promise | ||
|
||
if (node.tag === 'style' && node.content) { | ||
let meetsFilter = true; | ||
let meetsFilter = true | ||
|
||
if (filterType) { | ||
const typeAttr = (node.attrs && node.attrs.type) ? node.attrs.type.trim() : ''; | ||
const meetsTypeAttr = filterType.test(typeAttr); | ||
const meetsStandardType = filterType.test('text/css') && (meetsTypeAttr || typeAttr === ''); | ||
const meetsOtherType = !meetsStandardType && meetsTypeAttr; | ||
meetsFilter = meetsStandardType || meetsOtherType; | ||
const typeAttr = (node.attrs && node.attrs.type) ? node.attrs.type.trim() : '' | ||
const meetsTypeAttr = filterType.test(typeAttr) | ||
const meetsStandardType = filterType.test('text/css') && (meetsTypeAttr || typeAttr === '') | ||
const meetsOtherType = !meetsStandardType && meetsTypeAttr | ||
meetsFilter = meetsStandardType || meetsOtherType | ||
} | ||
|
||
if (meetsFilter) { | ||
const styles = [].concat(node.content).join(''); | ||
const from = options.from || tree.options.from; | ||
const styles = [].concat(node.content).join('') | ||
const from = options.from || tree.options.from | ||
|
||
promise = css.process(styles, {...options, from}) | ||
.then(result => { | ||
node.content = [result.css]; | ||
}); | ||
node.content = [result.css] | ||
}) | ||
|
||
promises.push(promise); | ||
promises.push(promise) | ||
} | ||
} | ||
|
||
if (node.attrs && node.attrs.style) { | ||
promise = css.process(node.attrs.style, options) | ||
.then(result => { | ||
node.attrs.style = result.css; | ||
}); | ||
node.attrs.style = result.css | ||
}) | ||
|
||
promises.push(promise); | ||
promises.push(promise) | ||
} | ||
|
||
return node; | ||
}); | ||
return node | ||
}) | ||
|
||
return Promise.all(promises).then(() => { | ||
return tree; | ||
}); | ||
}; | ||
}; | ||
return tree | ||
}) | ||
} | ||
} | ||
|
||
export default plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {defineConfig} from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ['**/*test.{js,ts}'], | ||
}, | ||
}) |
This file was deleted.
Oops, something went wrong.