Skip to content

Commit

Permalink
fix(cli): fix missing validation message
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Dec 31, 2023
1 parent 3aff462 commit 52cb975
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function interactive({
let _overwrite = _force

if (_inputs) {
const validationError = _inputs.find(p => inputFileGlobValidation(p) !== undefined)
const validationError = getValidateFromPaths(_inputs, inputFileGlobValidation)
if (validationError) {
log.error(validationError)
return process.exit(1)
Expand Down Expand Up @@ -435,7 +435,7 @@ async function nonInteractive(features: Feature[], {
return process.exit(1)
}

const inputValidationError = _inputs.find(p => inputFileGlobValidation(p))
const inputValidationError = getValidateFromPaths(_inputs, inputFileGlobValidation)
if (inputValidationError) {
log.error(inputValidationError)
return process.exit(1)
Expand All @@ -461,7 +461,7 @@ async function nonInteractive(features: Feature[], {
if (features.includes(Feature.Unpacker)) outputPathsToCheck.push(unpackerOutput)
if (features.includes(Feature.Unminify)) outputPathsToCheck.push(unminifyOutput)

const outputValidationError = outputPathsToCheck.find(p => outputFolderValidation(p))
const outputValidationError = getValidateFromPaths(outputPathsToCheck, outputFolderValidation)
if (outputValidationError) {
log.error(outputValidationError)
return process.exit(1)
Expand Down Expand Up @@ -648,3 +648,11 @@ function getModuleFileName(dep: Module) {
}
return `module-${dep.id}.js`
}

function getValidateFromPaths(paths: string[], validate: (path: string) => string | undefined) {
for (const path of paths) {
const error = validate(path)
if (error) return error
}
return undefined
}

0 comments on commit 52cb975

Please sign in to comment.