-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
130 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 0 additions & 86 deletions
86
packages/astro/src/vite-plugin-astro-server/devPipeline.ts
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
packages/astro/src/vite-plugin-astro-server/environment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { AstroConfig, AstroSettings, ComponentInstance, SSRLoadedRenderer, SSRManifest } from '../@types/astro.js'; | ||
import type { Logger } from '../core/logger/core.js'; | ||
import type { ModuleLoader } from '../core/module-loader/index.js'; | ||
import { Environment, loadRenderer } from '../core/render/index.js'; | ||
import { RouteCache } from '../core/render/route-cache.js'; | ||
import { viteID } from '../core/util.js'; | ||
import { isServerLikeOutput } from '../prerender/utils.js'; | ||
import { createResolve } from './resolve.js'; | ||
import { AggregateError, CSSError, MarkdownError } from '../core/errors/index.js'; | ||
import { enhanceViteSSRError } from '../core/errors/dev/index.js'; | ||
|
||
export class DevEnvironment extends Environment { | ||
constructor( | ||
readonly loader: ModuleLoader, | ||
readonly logger: Logger, | ||
readonly manifest: SSRManifest, | ||
readonly settings: AstroSettings, | ||
readonly config = settings.config, | ||
) { | ||
const mode = 'development' | ||
const resolve = createResolve(loader, settings.config.root); | ||
const serverLike = isServerLikeOutput(settings.config); | ||
const streaming = true; | ||
const routeCache = new RouteCache(logger, mode); | ||
super(logger, manifest, mode, [], resolve, serverLike, streaming, routeCache); | ||
} | ||
|
||
async preload(filePath: URL) { | ||
const { loader } = this; | ||
|
||
// Important: This needs to happen first, in case a renderer provides polyfills. | ||
const renderers__ = this.settings.renderers.map((r) => loadRenderer(r, loader)); | ||
const renderers_ = await Promise.all(renderers__); | ||
this.renderers = renderers_.filter((r): r is SSRLoadedRenderer => Boolean(r)); | ||
|
||
try { | ||
// Load the module from the Vite SSR Runtime. | ||
return await loader.import(viteID(filePath)) as ComponentInstance; | ||
} catch (error) { | ||
// If the error came from Markdown or CSS, we already handled it and there's no need to enhance it | ||
if (MarkdownError.is(error) || CSSError.is(error) || AggregateError.is(error)) { | ||
throw error; | ||
} | ||
|
||
throw enhanceViteSSRError({ error, filePath, loader }); | ||
} | ||
} | ||
|
||
clearRouteCache() { | ||
this.routeCache.clearAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,3 @@ | ||
import type { ComponentInstance } from '../@types/astro.js'; | ||
import { enhanceViteSSRError } from '../core/errors/dev/index.js'; | ||
import { AggregateError, CSSError, MarkdownError } from '../core/errors/index.js'; | ||
import { viteID } from '../core/util.js'; | ||
import type DevPipeline from './devPipeline.js'; | ||
|
||
export async function preload({ | ||
pipeline, | ||
filePath, | ||
}: { | ||
pipeline: DevPipeline; | ||
filePath: URL; | ||
}): Promise<ComponentInstance> { | ||
// Important: This needs to happen first, in case a renderer provides polyfills. | ||
await pipeline.loadRenderers(); | ||
|
||
try { | ||
// Load the module from the Vite SSR Runtime. | ||
const mod = (await pipeline.getModuleLoader().import(viteID(filePath))) as ComponentInstance; | ||
|
||
return mod; | ||
} catch (error) { | ||
// If the error came from Markdown or CSS, we already handled it and there's no need to enhance it | ||
if (MarkdownError.is(error) || CSSError.is(error) || AggregateError.is(error)) { | ||
throw error; | ||
} | ||
|
||
throw enhanceViteSSRError({ error, filePath, loader: pipeline.getModuleLoader() }); | ||
} | ||
} | ||
|
||
export { createController, runWithErrorHandling } from './controller.js'; | ||
export { default as vitePluginAstroServer } from './plugin.js'; | ||
export { handleRequest } from './request.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.