Fix FilePathSource/FilePathTarget not working in server-side environments using CJS (closes #360)

This commit is contained in:
Vanilagy
2026-04-27 18:29:52 +02:00
parent 15beb69137
commit c89e7429f7
4 changed files with 12 additions and 4 deletions
+7 -1
View File
@@ -692,12 +692,18 @@ export class FilePathTarget extends Target {
throw new TypeError('options must be an object.');
}
if (!node.getFs) {
throw new Error(
'FilePathTarget is only available in server-side environments (Node.js, Bun, Deno).',
);
}
super();
// Let's back this target with a StreamTarget, makes the implementation very simple
const writable = new WritableStream<StreamTargetChunk>({
start: async () => {
this._fileHandle = await node.fs.open(filePath, 'w');
this._fileHandle = await (await node.getFs()).open(filePath, 'w');
},
write: async (chunk) => {
assert(this._fileHandle);