Skip to content

Commit

Permalink
Merge branch 'main' into fix/vercel-dynamic-routes
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanM04 committed Apr 12, 2022
2 parents 1728ab7 + b835e28 commit 64ff2a6
Show file tree
Hide file tree
Showing 30 changed files with 262 additions and 186 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-mugs-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix bug with inconsistent url search params
5 changes: 5 additions & 0 deletions .changeset/forty-plants-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': patch
---

Improved type checking
5 changes: 5 additions & 0 deletions .changeset/lemon-elephants-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---

Make Netlify adapter actually append redirects
5 changes: 5 additions & 0 deletions .changeset/small-months-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Improved markdown config type checking
3 changes: 3 additions & 0 deletions examples/framework-alpine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
},
"devDependencies": {
"astro": "^1.0.0-beta.7"
},
"dependencies": {
"alpinejs": "^3.9.6"
}
}
8 changes: 6 additions & 2 deletions examples/framework-alpine/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ import Counter from '../components/Counter.astro';
}
</style>

<!-- Be sure to include AlpineJS -->
<script src="//unpkg.com/alpinejs" defer is:inline></script>
<!-- Load AlpineJS on the page -->
<script>
import Alpine from 'alpinejs';
window.Alpine = Alpine;
Alpine.start();
</script>
</head>
<body>
<main>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"build:ci": "turbo run build:ci --no-deps --scope=astro --scope=create-astro --scope=\"@astrojs/*\"",
"build:examples": "turbo run build --scope=\"@example/*\"",
"dev": "turbo run dev --no-deps --no-cache --parallel --scope=astro --scope=create-astro --scope=\"@astrojs/*\"",
"test": "pnpm run test --filter astro --filter @astrojs/webapi --filter @astrojs/deno --filter @astrojs/netlify",
"test": "turbo run test --filter=!create-astro --concurrency=1",
"test:match": "cd packages/astro && pnpm run test:match",
"test:templates": "pnpm run test --filter create-astro",
"test:templates": "turbo run test --filter=create-astro --concurrency=1",
"test:smoke": "node scripts/smoke/index.js",
"benchmark": "turbo run benchmark --scope=astro",
"lint": "eslint \"packages/**/*.ts\"",
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"execa": "^6.1.0",
"fast-glob": "^3.2.11",
"fast-xml-parser": "^4.0.7",
"gray-matter": "^4.0.3",
"html-entities": "^2.3.3",
"html-escaper": "^3.0.3",
"htmlparser2": "^7.2.0",
Expand Down Expand Up @@ -156,6 +157,7 @@
"@types/resolve": "^1.20.1",
"@types/rimraf": "^3.0.2",
"@types/send": "^0.17.1",
"@types/unist": "^2.0.6",
"@types/yargs-parser": "^21.0.0",
"astro-scripts": "workspace:*",
"chai": "^4.3.6",
Expand Down
34 changes: 19 additions & 15 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AddressInfo } from 'net';
import type * as babel from '@babel/core';
import type * as vite from 'vite';
import { z } from 'zod';
import type { ShikiConfig, Plugin } from '@astrojs/markdown-remark';
import type { ShikiConfig, RemarkPlugins, RehypePlugins } from '@astrojs/markdown-remark';
import type { AstroConfigSchema } from '../core/config';
import type { AstroComponentFactory, Metadata } from '../runtime/server';
import type { ViteConfigWithSSR } from '../core/create-vite';
Expand Down Expand Up @@ -481,14 +481,24 @@ export interface AstroUserConfig {
*/
drafts?: boolean;

/**
* @docs
* @name markdown.mode
* @type {'md' | 'mdx'}
* @default `mdx`
* @description
* Control wheater to allow components inside markdown files ('mdx') or not ('md').
*/
mode?: 'md' | 'mdx';

/**
* @docs
* @name markdown.shikiConfig
* @type {ShikiConfig}
* @typeraw {Partial<ShikiConfig>}
* @description
* Shiki configuration options. See [the markdown configuration docs](https://docs.astro.build/en/guides/markdown-content/#shiki-configuration) for usage.
*/
shikiConfig?: ShikiConfig;
shikiConfig?: Partial<ShikiConfig>;

/**
* @docs
Expand All @@ -515,7 +525,7 @@ export interface AstroUserConfig {
/**
* @docs
* @name markdown.remarkPlugins
* @type {Plugin[]}
* @type {RemarkPlugins}
* @description
* Pass a custom [Remark](https://github.com/remarkjs/remark) plugin to customize how your Markdown is built.
*
Expand All @@ -530,11 +540,11 @@ export interface AstroUserConfig {
* };
* ```
*/
remarkPlugins?: Plugin[];
remarkPlugins?: RemarkPlugins;
/**
* @docs
* @name markdown.rehypePlugins
* @type {Plugin[]}
* @type {RehypePlugins}
* @description
* Pass a custom [Rehype](https://github.com/remarkjs/remark-rehype) plugin to customize how your Markdown is built.
*
Expand All @@ -549,7 +559,7 @@ export interface AstroUserConfig {
* };
* ```
*/
rehypePlugins?: Plugin[];
rehypePlugins?: RehypePlugins;
};

