forked from netlify/build
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move validation related to duplicated plugins configuration (ne…
- Loading branch information
Showing
6 changed files
with
38 additions
and
7 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,24 @@ | ||
'use strict' | ||
|
||
const { throwError } = require('../error') | ||
|
||
// Validate that plugin are configured only once per origin | ||
// (`netlify.toml` or UI). | ||
// Exception: context-specific configuration since we allow context-specific | ||
// overrides. This does not validate them since contexts have not been merged | ||
// yet. | ||
const validateIdenticalPlugins = function ({ plugins = [] }) { | ||
plugins.filter(hasIdenticalPlugin).forEach(throwIndenticalPlugin) | ||
} | ||
|
||
const hasIdenticalPlugin = function ({ package: packageName, origin }, index, plugins) { | ||
return plugins.slice(index + 1).some((pluginA) => packageName === pluginA.package && origin === pluginA.origin) | ||
} | ||
|
||
const throwIndenticalPlugin = function ({ package: packageName, origin }) { | ||
throwError(`Plugin "${packageName}" must not be specified twice in ${ORIGINS[origin]}`) | ||
} | ||
|
||
const ORIGINS = { config: 'netlify.toml', ui: 'the app' } | ||
|
||
module.exports = { validateIdenticalPlugins } |
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
Binary file not shown.
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