feat: replace ts-node
with tsx
for user configuration parsing and cypress runtime
#31185
Labels
ts-node
with tsx
for user configuration parsing and cypress runtime
#31185
What would you like?
To replace
ts-node
withtsx
for generic transpiling ofTypeScript
and generic file loadingWhy is this needed?
How
cypress
works withts-node
todayFor end users today, we currently use
ts-node
to:typescript
andesm
viats-node/esm
with--experimental-specifier-resolution=node
flag. We detect this based on the userspackage.json
.typescript
viacjs
uses the defaultts-node
loader.cjs
/esm
withouttypescript
usesnode
only.See ProjectConfigIpc.ts for more details.
Issues with
ts-node
todaycypress
on a subprocess, which is all run incommonjs
currently. The interoperability between ESM and CJS inside the node.js runtime is still something that isn't well supported. In other words, the process needs to either be executed as ESM or CJS. It cannot handle both. For this reason,commonjs
is forced as the module for typescript users. This is explained fairly well in our docs.Unfortunately, this leads to a whole new superset of problems when can be seen in this PR as well as a few of the issues linked in this issue.
tsconfig.json
in the users project root, even though cypress recommends having it's owntsconfig.json
. Given this is mostly to add cypress type checking to your editor in the cypress directory, it has two pitfalls:tsconfig.json
is not used to transpile thecypress
config, which may be a problem for users who have complex plugin configurations.Ideally, even if users don't have a
tsconfig
, cypress in 99% of cases for simple configs should be able to parse the file.Why
tsx
?Experimenting with
tsx
, it looks like we can fix most of the above issues withts-node
.tsx
works as a generic node loader with typescript support, meaning it can handle anyesm
,cjs
, andtypescript
variant. This allows us to use the same loader for any config format, eliminating the logic needed to try and discover the expected config module format.tsconfig.json
and it be compatible with our run time. This completely gets rid of the need to override a users typescript config, eliminating many of the bugs associated with such behavior.tsx
a unique tsconfig.json path, allowing us to actually use thetsconfig.json
defined in thecypress
directory or whatever directory theircypress
tests live.More details can be seen on the
tsx
spike commentOther
removing @packages/ts and updating
mocha
tests to usetsx
are out of scope for this issue. This issue should address the loading of the user's cypress config inside the require async child processes as well as replacing the registering of@packages/ts
inside cypress packages to usets-node
for runtime transpilation and instead usingtsx/cjs
.We should be able to build and test a binary with all of our tests passing. The only things that should be using the
@packages/ts
andts-node
runtimes are ourmocha
testsThe text was updated successfully, but these errors were encountered: