Registry / devops / detect-conflict

detect-conflict

JSON →
library1.0.1jsnpmunverified

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-conflict
INSTALL
IMPORT
SIG · DETECT-CONFLICT
D
detect-conflict
devopsjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

conflict
import conflict from 'detect-conflict';
import { conflict } from 'detect-conflict';
The primary `conflict` function is likely the default export in ESM environments.
conflict
const conflict = require('detect-conflict');
CommonJS usage is demonstrated directly in the package's README.
Type declarations
/// <reference types="detect-conflict" />
While explicit type imports aren't typically needed for single-function libraries, this indicates how TypeScript would infer types if the library ships them.

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.

import conflict from 'detect-conflict'; import fs from 'fs'; import path from 'path'; const filePath = path.join(process.cwd(), 'example-file.js'); const existingContent = 'console.log("Hello world!");\nconst foo = 1;'; const newContent = 'console.log("Greetings!");\nconst foo = 2;'; // This will conflict on 'foo' const safeContent = 'console.log("New message!");\nconst bar = 3;'; // This should not conflict // Ensure the file exists for demonstration fs.writeFileSync(filePath, existingContent, 'utf8'); console.log(`Checking for conflict in ${filePath}`); const isConflicting = conflict(filePath, newContent); console.log(`New content conflicts with existing: ${isConflicting}`); const isConflictingSafe = conflict(filePath, safeContent); console.log(`Safe content conflicts with existing: ${isConflictingSafe}`); // Clean up the created file fs.unlinkSync(filePath);
Debug
Known issues
gotchaIf the `filepath` argument points to a directory instead of a file, the `conflict` function will always return `true`.
fix
Ensure that `filepath` always resolves to an actual file. Use `fs.statSync(filepath).isFile()` to verify before calling `conflict` if directory handling is uncertain.
affects: >=1.0.0
gotchaWhen passing file `contents` as a string, `detect-conflict` assumes it is UTF-8 encoded. For other encodings, or for binary content, a `Buffer` must be passed.
fix
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.
affects: >=1.0.0
breakingVersions prior to 1.0.1 had a bug where passing `null` as the `contents` argument could lead to unexpected behavior or errors.
fix
Upgrade to `detect-conflict@1.0.1` or newer. Alternatively, ensure that the `contents` argument is always a `String` or `Buffer` and never `null`.
affects: <1.0.1
Errors
Common errors & fixes
Error: ENOTDIR: not a directory, open 'your-directory/file.js'
The `filepath` provided to `conflict` function resolves to a directory, but an attempt was made to open it as a file by underlying `fs` operations.
fix
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.
TypeError: conflict is not a function
This usually indicates an incorrect import statement or an attempt to call a non-existent function from the module.
fix
Ensure you are importing the `conflict` function correctly. For CommonJS, use `const conflict = require('detect-conflict');`. For ESM, use `import conflict from 'detect-conflict';`.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
detect-conflict — npm install detect-conflict · libregistry