Skip to content

Commit

Permalink
Add specific warning for require() PostCSS plugin (#10121)
Browse files Browse the repository at this point in the history
  • Loading branch information
jplhomer authored and Timer committed Jan 16, 2020
1 parent 57ec121 commit 80ed74b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/next/build/webpack/config/blocks/css/plugins.ts
Expand Up @@ -193,6 +193,15 @@ export async function getPostCssPlugins(
}
throw new Error(genericErrorText)
}
} else if (typeof plugin === 'function') {
console.error(
`${chalk.red.bold(
'Error'
)}: A PostCSS Plugin was passed as a function using require(), but it must be provided as a ${chalk.bold(
'string'
)}.`
)
throw new Error(genericErrorText)
} else {
console.error(
`${chalk.red.bold(
Expand Down
17 changes: 17 additions & 0 deletions test/integration/css-customization/test/index.test.js
Expand Up @@ -331,6 +331,23 @@ describe('Bad CSS Customization Array (7)', () => {
})
})

describe('Bad CSS Customization Array (8)', () => {
const appDir = join(fixturesDir, 'bad-custom-configuration-arr-8')

beforeAll(async () => {
await remove(join(appDir, '.next'))
})

it('should fail the build', async () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true })

expect(stderr).toMatch(
/A PostCSS Plugin was passed as a function using require\(\), but it must be provided as a string/
)
expect(stderr).toMatch(/Build error occurred/)
})
})

describe('Bad CSS Customization Function', () => {
const appDir = join(fixturesDir, 'bad-custom-configuration-func')

Expand Down
@@ -0,0 +1,12 @@
import React from 'react'
import App from 'next/app'
import '../styles/global.css'

class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}

export default MyApp
@@ -0,0 +1,3 @@
export default function Home() {
return <div />
}
@@ -0,0 +1,3 @@
module.exports = {
plugins: [require('postcss-trolling')],
}
@@ -0,0 +1,14 @@
/* this should pass through untransformed */
@media (480px <= width < 768px) {
a::before {
content: '';
}
::placeholder {
color: green;
}
}

/* this should be transformed to width/height */
.video {
-xyz-max-size: 400rem 300rem;
}

0 comments on commit 80ed74b

Please sign in to comment.