Skip to content

Commit df6d2d7

Browse files
feat!: remove Astro.glob (#14421)
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
1 parent 4f11510 commit df6d2d7

File tree

37 files changed

+52
-231
lines changed

37 files changed

+52
-231
lines changed

.changeset/kind-pears-behave.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'astro': major
3+
---
4+
5+
Removes `Astro.glob()`
6+
7+
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.
8+
9+
Astro 6.0 removes `Astro.glob()` entirely. Update to `import.meta.glob()` to keep your current behavior.
10+
11+
#### What should I do?
12+
13+
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.
14+
15+
```astro
16+
---
17+
// src/pages/blog.astro
18+
-const posts = await Astro.glob('./posts/*.md');
19+
+const posts = Object.values(import.meta.glob('./posts/*.md', { eager: true }));
20+
---
21+
{posts.map((post) => <li><a href={post.url}>{post.frontmatter.title}</a></li>)}
22+
```
23+
24+
Where appropriate, consider using content collections to organize your content, which has its own newer, more performant querying functions.

packages/astro/e2e/errors.test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,6 @@ test.describe('Error display', () => {
117117
expect(await page.locator('vite-error-overlay').count()).toEqual(0);
118118
});
119119

120-
test('astro glob no match error', async ({ page, astro }) => {
121-
await page.goto(astro.resolveUrl('/astro-glob-no-match'), { waitUntil: 'networkidle' });
122-
const message = (await getErrorOverlayContent(page)).message;
123-
expect(message).toMatch('did not return any matching files');
124-
});
125-
126-
test('astro glob used outside of an astro file', async ({ page, astro }) => {
127-
await page.goto(astro.resolveUrl('/astro-glob-outside-astro'), { waitUntil: 'networkidle' });
128-
const message = (await getErrorOverlayContent(page)).message;
129-
expect(message).toMatch('can only be used in');
130-
});
131-
132120
test('can handle DomException errors', async ({ page, astro }) => {
133121
await page.goto(astro.resolveUrl('/dom-exception'), { waitUntil: 'networkidle' });
134122
const message = (await getErrorOverlayContent(page)).message;

packages/astro/e2e/fixtures/errors/src/components/AstroGlobOutsideAstro.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/astro/e2e/fixtures/errors/src/pages/astro-glob-no-match.astro

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/astro/e2e/fixtures/errors/src/pages/astro-glob-outside-astro.astro

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/astro/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
"@capsizecss/unpack": "^2.4.0",
114114
"@oslojs/encoding": "^1.1.0",
115115
"@rollup/pluginutils": "^5.2.0",
116-
"acorn": "^8.15.0",
117116
"aria-query": "^5.3.2",
118117
"axobject-query": "^4.1.0",
119118
"boxen": "8.0.1",
@@ -130,7 +129,6 @@
130129
"dset": "^3.1.4",
131130
"es-module-lexer": "^1.7.0",
132131
"esbuild": "^0.25.0",
133-
"estree-walker": "^3.0.3",
134132
"flattie": "^1.1.1",
135133
"fontace": "~0.3.0",
136134
"github-slugger": "^2.0.0",

packages/astro/src/core/create-vite.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import astroDevToolbar from '../toolbar/vite-plugin-dev-toolbar.js';
2222
import astroTransitions from '../transitions/vite-plugin-transitions.js';
2323
import type { AstroSettings, RoutesList } from '../types/astro.js';
2424
import astroVitePlugin from '../vite-plugin-astro/index.js';
25-
import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.js';
2625
import { vitePluginAstroServer } from '../vite-plugin-astro-server/index.js';
2726
import configAliasVitePlugin from '../vite-plugin-config-alias/index.js';
2827
import vitePluginFileURL from '../vite-plugin-fileurl/index.js';
@@ -158,7 +157,6 @@ export async function createVite(
158157
astroEnv({ settings, sync, envLoader }),
159158
markdownVitePlugin({ settings, logger }),
160159
htmlVitePlugin(),
161-
astroPostprocessVitePlugin(),
162160
astroIntegrationsContainerPlugin({ settings, logger }),
163161
astroScriptsPageSSRPlugin({ settings }),
164162
astroHeadPlugin(),

packages/astro/src/core/errors/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ If the error cannot be triggered at all anymore, it can deprecated by adding a `
9797
```js
9898
/**
9999
* @docs
100-
* @deprecated Removed in Astro v9.8.6 as it is no longer relevant due to...
100+
* @deprecated This error was removed in Astro v6.0.0 along with the removal of...
101101
*/
102102
```
103103

packages/astro/src/core/errors/dev/vite.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { ErrorPayload } from 'vite';
66
import type { SSRLoadedRenderer } from '../../../types/public/internal.js';
77
import type { ModuleLoader } from '../../module-loader/index.js';
88
import { AstroError, type ErrorWithMetadata } from '../errors.js';
9-
import { FailedToLoadModuleSSR, InvalidGlob, MdxIntegrationMissingError } from '../errors-data.js';
9+
import { FailedToLoadModuleSSR, MdxIntegrationMissingError } from '../errors-data.js';
1010
import { createSafeError } from '../utils.js';
1111
import { getDocsForError, renderErrorMarkdown } from './utils.js';
1212

@@ -76,29 +76,6 @@ export function enhanceViteSSRError({
7676
stack: safeError.stack,
7777
}) as ErrorWithMetadata;
7878
}
79-
80-
// Since Astro.glob is a wrapper around Vite's import.meta.glob, errors don't show accurate information, let's fix that
81-
if (safeError.message.includes('Invalid glob')) {
82-
const globPattern = /glob: "(.+)" \(/.exec(safeError.message)?.[1];
83-
84-
if (globPattern) {
85-
safeError.message = InvalidGlob.message(globPattern);
86-
safeError.name = 'InvalidGlob';
87-
safeError.title = InvalidGlob.title;
88-
89-
const line = lns.findIndex((ln) => ln.includes(globPattern));
90-
91-
if (line !== -1) {
92-
const column = lns[line]?.indexOf(globPattern);
93-
94-
safeError.loc = {
95-
file: path,
96-
line: line + 1,
97-
column,
98-
};
99-
}
100-
}
101-
}
10279
}
10380

10481
return safeError;

packages/astro/src/core/errors/errors-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,7 @@ export const LocalImageUsedWrongly = {
951951
* - [Astro.glob](https://docs.astro.build/en/reference/api-reference/#astroglob)
952952
* @description
953953
* `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vite.dev/guide/features.html#glob-import) instead to achieve the same result.
954+
* @deprecated This error was removed in Astro v6.0.0 along with the removal of `Astro.glob()`.
954955
*/
955956
export const AstroGlobUsedOutside = {
956957
name: 'AstroGlobUsedOutside',
@@ -966,6 +967,7 @@ export const AstroGlobUsedOutside = {
966967
* - [Astro.glob](https://docs.astro.build/en/reference/api-reference/#astroglob)
967968
* @description
968969
* `Astro.glob()` did not return any matching files. There might be a typo in the glob pattern.
970+
* @deprecated This error was removed in Astro v6.0.0 along with the removal of `Astro.glob()`.
969971
*/
970972
export const AstroGlobNoMatch = {
971973
name: 'AstroGlobNoMatch',
@@ -1075,6 +1077,7 @@ export const FailedToLoadModuleSSR = {
10751077
* - [Glob Patterns](https://docs.astro.build/en/guides/imports/#glob-patterns)
10761078
* @description
10771079
* Astro encountered an invalid glob pattern. This is often caused by the glob pattern not being a valid file path.
1080+
* @deprecated This error was removed in Astro v6.0.0 along with the removal of `Astro.glob()`.
10781081
*/
10791082
export const InvalidGlob = {
10801083
name: 'InvalidGlob',

0 commit comments

Comments
 (0)