/**
Expand Down Expand Up @@ -618,13 +628,13 @@ export interface AstroUserConfig {

experimental?: {
/**
* Enable experimental support for 3rd-party integrations.
* Enable support for 3rd-party integrations.
* Default: false
*/
integrations?: boolean;

/**
* Enable a build for SSR support.
* Enable support for 3rd-party SSR adapters.
* Default: false
*/
ssr?: boolean;
Expand Down Expand Up @@ -757,12 +767,6 @@ export interface ManifestData {
routes: RouteData[];
}

export type MarkdownRenderOptions = [string | MarkdownParser, Record<string, any>];
export type MarkdownParser = (
contents: string,
options?: Record<string, any>
) => MarkdownParserResponse | PromiseLike<MarkdownParserResponse>;

export interface MarkdownParserResponse {
frontmatter: {
[key: string]: any;
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function printAstroHelp() {
['--config <path>', 'Specify the path to the Astro config file.'],
['--root <path>', 'Specify the path to the project root folder.'],
['--legacy-build', 'Use the build strategy prior to 0.24.0'],
['--experimental-ssr', 'Enable SSR compilation fot 3rd-party adapters.'],
['--drafts', 'Include markdown draft pages in the build.'],
['--verbose', 'Enable verbose logging'],
['--silent', 'Disable logging'],
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 @@ -82,7 +82,7 @@ export class App {
legacyBuild: false,
links,
logging: this.#logging,
markdownRender: manifest.markdown.render,
markdown: 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,10 +1,10 @@
import type {
RouteData,
SerializedRouteData,
MarkdownRenderOptions,
ComponentInstance,
SSRLoadedRenderer,
} from '../../@types/astro';
import type { MarkdownRenderingOptions } from '@astrojs/markdown-remark';

export type ComponentPath = string;

Expand All @@ -22,9 +22,7 @@ export type SerializedRouteInfo = Omit<RouteInfo, 'routeData'> & {
export interface SSRManifest {
routes: RouteInfo[];
site?: string;
markdown: {
render: MarkdownRenderOptions;
};
markdown: MarkdownRenderingOptions;
pageMap: Map<ComponentPath, ComponentInstance>;
renderers: SSRLoadedRenderer[];
entryModules: Record<string, string>;
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import astroRemark from '@astrojs/markdown-remark';
import fs from 'fs';
import { bgGreen, black, cyan, dim, green, magenta } from 'kleur/colors';
import npath from 'path';
Expand Down Expand Up @@ -197,7 +196,7 @@ async function generatePath(
legacyBuild: false,
links,
logging,
markdownRender: [astroRemark, astroConfig.markdown],
markdown: astroConfig.markdown,
mod,
origin,
pathname,
Expand Down
5 changes: 1 addition & 4 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 Down Expand Up @@ -110,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
49 changes: 35 additions & 14 deletions packages/astro/src/core/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { AstroConfig, AstroUserConfig, CLIFlags } from '../@types/astro';
import type { Arguments as Flags } from 'yargs-parser';
import type * as Postcss from 'postcss';
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
import type { RemarkPlugin, RehypePlugin } from '@astrojs/markdown-remark';

import * as colors from 'kleur/colors';
import path from 'path';
import { pathToFileURL, fileURLToPath } from 'url';
import { mergeConfig as mergeViteConfig } from 'vite';
import { BUNDLED_THEMES } from 'shiki';
import { z } from 'zod';
import load, { ProloadError } from '@proload/core';
import loadTypeScript from '@proload/plugin-tsm';
Expand Down Expand Up @@ -142,24 +145,42 @@ export const AstroConfigSchema = z.object({
.default({}),
markdown: z
.object({
drafts: z.boolean().optional().default(false),
mode: z
.union([z.literal('md'), z.literal('mdx')])
.optional()
// NOTE: "mdx" allows us to parse/compile Astro components in markdown.
// TODO: This should probably be updated to something more like "md" | "astro"
.default('mdx'),
// NOTE: "mdx" allows us to parse/compile Astro components in markdown.
// TODO: This should probably be updated to something more like "md" | "astro"
mode: z.enum(['md', 'mdx']).default('mdx'),
drafts: z.boolean().default(false),
syntaxHighlight: z
.union([z.literal('shiki'), z.literal('prism'), z.literal(false)])
.optional()
.default('shiki'),
// TODO: add better type checking
shikiConfig: z.any().optional().default({}),
remarkPlugins: z.array(z.any()).optional().default([]),
rehypePlugins: z.array(z.any()).optional().default([]),
shikiConfig: z
.object({
langs: z.custom<ILanguageRegistration>().array().default([]),
theme: z
.enum(BUNDLED_THEMES as [Theme, ...Theme[]])
.or(z.custom<IThemeRegistration>())
.default('github-dark'),
wrap: z.boolean().or(z.null()).default(false),
})
.default({}),
remarkPlugins: z
.union([
z.string(),
z.tuple([z.string(), z.any()]),
z.custom<RemarkPlugin>((data) => typeof data === 'function'),
z.tuple([z.custom<RemarkPlugin>((data) => typeof data === 'function'), z.any()]),
])
.array()
.default([]),
rehypePlugins: z
.union([
z.string(),
z.tuple([z.string(), z.any()]),
z.custom<RehypePlugin>((data) => typeof data === 'function'),
z.tuple([z.custom<RehypePlugin>((data) => typeof data === 'function'), z.any()]),
])
.array()
.default([]),
})
.passthrough()
.optional()
.default({}),
vite: z.any().optional().default({}),
experimental: z
Expand Down
9 changes: 4 additions & 5 deletions packages/astro/src/core/render/core.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type {
ComponentInstance,
EndpointHandler,
MarkdownRenderOptions,
Params,
Props,
SSRLoadedRenderer,
RouteData,
SSRElement,
} from '../../@types/astro';
import type { MarkdownRenderingOptions } from '@astrojs/markdown-remark';
import type { LogOptions } from '../logger/core.js';

import { renderHead, renderPage } from '../../runtime/server/index.js';
Expand Down Expand Up @@ -70,7 +69,7 @@ export interface RenderOptions {
legacyBuild: boolean;
logging: LogOptions;
links: Set<SSRElement>;
markdownRender: MarkdownRenderOptions;
markdown: MarkdownRenderingOptions;
mod: ComponentInstance;
origin: string;
pathname: string;
Expand All @@ -92,7 +91,7 @@ export async function render(
links,
logging,
origin,
markdownRender,
markdown,
mod,
pathname,
scripts,
Expand Down Expand Up @@ -132,7 +131,7 @@ export async function render(
legacyBuild,
links,
logging,
markdownRender,
markdown,
origin,
params,
pathname,
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/core/render/dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import astroRemark from '@astrojs/markdown-remark';
import { fileURLToPath } from 'url';
import type * as vite from 'vite';
import type {
Expand Down Expand Up @@ -164,7 +163,7 @@ export async function render(
legacyBuild: isLegacyBuild,
links,
logging,
markdownRender: [astroRemark, astroConfig.markdown],
markdown: astroConfig.markdown,
mod,
origin,
pathname,
Expand Down
Loading

0 comments on commit 64ff2a6

Please sign in to comment.