Update esm loader hooks API by jonaskello · Pull Request #1457 · TypeStrong/ts-node (original) (raw)
Thanks for the PR. I'm swamped with work, so I'll do my best to review in a timely manner, but it might drag a bit. However, anyone who wants to use this PR before it is merged and published can install directly from git. npm's documentation explains how to install dependencies directly from a git branch instead npmjs.com. Our CI also uploads a package tarball as an artifact, which anyone can download and install locally.
Re the warnings from node about deprecated hooks: I think we can detect the node version and conditionally export only the hooks expected by that version of node. We can export undefined
for the others. We do version detection in a few places in the codebase; here is one:
/** |
---|
* Does this version of node obey the package.json "type" field |
* and throw ERR_REQUIRE_ESM when attempting to require() an ESM modules. |
*/ |
const engineSupportsPackageTypeField = |
parseInt(process.versions.node.split('.')[0], 10) >= 12; |
function versionGte(version: string, requirement: string) { |
const [major, minor, patch, extra] = version |
.split(/[\.-]/) |
.map((s) => parseInt(s, 10)); |
const [reqMajor, reqMinor, reqPatch] = requirement |
.split('.') |
.map((s) => parseInt(s, 10)); |
return ( |
major > reqMajor | |
(major === reqMajor && |
(minor > reqMinor | |
); |
} |