-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: accept semver compatible postcss AST (#1049)
- Loading branch information
Showing
5 changed files
with
53 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,27 @@ | ||
import postcss from 'postcss'; | ||
import postcssPresetEnv from 'postcss-preset-env'; | ||
import postcssPkg from 'postcss/package.json'; | ||
import semver from 'semver'; | ||
|
||
const incomingVersion = semver.inc(postcssPkg.version, 'minor'); | ||
|
||
export default function astLoader(content) { | ||
const callback = this.async(); | ||
|
||
const { spy = jest.fn() } = this.query; | ||
|
||
postcss([postcssPresetEnv({ stage: 0 })]) | ||
.process(content) | ||
.then(({ css, map, root, messages }) => { | ||
const ast = { | ||
type: 'postcss', | ||
version: incomingVersion, | ||
}; | ||
|
||
Object.defineProperty(ast, 'root', { | ||
get: spy.mockReturnValue(root), | ||
}); | ||
|
||
callback(null, css, map, { ast, messages }); | ||
}); | ||
} |
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