Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: restart server on markdoc config change #7467

Merged
merged 6 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-apples-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdoc': patch
---

Restart the dev server whenever your markdoc config changes.
1 change: 1 addition & 0 deletions packages/integrations/markdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"gray-matter": "^4.0.3",
"kleur": "^4.1.5",
"shiki": "^0.14.1",
"vite-plugin-restart": "^0.3.1",
"zod": "^3.17.3"
},
"peerDependencies": {
Expand Down
31 changes: 13 additions & 18 deletions packages/integrations/markdoc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Markdoc from '@markdoc/markdoc';
import type { AstroConfig, AstroIntegration, ContentEntryType, HookParameters } from 'astro';
import crypto from 'node:crypto';
import fs from 'node:fs';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { fileURLToPath } from 'node:url';
import {
hasContentFlag,
isValidUrl,
Expand All @@ -15,11 +15,16 @@ import {
} from './utils.js';
// @ts-expect-error Cannot find module 'astro/assets' or its corresponding type declarations.
import { emitESMImage } from 'astro/assets';
import { bold, red, yellow } from 'kleur/colors';
import { bold, red } from 'kleur/colors';
import vitePluginRestart from 'vite-plugin-restart';
import path from 'node:path';
import type * as rollup from 'rollup';
import { normalizePath } from 'vite';
import { loadMarkdocConfig, type MarkdocConfigResult } from './load-config.js';
import {
loadMarkdocConfig,
SUPPORTED_MARKDOC_CONFIG_FILES,
type MarkdocConfigResult,
} from './load-config.js';
import { setupConfig } from './runtime.js';

type SetupHookParams = HookParameters<'astro:config:setup'> & {
Expand Down Expand Up @@ -204,15 +209,16 @@ export const Content = createComponent({

updateConfig({
vite: {
vite: {
ssr: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How long has that been there... :houston_panic:

external: ['@astrojs/markdoc/prism', '@astrojs/markdoc/shiki'],
},
ssr: {
external: ['@astrojs/markdoc/prism', '@astrojs/markdoc/shiki'],
},
build: {
rollupOptions,
},
plugins: [
vitePluginRestart({
restart: SUPPORTED_MARKDOC_CONFIG_FILES,
}),
{
name: '@astrojs/markdoc:astro-propagated-assets',
enforce: 'pre',
Expand All @@ -231,17 +237,6 @@ export const Content = createComponent({
},
});
},
'astro:server:setup': async ({ server }) => {
server.watcher.on('all', (event, entry) => {
if (prependForwardSlash(pathToFileURL(entry).pathname) === markdocConfigResultId) {
console.log(
yellow(
`${bold('[Markdoc]')} Restart the dev server for config changes to take effect.`
)
);
}
bholmesdev marked this conversation as resolved.
Show resolved Hide resolved
});
},
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/markdoc/src/load-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import type { AstroMarkdocConfig } from './config.js';

const SUPPORTED_MARKDOC_CONFIG_FILES = [
export const SUPPORTED_MARKDOC_CONFIG_FILES = [
'markdoc.config.js',
'markdoc.config.mjs',
'markdoc.config.mts',
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.