tinyglobby migration guide

General tips

Try to avoid crawling outside the cwd, as doing that makes tinyglobby use a path calculation algorithm that's considerably slower. This also applies when enabling the absolute option.

See cwd's documentation for more details.

Switching from globby

tinyglobby aims to be a drop-in replacement to globby for the vast majority of use cases. You won't need to change anything most of the time. Since globby is a wrapper of fast-glob, you might want to also check out the switching from fast-glob section.

gitignore

globby has a gitignore option that makes gitignored files get excluded from the results. tinyglobby does not implement this option as it's barely used and it would take an increase in dependencies to add. It's also apparently really slow in globby.

To make tinyglobby exclude gitignored files, you can use the following workaround by taking advantage of git's ls-files command:

import { execSync } from 'node:child_process';
import { glob, escapePath } from 'tinyglobby';

async function globWithGitignore(patterns, options = {}) {
  const { cwd = process.cwd(), ...restOptions } = options;

  try {
    const gitIgnored = execSync(
      'git ls-files --others --ignored --exclude-standard --directory',
      { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
    )
    .split('\n')
    .filter(Boolean)
    .map(p => escapePath(p));

    return glob(patterns, {
      ...restOptions,
      cwd,
      ignore: [...(restOptions.ignore || []), ...gitIgnored]
    });
  } catch {
    return glob(patterns, options);
  }
}
Thank you outslept for contributing this snippet.

Switching from fast-glob

expandDirectories

You should disable the expandDirectories option. It's only there for compatibility with globby. I've seen almost everyone switching from fast-glob forget to do this. In 99% of cases, you want this off, unless you want to recreate how globby works. Looking back this option should probably have been disabled by default.

Before:
import { glob } from 'fast-glob';

await glob('src/*.ts');
After:
import { glob } from 'tinyglobby';

await glob('src/*.ts', {
  expandDirectories: false
});

deep

This option works in a different way than fast-glob. See the library comparison page for an in-depth explanation of how the implementations differ.

fs

tinyglobby's fs option accepts different functions as fast-glob, you might need to change your usage to account for this.

Currently, the only difference in the object is that instead of accepting an lstat function, it accepts a realpath function instead.

A migration can look like this:

Before:
import { glob } from 'fast-glob';

await glob('src/*.ts', {
  fs: {
    lstat: myFs.lstat,
    readdir: myFs.readdir,
    stat: myFs.stat
  }
});
After:
import { glob } from 'tinyglobby';

await glob('src/*.ts', {
  expandDirectories: false,
  fs: {
    realpath: myFs.realpath,
    readdir: myFs.readdir,
    stat: myFs.stat
  }
});