[Feature Request] Allow opting out of ts-node
What Changed
I added an option to prevent auto from installing the ts-node require hook.
Why
We recently upgraded typescript to v5 and one of our deploy scripts that used the Auto class (as opposed to the auto cli) started failing with the following error:
/home/runner/work/tldraw/tldraw/node_modules/@auto-it/core/node_modules/ts-node/dist/index.js:3
Object.defineProperty(exports, "__esModule", { value: true });
^
TSError: ⨯ Unable to compile TypeScript:
error TS5109: Option 'moduleResolution' must be set to 'NodeNext' (or left unspecified) when option 'module' is set to 'NodeNext'.
at createTSError (/home/runner/work/tldraw/tldraw/node_modules/@auto-it/core/node_modules/ts-node/dist/index.js:3:6696)
at reportTSError (/home/runner/work/tldraw/tldraw/node_modules/@auto-it/core/node_modules/ts-node/dist/index.js:3:6848)
at /home/runner/work/tldraw/tldraw/node_modules/@auto-it/core/node_modules/ts-node/src/index.ts:1:67
at Object.compile (/home/runner/work/tldraw/tldraw/node_modules/@auto-it/core/node_modules/ts-node/src/index.ts:1:67)
at Module.m._compile (/home/runner/work/tldraw/tldraw/node_modules/@auto-it/core/node_modules/ts-node/src/index.ts:1:67)
at j (/home/runner/work/tldraw/tldraw/node_modules/tsx/dist/cjs/index.cjs:1:[11](https://github.com/tldraw/tldraw/actions/runs/7557438453/job/20576664393#step:8:12)97)
at Object.require.extensions.<computed> [as .ts] (/home/runner/work/tldraw/tldraw/node_modules/@auto-it/core/node_modules/ts-node/src/index.ts:1:67)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Function.Module._load (node:internal/modules/cjs/loader:960:[12](https://github.com/tldraw/tldraw/actions/runs/7557438453/job/20576664393#step:8:13))
at Module.require (node:internal/modules/cjs/loader:1[14](https://github.com/tldraw/tldraw/actions/runs/7557438453/job/20576664393#step:8:15)3:[19](https://github.com/tldraw/tldraw/actions/runs/7557438453/job/20576664393#step:8:20)) {
diagnosticCodes: [ 5109 ]
}
This is most likely a problem with ts-node, since it seems to be passing an incorrect config to the ts compiler when transpiling modules. But also we already use tsx for running this particular script, so we don't even need the ts-node hook to be registered. I'd appreciate if there was a semi-official way we could opt out of ts-node when using Auto as an api rather than a cli tool, hence this PR.
Todo:
- [ ] Add tests
- [ ] Add docs
Change Type
Indicate the type of change your pull request is:
- [ ]
documentation - [ ]
patch - [x]
minor - [ ]
major
Codecov Report
Attention: 1 lines in your changes are missing coverage. Please review.
Comparison is base (
7a6f0ae) 85.92% compared to head (edf02b6) 80.58%.
| Files | Patch % | Lines |
|---|---|---|
| packages/core/src/auto.ts | 83.33% | 0 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #2420 +/- ##
==========================================
- Coverage 85.92% 80.58% -5.34%
==========================================
Files 69 69
Lines 5675 5676 +1
Branches 1332 1275 -57
==========================================
- Hits 4876 4574 -302
- Misses 718 719 +1
- Partials 81 383 +302
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@ds300 could you add a reference to this in the docs?
@hipstersmoothie happy to. I don't see a convenient place to mention it, can you point me in the right direction?
So looking at the docs we don't list global options anywhere 💀 Gonna have to fix that
In the meantime:
The only way to use this option right now would be by using auto programmatically which you probably don't want. We should add this ass a global CLI option too.
- Add the option to
defaultOptionsinparse-args.ts - In another PR I'll add docs for the global CLI options
The only way to use this option right now would be by using auto programmatically which you probably don't want.
On the contrary! The only reason we need this option is because we are using auto programatically (is this kosher?). I don't think it would be an issue for anybody running auto on the cli.
Oh wow I didn't even realize it was you lol
Totally kosher to use pragmatically like that. Given you reasoning that seems fine to me!
:rocket: PR was released in v11.1.0 :rocket: