@@ -27,85 +27,62 @@ export type LwcDevServerModule = {
2727} ;
2828
2929/**
30- * Dynamically loads LWC dependencies based on version channel
30+ * Loads the LWC dev server module for the specified channel
31+ * Uses dynamic import to load the aliased package at runtime
32+ *
33+ * @param channel - The version channel ('latest', 'prerelease', or 'next')
34+ * @returns The loaded module
3135 */
32- export class DependencyLoader {
33- private static loadedModules : Map < VersionChannel , LwcDevServerModule > = new Map ( ) ;
34-
35- /**
36- * Loads the LWC dev server module for the specified channel
37- * Uses dynamic import to load the aliased package at runtime
38- *
39- * @param channel - The version channel ('latest' or 'prerelease')
40- * @returns The loaded module
41- */
42- public static async loadLwcDevServer ( channel : VersionChannel ) : Promise < LwcDevServerModule > {
43- // Check cache first
44- if ( this . loadedModules . has ( channel ) ) {
45- return this . loadedModules . get ( channel ) ! ;
46- }
36+ export async function loadLwcDevServer ( channel : VersionChannel ) : Promise < LwcDevServerModule > {
37+ const packageName = `@lwc/lwc-dev-server-${ channel } ` ;
4738
48- // Construct the aliased package name
49- const packageName = `@lwc/lwc-dev-server-${ channel } ` ;
50-
51- try {
52- // Dynamic import of the aliased package
53- const module = ( await import ( packageName ) ) as LwcDevServerModule ;
54- this . loadedModules . set ( channel , module ) ;
55- return module ;
56- } catch ( error ) {
57- throw new Error (
58- `Failed to load LWC dev server for channel '${ channel } '. ` +
59- `Package '${ packageName } ' could not be imported. ` +
60- `Error: ${ error instanceof Error ? error . message : String ( error ) } `
61- ) ;
62- }
39+ try {
40+ return ( await import ( packageName ) ) as LwcDevServerModule ;
41+ } catch ( error ) {
42+ throw new Error (
43+ `Failed to load LWC dev server for channel '${ channel } '. ` +
44+ `Package '${ packageName } ' could not be imported. ` +
45+ `Error: ${ error instanceof Error ? error . message : String ( error ) } ` ,
46+ ) ;
6347 }
48+ }
6449
65- /**
66- * Loads the LWC compiler module for the specified channel
67- *
68- * @param channel - The version channel ('latest' or 'prerelease ')
69- * @returns The loaded compiler module
70- */
71- public static async loadLwcCompiler ( channel : VersionChannel ) : Promise < unknown > {
72- const packageName = `@lwc/sfdc-lwc-compiler-${ channel } ` ;
50+ /**
51+ * Loads the LWC compiler module for the specified channel
52+ *
53+ * @param channel - The version channel ('latest', 'prerelease', or 'next ')
54+ * @returns The loaded compiler module
55+ */
56+ export async function loadLwcCompiler ( channel : VersionChannel ) : Promise < unknown > {
57+ const packageName = `@lwc/sfdc-lwc-compiler-${ channel } ` ;
7358
74- try {
75- return ( await import ( packageName ) ) as unknown ;
76- } catch ( error ) {
77- throw new Error (
78- `Failed to load LWC compiler for channel '${ channel } '. ` +
79- `Package '${ packageName } ' could not be imported. ` +
80- `Error: ${ error instanceof Error ? error . message : String ( error ) } `
81- ) ;
82- }
59+ try {
60+ return ( await import ( packageName ) ) as unknown ;
61+ } catch ( error ) {
62+ throw new Error (
63+ `Failed to load LWC compiler for channel '${ channel } '. ` +
64+ `Package '${ packageName } ' could not be imported. ` +
65+ `Error: ${ error instanceof Error ? error . message : String ( error ) } ` ,
66+ ) ;
8367 }
68+ }
8469
85- /**
86- * Loads the base LWC module for the specified channel
87- *
88- * @param channel - The version channel ('latest' or 'prerelease')
89- * @returns The loaded LWC module
90- */
91- public static async loadLwc ( channel : VersionChannel ) : Promise < unknown > {
92- const packageName = `lwc-${ channel } ` ;
93-
94- try {
95- return ( await import ( packageName ) ) as unknown ;
96- } catch ( error ) {
97- throw new Error (
98- `Failed to load LWC for channel '${ channel } '. ` +
99- `Package '${ packageName } ' could not be imported. ` +
100- `Error: ${ error instanceof Error ? error . message : String ( error ) } `
101- ) ;
102- }
103- }
70+ /**
71+ * Loads the base LWC module for the specified channel
72+ *
73+ * @param channel - The version channel ('latest', 'prerelease', or 'next')
74+ * @returns The loaded LWC module
75+ */
76+ export async function loadLwc ( channel : VersionChannel ) : Promise < unknown > {
77+ const packageName = `lwc-${ channel } ` ;
10478
105- /**
106- * Clears the module cache (useful for testing)
107- */
108- public static clearCache ( ) : void {
109- this . loadedModules . clear ( ) ;
79+ try {
80+ return ( await import ( packageName ) ) as unknown ;
81+ } catch ( error ) {
82+ throw new Error (
83+ `Failed to load LWC for channel '${ channel } '. ` +
84+ `Package '${ packageName } ' could not be imported. ` +
85+ `Error: ${ error instanceof Error ? error . message : String ( error ) } ` ,
86+ ) ;
11087 }
11188}
0 commit comments