From 618e187992e4a4c73560b06d0a4d7b61372dc134 Mon Sep 17 00:00:00 2001 From: David Murdoch <187813+davidmurdoch@users.noreply.github.com> Date: Fri, 10 Dec 2021 11:32:03 -0500 Subject: [PATCH 1/4] fix `requireResolveNonCached` for node 12.0.0 and node 12.0.1 This also drops removes support for node 10 and 11. --- src/bin.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index d97261a3b..59f2ffefe 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -427,12 +427,13 @@ 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.0.0 and 12.1.0 fallback: The trick below triggers a node 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 12 + // is end-of-life'd on 2022-04-30 + const [major, minor] = + process.versions.node.split('.').map(v => parseInt(v, 10)); + const isSupportedNodeVersion = major >= 13 || (major == 12 && minor > 1); if (!isSupportedNodeVersion) return require.resolve(absoluteModuleSpecifier); const { dir, base } = parsePath(absoluteModuleSpecifier); From 7beb4c3d3b4740eeb5dfb25eefad1cc4f8654347 Mon Sep 17 00:00:00 2001 From: David Murdoch Date: Fri, 10 Dec 2021 14:57:12 -0500 Subject: [PATCH 2/4] fix lint error --- src/bin.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 59f2ffefe..80a5c830e 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -431,8 +431,9 @@ function requireResolveNonCached(absoluteModuleSpecifier: string) { // 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 12 // is end-of-life'd on 2022-04-30 - const [major, minor] = - process.versions.node.split('.').map(v => parseInt(v, 10)); + const [major, minor] = process.versions.node + .split('.') + .map((v) => parseInt(v, 10)); const isSupportedNodeVersion = major >= 13 || (major == 12 && minor > 1); if (!isSupportedNodeVersion) return require.resolve(absoluteModuleSpecifier); From 0baab2024820d3ede16b4054eeb970026c5cd13c Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 27 Dec 2021 03:11:37 +0000 Subject: [PATCH 3/4] tweak logic to use our reusable version number comparison function --- src/bin.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 80a5c830e..59fecbe4e 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -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'; @@ -431,10 +431,7 @@ function requireResolveNonCached(absoluteModuleSpecifier: string) { // 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 12 // is end-of-life'd on 2022-04-30 - const [major, minor] = process.versions.node - .split('.') - .map((v) => parseInt(v, 10)); - const isSupportedNodeVersion = major >= 13 || (major == 12 && minor > 1); + const isSupportedNodeVersion = versionGteLt(process.versions.node, '12.2.0'); if (!isSupportedNodeVersion) return require.resolve(absoluteModuleSpecifier); const { dir, base } = parsePath(absoluteModuleSpecifier); From 11cb00e474260812221657c76ca7c54abce1bec0 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 27 Dec 2021 03:14:20 +0000 Subject: [PATCH 4/4] tweak code comments; I wrote them and they still confused me --- src/bin.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 59fecbe4e..dc688ce85 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -427,8 +427,8 @@ let guaranteedNonexistentDirectorySuffix = 0; * https://stackoverflow.com/questions/59865584/how-to-invalidate-cached-require-resolve-results */ function requireResolveNonCached(absoluteModuleSpecifier: string) { - // node 12.0.0 and 12.1.0 fallback: The trick below triggers a node bug. - // On those node versions, pollute the require cache instead. This is a deliberate + // 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');