mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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;
|
||||
}
|
||||
|
||||
try {
|
||||
const fs = await importFSPromises();
|
||||
const fs = await importFSPromises();
|
||||
|
||||
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;
|
||||
}
|
||||
await fs.writeFile(path, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -883,17 +883,7 @@ export class Frame {
|
||||
}
|
||||
|
||||
if (path) {
|
||||
let fs: typeof import('fs/promises');
|
||||
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;
|
||||
}
|
||||
const fs = await importFSPromises();
|
||||
|
||||
content = await fs.readFile(path, 'utf8');
|
||||
content += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/';
|
||||
|
@ -369,7 +369,16 @@ export async function importFSPromises(): Promise<
|
||||
typeof import('fs/promises')
|
||||
> {
|
||||
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;
|
||||
}
|
||||
@ -383,17 +392,7 @@ export async function getReadableAsBuffer(
|
||||
): Promise<Buffer | null> {
|
||||
const buffers = [];
|
||||
if (path) {
|
||||
let fs: typeof import('fs/promises');
|
||||
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 fs = await importFSPromises();
|
||||
const fileHandle = await fs.open(path, 'w+');
|
||||
for await (const chunk of readable) {
|
||||
buffers.push(chunk);
|
||||
|
Loading…
Reference in New Issue
Block a user