Skip to content

Commit

Permalink
fix requireResolveNonCached for node 12.0.x and node 12.1.x (#1566)
Browse files Browse the repository at this point in the history
* fix `requireResolveNonCached` for node 12.0.0 and node 12.0.1

This also drops removes support for node 10 and 11.

* fix lint error

* tweak logic to use our reusable version number comparison function

* tweak code comments; I wrote them and they still confused me

Co-authored-by: Andrew Bradley <[email protected]>
  • Loading branch information
davidmurdoch and cspotcode authored Dec 27, 2021
1 parent fe71967 commit feb7c45
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
STDIN_NAME,
REPL_FILENAME,
} from './repl';
import { VERSION, TSError, register } from './index';
import { VERSION, TSError, register, versionGteLt } from './index';
import type { TSInternal } from './ts-compiler-types';
import { addBuiltinLibsToObject } from '../dist-raw/node-cjs-helpers';

Expand Down Expand Up @@ -427,12 +427,11 @@ let guaranteedNonexistentDirectorySuffix = 0;
* https://stackoverflow.com/questions/59865584/how-to-invalidate-cached-require-resolve-results
*/
function requireResolveNonCached(absoluteModuleSpecifier: string) {
// node 10 and 11 fallback: The trick below triggers a node 10 & 11 bug
// On those node versions, pollute the require cache instead. This is a deliberate
// ts-node limitation that will *rarely* manifest, and will not matter once node 10
// is end-of-life'd on 2021-04-30
const isSupportedNodeVersion =
parseInt(process.versions.node.split('.')[0], 10) >= 12;
// node <= 12.1.x fallback: The trick below triggers a node bug on old versions.
// On these old versions, pollute the require cache instead. This is a deliberate
// ts-node limitation that will *rarely* manifest, and will not matter once node 12
// is end-of-life'd on 2022-04-30
const isSupportedNodeVersion = versionGteLt(process.versions.node, '12.2.0');
if (!isSupportedNodeVersion) return require.resolve(absoluteModuleSpecifier);

const { dir, base } = parsePath(absoluteModuleSpecifier);
Expand Down

0 comments on commit feb7c45

Please sign in to comment.