Skip to content

Commit 5afe212

Browse files
committed
update Bun polyfill to use Bun.write and Bun.mkdir instead of nodejs fs
1 parent e35fe2b commit 5afe212

File tree

6 files changed

+6
-292
lines changed

6 files changed

+6
-292
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
},
55
"name": "@scrapfly/scrapfly-sdk",
66
"exports": "./src/main.ts",
7-
"version": "0.6.3",
7+
"version": "0.6.4",
88
"description": "SDK for Scrapfly.io API for web scraping, screenshotting and data extraction",
99
"tasks": {
1010
"start": "deno run --allow-net --allow-read src/main.ts",

examples/bun/bun_examples.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ScrapflyClient, ScrapeConfig, ScreenshotConfig, ExtractionConfig, log } from 'scrapfly-sdk';
1+
import { ScrapflyClient, ScrapeConfig, ScreenshotConfig, ExtractionConfig, log } from '@scrapfly/scrapfly-sdk';
22
// You can enable debug logs to see more details
33
log.setLevel('DEBUG');
44

examples/get-account.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/package-lock.json

Lines changed: 0 additions & 249 deletions
This file was deleted.

examples/package.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/polyfill.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ export async function mkdir(path: string | URL, options: Deno.MkdirOptions): Pro
44
if (isDeno) {
55
await Deno.mkdir(path, options);
66
} else {
7-
// Dynamic import of 'fs' for Node.js/Bun
8-
const fs = await import('fs').then((mod) => mod.promises);
9-
const { recursive } = options;
10-
await fs.mkdir(path.toString(), { recursive: !!recursive });
11-
console.log('Directory created successfully!');
7+
// @ts-ignore: type for Bun
8+
await Bun.mkdir(path.toString(), options);
129
}
1310
}
1411

@@ -20,11 +17,7 @@ export async function writeFile(
2017
if (isDeno) {
2118
await Deno.writeFile(path, data, options);
2219
} else {
23-
// Dynamic import of 'fs' for Node.js/Bun
24-
const fs = await import('fs').then((mod) => mod.promises);
25-
await fs.writeFile(path.toString(), data, {
26-
encoding: 'utf-8',
27-
flag: options.append ? 'a' : 'w',
28-
});
20+
// @ts-ignore: type for Bun
21+
await Bun.write(path.toString(), data, options);
2922
}
3023
}

0 commit comments

Comments
 (0)