Skip to content

Commit 7897ce7

Browse files
committed
fix: windows cannot rename the file
1 parent 9f68d89 commit 7897ce7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cmp/compiler/src/metadata/manager.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ export class MetadataManager {
119119
DEFAULT_TIMEOUTS.METADATA,
120120
"Save metadata (atomic rename)",
121121
);
122+
} catch (error) {
123+
// On Windows, rename() can fail with EPERM if something briefly holds the file.
124+
// As a fallback, try writing directly to the destination (not atomic).
125+
if (
126+
error &&
127+
typeof error === "object" &&
128+
"code" in error &&
129+
error.code === "EPERM"
130+
) {
131+
await withTimeout(
132+
fsPromises.writeFile(this.filePath, json, "utf-8"),
133+
DEFAULT_TIMEOUTS.METADATA,
134+
"Save metadata (EPERM fallback direct write)",
135+
);
136+
return;
137+
}
138+
throw error;
122139
} finally {
123140
// Best-effort cleanup if rename failed for some reason
124141
await fsPromises.unlink(tmpPath).catch(() => {});

0 commit comments

Comments
 (0)