tiny-glob icon indicating copy to clipboard operation
tiny-glob copied to clipboard

[Feature request] Synchronous support

Open lokimckay opened this issue 2 years ago • 2 comments

Is it possible to execute tiny-glob synchronously?

My specific use case is in a rollup.config.js file, I need to execute tiny-glob to retrieve a list of file paths, and then use those paths to export a config object. E.g.:

import glob from "tiny-glob";

const components = await glob("src/components/**/*.component.js").then((paths) =>
  paths.map((path) => path.match(/.*[\\\/](.*?).component.js/)[1])
);

export default components.map((component) => ({
  ...
}));

But rollup does not play nice with the await keyword being used

Is there a way to run tiny-glob synchronously? and if not, would this feature be considered for inclusion?

lokimckay avatar Nov 19 '21 04:11 lokimckay

For future readers, I reluctantly worked around this issue by switching to this heavier lib fast-glob

lokimckay avatar Nov 27 '21 15:11 lokimckay

in the specfic case of rollup, this should work just fine:

(code taken from OP and modified minimally):

import glob from "tiny-glob";

export default (async () => {
  const components = await glob("src/components/**/*.component.js").then((paths) =>
    paths.map((path) => path.match(/.*[\\\/](.*?).component.js/)[1])
  );
  
  return components.map((component) => ({
    ...
  }));
})();

StephanBijzitter avatar Jan 11 '22 13:01 StephanBijzitter