Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Synchronous support #81

Open
lokimckay opened this issue Nov 19, 2021 · 2 comments
Open

[Feature request] Synchronous support #81

lokimckay opened this issue Nov 19, 2021 · 2 comments

Comments

@lokimckay
Copy link

lokimckay commented Nov 19, 2021

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 lokimckay changed the title [Feature request] Synchronous support? [Feature request] Synchronous support Nov 19, 2021
@lokimckay
Copy link
Author

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

@StephanBijzitter
Copy link

StephanBijzitter commented Jan 11, 2022

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) => ({
    ...
  }));
})();

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

No branches or pull requests

2 participants