@@ -2,7 +2,8 @@ import * as path from "path";
22import * as tstl from "../../src" ;
33import * as util from "../util" ;
44import * as ts from "typescript" ;
5- import { BuildMode , transpileProject } from "../../src" ;
5+ import { BuildMode } from "../../src" ;
6+ import { normalizeSlashes } from "../../src/utils" ;
67
78describe ( "basic module resolution" , ( ) => {
89 const projectPath = path . resolve ( __dirname , "module-resolution" , "project-with-node-modules" ) ;
@@ -236,8 +237,8 @@ describe("module resolution project with dependencies built by tstl library mode
236237 const projectPath = path . resolve ( __dirname , "module-resolution" , "project-with-tstl-library-modules" ) ;
237238
238239 // First compile dependencies into node_modules. NOTE: Actually writing to disk, very slow
239- transpileProject ( path . join ( projectPath , "dependency1-ts" , "tsconfig.json" ) ) ;
240- transpileProject ( path . join ( projectPath , "dependency2-ts" , "tsconfig.json" ) ) ;
240+ tstl . transpileProject ( path . join ( projectPath , "dependency1-ts" , "tsconfig.json" ) ) ;
241+ tstl . transpileProject ( path . join ( projectPath , "dependency2-ts" , "tsconfig.json" ) ) ;
241242
242243 const expectedResult = {
243244 dependency1IndexResult : "function in dependency 1 index: dependency1OtherFileFunc in dependency1/d1otherfile" ,
@@ -538,3 +539,54 @@ test("lualib_module with parent directory import (#1307)", () => {
538539 FEATURE_CONSTANT : 456 ,
539540 } ) ;
540541} ) ;
542+
543+ test ( "supports paths configuration" , ( ) => {
544+ // Package root
545+ const baseProjectPath = path . resolve ( __dirname , "module-resolution" , "monorepo-with-paths" ) ;
546+ // myprogram package
547+ const projectPath = path . join ( baseProjectPath , "myprogram" ) ;
548+ const projectTsConfig = path . join ( projectPath , "tsconfig.json" ) ;
549+ const mainFile = path . join ( projectPath , "main.ts" ) ;
550+
551+ const luaResult = util
552+ . testProject ( projectTsConfig )
553+ . setMainFileName ( mainFile )
554+ . expectToHaveNoDiagnostics ( )
555+ . getLuaResult ( ) ;
556+
557+ expect ( snapshotPaths ( luaResult . transpiledFiles ) ) . toMatchSnapshot ( ) ;
558+
559+ // Bundle to have all files required to execute and check result
560+ util . testProject ( projectTsConfig )
561+ . setMainFileName ( mainFile )
562+ . setOptions ( { luaBundle : "bundle.lua" , luaBundleEntry : mainFile } )
563+ . expectToEqual ( { foo : 314 , bar : 271 } ) ;
564+ } ) ;
565+
566+ test ( "supports complicated paths configuration" , ( ) => {
567+ // Package root
568+ const baseProjectPath = path . resolve ( __dirname , "module-resolution" , "monorepo-complicated" ) ;
569+ // myprogram package
570+ const projectPath = path . join ( baseProjectPath , "packages" , "myprogram" ) ;
571+ const projectTsConfig = path . join ( projectPath , "tsconfig.json" ) ;
572+ const mainFile = path . join ( projectPath , "src" , "main.ts" ) ;
573+
574+ const luaResult = util
575+ . testProject ( projectTsConfig )
576+ . setMainFileName ( mainFile )
577+ . expectToHaveNoDiagnostics ( )
578+ . getLuaResult ( ) ;
579+
580+ expect ( snapshotPaths ( luaResult . transpiledFiles ) ) . toMatchSnapshot ( ) ;
581+
582+ // Bundle to have all files required to execute
583+ util . testProject ( projectTsConfig )
584+ . setMainFileName ( mainFile )
585+ . setOptions ( { luaBundle : "bundle.lua" , luaBundleEntry : mainFile } )
586+ . debug ( )
587+ . expectToEqual ( { foo : 314 , bar : 271 } ) ;
588+ } ) ;
589+
590+ function snapshotPaths ( files : tstl . TranspiledFile [ ] ) {
591+ return files . map ( f => normalizeSlashes ( f . outPath ) . split ( "module-resolution" ) [ 1 ] ) . sort ( ) ;
592+ }
0 commit comments