File tree Expand file tree Collapse file tree
src/lib/components/files/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ export const CODEMIRROR_PACKAGES = [
2+ '@codemirror/autocomplete' ,
3+ '@codemirror/commands' ,
4+ '@codemirror/lang-cpp' ,
5+ '@codemirror/lang-css' ,
6+ '@codemirror/lang-html' ,
7+ '@codemirror/lang-java' ,
8+ '@codemirror/lang-javascript' ,
9+ '@codemirror/lang-json' ,
10+ '@codemirror/lang-markdown' ,
11+ '@codemirror/lang-php' ,
12+ '@codemirror/lang-python' ,
13+ '@codemirror/lang-rust' ,
14+ '@codemirror/lang-sql' ,
15+ '@codemirror/lang-xml' ,
16+ '@codemirror/language' ,
17+ '@codemirror/lint' ,
18+ '@codemirror/merge' ,
19+ '@codemirror/state' ,
20+ '@codemirror/theme-one-dark' ,
21+ '@codemirror/view' ,
22+ ] as const ;
Original file line number Diff line number Diff line change 1+ import { Compartment , EditorState } from '@codemirror/state' ;
2+ import { describe , expect , it } from 'vitest' ;
3+
4+ import { loadLanguageExtension } from '../language-loader' ;
5+
6+ describe ( 'loadLanguageExtension' , ( ) => {
7+ it ( 'loads a .svelte language extension that CodeMirror can reconfigure' , async ( ) => {
8+ const languageCompartment = new Compartment ( ) ;
9+ let editorState = EditorState . create ( {
10+ doc : '<script lang="ts">let count = 0;</script>\n<button>{count}</button>' ,
11+ extensions : [ languageCompartment . of ( [ ] ) ] ,
12+ } ) ;
13+
14+ const extensions = await loadLanguageExtension ( 'Counter.svelte' ) ;
15+ const transaction = editorState . update ( {
16+ effects : languageCompartment . reconfigure ( extensions ) ,
17+ } ) ;
18+ editorState = transaction . state ;
19+
20+ expect ( extensions . length ) . toBeGreaterThan ( 0 ) ;
21+ expect ( editorState . doc . lines ) . toBe ( 2 ) ;
22+ } ) ;
23+ } ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { sveltekit } from '@sveltejs/kit/vite';
33import tailwindcss from '@tailwindcss/vite' ;
44import { defineConfig } from 'vite' ;
55import path from 'node:path' ;
6+ import { CODEMIRROR_PACKAGES } from './codemirror-packages' ;
67
78export default defineConfig ( {
89 plugins : [
@@ -17,6 +18,11 @@ export default defineConfig({
1718 alias : {
1819 $shared : path . resolve ( __dirname , '../common' ) ,
1920 } ,
21+ // CodeMirror extensions rely on instanceof checks from @codemirror /state.
22+ dedupe : [ ...CODEMIRROR_PACKAGES ] ,
23+ } ,
24+ optimizeDeps : {
25+ include : [ ...CODEMIRROR_PACKAGES ] ,
2026 } ,
2127 build : {
2228 rollupOptions : {
Original file line number Diff line number Diff line change 11import { defineConfig } from 'vitest/config' ;
22import { svelte } from '@sveltejs/vite-plugin-svelte' ;
3+ import { CODEMIRROR_PACKAGES } from './codemirror-packages' ;
34
45export default defineConfig ( {
56 plugins : [ svelte ( ) ] ,
@@ -8,6 +9,13 @@ export default defineConfig({
89 globals : true ,
910 setupFiles : [ './src/test/vitest-setup.ts' ] ,
1011 include : [ 'src/**/*.test.ts' ] ,
12+ server : {
13+ deps : {
14+ // CodeMirror extensions rely on instanceof checks from @codemirror /state.
15+ // Inline the whole family so Vitest cannot mix externalized and Vite-transformed copies.
16+ inline : [ ...CODEMIRROR_PACKAGES ] ,
17+ } ,
18+ } ,
1119 alias : {
1220 $lib : new URL ( './src/lib' , import . meta. url ) . pathname ,
1321 $app : new URL ( './src/lib/mocks/app' , import . meta. url ) . pathname ,
@@ -16,5 +24,7 @@ export default defineConfig({
1624 } ,
1725 resolve : {
1826 conditions : [ 'browser' ] ,
27+ // CodeMirror extensions rely on instanceof checks from @codemirror /state.
28+ dedupe : [ ...CODEMIRROR_PACKAGES ] ,
1929 } ,
2030} ) ;
You can’t perform that action at this time.
0 commit comments