summaryrefslogtreecommitdiff
path: root/packages/integrations
diff options
context:
space:
mode:
authorGravatar Emanuele Stoppa <my.burning@gmail.com> 2024-06-05 11:39:42 +0100
committerGravatar GitHub <noreply@github.com> 2024-06-05 11:39:42 +0100
commit803dd8061df02138b4928442bcb76e77dcf6f5e7 (patch)
treec3ed3580e82716ea436dc783fdb31dd8bbc9f647 /packages/integrations
parent587e75f47efa346139b71e5e754e051f72bdac39 (diff)
downloadastro-803dd8061df02138b4928442bcb76e77dcf6f5e7.tar.gz
astro-803dd8061df02138b4928442bcb76e77dcf6f5e7.tar.zst
astro-803dd8061df02138b4928442bcb76e77dcf6f5e7.zip
feat(container): provide a virtual module to load renderers (#11144)
* feat(container): provide a virtual module to load renderers * address feedback * chore: restore some default to allow to have PHP prototype working * Thread through renderers and manifest * Pass manifest too * update changeset * add diff * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * fix diff * rebase and update lock --------- Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Diffstat (limited to 'packages/integrations')
-rw-r--r--packages/integrations/lit/src/index.ts9
-rw-r--r--packages/integrations/mdx/src/index.ts9
-rw-r--r--packages/integrations/preact/src/index.ts9
-rw-r--r--packages/integrations/react/src/index.ts15
-rw-r--r--packages/integrations/solid/src/index.ts14
-rw-r--r--packages/integrations/svelte/src/index.ts9
-rw-r--r--packages/integrations/vue/src/index.ts9
7 files changed, 67 insertions, 7 deletions
diff --git a/packages/integrations/lit/src/index.ts b/packages/integrations/lit/src/index.ts
index 6c86bd740..33aaf727d 100644
--- a/packages/integrations/lit/src/index.ts
+++ b/packages/integrations/lit/src/index.ts
@@ -1,5 +1,5 @@
import { readFileSync } from 'node:fs';
-import type { AstroIntegration } from 'astro';
+import type { AstroIntegration, ContainerRenderer } from 'astro';
function getViteConfiguration() {
return {
@@ -19,6 +19,13 @@ function getViteConfiguration() {
};
}
+export function getContainerRenderer(): ContainerRenderer {
+ return {
+ name: '@astrojs/lit',
+ serverEntrypoint: '@astrojs/lit/server.js',
+ };
+}
+
export default function (): AstroIntegration {
return {
name: '@astrojs/lit',
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts
index 3aaed8787..bd0278933 100644
--- a/packages/integrations/mdx/src/index.ts
+++ b/packages/integrations/mdx/src/index.ts
@@ -1,7 +1,7 @@
import fs from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { markdownConfigDefaults } from '@astrojs/markdown-remark';
-import type { AstroIntegration, ContentEntryType, HookParameters } from 'astro';
+import type { AstroIntegration, ContainerRenderer, ContentEntryType, HookParameters } from 'astro';
import astroJSXRenderer from 'astro/jsx/renderer.js';
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
import type { PluggableList } from 'unified';
@@ -28,6 +28,13 @@ type SetupHookParams = HookParameters<'astro:config:setup'> & {
addContentEntryType: (contentEntryType: ContentEntryType) => void;
};
+export function getContainerRenderer(): ContainerRenderer {
+ return {
+ name: 'astro:jsx',
+ serverEntrypoint: 'astro/jsx/server.js',
+ };
+}
+
export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroIntegration {
// @ts-expect-error Temporarily assign an empty object here, which will be re-assigned by the
// `astro:config:done` hook later. This is so that `vitePluginMdx` can get hold of a reference earlier.
diff --git a/packages/integrations/preact/src/index.ts b/packages/integrations/preact/src/index.ts
index bcca01dd0..aab4f9925 100644
--- a/packages/integrations/preact/src/index.ts
+++ b/packages/integrations/preact/src/index.ts
@@ -1,6 +1,6 @@
import { fileURLToPath } from 'node:url';
import { type PreactPluginOptions as VitePreactPluginOptions, preact } from '@preact/preset-vite';
-import type { AstroIntegration, AstroRenderer, ViteUserConfig } from 'astro';
+import type { AstroIntegration, AstroRenderer, ContainerRenderer, ViteUserConfig } from 'astro';
const babelCwd = new URL('../', import.meta.url);
@@ -12,6 +12,13 @@ function getRenderer(development: boolean): AstroRenderer {
};
}
+export function getContainerRenderer(): ContainerRenderer {
+ return {
+ name: '@astrojs/preact',
+ serverEntrypoint: '@astrojs/preact/server.js',
+ };
+}
+
export interface Options extends Pick<VitePreactPluginOptions, 'include' | 'exclude'> {
compat?: boolean;
devtools?: boolean;
diff --git a/packages/integrations/react/src/index.ts b/packages/integrations/react/src/index.ts
index 838640239..85d79eef8 100644
--- a/packages/integrations/react/src/index.ts
+++ b/packages/integrations/react/src/index.ts
@@ -1,5 +1,5 @@
import react, { type Options as ViteReactPluginOptions } from '@vitejs/plugin-react';
-import type { AstroIntegration } from 'astro';
+import type { AstroIntegration, ContainerRenderer } from 'astro';
import { version as ReactVersion } from 'react-dom';
import type * as vite from 'vite';
@@ -53,6 +53,19 @@ function getRenderer(reactConfig: ReactVersionConfig) {
};
}
+export function getContainerRenderer(): ContainerRenderer {
+ const majorVersion = getReactMajorVersion();
+ if (isUnsupportedVersion(majorVersion)) {
+ throw new Error(`Unsupported React version: ${majorVersion}.`);
+ }
+ const versionConfig = versionsConfig[majorVersion as SupportedReactVersion];
+
+ return {
+ name: '@astrojs/react',
+ serverEntrypoint: versionConfig.server,
+ };
+}
+
function optionsPlugin(experimentalReactChildren: boolean): vite.Plugin {
const virtualModule = 'astro:react:opts';
const virtualModuleId = '\0' + virtualModule;
diff --git a/packages/integrations/solid/src/index.ts b/packages/integrations/solid/src/index.ts
index a779dea60..1bbfa741f 100644
--- a/packages/integrations/solid/src/index.ts
+++ b/packages/integrations/solid/src/index.ts
@@ -1,4 +1,9 @@
-import type { AstroIntegration, AstroIntegrationLogger, AstroRenderer } from 'astro';
+import type {
+ AstroIntegration,
+ AstroIntegrationLogger,
+ AstroRenderer,
+ ContainerRenderer,
+} from 'astro';
import type { PluginOption, UserConfig } from 'vite';
import solid, { type Options as ViteSolidPluginOptions } from 'vite-plugin-solid';
@@ -94,6 +99,13 @@ function getRenderer(): AstroRenderer {
};
}
+export function getContainerRenderer(): ContainerRenderer {
+ return {
+ name: '@astrojs/solid',
+ serverEntrypoint: '@astrojs/solid-js/server.js',
+ };
+}
+
export interface Options extends Pick<ViteSolidPluginOptions, 'include' | 'exclude'> {
devtools?: boolean;
}
diff --git a/packages/integrations/svelte/src/index.ts b/packages/integrations/svelte/src/index.ts
index 9c38b9d05..b0db3505c 100644
--- a/packages/integrations/svelte/src/index.ts
+++ b/packages/integrations/svelte/src/index.ts
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'node:url';
import type { Options } from '@sveltejs/vite-plugin-svelte';
import { svelte, vitePreprocess } from '@sveltejs/vite-plugin-svelte';
-import type { AstroIntegration, AstroRenderer } from 'astro';
+import type { AstroIntegration, AstroRenderer, ContainerRenderer } from 'astro';
import { VERSION } from 'svelte/compiler';
import type { UserConfig } from 'vite';
@@ -15,6 +15,13 @@ function getRenderer(): AstroRenderer {
};
}
+export function getContainerRenderer(): ContainerRenderer {
+ return {
+ name: '@astrojs/svelte',
+ serverEntrypoint: isSvelte5 ? '@astrojs/svelte/server-v5.js' : '@astrojs/svelte/server.js',
+ };
+}
+
async function svelteConfigHasPreprocess(root: URL) {
const svelteConfigFiles = ['./svelte.config.js', './svelte.config.cjs', './svelte.config.mjs'];
for (const file of svelteConfigFiles) {
diff --git a/packages/integrations/vue/src/index.ts b/packages/integrations/vue/src/index.ts
index 6edb82526..81afe3a2e 100644
--- a/packages/integrations/vue/src/index.ts
+++ b/packages/integrations/vue/src/index.ts
@@ -3,7 +3,7 @@ import type { Options as VueOptions } from '@vitejs/plugin-vue';
import vue from '@vitejs/plugin-vue';
import type { Options as VueJsxOptions } from '@vitejs/plugin-vue-jsx';
import { MagicString } from '@vue/compiler-sfc';
-import type { AstroIntegration, AstroRenderer, HookParameters } from 'astro';
+import type { AstroIntegration, AstroRenderer, ContainerRenderer, HookParameters } from 'astro';
import type { Plugin, UserConfig } from 'vite';
import type { VitePluginVueDevToolsOptions } from 'vite-plugin-vue-devtools';
@@ -32,6 +32,13 @@ function getJsxRenderer(): AstroRenderer {
};
}
+export function getContainerRenderer(): ContainerRenderer {
+ return {
+ name: '@astrojs/vue',
+ serverEntrypoint: '@astrojs/vue/server.js',
+ };
+}
+
function virtualAppEntrypoint(options?: Options): Plugin {
let isBuild: boolean;
let root: string;