Skip to content

Overhaul crawler options building and handling - #174

Merged
SuperchupuDev merged 8 commits into
SuperchupuDev:mainfrom
Torathion:fdir-overhaul
Nov 20, 2025
Merged

Overhaul crawler options building and handling#174
SuperchupuDev merged 8 commits into
SuperchupuDev:mainfrom
Torathion:fdir-overhaul

Conversation

@Torathion

Copy link
Copy Markdown
Contributor

Goal

The goal of this PR is to reduce duplicate logic of building and handling the Crawler by reusing harmonizing flags and be more resilient to the result of getCrawler.

Why

This change is necessary out of three reasons:

  • Reducing duplicate code
  • Easing maintenance and future updates
  • Removing duplicate type checks and assignments of options

Instead of explicitly setting flags based on the given options, we reuse flags that logically harmonize states of fdir.

What has changed

  • Overhauled types by introducing the types Crawler, ProcessedPatterns and RelativeMapper and stricten types by adding explicit return types to some functions.
  • Outsourced functions and logic related only to the Crawler into an extra file for easier project maintenance.
  • Overhauled fdir options by reusing harmonizing GlobOptions options.
  • Introduced an internal function inside buildCrawler as ExcludePredicate under the assumption developers with debug: true don't have performance as their highest priority (yes, this impacts debugging performance very minimally)
  • Made formatPaths more resilent by always entering the function upon getCrawler result.
  • Instead of noop functions on empty patterns to crawl, we now handle an undefined Crawler and RelativeMapper.
  • commonPath inside InternalProps has been changed from null to undefined to reduce code.

Metrics

From Part 2 (#170) to Part 3, we now have an even further reduction

Before All:

ℹ [CJS] dist\index.cjs      14.22 kB │ gzip: 4.32 kB
ℹ [CJS] dist\index.cjs.map  26.15 kB │ gzip: 7.76 kB
ℹ [CJS] 2 files, total: 40.37 kB
ℹ [ESM] dist\index.mjs      12.92 kB │ gzip: 3.85 kB
ℹ [ESM] dist\index.mjs.map  26.09 kB │ gzip: 7.73 kB
ℹ [ESM] dist\index.d.mts     4.70 kB │ gzip: 1.62 kB
ℹ [ESM] 3 files, total: 43.71 kB
ℹ [CJS] dist\index.d.cts  4.70 kB │ gzip: 1.62 kB
ℹ [CJS] 1 files, total: 4.70 kB

After Part 2 (#170) [CURRENT]:

ℹ [CJS] dist\index.cjs      13.76 kB │ gzip: 4.42 kB
ℹ [CJS] dist\index.cjs.map  26.59 kB │ gzip: 8.23 kB
ℹ [CJS] 2 files, total: 40.35 kB
ℹ [ESM] dist\index.mjs      12.49 kB │ gzip: 3.97 kB
ℹ [ESM] dist\index.mjs.map  26.53 kB │ gzip: 8.19 kB
ℹ [ESM] dist\index.d.mts     4.70 kB │ gzip: 1.62 kB
ℹ [ESM] 3 files, total: 43.72 kB
ℹ [CJS] dist\index.d.cts  4.70 kB │ gzip: 1.62 kB
ℹ [CJS] 1 files, total: 4.70 kB

After this Part:

ℹ [CJS] dist\index.cjs      13.40 kB │ gzip: 4.41 kB
ℹ [CJS] dist\index.cjs.map  26.77 kB │ gzip: 8.40 kB
ℹ [CJS] 2 files, total: 40.17 kB
ℹ [ESM] dist\index.mjs      12.14 kB │ gzip: 3.96 kB
ℹ [ESM] dist\index.mjs.map  26.71 kB │ gzip: 8.34 kB
ℹ [ESM] dist\index.d.mts     4.70 kB │ gzip: 1.62 kB
ℹ [ESM] 3 files, total: 43.54 kB
ℹ [CJS] dist\index.d.cts  4.70 kB │ gzip: 1.62 kB
ℹ [CJS] 1 files, total: 4.70 kB

Total shipped sizes

Before all: 14.22KB + 12.92KB + 4.7KB + 4.7KB = 36.54KB
After part 2: 13.76 KB + 12.49 kB + 4.70 kB + 4.70 kB = 35.65 kB
After this part: 13.40 KB + 12.14 KB + 4.7 KB + 4.7 KB = 34.94 KB

This is a bundle size reduction of 1.6 KB (4.3%) and saves 60.8 GB (38 million weekly downloads) of weekly traffic.


This PR is a split part of the closed PR #88, which grew too much in scope and changes.

@pkg-pr-new

pkg-pr-new Bot commented Nov 15, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/tinyglobby@174

commit: cfa10ee

@Torathion

Torathion commented Nov 15, 2025

Copy link
Copy Markdown
Contributor Author

I'm a bit unhappy with this part in getCrawler:

  const cwd = options.cwd as string;

  if (Array.isArray(patterns) && patterns.length === 0) {
    return [];
  }

  const props: InternalProps = { root: cwd, depthOffset: 0 };
  return buildCrawler(props, options, processPatterns(options, patterns, props), cwd);

I want to separate the concerns of each step of tinyglobby to better manage this growing project, but with the entire pattern processing in index, I had to resort to write it a bit larger. I'm thinking about outsourcing processPatterns either into crawler.ts or its own file so we only have to pass options into buildCrawler.

@SuperchupuDev SuperchupuDev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two small nits, other than that lgtm!!! you're doing an amazing cleanup work ❤️

Comment thread src/index.ts
Comment thread src/utils.ts

@SuperchupuDev SuperchupuDev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@SuperchupuDev
SuperchupuDev merged commit d7827be into SuperchupuDev:main Nov 20, 2025
8 checks passed
@Torathion
Torathion deleted the fdir-overhaul branch November 20, 2025 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants