summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/long-months-rule.md19
-rw-r--r--packages/astro/src/runtime/server/astro-global.ts4
-rw-r--r--packages/astro/src/types/public/context.ts1
3 files changed, 24 insertions, 0 deletions
diff --git a/.changeset/long-months-rule.md b/.changeset/long-months-rule.md
new file mode 100644
index 000000000..2e44f0793
--- /dev/null
+++ b/.changeset/long-months-rule.md
@@ -0,0 +1,19 @@
+---
+'astro': major
+---
+
+Deprecate Astro.glob
+
+The `Astro.glob` function has been deprecated in favor of Content Collections and `import.meta.glob`.
+
+- If you want to query for markdown and MDX in your project, use Content Collections.
+- If you want to query source files in your project, use `import.meta.glob`(https://vitejs.dev/guide/features.html#glob-import).
+
+Also consider using glob packages from npm, like [fast-glob](https://www.npmjs.com/package/fast-glob), especially if statically generating your site, as it is faster for most use-cases.
+
+The easiest path is to migrate to `import.meta.glob` like so:
+
+```diff
+- const posts = Astro.glob('./posts/*.md');
++ const posts = Object.values(import.meta.glob('./posts/*.md', { eager: true }));
+```
diff --git a/packages/astro/src/runtime/server/astro-global.ts b/packages/astro/src/runtime/server/astro-global.ts
index 74b32e331..0602302cc 100644
--- a/packages/astro/src/runtime/server/astro-global.ts
+++ b/packages/astro/src/runtime/server/astro-global.ts
@@ -5,6 +5,10 @@ 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,
diff --git a/packages/astro/src/types/public/context.ts b/packages/astro/src/types/public/context.ts
index e8b4f7e38..c3d3ff14f 100644
--- a/packages/astro/src/types/public/context.ts
+++ b/packages/astro/src/types/public/context.ts
@@ -219,6 +219,7 @@ export interface AstroGlobalPartial {
* ```
*
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroglob)
+ * @deprecated Astro.glob is deprecated and will be removed in the next major version of Astro. Use `import.meta.glob` instead: https://vitejs.dev/guide/features.html#glob-import
*/
glob(globStr: `${any}.astro`): Promise<AstroInstance[]>;
glob<T extends Record<string, any>>(