File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ const baseURL = import.meta.env.BASE_URL;
38
38
}
39
39
</script >
40
40
<script >
41
- import * as builtInSwap from 'node_modules/astro/dist/transitions/swap-functions';
41
+ // @ts-ignore -- untyped
42
+ import * as builtInSwap from 'tutorialkit:astro-swap-functions';
42
43
43
44
declare global {
44
45
function setTutorialKitTheme(): void;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { fileURLToPath } from 'node:url';
4
4
import { extraIntegrations } from './integrations.js' ;
5
5
import { updateMarkdownConfig } from './remark/index.js' ;
6
6
import { tutorialkitCore } from './vite-plugins/core.js' ;
7
+ import { astroSwapFunctions } from './vite-plugins/astro-swap-functions.js' ;
7
8
import { userlandCSS , watchUserlandCSS } from './vite-plugins/css.js' ;
8
9
import { tutorialkitStore } from './vite-plugins/store.js' ;
9
10
import { overrideComponents , type OverrideComponentsOptions } from './vite-plugins/override-components.js' ;
@@ -108,6 +109,7 @@ export default function createPlugin({
108
109
tutorialkitStore ,
109
110
tutorialkitCore ,
110
111
overrideComponents ( { components, defaultRoutes : ! ! defaultRoutes } ) ,
112
+ astroSwapFunctions ( ) ,
111
113
process . env . TUTORIALKIT_DEV ? ( await import ( 'vite-plugin-inspect' ) ) . default ( ) : null ,
112
114
] ,
113
115
} ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * A plugin for importing Astro's private 'transitions/swap-functions.js' module.
3
+ * This is temporary solution and can break at any time when end-user's update their `astro` version.
4
+ */
5
+ import { readFile } from 'node:fs/promises' ;
6
+ import { createRequire } from 'node:module' ;
7
+ import { resolve } from 'node:path' ;
8
+ import type { VitePlugin } from '../types.js' ;
9
+
10
+ const require = createRequire ( import . meta. url ) ;
11
+ const astroDist = resolve ( require . resolve ( 'astro/package.json' ) , '..' ) ;
12
+ const swapFunctionEntry = resolve ( astroDist , 'dist/transitions/swap-functions.js' ) ;
13
+
14
+ const virtualModuleId = 'tutorialkit:astro-swap-functions' ;
15
+ const resolvedId = `\0${ virtualModuleId } ` ;
16
+
17
+ export function astroSwapFunctions ( ) : VitePlugin {
18
+ return {
19
+ name : 'tutorialkit-astro-swap-functions-plugin' ,
20
+ resolveId ( id ) {
21
+ if ( id === virtualModuleId ) {
22
+ return resolvedId ;
23
+ }
24
+
25
+ return undefined ;
26
+ } ,
27
+
28
+ async load ( id ) {
29
+ if ( id === resolvedId ) {
30
+ return await readFile ( swapFunctionEntry , 'utf8' ) ;
31
+ }
32
+
33
+ return undefined ;
34
+ } ,
35
+ } ;
36
+ }
You can’t perform that action at this time.
0 commit comments