Specifying an external dangerfile.js breaks project dependencies
- Dominant language
- TypeScript
- Stars
- 5.5k
- Forks
- 379
- Avg merge
- 2h 8m
- Merged PRs (30d)
- 6
Description
# Report
## What did you do?
I invoked `npx danger local` within a Node.js project, specifying a `dangerfile.js` that lives outside of the project.
*Reproduction case:*
```
#!/bin/bash
set -eu
rm -rf ./project ./tool
mkdir tool && (
cd tool && \
cat >dangerfile.js <<:DANGERFILE
try{
console.log(require('array-first'));
console.log(require('array-last'));
} catch(e) {
console.log('ERROR', e);
}
:DANGERFILE
)
mkdir project && (
cd project && \
npm init -y >/dev/null 2>&1 && \
npm i danger array-first array-last && \
git init . && \
git add package.json package-lock.json && \
git commit -m 'NPM installed' && \
git checkout -b test && \
cp ../tool/dangerfile.js . && \
git add dangerfile.js && \
git commit -m 'Initial dangerfile' )
echo 'Running Danger in project'
(
cd project && \
npx danger local) || true
echo 'Running Danger in project, using external Dangerfile'
(
cd project && \
npx danger local -d '../tool/dangerfile.js' ) || true
```
## What did you expect to happen?
Ideally, `danger` should evaluate an external Dangerfile as if it lived within the project directory from which `danger` was invoked. Alternatively, it would be desirable to have a command-line parameter that lets me specify the directory that `danger` considers to be the project directory.
NOTE: `danger.import_dangerfile` seemed like it might be a solution for this problem, but I could not get it to work from within danger-js. The documentation is pretty sparse and unclear, so I'm not sure if I was doing something wrong.
## What happened instead?
Danger was not able to see the `node_modules` in the directory from which I invoked `danger`:
```
Running Danger in project
[Function: arrayFirst]
[Function: last]
Danger: ✓ passed review, received no feedback.
Running Danger in project, using external Dangerfile
ERROR { Error: Cannot find module 'array-first'
```
## Your Environment
* Which CI are you running on? *local*
* Are you running the latest version of Danger? *9.2.8*
* What is your Dangerfile?
```
try{
console.log(require('array-first'));
console.log(require('array-last'));
} catch(e) {
console.log('ERROR', e);
}
```
Contributor guide
Research direction
Start by running the reproduction script and compare `npx danger local` with `npx danger local -d '../tool/dangerfile.js'`. Trace the `-d` external Dangerfile entry point and dependency lookup, then verify that the external file can require `array-first` and `array-last` from the project’s `node_modules`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100