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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
run
✓ import { run } from 'endanger'
✗ const { run } = require('endanger')
Endanger is primarily designed for ESM. CommonJS `require` can lead to `TypeError` if not handled with interop.
Rule
✓ import { Rule } from 'endanger'
✗ import Rule from 'endanger'
The `Rule` class is a named export, not a default export. Ensure curly braces are used for destructuring.
RuleContext
✓ import type { RuleContext } from 'endanger'
Import types separately for clarity and bundler optimization when not in TypeScript-only environments.
Demonstrates setting up a Dangerfile with `endanger` using a modular rule to warn about changes in critical system files and ensure corresponding security documentation exists.
import { run, Rule } from 'endanger';
// dangerfile.ts
// This file is typically located at the root of your repository.
import myFirstRule from './danger/myFirstRule';
// Execute the defined rules. You can pass multiple rule instances.
run(
myFirstRule()
);
// danger/myFirstRule.ts
// Create this file inside a 'danger/' directory.
export default function myFirstRule() {
return new Rule({
match: {
// This rule will only run if files matching this glob pattern are created or modified.
files: ["src/critical-system/**", "docs/security/**"],
// You can also match commits by regex: commit: [/^fix\(security\):/]
},
messages: {
criticalFileChangeWarning: `
🚨 Warning: Changes detected in critical system or security documentation files.
Please ensure thorough review and necessary approvals.
`,
missingSecurityDocs: `
🚫 A new file was added to 'src/critical-system/' without corresponding security documentation.
`
},
async run({ files, context }) {
// Iterate over newly created files that match the glob
for (let file of files.created) {
context.warn("criticalFileChangeWarning", { file });
// Example: Check for companion security documentation
const docPath = file.filePath.replace('src/critical-system/', 'docs/security/');
if (!(await context.git.fileMatch(docPath).createdOrModified())) {
context.fail("missingSecurityDocs", { file });
}
}
// Iterate over modified files
for (let file of files.modified) {
context.message("criticalFileChangeWarning", { file });
}
}
});
}
// To run this example:
// 1. Install dependencies: npm install --save-dev danger endanger typescript
// 2. Set up a simple git repository and make a commit.
// 3. Create or modify a file within 'src/critical-system/' (e.g., 'src/critical-system/new-feature.ts').
// 4. Run Danger locally: npx danger local --dangerfile dangerfile.ts
// (Ensure your package.json has `"type": "module"` if you face module resolution issues.)
Errors
Common errors & fixes
Error: Cannot find module 'endanger' from '/path/to/project'
The `endanger` package has not been installed or is not resolvable in the current environment.
fixRun `npm install --save-dev endanger` or `yarn add --dev endanger` to add the package to your project dependencies.
TypeError: (0, endanger_1.run) is not a function
This error typically occurs when trying to `require` Endanger in a CommonJS context or when module resolution is incorrect for ESM imports, leading to `run` not being correctly imported.
fixEnsure your `dangerfile.ts` (or `.js`) is treated as an ESM module. Add `"type": "module"` to your `package.json`, or rename your Dangerfile to `.mts` or `.mjs`. Always use `import { run } from 'endanger';`. Endanger requires `danger@10.5.3` and above
The installed version of `danger` does not meet the peer dependency requirement of `endanger`.
fixUpdate your `danger` package to a compatible version: `npm install danger@^10.5.3 --save-dev` or `yarn upgrade danger@^10.5.3`.
Audit
Dependencies
dangerrequiredRequired peer dependency for runtime execution of Dangerfiles. Endanger builds on top of Danger's core functionality.