{"id":17033,"library":"merge-yaml-cli","title":"YAML File Merger CLI","description":"merge-yaml-cli is a command-line utility for concatenating and merging multiple YAML files into a single output file. It leverages `glob` patterns for flexible input file selection, making it suitable for configuration management in projects with fragmented YAML setups. The package also exposes a Node.js API, allowing programmatic integration into larger JavaScript applications. The current stable version is 1.1.2. Based on its last publish date 8 years ago and limited recent activity, the project appears to be in a maintenance state with infrequent updates. While it provides a core utility, users seeking more advanced merge strategies (e.g., array concatenation vs. deep merging, or specific key-based merging) might need to explore alternatives like `yq` or `yaml-merge` which offer more nuanced control over the merge process.","status":"maintenance","version":"1.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/brainsiq/merge-yaml-cli","tags":["javascript","merge","yaml","cli"],"install":[{"cmd":"npm install merge-yaml-cli","lang":"bash","label":"npm"},{"cmd":"yarn add merge-yaml-cli","lang":"bash","label":"yarn"},{"cmd":"pnpm add merge-yaml-cli","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for resolving input file patterns specified in the CLI or API.","package":"glob","optional":false},{"reason":"Core library for parsing and stringifying YAML content.","package":"js-yaml","optional":false}],"imports":[{"note":"This package is CommonJS-only. Direct ESM 'import' syntax is not supported and will result in an error. The `require()` call provides the main API object.","wrong":"import mergeYaml from 'merge-yaml-cli'","symbol":"mergeYaml","correct":"const mergeYaml = require('merge-yaml-cli')"},{"note":"The `merge` function is a method on the default CommonJS export. It's not a named export for ESM. Ensure you destructure from the `require`d object if you wish to use it directly.","wrong":"import { merge } from 'merge-yaml-cli'","symbol":"mergeYaml.merge","correct":"const mergeYaml = require('merge-yaml-cli');\nconst result = mergeYaml.merge(['file1.yml', 'file2.yml'])"},{"note":"The `mergeYaml` object acts as an `EventEmitter` for progress or information. Use the Node.js `on` method, not browser-style `addEventListener`.","wrong":"mergeYaml.addEventListener('files', ...)","symbol":"mergeYaml.on","correct":"const mergeYaml = require('merge-yaml-cli');\nmergeYaml.on('files', (files) => console.log('Files found:', files))"}],"quickstart":{"code":"#!/usr/bin/env node\n\n// Create dummy YAML files for demonstration\nconst fs = require('fs');\nfs.writeFileSync('config/base.yml', 'name: MyApp\\nversion: 1.0.0\\nenvironment: development');\nfs.writeFileSync('config/overrides/prod.yml', 'environment: production\\nscale: large\\nfeatures:\\n  - analytics\\n  - monitoring');\nfs.writeFileSync('config/overrides/test.yml', 'environment: testing\\nscale: medium\\nfeatures:\\n  - logging');\n\nconsole.log('Dummy YAML files created.');\nconsole.log('Running merge-yaml-cli...');\n\n// Simulate CLI execution (assuming global install or PATH setup)\nconst { execSync } = require('child_process');\ntry {\n  execSync('npm i -g merge-yaml-cli', { stdio: 'inherit' });\n  const cliCommand = 'merge-yaml -i config/base.yml config/overrides/*.yml -o merged.yml';\n  console.log(`Executing: ${cliCommand}`);\n  execSync(cliCommand, { stdio: 'inherit' });\n  console.log('\\nMerged YAML content:');\n  console.log(fs.readFileSync('merged.yml', 'utf8'));\n\n  // Clean up dummy files\n  fs.unlinkSync('config/base.yml');\n  fs.unlinkSync('config/overrides/prod.yml');\n  fs.unlinkSync('config/overrides/test.yml');\n  fs.unlinkSync('merged.yml');\n  fs.rmdirSync('config/overrides');\n  fs.rmdirSync('config');\n  console.log('\\nCleanup complete.');\n} catch (error) {\n  console.error(`Error during quickstart: ${error.message}`);\n  process.exit(1);\n}\n","lang":"javascript","description":"Demonstrates global installation and usage of the `merge-yaml-cli` command-line utility to merge multiple YAML files using glob patterns and output the result."},"warnings":[{"fix":"Evaluate alternative, more actively maintained YAML merging tools for production environments or critical projects. If using `merge-yaml-cli`, thoroughly test its behavior in your specific environment and Node.js version.","message":"The project's npm page indicates the last publish was 8 years ago, suggesting the package is not actively maintained. This could lead to unaddressed bugs or compatibility issues with newer Node.js versions or YAML specifications. Consider checking GitHub for more recent activity or forks.","severity":"gotcha","affected_versions":"<=1.1.2"},{"fix":"Always test glob patterns thoroughly, especially after Node.js runtime upgrades. Consider explicit file lists if glob behavior becomes unpredictable for critical merges.","message":"The package uses `glob` for file pattern matching. Changes in `glob`'s behavior or updates to Node.js's file system APIs could potentially alter how file paths are resolved or matched, leading to unexpected merge inputs or outputs. No specific breaking changes are documented for `merge-yaml-cli` itself between versions in the provided context, but `glob` updates could cause subtle issues.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Understand the merging logic (last-in wins for conflicting keys). If array concatenation or other sophisticated merge strategies are required, consider pre-processing your YAML files or using a different tool (e.g., `yq` or `combine-yaml-cli`) that supports these specific behaviors.","message":"The `merge-yaml-cli` tool performs a simple deep merge, where later files in the input list will overwrite conflicting keys from earlier files. It does not specify advanced merging strategies like array concatenation, which might be desired for certain configurations. For example, if both files define an array for the same key, the array from the later file will replace the earlier one, not combine them.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid using `merge-yaml-cli` to process YAML files from untrusted sources. Regularly check the project's Snyk report or similar vulnerability scanners for updates on its dependencies. For programmatic usage, ensure no unsafe `yaml.load` equivalents are exposed or used internally without proper sanitization if user input is involved.","message":"Security vulnerabilities in YAML parsing libraries (like `js-yaml`, which this package likely uses) are a known risk, especially when processing untrusted input. Exploits can include arbitrary code execution through unsafe loading of YAML documents. While the Snyk badge indicates known vulnerabilities for the project, the specific details aren't provided in the excerpt.","severity":"gotcha","affected_versions":"<=1.1.2"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Install the package globally using `npm install -g merge-yaml-cli` or `yarn global add merge-yaml-cli`. Alternatively, if installed locally, run it via `npx merge-yaml-cli` or by adding it to your `package.json` scripts.","cause":"The `merge-yaml-cli` package was installed locally or not installed at all, rather than globally.","error":"command not found: merge-yaml"},{"fix":"Verify that all file paths and glob patterns are correct and that the files exist relative to the current working directory or as absolute paths. Double-check for typos in file names or directories.","cause":"One or more of the input YAML files specified in the command-line arguments or API call does not exist at the given path.","error":"Error: ENOENT: no such file or directory, open 'nonexistent.yml'"},{"fix":"Review the indicated YAML file (and line/column number if provided) for incorrect indentation. YAML is very sensitive to whitespace for defining structure. Use a YAML linter or validator to identify and fix syntax errors.","cause":"One of the input YAML files contains invalid YAML syntax, specifically an indentation error.","error":"YAMLException: bad indentation of a mapping entry at line X, column Y"}],"ecosystem":"npm","meta_description":null}