mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
[ci] format
This commit is contained in:
parent
12a1bccc81
commit
b15949f8fa
8 changed files with 85 additions and 79 deletions
|
@ -1,6 +1,7 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
This is a card
|
This is a card
|
||||||
<slot />
|
<slot />
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
---
|
---
|
||||||
export function getStaticPaths() {
|
export function getStaticPaths() {
|
||||||
return [
|
return [{ params: { locale: 'en' } }];
|
||||||
{params: {locale: 'en'}},
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
const { locale } = Astro.params
|
const { locale } = Astro.params;
|
||||||
---
|
---
|
||||||
|
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
|
@ -7,10 +7,10 @@ test('ReactWrapper with react renderer', async () => {
|
||||||
renderers: [
|
renderers: [
|
||||||
{
|
{
|
||||||
name: '@astrojs/react',
|
name: '@astrojs/react',
|
||||||
clientEntrypoint: "@astrojs/react/client.js",
|
clientEntrypoint: '@astrojs/react/client.js',
|
||||||
serverEntrypoint: "@astrojs/react/server.js",
|
serverEntrypoint: '@astrojs/react/server.js',
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
const result = await container.renderToString(ReactWrapper);
|
const result = await container.renderToString(ReactWrapper);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ test('Dynamic route', async () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const result = await container.renderToString(Locale, {
|
const result = await container.renderToString(Locale, {
|
||||||
params: {
|
params: {
|
||||||
"locale": 'en'
|
locale: 'en',
|
||||||
},
|
},
|
||||||
request: new Request('http://example.com/en'),
|
request: new Request('http://example.com/en'),
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
import { posix } from 'node:path';
|
||||||
import type {
|
import type {
|
||||||
|
AstroRenderer,
|
||||||
|
AstroUserConfig,
|
||||||
ComponentInstance,
|
ComponentInstance,
|
||||||
MiddlewareHandler,
|
MiddlewareHandler,
|
||||||
RouteData,
|
RouteData,
|
||||||
|
@ -6,19 +9,16 @@ import type {
|
||||||
SSRLoadedRenderer,
|
SSRLoadedRenderer,
|
||||||
SSRManifest,
|
SSRManifest,
|
||||||
SSRResult,
|
SSRResult,
|
||||||
AstroUserConfig,
|
|
||||||
AstroRenderer,
|
|
||||||
} from '../@types/astro.js';
|
} from '../@types/astro.js';
|
||||||
import { ContainerPipeline } from './pipeline.js';
|
|
||||||
import { Logger } from '../core/logger/core.js';
|
|
||||||
import { nodeLogDestination } from '../core/logger/node.js';
|
|
||||||
import { validateConfig } from '../core/config/config.js';
|
import { validateConfig } from '../core/config/config.js';
|
||||||
import { ASTRO_CONFIG_DEFAULTS } from '../core/config/schema.js';
|
import { ASTRO_CONFIG_DEFAULTS } from '../core/config/schema.js';
|
||||||
import { RenderContext } from '../core/render-context.js';
|
import { Logger } from '../core/logger/core.js';
|
||||||
import { posix } from 'node:path';
|
import { nodeLogDestination } from '../core/logger/node.js';
|
||||||
import { getParts, getPattern, validateSegment } from '../core/routing/manifest/create.js';
|
|
||||||
import { removeLeadingForwardSlash } from '../core/path.js';
|
import { removeLeadingForwardSlash } from '../core/path.js';
|
||||||
import type {AstroComponentFactory} from "../runtime/server/index.js";
|
import { RenderContext } from '../core/render-context.js';
|
||||||
|
import { getParts, getPattern, validateSegment } from '../core/routing/manifest/create.js';
|
||||||
|
import type { AstroComponentFactory } from '../runtime/server/index.js';
|
||||||
|
import { ContainerPipeline } from './pipeline.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options to be passed when rendering a route
|
* Options to be passed when rendering a route
|
||||||
|
@ -102,7 +102,7 @@ function createManifest(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AstroContainerUserConfig = Omit<AstroUserConfig, 'integrations' | 'adapter' >
|
export type AstroContainerUserConfig = Omit<AstroUserConfig, 'integrations' | 'adapter'>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options that are used for the entire lifecycle of the current instance of the container.
|
* Options that are used for the entire lifecycle of the current instance of the container.
|
||||||
|
@ -238,10 +238,7 @@ export class experimental_AstroContainer {
|
||||||
public static async create(
|
public static async create(
|
||||||
containerOptions: AstroContainerOptions = {}
|
containerOptions: AstroContainerOptions = {}
|
||||||
): Promise<experimental_AstroContainer> {
|
): Promise<experimental_AstroContainer> {
|
||||||
const {
|
const { streaming = false, renderers = [] } = containerOptions;
|
||||||
streaming = false,
|
|
||||||
renderers = [],
|
|
||||||
} = containerOptions;
|
|
||||||
const loadedRenderers = await Promise.all(
|
const loadedRenderers = await Promise.all(
|
||||||
renderers.map(async (renderer) => {
|
renderers.map(async (renderer) => {
|
||||||
const mod = await import(renderer.serverEntrypoint);
|
const mod = await import(renderer.serverEntrypoint);
|
||||||
|
@ -261,7 +258,9 @@ export class experimental_AstroContainer {
|
||||||
|
|
||||||
// NOTE: we keep this private via TS instead via `#` so it's still available on the surface, so we can play with it.
|
// NOTE: we keep this private via TS instead via `#` so it's still available on the surface, so we can play with it.
|
||||||
// @ematipico: I plan to use it for a possible integration that could help people
|
// @ematipico: I plan to use it for a possible integration that could help people
|
||||||
private static async createFromManifest(manifest: SSRManifest): Promise<experimental_AstroContainer> {
|
private static async createFromManifest(
|
||||||
|
manifest: SSRManifest
|
||||||
|
): Promise<experimental_AstroContainer> {
|
||||||
const config = await validateConfig(ASTRO_CONFIG_DEFAULTS, process.cwd(), 'container');
|
const config = await validateConfig(ASTRO_CONFIG_DEFAULTS, process.cwd(), 'container');
|
||||||
const container = new experimental_AstroContainer({
|
const container = new experimental_AstroContainer({
|
||||||
manifest,
|
manifest,
|
||||||
|
@ -278,13 +277,12 @@ export class experimental_AstroContainer {
|
||||||
}: {
|
}: {
|
||||||
path: string;
|
path: string;
|
||||||
componentInstance: ComponentInstance;
|
componentInstance: ComponentInstance;
|
||||||
route?: string,
|
route?: string;
|
||||||
params?: Record<string, string | undefined>;
|
params?: Record<string, string | undefined>;
|
||||||
type?: RouteType;
|
type?: RouteType;
|
||||||
}): RouteData {
|
}): RouteData {
|
||||||
const pathUrl = new URL(path, 'https://example.com');
|
const pathUrl = new URL(path, 'https://example.com');
|
||||||
const routeData: RouteData = this.#createRoute(pathUrl,
|
const routeData: RouteData = this.#createRoute(pathUrl, params, type);
|
||||||
params, type);
|
|
||||||
this.#pipeline.manifest.routes.push({
|
this.#pipeline.manifest.routes.push({
|
||||||
routeData,
|
routeData,
|
||||||
file: '',
|
file: '',
|
||||||
|
@ -349,7 +347,10 @@ export class experimental_AstroContainer {
|
||||||
const { routeType = 'page', slots } = options;
|
const { routeType = 'page', slots } = options;
|
||||||
const request = options?.request ?? new Request('https://example.com/');
|
const request = options?.request ?? new Request('https://example.com/');
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const componentInstance = routeType === "endpoint" ? component as unknown as ComponentInstance : this.#wrapComponent(component, options.params);
|
const componentInstance =
|
||||||
|
routeType === 'endpoint'
|
||||||
|
? (component as unknown as ComponentInstance)
|
||||||
|
: this.#wrapComponent(component, options.params);
|
||||||
const routeData = this.#insertRoute({
|
const routeData = this.#insertRoute({
|
||||||
path: request.url,
|
path: request.url,
|
||||||
componentInstance,
|
componentInstance,
|
||||||
|
@ -387,7 +388,11 @@ export class experimental_AstroContainer {
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
params: Object.keys(params),
|
params: Object.keys(params),
|
||||||
pattern: getPattern(segments, ASTRO_CONFIG_DEFAULTS.base, ASTRO_CONFIG_DEFAULTS.trailingSlash),
|
pattern: getPattern(
|
||||||
|
segments,
|
||||||
|
ASTRO_CONFIG_DEFAULTS.base,
|
||||||
|
ASTRO_CONFIG_DEFAULTS.trailingSlash
|
||||||
|
),
|
||||||
prerender: false,
|
prerender: false,
|
||||||
segments,
|
segments,
|
||||||
type,
|
type,
|
||||||
|
@ -402,15 +407,18 @@ export class experimental_AstroContainer {
|
||||||
* @param params
|
* @param params
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
#wrapComponent(componentFactory: AstroComponentFactory, params?: Record<string, string | undefined>): ComponentInstance {
|
#wrapComponent(
|
||||||
|
componentFactory: AstroComponentFactory,
|
||||||
|
params?: Record<string, string | undefined>
|
||||||
|
): ComponentInstance {
|
||||||
if (params) {
|
if (params) {
|
||||||
return {
|
return {
|
||||||
default: componentFactory,
|
default: componentFactory,
|
||||||
getStaticPaths() {
|
getStaticPaths() {
|
||||||
return [{ params }];
|
return [{ params }];
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
return ({ default: componentFactory })
|
return { default: componentFactory };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { type HeadElements, Pipeline } from '../core/base-pipeline.js';
|
|
||||||
import type {
|
import type {
|
||||||
ComponentInstance,
|
ComponentInstance,
|
||||||
RewritePayload,
|
RewritePayload,
|
||||||
|
@ -6,13 +5,14 @@ import type {
|
||||||
SSRElement,
|
SSRElement,
|
||||||
SSRResult,
|
SSRResult,
|
||||||
} from '../@types/astro.js';
|
} from '../@types/astro.js';
|
||||||
|
import { type HeadElements, Pipeline } from '../core/base-pipeline.js';
|
||||||
|
import type { SinglePageBuiltModule } from '../core/build/types.js';
|
||||||
|
import { RouteNotFound } from '../core/errors/errors-data.js';
|
||||||
|
import { AstroError } from '../core/errors/index.js';
|
||||||
import {
|
import {
|
||||||
createModuleScriptElement,
|
createModuleScriptElement,
|
||||||
createStylesheetElementSet,
|
createStylesheetElementSet,
|
||||||
} from '../core/render/ssr-element.js';
|
} from '../core/render/ssr-element.js';
|
||||||
import { AstroError } from '../core/errors/index.js';
|
|
||||||
import { RouteNotFound } from '../core/errors/errors-data.js';
|
|
||||||
import type { SinglePageBuiltModule } from '../core/build/types.js';
|
|
||||||
|
|
||||||
export class ContainerPipeline extends Pipeline {
|
export class ContainerPipeline extends Pipeline {
|
||||||
/**
|
/**
|
||||||
|
@ -110,6 +110,5 @@ export class ContainerPipeline extends Pipeline {
|
||||||
|
|
||||||
// At the moment it's not used by the container via any public API
|
// At the moment it's not used by the container via any public API
|
||||||
// @ts-expect-error It needs to be implemented.
|
// @ts-expect-error It needs to be implemented.
|
||||||
async getComponentByRoute(_routeData: RouteData): Promise<ComponentInstance> {
|
async getComponentByRoute(_routeData: RouteData): Promise<ComponentInstance> {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
import { describe, it } from 'node:test';
|
import { describe, it } from 'node:test';
|
||||||
|
import { experimental_AstroContainer } from '../dist/container/index.js';
|
||||||
import {
|
import {
|
||||||
Fragment,
|
Fragment,
|
||||||
createComponent,
|
createComponent,
|
||||||
|
@ -8,8 +10,6 @@ import {
|
||||||
renderHead,
|
renderHead,
|
||||||
renderSlot,
|
renderSlot,
|
||||||
} from '../dist/runtime/server/index.js';
|
} from '../dist/runtime/server/index.js';
|
||||||
import { experimental_AstroContainer } from '../dist/container/index.js';
|
|
||||||
import assert from 'node:assert/strict';
|
|
||||||
|
|
||||||
const BaseLayout = createComponent((result, _props, slots) => {
|
const BaseLayout = createComponent((result, _props, slots) => {
|
||||||
return render`<html>
|
return render`<html>
|
||||||
|
|
Loading…
Reference in a new issue