17
17
import fs from 'fs' ;
18
18
import url from 'url' ;
19
19
20
- import { monotonicTime , raceAgainstDeadline } from 'playwright-core/lib/utils' ;
21
-
22
20
import { addToCompilationCache , currentFileDepsCollector , serializeCompilationCache , startCollectingFileDeps , stopCollectingFileDeps } from './compilationCache' ;
23
21
import { PortTransport } from './portTransport' ;
24
22
import { resolveHook , setSingleTSConfig , setTransformConfig , shouldTransform , transformHook } from './transform' ;
25
- import { debugTest , fileIsModule } from '../util' ;
26
-
27
- // See note on pushToCompilationCache()
28
- // Once we enter a deadlock scenario, we will fallback to unawaited IPC
29
- let workerShouldFallbackCompilationCache = false ;
23
+ import { fileIsModule } from '../util' ;
30
24
31
25
// Node < 18.6: defaultResolve takes 3 arguments.
32
26
// Node >= 18.6: nextResolve from the chain takes 2 arguments.
@@ -60,7 +54,7 @@ const kSupportedFormats = new Map([
60
54
61
55
// Node < 18.6: defaultLoad takes 3 arguments.
62
56
// Node >= 18.6: nextLoad from the chain takes 2 arguments.
63
- async function load ( moduleUrl : string , context : { format ?: string } , defaultLoad : Function ) {
57
+ function load ( moduleUrl : string , context : { format ?: string } , defaultLoad : Function ) {
64
58
// Bail out for wasm, json, etc.
65
59
if ( ! kSupportedFormats . has ( context . format ) )
66
60
return defaultLoad ( moduleUrl , context , defaultLoad ) ;
@@ -79,7 +73,7 @@ async function load(moduleUrl: string, context: { format?: string }, defaultLoad
79
73
80
74
// Flush the source maps to the main thread, so that errors during import() are source-mapped.
81
75
if ( transformed . serializedCache && transport )
82
- await pushToCompilationCache ( transport , transformed . serializedCache ) ;
76
+ transport . post ( 'pushToCompilationCache' , { cache : transformed . serializedCache } ) ;
83
77
84
78
// Output format is required, so we determine it manually when unknown.
85
79
// shortCircuit is required by Node >= 18.6 to designate no more loaders should be called.
@@ -90,23 +84,6 @@ async function load(moduleUrl: string, context: { format?: string }, defaultLoad
90
84
} ;
91
85
}
92
86
93
- // Under certain conditions with ESM -> CJS -> any imports, we can enter deadlock awaiting the
94
- // MessagePort transfer simultaneously with the Node.js worker thread that is performing the load().
95
- // Attempt to await the IPC transfer, and if it takes too long, fallback to a non-awaiting transfer
96
- async function pushToCompilationCache ( transport : PortTransport , cache : any ) {
97
- if ( workerShouldFallbackCompilationCache ) {
98
- transport . send ( 'pushToCompilationCache' , { cache } )
99
- . catch ( e => debugTest ( 'Failed to push compilation cache' , e ) ) ;
100
- return ;
101
- }
102
-
103
- const { timedOut } = await raceAgainstDeadline ( ( ) => transport . send ( 'pushToCompilationCache' , { cache } ) , monotonicTime ( ) + 1000 ) ;
104
- if ( timedOut ) {
105
- debugTest ( 'Falling back to unawaited compilation cache' ) ;
106
- workerShouldFallbackCompilationCache = true ;
107
- }
108
- }
109
-
110
87
let transport : PortTransport | undefined ;
111
88
112
89
function initialize ( data : { port : MessagePort } ) {
0 commit comments