-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94503a7
deps: vite-plugin-restart
bholmesdev ebf889c
feat: restart on markdoc config change
bholmesdev d75d44d
chore: changeset
bholmesdev 1397bd4
chore: roll our own restarter!
bholmesdev 23d1ebf
deps: remove vite-plugin-restart
bholmesdev ce2f157
refactor: use good enough option
bholmesdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -15,11 +15,15 @@ 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 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'> & { | ||
|
@@ -45,15 +49,13 @@ export default function markdocIntegration(legacyConfig?: any): AstroIntegration | |
} | ||
let markdocConfigResult: MarkdocConfigResult | undefined; | ||
let markdocConfigResultId = ''; | ||
let astroConfig: AstroConfig; | ||
return { | ||
name: '@astrojs/markdoc', | ||
hooks: { | ||
'astro:config:setup': async (params) => { | ||
const { | ||
config: astroConfig, | ||
updateConfig, | ||
addContentEntryType, | ||
} = params as SetupHookParams; | ||
const { updateConfig, addContentEntryType } = params as SetupHookParams; | ||
astroConfig = params.config; | ||
|
||
markdocConfigResult = await loadMarkdocConfig(astroConfig); | ||
if (markdocConfigResult) { | ||
|
@@ -204,10 +206,8 @@ export const Content = createComponent({ | |
|
||
updateConfig({ | ||
vite: { | ||
vite: { | ||
ssr: { | ||
external: ['@astrojs/markdoc/prism', '@astrojs/markdoc/shiki'], | ||
}, | ||
ssr: { | ||
external: ['@astrojs/markdoc/prism', '@astrojs/markdoc/shiki'], | ||
}, | ||
build: { | ||
rollupOptions, | ||
|
@@ -233,12 +233,11 @@ 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.` | ||
) | ||
); | ||
for (const markdocConfigBase of SUPPORTED_MARKDOC_CONFIG_FILES) { | ||
const absolutePath = new URL(markdocConfigBase, astroConfig.root); | ||
if (entry === fileURLToPath(absolutePath)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this will be the file path and not a Vite ID. Let me know if that's wrong!
bluwy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
server.restart(); | ||
} | ||
} | ||
}); | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: