* require.resolve an absolute path, tricking node into *not* caching the results. * Necessary so that we do not pollute require.resolve cache prior to installing require.extensions * * Is a terrible hack, because node does not expose the necessary cache invalidation APIs * https://stackoverflow.
(absoluteModuleSpecifier: string)
| 742 | * https://stackoverflow.com/questions/59865584/how-to-invalidate-cached-require-resolve-results |
| 743 | */ |
| 744 | function requireResolveNonCached(absoluteModuleSpecifier: string) { |
| 745 | // node <= 12.1.x fallback: The trick below triggers a node bug on old versions. |
| 746 | // On these old versions, pollute the require cache instead. This is a deliberate |
| 747 | // ts-node limitation that will *rarely* manifest, and will not matter once node 12 |
| 748 | // is end-of-life'd on 2022-04-30 |
| 749 | const isSupportedNodeVersion = versionGteLt(process.versions.node, '12.2.0'); |
| 750 | if (!isSupportedNodeVersion) return require.resolve(absoluteModuleSpecifier); |
| 751 | |
| 752 | const { dir, base } = parsePath(absoluteModuleSpecifier); |
| 753 | const relativeModuleSpecifier = `./${base}`; |
| 754 | |
| 755 | const req = createRequire( |
| 756 | join(dir, 'imaginaryUncacheableRequireResolveScript') |
| 757 | ); |
| 758 | return req.resolve(relativeModuleSpecifier, { |
| 759 | paths: [ |
| 760 | `${guaranteedNonexistentDirectoryPrefix}${guaranteedNonexistentDirectorySuffix++}`, |
| 761 | ...(req.resolve.paths(relativeModuleSpecifier) || []), |
| 762 | ], |
| 763 | }); |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Evaluate an [eval] or [stdin] script |
no test coverage detected
searching dependent graphs…