File tree Expand file tree Collapse file tree
packages/tooling/snapshot
src/side_effects/filesystem
tests/dev_and_build/js_module_syntax_error/_js_module_syntax_error_build.test.mjs/0_basic Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " @jsenv/snapshot" ,
3- "version" : " 2.19.4 " ,
3+ "version" : " 2.19.5 " ,
44 "type" : " module" ,
55 "description" : " Snapshot testing" ,
66 "repository" : {
Original file line number Diff line number Diff line change @@ -241,22 +241,26 @@ export const spyFilesystemCalls = (
241241 _internalFs ,
242242 "close" ,
243243 ( fileDescriptor ) => {
244+ // Resolved when close is called, while the descriptor still belongs to
245+ // this file: an asynchronous close frees it in the threadpool before
246+ // its callback runs, and a synchronous open happening in between reuses
247+ // the same number, so a lookup at callback time finds that other file
248+ // (or nothing) and this file's write goes unnoticed.
249+ const filePath = fileDescriptorPathMap . get ( fileDescriptor ) ;
250+ if ( ! filePath ) {
251+ return { } ;
252+ }
253+ fileDescriptorPathMap . delete ( fileDescriptor ) ;
254+ const stateBefore = filesystemStateInfoMap . get ( filePath ) ;
255+ if ( ! stateBefore ) {
256+ return { } ;
257+ }
258+ filesystemStateInfoMap . delete ( filePath ) ;
244259 return {
245260 return : ( buffer ) => {
246- const filePath = fileDescriptorPathMap . get ( fileDescriptor ) ;
247- if ( ! filePath ) {
248- return ;
249- }
250- const stateBefore = filesystemStateInfoMap . get ( filePath ) ;
251- if ( ! stateBefore ) {
252- fileDescriptorPathMap . delete ( fileDescriptor ) ;
253- return ;
254- }
255261 if ( buffer ) {
256262 onReadFile ( filePath ) ;
257263 }
258- fileDescriptorPathMap . delete ( fileDescriptor ) ;
259- filesystemStateInfoMap . delete ( filePath ) ;
260264 const stateAfter = getFileStateWithinHook ( filePath ) ;
261265 onWriteFileDone ( stateBefore , stateAfter ) ;
262266 } ,
Original file line number Diff line number Diff line change @@ -275,8 +275,14 @@ export const createUrlInfoTransformer = ({
275275 writeFileSync ( fileUrl , content , { force : true } ) ;
276276 return undefined ;
277277 }
278+ // keyed by the file on disk: two urls differing by their search params
279+ // ("file.css.map" and "file.css.map?side_effect") land in the same file,
280+ // and two writes racing on it would interleave their bytes
281+ const filePath = isFileSystemPath ( fileUrl )
282+ ? fileUrl
283+ : urlToFileSystemPath ( fileUrl ) ;
278284 const previousWritePromise =
279- pendingWritePromiseMap . get ( fileUrl ) || Promise . resolve ( ) ;
285+ pendingWritePromiseMap . get ( filePath ) || Promise . resolve ( ) ;
280286 const writePromise = previousWritePromise . then ( async ( ) => {
281287 try {
282288 await writeFile ( fileUrl , content ) ;
@@ -289,10 +295,10 @@ export const createUrlInfoTransformer = ({
289295 }
290296 }
291297 } ) ;
292- pendingWritePromiseMap . set ( fileUrl , writePromise ) ;
298+ pendingWritePromiseMap . set ( filePath , writePromise ) ;
293299 writePromise . then ( ( ) => {
294- if ( pendingWritePromiseMap . get ( fileUrl ) === writePromise ) {
295- pendingWritePromiseMap . delete ( fileUrl ) ;
300+ if ( pendingWritePromiseMap . get ( filePath ) === writePromise ) {
301+ pendingWritePromiseMap . delete ( filePath ) ;
296302 }
297303 } ) ;
298304 return writePromise ;
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ Unexpected token (4:15)
1717base/client/main.html:9:27
1818--- plugin name ---
1919"jsenv:js_reference_analysis"
20- at async @jsenv/core/src/kitchen/kitchen.js:661 :11
21- at async @jsenv/core/src/kitchen/kitchen.js:647 :9
20+ at async @jsenv/core/src/kitchen/kitchen.js:666 :11
21+ at async @jsenv/core/src/kitchen/kitchen.js:651 :9
2222```
2323
2424---
You can’t perform that action at this time.
0 commit comments