Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Apr 8, 2022
1 parent db77891 commit 51cdda6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 50 deletions.
1 change: 0 additions & 1 deletion packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,6 @@ export interface AstroConfig extends z.output<typeof AstroConfigSchema> {
adapter: AstroAdapter | undefined;
renderers: AstroRenderer[];
scripts: { stage: InjectedScriptStage; content: string }[];
projectFlags: number;
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { SSRManifest as Manifest, RouteInfo } from './types';
import type { LogOptions } from '../logger/core.js';

import mime from 'mime';
import astroRemark from '@astrojs/markdown-remark';
import { consoleLogDestination } from '../logger/console.js';
export { deserializeManifest } from './common.js';
import { matchRoute } from '../routing/match.js';
Expand All @@ -19,7 +20,6 @@ import {
createModuleScriptElementWithSrcSet,
} from '../render/ssr-element.js';
import { prependForwardSlash } from '../path.js';
import { createRequest } from '../request.js';

export class App {
#manifest: Manifest;
Expand Down Expand Up @@ -82,7 +82,7 @@ export class App {
legacyBuild: false,
links,
logging: this.#logging,
markdownRender: manifest.markdown.render,
markdownRender: [astroRemark, this.#manifest.markdown ?? {}],
mod,
origin: url.origin,
pathname: url.pathname,
Expand Down
6 changes: 2 additions & 4 deletions packages/astro/src/core/app/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
AstroUserConfig,
RouteData,
SerializedRouteData,
MarkdownRenderOptions,
ComponentInstance,
SSRLoadedRenderer,
} from '../../@types/astro';
Expand All @@ -22,9 +22,7 @@ export type SerializedRouteInfo = Omit<RouteInfo, 'routeData'> & {
export interface SSRManifest {
routes: RouteInfo[];
site?: string;
markdown: {
render: MarkdownRenderOptions;
};
markdown: AstroUserConfig['markdown'];
pageMap: Map<ComponentPath, ComponentInstance>;
renderers: SSRLoadedRenderer[];
entryModules: Record<string, string>;
Expand Down
20 changes: 3 additions & 17 deletions packages/astro/src/core/build/vite-plugin-ssr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import astroRemark from '@astrojs/markdown-remark';
import type { Plugin as VitePlugin } from 'vite';
import type { BuildInternals } from './internal.js';
import type { AstroAdapter } from '../../@types/astro';
Expand All @@ -10,7 +9,6 @@ import { eachPageData } from './internal.js';
import { addRollupInput } from './add-rollup-input.js';
import { virtualModuleId as pagesVirtualModuleId } from './vite-plugin-pages.js';
import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
import { hasUserConfig } from '../project-flags.js';

export const virtualModuleId = '@astrojs-ssr-virtual-entry';
const resolvedVirtualModuleId = '\0' + virtualModuleId;
Expand All @@ -35,21 +33,11 @@ export function vitePluginSSR(
load(id) {
if (id === resolvedVirtualModuleId) {
return `import * as adapter from '${adapter.serverEntrypoint}';
import _astroRemark from '@astrojs/markdown-remark';
import * as _main from '${pagesVirtualModuleId}';
import { deserializeManifest as _deserializeManifest } from 'astro/app';
${hasUserConfig(buildOpts.astroConfig) ?
`import _astroConfig from '/astro.config';` :
`const _astroConfig = undefined;`
}
const _markdownRender = _astroConfig?.markdown?.render ? _astroConfig.markdown.render[0] : _astroRemark;
let _manifest = _deserializeManifest('${manifestReplace}');
Object.assign(_manifest, {
const _manifest = Object.assign(_deserializeManifest('${manifestReplace}'), {
pageMap: _main.pageMap,
renderers: _main.renderers,
markdown: {
render: [_markdownRender, _manifest.markdown.render[1]],
},
renderers: _main.renderers
});
const _args = ${adapter.args ? JSON.stringify(adapter.args) : 'undefined'};
Expand Down Expand Up @@ -121,9 +109,7 @@ function buildManifest(opts: StaticBuildOptions, internals: BuildInternals): Ser
const ssrManifest: SerializedSSRManifest = {
routes,
site: astroConfig.site,
markdown: {
render: [astroRemark, astroConfig.markdown],
},
markdown: astroConfig.markdown,
pageMap: null as any,
renderers: [],
entryModules,
Expand Down
15 changes: 4 additions & 11 deletions packages/astro/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import loadTypeScript from '@proload/plugin-tsm';
import postcssrc from 'postcss-load-config';
import { arraify, isObject } from './util.js';
import { appendForwardSlash, trimSlashes } from './path.js';
import { flags as projectFlags } from './project-flags.js';

load.use([loadTypeScript]);

Expand Down Expand Up @@ -177,7 +176,6 @@ export async function validateConfig(
userConfig: any,
root: string,
cmd: string,
hasUserConfig: boolean
): Promise<AstroConfig> {
const fileProtocolRoot = pathToFileURL(root + path.sep);
// Manual deprecation checks
Expand Down Expand Up @@ -279,11 +277,8 @@ export async function validateConfig(
// First-Pass Validation
const result = {
...(await AstroConfigRelativeSchema.parseAsync(userConfig)),
_ctx: { scripts: [], renderers: [], adapter: undefined, projectFlags: 0 },
_ctx: { scripts: [], renderers: [], adapter: undefined },
};
if(hasUserConfig) {
result._ctx.projectFlags |= projectFlags.USER_CONFIG;
}
// Final-Pass Validation (perform checks that require the full config object)
if (
!result.experimental?.integrations &&
Expand Down Expand Up @@ -391,7 +386,7 @@ export async function loadConfig(configOptions: LoadConfigOptions): Promise<Astr

// Automatically load config file using Proload
// If `userConfigPath` is `undefined`, Proload will search for `astro.config.[cm]?[jt]s`
let config, hasUserConfig = false;
let config;
try {
config = await load('astro', {
mustExist: !!userConfigPath,
Expand All @@ -405,10 +400,9 @@ export async function loadConfig(configOptions: LoadConfigOptions): Promise<Astr
throw err;
}
if (config) {
hasUserConfig = true;
userConfig = config.value;
}
return resolveConfig(userConfig, root, flags, configOptions.cmd, hasUserConfig);
return resolveConfig(userConfig, root, flags, configOptions.cmd);
}

/** Attempt to resolve an Astro configuration object. Normalize, validate, and return. */
Expand All @@ -417,10 +411,9 @@ export async function resolveConfig(
root: string,
flags: CLIFlags = {},
cmd: string,
hasUserConfig: boolean
): Promise<AstroConfig> {
const mergedConfig = mergeCLIFlags(userConfig, flags, cmd);
const validatedConfig = await validateConfig(mergedConfig, root, cmd, hasUserConfig);
const validatedConfig = await validateConfig(mergedConfig, root, cmd);

return validatedConfig;
}
Expand Down
13 changes: 0 additions & 13 deletions packages/astro/src/core/project-flags.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/astro/test/ssr-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ describe('Markdown pages in SSR', () => {
expect($('#subheading').text()).to.equal('Subheading');
});

it.only('Renders the Markdown component correctly', async () => {
it('Renders the Markdown component correctly', async () => {
const html = await fetchHTML('/page');
console.log(html);
const $ = cheerioLoad(html);
expect($('#something')).to.have.lengthOf(1);
});
});

0 comments on commit 51cdda6

Please sign in to comment.