-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat!: remove Astro.glob #14421
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
Merged
Merged
feat!: remove Astro.glob #14421
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3038d33
feat: e2e
florian-lefebvre 7adc7e2
feat: remove Astro.glob mentions
florian-lefebvre 5427d65
feat: remove glob
florian-lefebvre 1cf1dd0
Merge branch 'next' into feat/remove-astro-glob
florian-lefebvre 6abba64
Merge branch 'next' into feat/remove-astro-glob
florian-lefebvre 6e615d3
Merge branch 'next' into feat/remove-astro-glob
florian-lefebvre 1a3fcb9
chore: remove unused deps
florian-lefebvre f70277e
chore: changeset
florian-lefebvre 8d7a084
Discard changes to packages/astro/src/core/errors/errors-data.ts
florian-lefebvre ab15391
feat: deprecate errors
florian-lefebvre 416efed
Merge branch 'next' into feat/remove-astro-glob
florian-lefebvre aefc987
Merge branch 'next' into feat/remove-astro-glob
florian-lefebvre a703728
Merge branch 'next' into feat/remove-astro-glob
florian-lefebvre 105c419
Deprecate Astro.glob() in favor of import.meta.glob()
florian-lefebvre 3ab9fee
Merge branch 'next' into feat/remove-astro-glob
florian-lefebvre ea7635d
Update .changeset/kind-pears-behave.md
florian-lefebvre 54a220c
Apply suggestions from code review
florian-lefebvre 93c0a3a
feat: update template
florian-lefebvre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| 'astro': major | ||
| --- | ||
|
|
||
| Removes `Astro.glob()` | ||
|
|
||
| In Astro 5.0, `Astro.glob()` was deprecated in favor of using `getCollection()` to query your collections, and `import.meta.glob()` to query other source files in your project. | ||
|
|
||
| Astro 6.0 removes `Astro.glob()` entirely. Update to `import.meta.glob()` to keep your current behavior. | ||
|
|
||
| #### What should I do? | ||
|
|
||
| Replace all use of `Astro.glob()` with `import.meta.glob()`. Note that `import.meta.glob()` no longer returns a `Promise`, so you may have to update your code accordingly. You should not require any updates to your glob patterns. | ||
|
|
||
| ```astro | ||
| --- | ||
| // src/pages/blog.astro | ||
| -const posts = await Astro.glob('./posts/*.md'); | ||
| +const posts = Object.values(import.meta.glob('./posts/*.md', { eager: true })); | ||
| --- | ||
| {posts.map((post) => <li><a href={post.url}>{post.frontmatter.title}</a></li>)} | ||
| ``` | ||
|
|
||
| Where appropriate, consider using content collections to organize your content, which has its own newer, more performant querying functions. | ||
|
|
||
| You may also wish to consider using glob packages from NPM, such as `fast-glob`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
packages/astro/e2e/fixtures/errors/src/components/AstroGlobOutsideAstro.js
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
packages/astro/e2e/fixtures/errors/src/pages/astro-glob-no-match.astro
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
packages/astro/e2e/fixtures/errors/src/pages/astro-glob-outside-astro.astro
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,11 @@ | ||
| import { ASTRO_VERSION } from '../../core/constants.js'; | ||
| import { AstroError, AstroErrorData } from '../../core/errors/index.js'; | ||
| import type { AstroGlobalPartial } from '../../types/public/context.js'; | ||
|
|
||
| /** Create the Astro.glob() runtime function. */ | ||
| function createAstroGlobFn() { | ||
| const globHandler = (importMetaGlobResult: Record<string, any>) => { | ||
| // This is created inside of the runtime so we don't have access to the Astro logger. | ||
| console.warn(`Astro.glob is deprecated and will be removed in a future major version of Astro. | ||
| Use import.meta.glob instead: https://vitejs.dev/guide/features.html#glob-import`); | ||
|
|
||
| if (typeof importMetaGlobResult === 'string') { | ||
| throw new AstroError({ | ||
| ...AstroErrorData.AstroGlobUsedOutside, | ||
| message: AstroErrorData.AstroGlobUsedOutside.message(JSON.stringify(importMetaGlobResult)), | ||
| }); | ||
| } | ||
| let allEntries = [...Object.values(importMetaGlobResult)]; | ||
| if (allEntries.length === 0) { | ||
| throw new AstroError({ | ||
| ...AstroErrorData.AstroGlobNoMatch, | ||
| message: AstroErrorData.AstroGlobNoMatch.message(JSON.stringify(importMetaGlobResult)), | ||
| }); | ||
| } | ||
| // Map over the `import()` promises, calling to load them. | ||
| return Promise.all(allEntries.map((fn) => fn())); | ||
| }; | ||
| // Cast the return type because the argument that the user sees (string) is different from the argument | ||
| // that the runtime sees post-compiler (Record<string, Module>). | ||
| return globHandler as unknown as AstroGlobalPartial['glob']; | ||
| } | ||
|
|
||
| // This is used to create the top-level Astro global; the one that you can use | ||
| // inside of getStaticPaths. See the `astroGlobalArgs` option for parameter type. | ||
| export function createAstro(site: string | undefined): AstroGlobalPartial { | ||
| return { | ||
| site: site ? new URL(site) : undefined, | ||
| generator: `Astro v${ASTRO_VERSION}`, | ||
| glob: createAstroGlobFn(), | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/astro/test/fixtures/astro-global/src/pages/omit-markdown-extensions.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/astro/test/fixtures/astro-pagination/src/pages/posts/[slug]/[page].astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.