detect-conflict is a focused utility library designed to determine if new content for a file can be safely merged with an existing file on disk without introducing conflicts. It achieves this by performing a content-based comparison, returning `true` if a conflict is detected and `false` otherwise. The current stable version is 1.0.1. As a specialized utility, its release cadence is generally slow, with updates primarily addressing bug fixes or minor enhancements rather than frequent new features. It differentiates itself by providing a simple, direct API for conflict *detection* rather than full merging capabilities, making it suitable for use cases like code generators, scaffolding tools, or deployment scripts that need to prevent overwriting user modifications.
npm install detect-conflictVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `detect-conflict` to check if new content for a file will conflict with the content currently on disk, showing both a conflicting and non-conflicting scenario.
Ensure that `filepath` always resolves to an actual file. Use `fs.statSync(filepath).isFile()` to verify before calling `conflict` if directory handling is uncertain.
For non-UTF8 text files or binary files, read the file content into a Node.js `Buffer` using `fs.readFileSync(filepath)` (without specifying encoding) and pass the `Buffer` directly to the `conflict` function.
Upgrade to `detect-conflict@1.0.1` or newer. Alternatively, ensure that the `contents` argument is always a `String` or `Buffer` and never `null`.
The library explicitly states that if `filepath` is a directory, it returns `true`. This error likely comes from *your* code trying to interact with the path as a file. Ensure `filepath` points to an actual file before passing it to `detect-conflict`, or handle the `true` return specifically for directories.
Ensure you are importing the `conflict` function correctly. For CommonJS, use `const conflict = require('detect-conflict');`. For ESM, use `import conflict from 'detect-conflict';`.No dependency data recorded yet.