-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix linting errors and transfer from original PR (#464)
- Loading branch information
1 parent
da7b090
commit 3007f58
Showing
5 changed files
with
87 additions
and
49 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 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,47 @@ | ||
import _ from 'lodash' | ||
import invariant from 'invariant' | ||
import path from 'path' | ||
import validate from 'webpack-validator' | ||
|
||
let modifyWebpackConfig | ||
try { | ||
const gatsbyNodeConfig = path.resolve(process.cwd(), `./gatsby-node`) | ||
const nodeConfig = require(gatsbyNodeConfig) | ||
modifyWebpackConfig = nodeConfig.modifyWebpackConfig | ||
} catch (e) { | ||
if (e.code !== `MODULE_NOT_FOUND` && !_.includes(e.Error, `gatsby-node`)) { | ||
console.log(e) | ||
} | ||
} | ||
|
||
export default function ValidateWebpackConfig (module, config, stage) { | ||
let userWebpackConfig = module(config) | ||
if (modifyWebpackConfig) { | ||
userWebpackConfig = modifyWebpackConfig(userWebpackConfig, stage) | ||
|
||
invariant(_.isObject(userWebpackConfig) && _.isFunction(userWebpackConfig.resolve), | ||
` | ||
You must return an webpack-configurator instance when modifying the Webpack config. | ||
Returned: ${userWebpackConfig} | ||
stage: ${stage} | ||
`) | ||
} | ||
|
||
const validationState = validate(userWebpackConfig.resolve(), { | ||
returnValidation: true, | ||
}) | ||
|
||
if (!validationState.error) { | ||
return userWebpackConfig | ||
} | ||
|
||
console.log(`There were errors with your webpack config:`) | ||
validationState.error.details.forEach((err, index) => { | ||
console.log(`[${index + 1}]`) | ||
console.log(err.path) | ||
console.log(err.type, `,`, err.message) | ||
console.log(`\n`) | ||
}) | ||
|
||
return process.exit(1) | ||
} |
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