Skip to content

Commit

Permalink
Improve validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 29, 2022
1 parent 63f622d commit 525c925
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/config/normalize/lib/keywords/list/rename.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { normalizePath } from 'wild-wild-parser'

const normalize = function (definition) {
return normalizePath(definition)
}

const main = function (definition) {
return { rename: definition }
}
Expand All @@ -8,5 +14,6 @@ const main = function (definition) {
export default {
name: 'rename',
hasInput: true,
normalize,
main,
}
15 changes: 14 additions & 1 deletion src/config/normalize/lib/keywords/list/transform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import isPlainObj from 'is-plain-obj'
import { normalizePath } from 'wild-wild-parser'

import { wrapError } from '../../../../../error/wrap.js'

const normalize = function (definition) {
return isTransformMove(definition) ? definition : { value: definition }
if (!isTransformMove(definition)) {
return { value: definition }
}

const { value, newProp } = definition

try {
return { value, newProp: normalizePath(newProp) }
} catch (error) {
throw wrapError(error, 'Invalid "newProp" return value:')
}
}

// `transform()` can return a `{ newProp, value }` object to indicate the
Expand Down

0 comments on commit 525c925

Please sign in to comment.