Skip to content

Commit 2ddd3c4

Browse files
committed
fix(NodeTestConductor): remove use of --experimental-network-imports
1 parent dcdb29b commit 2ddd3c4

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/conductor/NodeTestConductor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export class NodeTestConductor extends TestConductor {
5454
return new AbortablePromise<void>(abortController, (resolve, reject, onTeardown) => {
5555
const child = spawn('node', [
5656
'--input-type=module',
57-
'--experimental-network-imports',
5857
'--experimental-import-meta-resolve',
5958
'--require', `${loaderPath}/experimental.cjs`,
6059
// TODO: handle resolved source mappings in ReporterServer
@@ -124,6 +123,16 @@ exit()
124123
await new Promise<void>((res, rej) => {
125124
child.on('error', rej)
126125

126+
child.stdin.on('error', (e: NodeJS.ErrnoException) => {
127+
child.kill()
128+
if (e.code === 'EPIPE') {
129+
// Bad options cause pipe errors on stdin.
130+
// Just killing the child provides a clearer error message.
131+
} else {
132+
throw e
133+
}
134+
})
135+
127136
child.stdin.end(childCode)
128137

129138
child.on('exit', (code, signal) => {

src/node/loader-netlocal.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import module from 'node:module'
66
import process from 'node:process'
77
import url from 'node:url'
8+
import { get } from 'node:http'
89

910
/**
1011
* @type NodeJSLoader.Resolver
1112
*/
1213
export const resolve = async (specifier, context, nextResolve) => {
1314
if (context.parentURL?.startsWith('http://127.0.0.1:')) {
14-
if (specifier.startsWith('file:///')) {
15+
if (specifier.startsWith('file:///') || specifier.startsWith('http://127.0.0.1:')) {
1516
return {
1617
shortCircuit: true,
1718
url: specifier,
@@ -31,3 +32,27 @@ export const resolve = async (specifier, context, nextResolve) => {
3132

3233
return nextResolve(specifier, context)
3334
}
35+
36+
/**
37+
* @type NodeJSLoader.Loader
38+
*/
39+
export const load = (url, context, nextLoad) => {
40+
if (url.startsWith('http://127.0.0.1:')) {
41+
return new Promise((res, rej) => {
42+
get(url, r => {
43+
let content = ''
44+
r.setEncoding('utf8')
45+
r.on('data', c => content += c)
46+
r.on('end', () => {
47+
res({
48+
format: 'module',
49+
shortCircuit: true,
50+
source: content,
51+
})
52+
})
53+
}).on('error', rej)
54+
})
55+
}
56+
57+
return nextLoad(url, context)
58+
}

0 commit comments

Comments
 (0)