chore: importFs handles it's own error (#9971)
This commit is contained in:
parent
0b1e20cf5b
commit
327febe2c9
@ -2116,18 +2116,9 @@ export class Page extends EventEmitter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const fs = await importFSPromises();
|
||||||
const fs = await importFSPromises();
|
|
||||||
|
|
||||||
await fs.writeFile(path, buffer);
|
await fs.writeFile(path, buffer);
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof TypeError) {
|
|
||||||
throw new Error(
|
|
||||||
'Can only pass a file path in a Node-like environment.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -883,17 +883,7 @@ export class Frame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
let fs: typeof import('fs/promises');
|
const fs = await importFSPromises();
|
||||||
try {
|
|
||||||
fs = await importFSPromises();
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof TypeError) {
|
|
||||||
throw new Error(
|
|
||||||
'Can only pass a file path in a Node-like environment.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
content = await fs.readFile(path, 'utf8');
|
content = await fs.readFile(path, 'utf8');
|
||||||
content += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/';
|
content += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/';
|
||||||
|
@ -369,7 +369,16 @@ export async function importFSPromises(): Promise<
|
|||||||
typeof import('fs/promises')
|
typeof import('fs/promises')
|
||||||
> {
|
> {
|
||||||
if (!fs) {
|
if (!fs) {
|
||||||
fs = await import('fs/promises');
|
try {
|
||||||
|
fs = await import('fs/promises');
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof TypeError) {
|
||||||
|
throw new Error(
|
||||||
|
'Cannot write to a path outside of a Node-like environment.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
@ -383,17 +392,7 @@ export async function getReadableAsBuffer(
|
|||||||
): Promise<Buffer | null> {
|
): Promise<Buffer | null> {
|
||||||
const buffers = [];
|
const buffers = [];
|
||||||
if (path) {
|
if (path) {
|
||||||
let fs: typeof import('fs/promises');
|
const fs = await importFSPromises();
|
||||||
try {
|
|
||||||
fs = await importFSPromises();
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof TypeError) {
|
|
||||||
throw new Error(
|
|
||||||
'Cannot write to a path outside of a Node-like environment.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
const fileHandle = await fs.open(path, 'w+');
|
const fileHandle = await fs.open(path, 'w+');
|
||||||
for await (const chunk of readable) {
|
for await (const chunk of readable) {
|
||||||
buffers.push(chunk);
|
buffers.push(chunk);
|
||||||
|
Loading…
Reference in New Issue
Block a user