Skip to content

Commit

Permalink
Fix #1943
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Feb 7, 2023
1 parent 7fbc75e commit 218a45e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/bin.ts
Expand Up @@ -630,7 +630,7 @@ function phase4(payload: BootstrapState) {
if (executeEntrypoint) {
if (
payload.isInChildProcess &&
versionGteLt(process.versions.node, '18.6.0')
versionGteLt(process.versions.node, '18.6.0', '18.7.0')
) {
// HACK workaround node regression
require('../dist-raw/runmain-hack.js').run(entryPointPath);
Expand Down
9 changes: 7 additions & 2 deletions src/esm.ts
Expand Up @@ -6,7 +6,7 @@ import {
fileURLToPath,
pathToFileURL,
} from 'url';
import { extname } from 'path';
import { extname, resolve as pathResolve } from 'path';
import * as assert from 'assert';
import { normalizeSlashes, versionGteLt } from './util';
import { createRequire } from 'module';
Expand Down Expand Up @@ -137,12 +137,17 @@ export function createEsmHooks(tsNodeService: Service) {
return protocol === null || protocol === 'file:';
}

const runMainHackUrl = pathToFileURL(pathResolve(__dirname, '../dist-raw/runmain-hack.js')).toString();

/**
* Named "probably" as a reminder that this is a guess.
* node does not explicitly tell us if we're resolving the entrypoint or not.
*/
function isProbablyEntrypoint(specifier: string, parentURL: string) {
return parentURL === undefined && specifier.startsWith('file://');
return (
(parentURL === undefined || parentURL === runMainHackUrl) &&
specifier.startsWith('file://')
);
}
// Side-channel between `resolve()` and `load()` hooks
const rememberIsProbablyEntrypoint = new Set();
Expand Down

0 comments on commit 218a45e

Please sign in to comment.