Skip to content

refactor: replace globby with faster alternative - #1158

Merged
sxzz merged 2 commits into
egoist:devfrom
SuperchupuDev:refactor/globby-but-fast
Jul 19, 2024
Merged

sxzz merged 2 commits into
egoist:devfrom
SuperchupuDev:refactor/globby-but-fast

Conversation

@SuperchupuDev

@SuperchupuDev SuperchupuDev commented Jul 17, 2024 •

Copy link
Copy Markdown
Contributor

globby has a count of 23 subdependencies, which is far from ideal for something as simple as globbing. This PR switches to a lighter and faster alternative using fdir and picomatch. They have both a total of zero (0) subdependencies, making this not just a faster approach, but also one that's way lighter.

This makes tsup go from 102 subdependencies down to just 88.

Note: The patterns at

tsup/src/utils.ts

Lines 69 to 77 in 57a372b

const matchPatterns: string[] = []
const ignorePatterns: string[] = []
for (const pattern of patterns) {
if (pattern.startsWith('!') && pattern[1] !== '(') {
ignorePatterns.push(pattern.slice(1))
} else {
matchPatterns.push(pattern)
}
}
are filtered this way to properly match what globby (or more specifically, fast-glob which is used by globby) does. It has some behavior around negated patterns no other globbing library has.

Relevant prior work: dotenvx/dotenvx#278

@codesandbox

codesandbox Bot commented Jul 17, 2024

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web Editor • VS Code • Insiders

Open Preview

@vercel

vercel Bot commented Jul 17, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tsup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 19, 2024 2:53pm

@SuperchupuDev

SuperchupuDev commented Jul 17, 2024 •

Copy link
Copy Markdown
Contributor Author

tests are failing on windows but not on linux...weird

@sxzz

sxzz commented Jul 19, 2024 •

Copy link
Copy Markdown
Collaborator

I think we can use fdir and picomatch to create a new library for lightweight glob, enhancing maintainability.

@SuperchupuDev

SuperchupuDev commented Jul 19, 2024 •

Copy link
Copy Markdown
Contributor Author

the implementation here isnt big really, there's a pr in fdir to add a glob function method though (requiring a matcher function) that maybe could be used in the future. i dont really see a need of making it a lib if sometimes fdir is called in a way picomatch (therefore globbing) isnt even needed

@sxzz
sxzz merged commit 0f0b4b2 into egoist:dev Jul 19, 2024
@SuperchupuDev
SuperchupuDev deleted the refactor/globby-but-fast branch July 19, 2024 15:05
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This issue has been resolved in version 8.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lenovouser

Copy link
Copy Markdown

I am getting this now after upgrading to 8.2.1

Screenshot 2024-07-21 at 11 47 51

@SuperchupuDev

SuperchupuDev commented Jul 21, 2024 •

Copy link
Copy Markdown
Contributor Author

i am aware, when conflicts were solved, it looks like picomatch was updated to v4 which fdir's package.json doesn't allow. to fix this tsup must downgrade to picomatch v3 or fdir must release a new version which contains a fix i submitted a few days ago thecodrr/fdir#101

This branch was successfully deployed

1 active deployment
Preview — ff3acc0e Deployed Jul 19, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants