From 51cdda69609b18de7f4ce5162afed70526b0c4e2 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 8 Apr 2022 08:58:15 -0400 Subject: [PATCH] Update --- packages/astro/src/@types/astro.ts | 1 - packages/astro/src/core/app/index.ts | 4 ++-- packages/astro/src/core/app/types.ts | 6 ++---- .../astro/src/core/build/vite-plugin-ssr.ts | 20 +++---------------- packages/astro/src/core/config.ts | 15 ++++---------- packages/astro/src/core/project-flags.ts | 13 ------------ packages/astro/test/ssr-markdown.test.js | 4 ++-- 7 files changed, 13 insertions(+), 50 deletions(-) delete mode 100644 packages/astro/src/core/project-flags.ts diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index e25b603bd034a..76e24a4a0fcab 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -589,7 +589,6 @@ export interface AstroConfig extends z.output { adapter: AstroAdapter | undefined; renderers: AstroRenderer[]; scripts: { stage: InjectedScriptStage; content: string }[]; - projectFlags: number; }; } diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 81e19f914ce1a..541b468d916f9 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -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'; @@ -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; @@ -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, diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index 27af8b6655683..8fcbac41dce8a 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -1,7 +1,7 @@ import type { + AstroUserConfig, RouteData, SerializedRouteData, - MarkdownRenderOptions, ComponentInstance, SSRLoadedRenderer, } from '../../@types/astro'; @@ -22,9 +22,7 @@ export type SerializedRouteInfo = Omit & { export interface SSRManifest { routes: RouteInfo[]; site?: string; - markdown: { - render: MarkdownRenderOptions; - }; + markdown: AstroUserConfig['markdown']; pageMap: Map; renderers: SSRLoadedRenderer[]; entryModules: Record; diff --git a/packages/astro/src/core/build/vite-plugin-ssr.ts b/packages/astro/src/core/build/vite-plugin-ssr.ts index 73ca153eefc54..3e7257f02e762 100644 --- a/packages/astro/src/core/build/vite-plugin-ssr.ts +++ b/packages/astro/src/core/build/vite-plugin-ssr.ts @@ -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'; @@ -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; @@ -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'}; @@ -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, diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index d65c7fc453cbd..9426503d8b8f1 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -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]); @@ -177,7 +176,6 @@ export async function validateConfig( userConfig: any, root: string, cmd: string, - hasUserConfig: boolean ): Promise { const fileProtocolRoot = pathToFileURL(root + path.sep); // Manual deprecation checks @@ -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 && @@ -391,7 +386,7 @@ export async function loadConfig(configOptions: LoadConfigOptions): Promise { const mergedConfig = mergeCLIFlags(userConfig, flags, cmd); - const validatedConfig = await validateConfig(mergedConfig, root, cmd, hasUserConfig); + const validatedConfig = await validateConfig(mergedConfig, root, cmd); return validatedConfig; } diff --git a/packages/astro/src/core/project-flags.ts b/packages/astro/src/core/project-flags.ts deleted file mode 100644 index 28a40013655dd..0000000000000 --- a/packages/astro/src/core/project-flags.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { AstroConfig } from '../@types/astro'; - -export const flags = { - USER_CONFIG: 1 << 0 -}; - -export function hasFlag(config: AstroConfig, flag: number): boolean { - return !!(config._ctx.projectFlags & flag); -} - -export function hasUserConfig(config: AstroConfig): boolean { - return hasFlag(config, flags.USER_CONFIG); -} diff --git a/packages/astro/test/ssr-markdown.test.js b/packages/astro/test/ssr-markdown.test.js index fc66f1ab5c105..17105330f46c4 100644 --- a/packages/astro/test/ssr-markdown.test.js +++ b/packages/astro/test/ssr-markdown.test.js @@ -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); }); });