11import path from 'node:path'
2+ import { pathToFileURL } from 'node:url'
23
34import type { WorkerMetaContext } from '@vscode-wdio/types'
45import type { createTempConfigFile } from './config.js'
@@ -10,15 +11,29 @@ const VSCODE_WINDOWS_CONFIG_CREATOR_PATH = path.resolve(__dirname, 'parser/ast.c
1011let tempConfigCreator : TempConfigFileCreator | undefined
1112
1213export async function getTempConfigCreator ( context : WorkerMetaContext ) : Promise < TempConfigFileCreator > {
13- if ( tempConfigCreator ) {
14- context . log . debug ( 'Use cached TempConfigFileCreator' )
15- return tempConfigCreator
16- }
17- context . log . debug ( 'Import TempConfigFileCreator' )
18- tempConfigCreator = ( await import ( VSCODE_WINDOWS_CONFIG_CREATOR_PATH ) ) . createTempConfigFile as TempConfigFileCreator
19- return tempConfigCreator
14+ return ( await dynamicLoader (
15+ context ,
16+ tempConfigCreator ,
17+ VSCODE_WINDOWS_CONFIG_CREATOR_PATH ,
18+ 'createTempConfigFile'
19+ ) ) as TempConfigFileCreator
2020}
2121
2222export function isWindows ( ) {
2323 return process . platform === 'win32'
2424}
25+
26+ export async function dynamicLoader (
27+ context : WorkerMetaContext ,
28+ libModule : unknown ,
29+ modulePath : string ,
30+ fnName : string
31+ ) : Promise < unknown > {
32+ if ( libModule ) {
33+ context . log . debug ( `Use cached ${ path . dirname ( modulePath ) } ` )
34+ return libModule
35+ }
36+ context . log . debug ( `Import ${ path . basename ( modulePath ) } ` )
37+ libModule = ( await import ( pathToFileURL ( modulePath ) . href ) ) [ fnName ]
38+ return libModule
39+ }
0 commit comments