Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
perf: lazy-load `file-type` and `csv-stringify` (#3989)
Jindřich Bär60c4b55491ad
diff --git a/packages/basic-crawler/src/internals/basic-crawler.ts b/packages/basic-crawler/src/internals/basic-crawler.tsindex 6e7dece43..b42bdf55b 100644--- a/packages/basic-crawler/src/internals/basic-crawler.ts+++ b/packages/basic-crawler/src/internals/basic-crawler.ts@@ -88,7 +88,6 @@ import type {StorageBackend,} from '@crawlee/types';import { isAsyncIterable, isIterable, RobotsTxtFile, ROTATE_PROXY_ERRORS } from '@crawlee/utils';-import { stringify } from 'csv-stringify/sync';import ow, { ArgumentError, type BasePredicate } from 'ow';import { getDomain } from 'tldts';import type { ReadonlyDeep, SetRequired } from 'type-fest';@@ -2044,6 +2043,8 @@ export class BasicCrawler<? Array.from(new Set(items.flatMap(Object.keys))): Object.keys(items[0]);+ const { stringify } = await import('csv-stringify/sync');+value = stringify([keys,...items.map((item) => {diff --git a/packages/core/src/storages/dataset.ts b/packages/core/src/storages/dataset.tsindex 4d46b321b..3ebd767a5 100644--- a/packages/core/src/storages/dataset.ts+++ b/packages/core/src/storages/dataset.ts@@ -1,5 +1,4 @@import type { Awaitable, DatasetBackend, DatasetInfo, Dictionary, PaginatedList } from '@crawlee/types';-import { stringify } from 'csv-stringify/sync';import ow from 'ow';import { tryCancel } from '@apify/timeout';@@ -410,6 +409,8 @@ export class Dataset<Data extends Dictionary = Dictionary> {? Array.from(new Set(items.flatMap(Object.keys))): Object.keys(items[0]);+ const { stringify } = await import('csv-stringify/sync');+const value = stringify([keys,...items.map((item) => {diff --git a/packages/utils/src/internals/sitemap.ts b/packages/utils/src/internals/sitemap.tsindex ffaaf276a..7934d4a60 100644--- a/packages/utils/src/internals/sitemap.ts+++ b/packages/utils/src/internals/sitemap.ts@@ -6,7 +6,6 @@ import { createGunzip } from 'node:zlib';import { FetchHttpClient } from '@crawlee/http-client';import type { BaseHttpClient, CrawleeLogger } from '@crawlee/types';-import { fileTypeStream } from 'file-type';import sax from 'sax';import MIMEType from 'whatwg-mimetype';@@ -309,6 +308,7 @@ export async function* parseSitemap<T extends ParseSitemapOptions>(if (sitemapResponse.body === null) {break;}+ const { fileTypeStream } = await import('file-type');const streamWithType = await fileTypeStream(Readable.fromWeb(sitemapResponse.body as any));if (streamWithType.fileType !== undefined) {contentType = streamWithType.fileType.mime;