Skip to content

Commit

Permalink
update postcss dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Jan 23, 2019
1 parent 5596ca9 commit 09c0137
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 43 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
"xo": "^0.18.2"
},
"dependencies": {
"chalk": "^2.0.0",
"chalk": "^2.4.2",
"concat-with-sourcemaps": "^1.0.5",
"cssnano": "^4.1.5",
"cssnano": "^4.1.8",
"import-cwd": "^2.1.0",
"p-queue": "^2.4.2",
"pify": "^3.0.0",
"postcss": "^6.0.21",
"postcss-load-config": "^1.2.0",
"postcss": "^7.0.14",
"postcss-load-config": "^2.0.0",
"postcss-modules": "^1.4.1",
"promise.series": "^0.2.0",
"reserved-words": "^0.1.2",
Expand Down
45 changes: 27 additions & 18 deletions src/postcss-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function loadConfig(id, { ctx: configOptions, path: configPath }) {
options: configOptions || {}
}

return findPostcssConfig(ctx, configPath, { argv: false }).catch(handleError)
return findPostcssConfig(ctx, configPath).catch(handleError)
}

function escapeClassNameDashes(str) {
Expand Down Expand Up @@ -59,9 +59,9 @@ export default {
alwaysProcess: true,
// `test` option is dynamically set in ./loaders
async process({ code, map }) {
const config = this.options.config ?
await loadConfig(this.id, this.options.config) :
{}
const config = this.options.config
? await loadConfig(this.id, this.options.config)
: {}

const options = this.options
const plugins = [
Expand All @@ -79,9 +79,9 @@ export default {
require('postcss-modules')({
// In tests
// Skip hash in names since css content on windows and linux would differ because of `new line` (\r?\n)
generateScopedName: process.env.ROLLUP_POSTCSS_TEST ?
'[name]_[local]' :
'[name]_[local]__[hash:base64:5]',
generateScopedName: process.env.ROLLUP_POSTCSS_TEST
? '[name]_[local]'
: '[name]_[local]__[hash:base64:5]',
...options.modules,
getJSON(filepath, json, outpath) {
modulesExported[filepath] = json
Expand All @@ -107,11 +107,11 @@ export default {
// Followings are never modified by user config config
from: this.id,
to: this.id,
map: this.sourceMap ?
shouldExtract ?
{ inline: false, annotation: false } :
{ inline: true, annotation: false } :
false
map: this.sourceMap
? shouldExtract
? { inline: false, annotation: false }
: { inline: true, annotation: false }
: false
}
delete postcssOpts.plugins

Expand All @@ -123,6 +123,15 @@ export default {
postcssOpts.map.prev = typeof map === 'string' ? JSON.parse(map) : map
}

if (plugins.length === 0) {
// Prevent from postcss warning:
// You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js
const noopPlugin = postcss.plugin('postcss-noop-plugin', () => () => {
/* noop */
})
plugins.push(noopPlugin())
}

const res = await postcss(plugins).process(code, postcssOpts)

for (const msg of res.messages) {
Expand All @@ -146,9 +155,9 @@ export default {
if (options.namedExports) {
const json = modulesExported[this.id]
const getClassName =
typeof options.namedExports === 'function' ?
options.namedExports :
ensureClassName
typeof options.namedExports === 'function'
? options.namedExports
: ensureClassName
// eslint-disable-next-line guard-for-in
for (const name in json) {
const newName = getClassName(name)
Expand Down Expand Up @@ -181,9 +190,9 @@ export default {
}
if (!shouldExtract && shouldInject) {
output += `\nimport styleInject from '${styleInjectPath}';\nstyleInject(css${
Object.keys(options.inject).length > 0 ?
`,${JSON.stringify(options.inject)}` :
''
Object.keys(options.inject).length > 0
? `,${JSON.stringify(options.inject)}`
: ''
});`
}

Expand Down
Loading

0 comments on commit 09c0137

Please sign in to comment.