New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

yaml-verify

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml-verify - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

YAML/duplicateException.yaml

4

package.json
{
"name": "yaml-verify",
"version": "1.0.2",
"version": "1.0.3",
"type": "module",

@@ -31,3 +31,3 @@ "description": "A CLI utility to ensure proper formatting of YAML files.",

"js-yaml": "^4.1.0",
"ora": "^8.0.1"
"listr2": "^8.0.2"
},

@@ -34,0 +34,0 @@ "devDependencies": {

@@ -8,4 +8,4 @@ #!/usr/bin/env node

const fsPromises = fs.promises // Use fs.promises for async operations
import ora from 'ora'
import glob from 'fast-glob'
import { Listr } from 'listr2'

@@ -72,3 +72,3 @@ // Asynchronous function to check for duplicates in YAML data

// Asynchronously process and validate YAML files with parallel processing
// Asynchronously process and validate YAML files with listr2
async function processFiles(filePaths) {

@@ -78,34 +78,83 @@ let allFilesPromises = filePaths.map(async (filePath) => {

if (stat.isDirectory()) {
return findYamlFilesAsync(filePath) // Returns a promise
return findYamlFilesAsync(filePath)
}
return [filePath] // Wrap in array to normalize structure
return [filePath]
})
let allFilesArrays = await Promise.all(allFilesPromises) // Resolve all promises
let allFiles = allFilesArrays.flat() // Flatten array of arrays into a single array
let allFilesArrays = await Promise.all(allFilesPromises)
let allFiles = allFilesArrays.flat()
// Process files in parallel
const validationPromises = allFiles.map(async (file) => {
const spinner = ora(`Validating YAML file ${file}...`).start()
// Create listr2 tasks for each file
const tasks = new Listr(
allFiles.map((file) => ({
title: `Validating YAML file ${file}`,
task: async (ctx, task) => {
const fileContents = await fsPromises.readFile(file, 'utf8')
let data = null
try {
data = yaml.load(fileContents)
} catch (error) {
throw new Error(
`Validation ${chalk.bgRed.whiteBright('FAILED')} for file ${file}: ${chalk.red(error.message)}`,
)
}
const errors = checkForDuplicates(data)
if (errors.length > 0) {
// Generate a detailed error message including the filename
throw new Error(
`Validation ${chalk.bgRed.whiteBright('FAILED')} for file ${file}; Errors: ${chalk.red(errors.join('\n'))}`,
)
}
task.title = `Validation ${chalk.bgAnsi256(22).whiteBright('PASSED')} for file ${file}`
task.output = file
},
})),
{
concurrent: true, // Run tasks concurrently
exitOnError: false, // Continue with other tasks even if some fail
},
)
try {
const fileContents = await fsPromises.readFile(file, 'utf8')
const data = yaml.load(fileContents)
const errors = checkForDuplicates(data)
let validationPassed = true // Track overall validation success
let totalFiles = 0
let totalErrors = 0
if (errors.length > 0) {
spinner.fail(`Validation failed for file ${file}.`)
errors.forEach((error) => console.error(error))
} else {
spinner.succeed(`Validation passed for file ${file}.`)
// Run tasks
try {
await tasks.run()
totalFiles = tasks.tasks.length
// Check the state of each task after running
tasks.tasks.forEach((task) => {
if (task.state === 'FAILED') {
validationPassed = false
if (totalErrors == 0) console.log()
totalErrors += 1
console.error(
`Task '${task.title}' ${chalk.bgRed.whiteBright('FAILED')}`,
)
}
} catch (e) {
spinner.fail(`YAML file validation failed for file ${file}.`)
console.error(e.message)
}
console.log()
})
})
} catch (e) {
validationPassed = false // Update flag if any task fails
console.error(
chalk.red('Validation errors found in one or more files.'),
)
}
// Wait for all validations to complete
await Promise.allSettled(validationPromises)
// Check the overall validation result before printing the final message
console.log()
if (validationPassed) {
console.log(
chalk.green(
`All ${totalFiles} file(s) have been successfully validated.`,
),
)
} else {
console.error(
chalk.red(
`${totalErrors} out of ${totalFiles} file(s) failed validation.`,
),
)
process.exit(1)
}
}

@@ -112,0 +161,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc