Skip to content

Commit 21f3bed

Browse files
authored
Issue/61 (#62)
* feat: add global readFile method * chore: add changeset
1 parent 9e0ac3a commit 21f3bed

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

.changeset/sixty-laws-draw.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@heymp/scratchpad": minor
3+
---
4+
5+
Add global readFile method
6+
7+
Example
8+
9+
```js
10+
await readFile('./log.txt', 'utf8');
11+
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ To send log information from the Chromium browser to node.js we expose the follo
7070
| clear | Clear the previous console output results. | `clear()` |
7171
| writeFile | Write data to a local file. | `writeFile('./log.txt', data)` |
7272
| appendFile | Append data to a local file. | `appendFile('./log.txt', data)` |
73+
| readFile | read data from a local file. | `readFile('./log.txt', 'utf8')` |
7374

7475

7576
Example

src/browser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ function appendFile(path: string, data: any) {
1818
return fs.appendFile(join(process.cwd(), path), data);
1919
}
2020

21+
function readFile(...args: Parameters<typeof fs.readFile>) {
22+
return fs.readFile(...args);
23+
}
2124

2225
export async function browser(processor: Processor) {
2326
// Launch the browser
@@ -32,6 +35,7 @@ export async function browser(processor: Processor) {
3235
// Exposed functions
3336
await context.exposeFunction('writeFile', writeFile);
3437
await context.exposeFunction('appendFile', appendFile);
38+
await context.exposeFunction('readFile', readFile);
3539
await context.exposeFunction('nodelog', (...value: any) => {
3640
console.log(...value);
3741
});

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ async function importConfig(): Promise<Partial<Config>> {
5454
format: 'esm',
5555
bundle: true,
5656
write: false,
57+
platform: 'node'
5758
});
5859
const contents = new TextDecoder().decode(stdout.contents);
5960
const module = await import(esm`${contents}`);

0 commit comments

Comments
 (0)