Open mokagio opened 4 years ago
Solved!
I run DEBUG=* danger pr
and scrolling through the log I noticed a "Does not have TypeScript set up" message.
I found the message in the transpiler source https://github.com/danger/danger-js/blob/92c2040c15947b6eb24182b46ff026a480936229/source/runner/runners/utils/transpiler.ts#L35
Now it all makes sense! I was wondering how Danger was able to read both JS and TS files. I does so by relying on the user's tools š” .
Once I yarn add typescript -D
to my project which only uses Node for Danger JS, everything worked š
I'm going to close this issue, but I wonder if Danger could do something better to let users know that they're running a .ts
file without having TypeScript set up. cc @danger-systems
Yeah, leaving this open for someone to make an error message around this š
I'm fine with it fully bailing and raising an exception in this case
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 doexport default async () => { ... }
.If I run Danger against a
Dangerfile
that exposes its rules within that async function, like this one, I get this error: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.I can fix the issue if I run everything sync, like here.
To be clear this is what I mean by run everything sync
I wouldn't find this too surprising if it wasn't for the fact that the same
Dangerfile
withexport default async () => { ... }
works when run using the Danger GitHub Action. š¤ .Real life examples:
Dangerfile
usingexport default async...
, hereDangerfile
like the above but without the code beingasync
, hereDangerfile
that results in a failure, but using the GitHub Action instead than callingdanger
directly, hereLooking at the examples in the "About the Dangerfile" guide, the only
Dangerfile
I could find using that syntax wasdanger-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 () => { ... }
inDangerfile
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?