I'm trying to split dangerfile into small parts because we added many checks/automation so it's super helpful but it gets harder to manage it. but when I try to make it, it always gives me this error;
Unable to evaluate the Dangerfile
Hey there, it looks like you're trying to import the danger module. Turns out
that the code you write in a Dangerfile.js is actually a bit of a sneaky hack.
When running Danger, the import or require for Danger is removed before the code
is evaluated. Instead all of the imports are added to the global runtime, so if
you are importing Danger to use one of it's functions - you should instead just
use the global object for the root DSL elements.
There is a spectrum thread for discussion here:
- https://spectrum.chat/?t=0a005b56-31ec-4919-9a28-ced623949d4d
Maybe as you know that spectrum is not available anymore, I really couldn't find any way to run it properly. Do you have any idea how it would work? This is my example to run;
// ./DANGERFILE.TS
//
//
import { OtherChecks } from './dangerjs/checks/other';
OtherChecks();
// ./dangerjs/checks/other.ts
//
//
import mentor from 'danger-plugin-mentor';
import { isGoingToProd, isSkipDanger } from '../variables';
export function OtherChecks() {
if (!isSkipDanger) {
if (!isGoingToProd) {
mentor();
}
}
}
// ./dangerjs/variable.ts
//
//
import { danger } from 'danger';
import {
committedFiles,
inCommit,
prTitle,
linkToSourceRepo,
} from 'danger-plugin-toolbox';
//
// CONSTS
//
export const packageChanged: boolean = inCommit('package.json');
export const lockfileChanged: boolean = inCommit('yarn.lock');
export const npmLockfile: boolean = inCommit('package-lock.json');
export const allFilesLen: number = committedFiles.length;
export const isWIP: boolean = prTitle.includes('[WIP]');
export const isSkipped: boolean = prTitle.includes('[SKIP]');
export const isSkipDanger: boolean = prTitle.includes('[SKIP-DANGER]');
export const { assignees } = danger.github.pr;
// gits
export const targetBranch = danger.github.pr.base.ref;
export const headBranch = danger.github.pr.head.ref;
export const isMergeRefMaster = targetBranch === 'master';
export const isMergeRefProd = targetBranch === 'production';
export const isMergeHeadDev = headBranch === 'dev';
export const isMergeHeadMaster = headBranch === 'master';
export const isGoingToProd = isMergeRefProd && isMergeHeadMaster;