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

feat: Make import.meta.glob and import.meta.globEager generic #5073

Merged
merged 5 commits into from
Feb 12, 2022

Conversation

michaeloliverx
Copy link
Contributor

This is my first PR so my apologies if I have done anything wrong.

Description

It would be useful if import.meta.glob and import.meta.globEager were generic functions. This change will allow users to do stuff like this:

import readingTime from "reading-time";

export type PostFrontmatter = {
  title?: string;
  description?: string;
  publishDate?: string;
  isPublished?: boolean;
};

type PostModule = {
  metadata: PostFrontmatter;
  default: { render: () => { html: string; css: string; head: string } };
};

const modules = import.meta.globEager<PostModule>("/content/blog/**/*.svx");
const postsMetadata = Object.entries(modules).map(([path, module]) => {
  // `module` is is now `PostModule` type
  const { metadata } = module;
  const { html } = module.default.render();
});

Additional context

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@michaeloliverx michaeloliverx changed the title Make import.meta.glob and import.meta.globEager generic feat: Make import.meta.glob and import.meta.globEager generic Sep 24, 2021
@Shinigami92 Shinigami92 added the p2-nice-to-have Not breaking anything but nice to have (priority) label Sep 27, 2021
Shinigami92
Shinigami92 previously approved these changes Sep 28, 2021
@Shinigami92
Copy link
Member

@patak-js seems we have flaky tests again 😭
The changes shouldn't have any effects on the failed tests, especially not for windows only 👀

@michaeloliverx
Copy link
Contributor Author

At the risk of this going stale let me know if there is anything else I can do for this PR 😄

@patak-dev patak-dev merged commit 78e84c8 into vitejs:main Feb 12, 2022
@patak-dev
Copy link
Member

Thanks for the PR @michaeloliverx, sorry this one took us so long

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants