Repository navigation
fix(monaco): whitelist the monaco-write path the dev server actually resolves - #2740
Merged
Merged
Conversation
…resolves
resolveSnippetImport returns both the raw specifier as typed in the Markdown
and the resolved absolute path. Reading uses the resolved one; the
{monaco-write} branch whitelisted and embedded the raw one.
createMonacoWriterPlugin resolves whatever it receives against userRoot, so
an @/ alias became <userRoot>/@/... and a slide-relative path was resolved
from the wrong directory. Saving from the editor either failed with ENOENT
or wrote to a different file than the one displayed.
Hand it the userRoot-relative form of the resolved path instead, which keeps
the writer's outside-the-root guard meaningful.
✅ Deploy Preview for slidev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@slidev/client
create-slidev
create-slidev-theme
@slidev/parser
@slidev/cli
@slidev/types
commit: |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
resolveSnippetImportreturns two different things:filepathis the specifier exactly as typed in the Markdown;srcis where it actually lives. Reading usessrc. The{monaco-write}branch usedfilepath:and
createMonacoWriterPluginresolves whatever it receives againstuserRoot:So the snippet is read through one resolution scheme and written back through another.
<<< @/snippets/x.ts {monaco-write}<userRoot>/snippets/x.ts<userRoot>/@/snippets/x.ts<<< ./x.ts {monaco-write}inpages/deck.md<userRoot>/pages/x.ts<userRoot>/x.tsThe
@/form — the one the docs recommend — writes into a directory literally named@, which does not exist, sofs.writeFilerejects with ENOENT inside the websocket handler and the save is lost with no feedback in the editor. The relative form silently writes to a different file than the one on screen.Fix
Hand the writer the
userRoot-relative form of the resolved path, which is the scheme it resolves in:monacoWrite.tsandMonaco.vueare untouched. The plugin'srel.startsWith('..')guard keeps working and becomes meaningful — it now compares a path that really was resolved againstuserRoot.Test plan
packages/slidev/node/syntax/snippet.test.ts, reusing itstest/fixtures/root andsnippets/snippet.tsfixture. It asserts the whitelisted value, thewritableattribute, and thatpath.resolve(userRoot, whitelisted)lands back on the file that was read — the writer's own expression.vitest run packages/slidev/node/syntax/snippet.test.ts→ 6 passed.snippet.tsfails the new test with[ '@/snippets/snippet.ts' ]instead of[ 'snippets/snippet.ts' ].eslinton both touched files → clean.