Skip to content

Commit

Permalink
update Bun polyfill to use Bun.write and Bun.mkdir instead of nodejs fs
Browse files Browse the repository at this point in the history
  • Loading branch information
Granitosaurus committed Jul 31, 2024
1 parent e35fe2b commit 5afe212
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 292 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"name": "@scrapfly/scrapfly-sdk",
"exports": "./src/main.ts",
"version": "0.6.3",
"version": "0.6.4",
"description": "SDK for Scrapfly.io API for web scraping, screenshotting and data extraction",
"tasks": {
"start": "deno run --allow-net --allow-read src/main.ts",
Expand Down
2 changes: 1 addition & 1 deletion examples/bun/bun_examples.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScrapflyClient, ScrapeConfig, ScreenshotConfig, ExtractionConfig, log } from 'scrapfly-sdk';
import { ScrapflyClient, ScrapeConfig, ScreenshotConfig, ExtractionConfig, log } from '@scrapfly/scrapfly-sdk';
// You can enable debug logs to see more details
log.setLevel('DEBUG');

Expand Down
14 changes: 0 additions & 14 deletions examples/get-account.js

This file was deleted.

249 changes: 0 additions & 249 deletions examples/package-lock.json

This file was deleted.

16 changes: 0 additions & 16 deletions examples/package.json

This file was deleted.

15 changes: 4 additions & 11 deletions src/polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ export async function mkdir(path: string | URL, options: Deno.MkdirOptions): Pro
if (isDeno) {
await Deno.mkdir(path, options);
} else {
// Dynamic import of 'fs' for Node.js/Bun
const fs = await import('fs').then((mod) => mod.promises);
const { recursive } = options;
await fs.mkdir(path.toString(), { recursive: !!recursive });
console.log('Directory created successfully!');
// @ts-ignore: type for Bun
await Bun.mkdir(path.toString(), options);
}
}

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

0 comments on commit 5afe212

Please sign in to comment.