Description
There's a chance this question is silly or obvious, due to my lack of knowledge of TypeScript and JavaScript. If that's the case, I apologize. 🙏
I'm a bit surprised by the how Danger is behaving in regards to Dangerfile
s with that do export default async () => { ... }
.
If I run Danger against a Dangerfile
that exposes its rules within that async function, like this one, I get this error:
Unexpected token export
path/to/dangerfile.ts
export default async () => {
^^^^^^
Click to see the full error log.
Unexpected token export
peril-downloaded-Automattic/peril-settings/org/pr/label.ts:3
export default async () => {
^^^^^^
SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.requireFromString [as default] (/home/runner/work/WordPress-iOS/WordPress-iOS/node_modules/require-from-string/index.js:28:4)
at Object.<anonymous> (/home/runner/work/WordPress-iOS/WordPress-iOS/node_modules/danger/distribution/runner/runners/inline.js:144:63)
at step (/home/runner/work/WordPress-iOS/WordPress-iOS/node_modules/danger/distribution/runner/runners/inline.js:32:23)
at Object.next (/home/runner/work/WordPress-iOS/WordPress-iOS/node_modules/danger/distribution/runner/runners/inline.js:13:53)
at /home/runner/work/WordPress-iOS/WordPress-iOS/node_modules/danger/distribution/runner/runners/inline.js:7:71
at new Promise (<anonymous>)
at __awaiter (/home/runner/work/WordPress-iOS/WordPress-iOS/node_modules/danger/distribution/runner/runners/inline.js:3:12)
at exports.runDangerfileEnvironment (/home/runner/work/WordPress-iOS/WordPress-iOS/node_modules/danger/distribution/runner/runners/inline.js:105:136)
at Object.<anonymous> (/home/runner/work/WordPress-iOS/WordPress-iOS/node_modules/danger/distribution/platforms/GitHub.js:169:38)
I can fix the issue if I run everything sync, like here.
To be clear this is what I mean by run everything sync
// dangerfile.ts
import {warn, danger} from "danger";
- export default async () => {
- warn("A warning")
- };
+ warn("A warning")
I wouldn't find this too surprising if it wasn't for the fact that the same Dangerfile
with export default async () => { ... }
works when run using the Danger GitHub Action. 🤔 .
Real life examples:
- A failing GitHub workflow build running a remote
Dangerfile
usingexport default async...
, here - A passing GitHub workflow build running a
Dangerfile
like the above but without the code beingasync
, here - A passing GitHub workflow build running the remote
Dangerfile
that results in a failure, but using the GitHub Action instead than callingdanger
directly, here
Looking at the examples in the "About the Dangerfile" guide, the only Dangerfile
I could find using that syntax was danger-js/dangerfile.ts
but I can't find an example of it behaves when run.
At this point, my assumption is that the async code works for Peril but not for Danger, because of differences in the internals. It also works when Danger is used as a GitHub Action because of how the GitHub Action is implemented. Otherwise, one should avoid export default async () => { ... }
in Dangerfile
s. Is this correct? If it isn't (which is what I hope) what is it that I'm missing? How can I get it to work async?
Activity