Open justjake opened 3 years ago
Quick guess because I'm about go step into a meeting. I'm not certain the root cause will be those overrides (though I think it's a good guess) - it's possible that the "evaluation" sub-process doesn't know about ts-node at all ( e.g. the thing that powers this:: https://danger.systems/js/usage/danger-process.html )
e.g. maybe some of these flags need to go through this?
@orta also off the cuff because I'm about to head to a meeting, setting NODE_OPTIONS="-r ts-node/register/transpile-only"
in the environment should be enough to ensure that all child node processes require ts-node/regsiter/transpile-only because those flags are env environment variables, not being passed directly as argv to the child process; I would expect the only thing that would break the NODE_OPTIONS is if you clear out the environment used by the subprocess.
My two theories are (1) the overriding of require.extensions as i shared originally, and (2) maybe it would work, but perhaps dangerfile.ts
isn't actually require
'd, so no matter what it wouldn't get the benefit of ts-node
(?) but i haven't investigated (2) yet.
I did want to give y'all an example of this problem and a workaround; so even if this issue gets closed WONTFIX TOO WEIRD, the next person googling "tsconfig ts-node dangerfile syntax error" will find my workaround :).
Great points, after a re-read, I think your original suggestion is probably the right call here.
I think if DANGER_DISABLE_TRANSPILATION
is truthy, or any env vars relating to ts-node (or maybe this https://github.com/TypeStrong/ts-node/issues/846#issuecomment-631828160 ) are present we should not add those custom require handlers 👍🏻
Describe the bug
Danger's built-in transpiler for Typescript produces syntax errors when it tries to build some code we import in
dangerfile.ts
. This bug report is not about danger's typescript transpiler. It's about struggling to find a work-around to a bug in danger's traspiler compiler.Because Danger's built-in transpiler can't run our dangerfile, we want to use our standard
TS_NODE_PROJECT="tsconfig.tsnode.json" node -r ts-node/register/transpile-only
workflow withdanger
. However, even when settingDANGER_DISABLE_TRANSPILATION=true
,danger
still doesn't pick up the custom require plugins registered by ts-node.This is the command I'm running:
It outputs as you'd expect for a .ts file run through danger without transpilation:
I suspect this is happening because danger overrides
require.extensions
even when transpilation is supposed to be disabled here:https://github.com/danger/danger-js/blob/c4fa1308d969af7acc1b2ae052c1a75fbe26a9c3/source/runner/runners/inline.ts#L67-L82
To Reproduce Steps to reproduce the behavior:
danger
andts-node
.dangerfile.ts
file that does some importsExpected behavior Danger should respect already-register
require
plugins when transpilation is disabled. I would expect the command posted to work without syntax errors.Additional context
To work around both this problem, and the original problem with Danger's typescript compiler producing syntax errors, I've decided to transpile
dangerfile.ts
usingtsc
as part of our normal build process. In that case, a different work-around is needed to avoid the transpiled typescript from erroring out due to importing the dummydanger
node module at runtime. Here's the code snippet I'm employing: