@@ -2,7 +2,6 @@ import { EventEmitter } from "events";
22import fs from "fs" ;
33import path from "path" ;
44
5- import type { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata" ;
65import type {
76 CompilerOptions ,
87 EmitOutput ,
@@ -59,10 +58,24 @@ export class TypescriptCompiler {
5958 appInfo,
6059 sourceFiles : files ,
6160 } : IAppSource ) : ICompilerResult {
61+ // Normalize all file keys, file names, and classFile to POSIX separators
62+ // once up front so getScriptFileNames(), getScriptVersion(), getScriptSnapshot(),
63+ // and all subsequent lookups into result.files operate on consistent keys.
64+ const posixClassFile = appInfo . classFile . replace ( / \\ / g, "/" ) ;
65+ const normalizedFiles : IMapCompilerFile = { } ;
66+ for ( const [ key , file ] of Object . entries ( files ) ) {
67+ const posixKey = key . replace ( / \\ / g, "/" ) ;
68+ normalizedFiles [ posixKey ] = {
69+ ...file ,
70+ name : file . name . replace ( / \\ / g, "/" ) ,
71+ } ;
72+ }
73+ files = normalizedFiles ;
74+
6275 if (
63- ! appInfo . classFile ||
64- ! files [ appInfo . classFile ] ||
65- ! this . isValidFile ( files [ appInfo . classFile ] )
76+ ! posixClassFile ||
77+ ! files [ posixClassFile ] ||
78+ ! this . isValidFile ( files [ posixClassFile ] )
6679 ) {
6780 throw new Error (
6881 `Invalid App package. Could not find the classFile (${ appInfo . classFile } ) file.` ,
@@ -219,7 +232,7 @@ export class TypescriptCompiler {
219232
220233 result . implemented = this . getImplementedInterfaces (
221234 languageService ,
222- appInfo ,
235+ posixClassFile ,
223236 ) ;
224237
225238 Object . defineProperty ( result , "diagnostics" , {
@@ -242,11 +255,10 @@ export class TypescriptCompiler {
242255 file . compiled = output . outputFiles [ 0 ] . text ;
243256 } ) ;
244257
245- result . mainFile =
246- result . files [ appInfo . classFile . replace ( / \. t s $ / , ".js" ) ] ;
258+ result . mainFile = result . files [ posixClassFile . replace ( / \. t s $ / , ".js" ) ] ;
247259
248260 this . appValidator . checkInheritance (
249- appInfo . classFile . replace ( / \. t s $ / , "" ) ,
261+ posixClassFile . replace ( / \. t s $ / , "" ) ,
250262 result ,
251263 ) ;
252264
@@ -344,13 +356,11 @@ export class TypescriptCompiler {
344356
345357 private getImplementedInterfaces (
346358 languageService : LanguageService ,
347- appInfo : IAppInfo ,
359+ classFile : string ,
348360 ) : ICompilerResult [ "implemented" ] {
349361 const result : ICompilerResult [ "implemented" ] = [ ] ;
350362
351- const src = languageService
352- . getProgram ( )
353- . getSourceFile ( appInfo . classFile ) ;
363+ const src = languageService . getProgram ( ) . getSourceFile ( classFile ) ;
354364
355365 this . ts . forEachChild ( src , ( n ) => {
356366 if ( ! this . ts . isClassDeclaration ( n ) ) {
@@ -406,10 +416,6 @@ export class TypescriptCompiler {
406416 return false ;
407417 }
408418
409- return (
410- file . name . trim ( ) !== "" &&
411- path . posix . normalize ( file . name ) &&
412- file . content . trim ( ) !== ""
413- ) ;
419+ return file . name . trim ( ) !== "" && file . content . trim ( ) !== "" ;
414420 }
415421}
0 commit comments