【发布时间】:2021-11-08 18:13:28
【问题描述】:
我正在尝试将危险文件拆分为小部分,因为我们添加了许多检查/自动化功能,因此它非常有用,但管理起来却变得更加困难。但是当我尝试成功时,它总是给我这个错误;
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
也许您知道频谱不再可用,我真的找不到任何方法来正常运行它。你知道它是如何工作的吗?这是我要运行的示例;
// ./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;
【问题讨论】:
标签: danger