Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bin.ts
Original file line number Diff line number Diff line change
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
11 changes: 9 additions & 2 deletions src/esm.ts
Original file line number Diff line number Diff line change
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,19 @@ 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
8 changes: 8 additions & 0 deletions src/test/esm-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ test.suite('esm', (test) => {
});
}

test('extensionless entrypoint, regression test for #1943', async (t) => {
const { err, stdout } = await exec(
`${BIN_ESM_PATH} ./esm-loader-entrypoint-cjs-fallback/extensionless-entrypoint`
);
expect(err).toBe(null);
expect(stdout.trim()).toBe('Hello world!');
});

test.suite('parent passes signals to child', (test) => {
signalTest('SIGINT');
signalTest('SIGTERM');
Expand Down