From e4fc2a0bafb4723566552d0c5954b25447890f51 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 12 Jun 2024 11:28:26 +0100 Subject: [PATCH] fix: provide a plugin to resolve the virtual module (#11242) --- .changeset/fair-wasps-hunt.md | 5 +++++ .../astro/src/container/vite-plugin-container.ts | 15 +++++++++++++++ packages/astro/src/core/create-vite.ts | 2 ++ pnpm-lock.yaml | 1 - 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/fair-wasps-hunt.md create mode 100644 packages/astro/src/container/vite-plugin-container.ts diff --git a/.changeset/fair-wasps-hunt.md b/.changeset/fair-wasps-hunt.md new file mode 100644 index 000000000000..174ce02f8fd2 --- /dev/null +++ b/.changeset/fair-wasps-hunt.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a case where the virtual module `astro:container` wasn't resolved diff --git a/packages/astro/src/container/vite-plugin-container.ts b/packages/astro/src/container/vite-plugin-container.ts new file mode 100644 index 000000000000..2098ff0866e2 --- /dev/null +++ b/packages/astro/src/container/vite-plugin-container.ts @@ -0,0 +1,15 @@ +import type * as vite from 'vite'; + +const virtualModuleId = 'astro:container'; + +export default function astroContainer(): vite.Plugin { + return { + name: 'astro:container', + enforce: 'pre', + resolveId(id) { + if (id === virtualModuleId) { + return this.resolve('astro/virtual-modules/container.js'); + } + }, + }; +} diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 163c16482f6b..c875860f5952 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -38,6 +38,7 @@ import { createViteLogger } from './logger/vite.js'; import { vitePluginMiddleware } from './middleware/vite-plugin.js'; import { joinPaths } from './path.js'; import { isObject } from './util.js'; +import astroContainer from "../container/vite-plugin-container.js"; interface CreateViteOptions { settings: AstroSettings; @@ -157,6 +158,7 @@ export async function createVite( astroDevToolbar({ settings, logger }), vitePluginFileURL({}), astroInternationalization({ settings }), + astroContainer() ], publicDir: fileURLToPath(settings.config.publicDir), root: fileURLToPath(settings.config.root), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b8a8f8471758..439dfd84216d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9575,7 +9575,6 @@ packages: libsql@0.3.12: resolution: {integrity: sha512-to30hj8O3DjS97wpbKN6ERZ8k66MN1IaOfFLR6oHqd25GMiPJ/ZX0VaZ7w+TsPmxcFS3p71qArj/hiedCyvXCg==} - cpu: [x64, arm64, wasm32] os: [darwin, linux, win32] lilconfig@2.1.0: