Support ESM configs and explicit .cjs and .mjs config extensions #746
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update the config loading approach and introduce new binaries to support ESM configs. This addresses part of #572 and #686 as much as is possible without a potential breaking change.
Allow more extensions for config files
.cjsand.mjsconfigs will "just work".ctsconfigs will work withts-node10 (which added.ctsand.mtssupport).mtsis allowed, but will ONLY work if with the newjust-esm/just-scripts-esmbinaries (next section).tsconfigs in a module context (type: "module"in package.json)Add new binaries to support TS ESM config files (+
tsxsupport)Add two new binaries which spawn a new process to run the Just CLI via
tsxorts-node-esm(depending on what's installed in the repo):just-scripts-esm(just-scriptspackage)just-esm(just-taskpackage)You must use one of these binaries if you want to use a
.tsor.mtsconfig file in a module context (type: "module"in package.json).They should also work in a CJS context, like if you just want to use
tsxinstead ofts-node. (It unfortunately doesn't appear to be possible to enabletsxorts-node-esmwith an after-the-factregister()call like with traditionalts-node.)Load ESM configs with
import()Update the config loading logic to use
import()for ESM configs. A config is considered ESM if one of the following is true:.mjsor.mtsextension"type": "module"and the config has a.jsor.tsextension (but see notes below)This required updating the repo version of
typescriptto 4.7 so that I could use themodule/moduleResolution"Node16"setting to prevent theimport()from being transpiled torequire().Updates to
ts-nodesetupAlso made some updates to the
ts-noderegister()logic, for the previous TS loading approachtypescriptversion and if it's >= 4.7, setts-node'smodule/moduleResolutionto"Node16"(to prevent dynamicimport()from being transpiled torequire())ts-noderegister()if already running ints-nodeortsx(from the new binaries)