Skip to content

Commit a376570

Browse files
authored
Fix #1943 (#1952)
* Fix #1943 * add regression test
1 parent 7fbc75e commit a376570

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/bin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ function phase4(payload: BootstrapState) {
630630
if (executeEntrypoint) {
631631
if (
632632
payload.isInChildProcess &&
633-
versionGteLt(process.versions.node, '18.6.0')
633+
versionGteLt(process.versions.node, '18.6.0', '18.7.0')
634634
) {
635635
// HACK workaround node regression
636636
require('../dist-raw/runmain-hack.js').run(entryPointPath);

src/esm.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
fileURLToPath,
77
pathToFileURL,
88
} from 'url';
9-
import { extname } from 'path';
9+
import { extname, resolve as pathResolve } from 'path';
1010
import * as assert from 'assert';
1111
import { normalizeSlashes, versionGteLt } from './util';
1212
import { createRequire } from 'module';
@@ -137,12 +137,19 @@ export function createEsmHooks(tsNodeService: Service) {
137137
return protocol === null || protocol === 'file:';
138138
}
139139

140+
const runMainHackUrl = pathToFileURL(
141+
pathResolve(__dirname, '../dist-raw/runmain-hack.js')
142+
).toString();
143+
140144
/**
141145
* Named "probably" as a reminder that this is a guess.
142146
* node does not explicitly tell us if we're resolving the entrypoint or not.
143147
*/
144148
function isProbablyEntrypoint(specifier: string, parentURL: string) {
145-
return parentURL === undefined && specifier.startsWith('file://');
149+
return (
150+
(parentURL === undefined || parentURL === runMainHackUrl) &&
151+
specifier.startsWith('file://')
152+
);
146153
}
147154
// Side-channel between `resolve()` and `load()` hooks
148155
const rememberIsProbablyEntrypoint = new Set();

src/test/esm-loader.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,14 @@ test.suite('esm', (test) => {
336336
});
337337
}
338338

339+
test('extensionless entrypoint, regression test for #1943', async (t) => {
340+
const { err, stdout } = await exec(
341+
`${BIN_ESM_PATH} ./esm-loader-entrypoint-cjs-fallback/extensionless-entrypoint`
342+
);
343+
expect(err).toBe(null);
344+
expect(stdout.trim()).toBe('Hello world!');
345+
});
346+
339347
test.suite('parent passes signals to child', (test) => {
340348
signalTest('SIGINT');
341349
signalTest('SIGTERM');

0 commit comments

Comments
 (0)