Skip to content

Commit

Permalink
fix: make root serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Jul 18, 2024
1 parent f29d425 commit 0ee05a1
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/astro/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function createManifest(
};

return {
root: import.meta.url,
hrefRoot: new URL(import.meta.url).href,
rewritingEnabled: false,
trailingSlash: manifest?.trailingSlash ?? ASTRO_CONFIG_DEFAULTS.trailingSlash,
buildFormat: manifest?.buildFormat ?? ASTRO_CONFIG_DEFAULTS.build.format,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class App {
manifest: this.#manifest,
mode: 'production',
renderers: this.#manifest.renderers,
defaultRoutes: createDefaultRoutes(this.#manifest, new URL(this.#manifest.root)),
defaultRoutes: createDefaultRoutes(this.#manifest),
resolve: async (specifier: string) => {
if (!(specifier in this.#manifest.entryModules)) {
throw new Error(`Unable to resolve [${specifier}]`);
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type AssetsPrefix =
| undefined;

export type SSRManifest = {
root: string;
hrefRoot: string;
adapterName: string;
routes: RouteInfo[];
site?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/base-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export abstract class Pipeline {
* Array of built-in, internal, routes.
* Used to find the route module
*/
readonly defaultRoutes = createDefaultRoutes(manifest, new URL(import.meta.url))
readonly defaultRoutes = createDefaultRoutes(manifest)
) {
this.internalMiddleware = [];
// We do use our middleware only if the user isn't using the manual setup
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ function createBuildManifest(
};
}
return {
root: fileURLToPath(settings.config.root),
hrefRoot: settings.config.root.href,
trailingSlash: settings.config.trailingSlash,
assets: new Set(),
entryModules: Object.fromEntries(internals.entrySpecifierToBundleMap.entries()),
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/core/build/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export class BuildPipeline extends Pipeline {
readonly options: StaticBuildOptions,
readonly config = options.settings.config,
readonly settings = options.settings,
readonly defaultRoutes = createDefaultRoutes(manifest, config.root)
readonly defaultRoutes = createDefaultRoutes(manifest)
) {
const resolveCache = new Map<string, string>();

async function resolve(specifier: string) {
if (resolveCache.has(specifier)) {
return resolveCache.get(specifier)!;
Expand All @@ -76,6 +77,7 @@ export class BuildPipeline extends Pipeline {
resolveCache.set(specifier, assetLink);
return assetLink;
}

const serverLike = isServerLikeOutput(config);
// We can skip streaming in SSG for performance as writing as strings are faster
const streaming = serverLike;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/plugins/plugin-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function buildManifest(
}

return {
root: import.meta.url,
hrefRoot: new URL(import.meta.url).href,
adapterName: opts.settings.adapter?.name ?? '',
routes,
site: settings.config.site,
Expand Down
8 changes: 5 additions & 3 deletions packages/astro/src/core/routing/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ type DefaultRouteParams = {
component: string;
};

export function createDefaultRoutes(manifest: SSRManifest, root: URL): DefaultRouteParams[] {
export function createDefaultRoutes(manifest: SSRManifest): DefaultRouteParams[] {
return [
{
instance: default404Instance,
matchesComponent: (filePath) => filePath.href === new URL(DEFAULT_404_COMPONENT, root).href,
matchesComponent: (filePath) =>
filePath.href === new URL(DEFAULT_404_COMPONENT, manifest.hrefRoot).href,
route: DEFAULT_404_ROUTE.route,
component: DEFAULT_404_COMPONENT,
},
{
instance: createServerIslandEndpoint(manifest),
matchesComponent: (filePath) => filePath.href === new URL(SERVER_ISLAND_COMPONENT, root).href,
matchesComponent: (filePath) =>
filePath.href === new URL(SERVER_ISLAND_COMPONENT, manifest.hrefRoot).href,
route: SERVER_ISLAND_ROUTE,
component: SERVER_ISLAND_COMPONENT,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-server/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class DevPipeline extends Pipeline {
readonly manifest: SSRManifest,
readonly settings: AstroSettings,
readonly config = settings.config,
readonly defaultRoutes = createDefaultRoutes(manifest, config.root)
readonly defaultRoutes = createDefaultRoutes(manifest)
) {
const mode = 'development';
const resolve = createResolve(loader, config.root);
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function createDevelopmentManifest(settings: AstroSettings): SSRManifest
};
}
return {
root: import.meta.url,
hrefRoot: new URL(import.meta.url).href,
trailingSlash: settings.config.trailingSlash,
buildFormat: settings.config.build.format,
compressHTML: settings.config.compressHTML,
Expand Down

0 comments on commit 0ee05a1

Please sign in to comment.