Skip to content

Commit 2d64283

Browse files
committed
work
1 parent 8feeb67 commit 2d64283

4 files changed

Lines changed: 28 additions & 18 deletions

File tree

packages/tooling/snapshot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jsenv/snapshot",
3-
"version": "2.19.4",
3+
"version": "2.19.5",
44
"type": "module",
55
"description": "Snapshot testing",
66
"repository": {

packages/tooling/snapshot/src/side_effects/filesystem/spy_filesystem_calls.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff 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
},

src/kitchen/url_graph/url_info_transformations.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff 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;

tests/dev_and_build/js_module_syntax_error/_js_module_syntax_error_build.test.mjs/0_basic/0_basic.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Unexpected token (4:15)
1717
base/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
---

0 commit comments

Comments
 (0)