-
Notifications
You must be signed in to change notification settings - Fork 157
added support postcss #195
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2563b97
add support postcss
666e386
test
5ced9c0
fixes
a075a9d
fix after lint
ef459ed
fix test
dd57354
fix plugins
c9f3fd2
replace throw to log
049c0e8
add check for async plugins
faa0e3c
fix
85fa13f
fixes
6ad95c4
fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,77 @@ | ||
const postcss = require('postcss') | ||
const postcssrc = require('postcss-load-config') | ||
const ctx = { parser: true, map: 'inline' } | ||
const { plugins } = postcssrc.sync(ctx) | ||
const logger = require('../logger') | ||
const getVueJestConfig = require('../get-vue-jest-config') | ||
const ensureRequire = require('../ensure-require') | ||
|
||
let prevCheckIsAsync = null | ||
function hasAsyncPlugin () { | ||
if (prevCheckIsAsync !== null) { | ||
return prevCheckIsAsync | ||
} | ||
const result = postcss(plugins) | ||
.process('', { | ||
from: undefined | ||
}) | ||
|
||
if (result.processing) { | ||
prevCheckIsAsync = true | ||
return prevCheckIsAsync | ||
} | ||
for (const plugin of result.processor.plugins) { | ||
const promise = result.run(plugin) | ||
if (typeof promise === 'object' && typeof promise.then === 'function') { | ||
prevCheckIsAsync = true | ||
break | ||
} | ||
} | ||
if (prevCheckIsAsync === null) { | ||
prevCheckIsAsync = false | ||
} | ||
|
||
return prevCheckIsAsync | ||
} | ||
|
||
function catchError (error, filePath, jestConfig) { | ||
if (!getVueJestConfig(jestConfig).hideStyleWarn) { | ||
logger.warn(`There was an error rendering the POSTCSS in ${filePath}. `) | ||
logger.warn(`Error while compiling styles: ${error}`) | ||
} | ||
} | ||
|
||
module.exports = (content, filePath, jestConfig) => { | ||
ensureRequire('postcss', ['postcss']) | ||
|
||
let css = null | ||
|
||
const res = postcss(plugins) | ||
.process(content, { | ||
from: undefined | ||
}) | ||
|
||
if (hasAsyncPlugin()) { | ||
res | ||
.then(result => { | ||
css = result.css || '' | ||
}) | ||
.catch((e) => { | ||
css = '' | ||
catchError(e, filePath, jestConfig) | ||
}) | ||
|
||
while (css === null) { //eslint-disable-line | ||
require('deasync').sleep(100) | ||
} | ||
|
||
return css | ||
} | ||
|
||
try { | ||
return res.css | ||
} catch (e) { | ||
catchError(e, filePath, jestConfig) | ||
return '' | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,6 @@ | ||
module.exports = { | ||
plugins: { | ||
'postcss-css-variables': {}, | ||
'postcss-nested': {} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we could return early at this point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed