@@ -1375,78 +1375,70 @@ function foo() {
1375
1375
} ) ;
1376
1376
1377
1377
describe ( "when references are monorepo like with symlinks" , ( ) => {
1378
- function verifySession ( alreadyBuilt : boolean , extraOptions : CompilerOptions ) {
1379
- const bPackageJson : File = {
1380
- path : `${ projectRoot } /packages/B/package.json` ,
1381
- content : JSON . stringify ( {
1382
- main : "lib/index.js" ,
1383
- types : "lib/index.d.ts"
1384
- } )
1385
- } ;
1378
+ interface Packages {
1379
+ bPackageJson : File ;
1380
+ aTest : File ;
1381
+ bFoo : File ;
1382
+ bBar : File ;
1383
+ }
1384
+ function verifySymlinkScenario ( packages : ( ) => Packages ) {
1385
+ describe ( "when solution is not built" , ( ) => {
1386
+ it ( "with preserveSymlinks turned off" , ( ) => {
1387
+ verifySession ( packages ( ) , /*alreadyBuilt*/ false , { } ) ;
1388
+ } ) ;
1389
+
1390
+ it ( "with preserveSymlinks turned on" , ( ) => {
1391
+ verifySession ( packages ( ) , /*alreadyBuilt*/ false , { preserveSymlinks : true } ) ;
1392
+ } ) ;
1393
+ } ) ;
1394
+
1395
+ describe ( "when solution is already built" , ( ) => {
1396
+ it ( "with preserveSymlinks turned off" , ( ) => {
1397
+ verifySession ( packages ( ) , /*alreadyBuilt*/ true , { } ) ;
1398
+ } ) ;
1399
+
1400
+ it ( "with preserveSymlinks turned on" , ( ) => {
1401
+ verifySession ( packages ( ) , /*alreadyBuilt*/ true , { preserveSymlinks : true } ) ;
1402
+ } ) ;
1403
+ } ) ;
1404
+ }
1405
+
1406
+ function verifySession ( { bPackageJson, aTest, bFoo, bBar } : Packages , alreadyBuilt : boolean , extraOptions : CompilerOptions ) {
1386
1407
const aConfig = config ( "A" , extraOptions , [ "../B" ] ) ;
1387
1408
const bConfig = config ( "B" , extraOptions ) ;
1388
- const aIndex = index ( "A" , `import { foo } from 'b';
1389
- import { bar } from 'b/lib/bar';
1390
- foo();
1391
- bar();` ) ;
1392
- const bIndex = index ( "B" , `export function foo() { }` ) ;
1393
- const bBar : File = {
1394
- path : `${ projectRoot } /packages/B/src/bar.ts` ,
1395
- content : `export function bar() { }`
1396
- } ;
1397
1409
const bSymlink : SymLink = {
1398
1410
path : `${ projectRoot } /node_modules/b` ,
1399
1411
symLink : `${ projectRoot } /packages/B`
1400
1412
} ;
1401
-
1402
- const files = [ libFile , bPackageJson , aConfig , bConfig , aIndex , bIndex , bBar , bSymlink ] ;
1413
+ const files = [ libFile , bPackageJson , aConfig , bConfig , aTest , bFoo , bBar , bSymlink ] ;
1403
1414
const host = alreadyBuilt ?
1404
1415
createHost ( files , [ aConfig . path ] ) :
1405
1416
createServerHost ( files ) ;
1406
1417
1407
1418
// Create symlink in node module
1408
1419
const session = createSession ( host , { canUseEvents : true } ) ;
1409
- openFilesForSession ( [ aIndex ] , session ) ;
1420
+ openFilesForSession ( [ aTest ] , session ) ;
1410
1421
const service = session . getProjectService ( ) ;
1411
1422
const project = service . configuredProjects . get ( aConfig . path . toLowerCase ( ) ) ! ;
1412
1423
assert . deepEqual ( project . getAllProjectErrors ( ) , [ ] ) ;
1413
1424
checkProjectActualFiles (
1414
1425
project ,
1415
- [ aConfig . path , aIndex . path , bIndex . path , bBar . path , libFile . path ]
1426
+ [ aConfig . path , aTest . path , bFoo . path , bBar . path , libFile . path ]
1416
1427
) ;
1417
1428
verifyGetErrRequest ( {
1418
1429
host,
1419
1430
session,
1420
1431
expected : [
1421
- { file : aIndex , syntax : [ ] , semantic : [ ] , suggestion : [ ] }
1432
+ { file : aTest , syntax : [ ] , semantic : [ ] , suggestion : [ ] }
1422
1433
]
1423
1434
} ) ;
1424
1435
}
1425
1436
1426
- function verifySymlinkScenario ( alreadyBuilt : boolean ) {
1427
- it ( "with preserveSymlinks turned off" , ( ) => {
1428
- verifySession ( alreadyBuilt , { } ) ;
1429
- } ) ;
1430
-
1431
- it ( "with preserveSymlinks turned on" , ( ) => {
1432
- verifySession ( alreadyBuilt , { preserveSymlinks : true } ) ;
1433
- } ) ;
1434
- }
1435
-
1436
- describe ( "when solution is not built" , ( ) => {
1437
- verifySymlinkScenario ( /*alreadyBuilt*/ false ) ;
1438
- } ) ;
1439
-
1440
- describe ( "when solution is already built" , ( ) => {
1441
- verifySymlinkScenario ( /*alreadyBuilt*/ true ) ;
1442
- } ) ;
1443
-
1444
1437
function config ( packageName : string , extraOptions : CompilerOptions , references ?: string [ ] ) : File {
1445
1438
return {
1446
1439
path : `${ projectRoot } /packages/${ packageName } /tsconfig.json` ,
1447
1440
content : JSON . stringify ( {
1448
1441
compilerOptions : {
1449
- baseUrl : "." ,
1450
1442
outDir : "lib" ,
1451
1443
rootDir : "src" ,
1452
1444
composite : true ,
@@ -1458,12 +1450,45 @@ bar();`);
1458
1450
} ;
1459
1451
}
1460
1452
1461
- function index ( packageName : string , content : string ) : File {
1453
+ function file ( packageName : string , fileName : string , content : string ) : File {
1462
1454
return {
1463
- path : `${ projectRoot } /packages/${ packageName } /src/index.ts ` ,
1455
+ path : `${ projectRoot } /packages/${ packageName } /src/${ fileName } ` ,
1464
1456
content
1465
1457
} ;
1466
1458
}
1459
+
1460
+ describe ( "when packageJson has types field and has index.ts" , ( ) => {
1461
+ verifySymlinkScenario ( ( ) => ( {
1462
+ bPackageJson : {
1463
+ path : `${ projectRoot } /packages/B/package.json` ,
1464
+ content : JSON . stringify ( {
1465
+ main : "lib/index.js" ,
1466
+ types : "lib/index.d.ts"
1467
+ } )
1468
+ } ,
1469
+ aTest : file ( "A" , "index.ts" , `import { foo } from 'b';
1470
+ import { bar } from 'b/lib/bar';
1471
+ foo();
1472
+ bar();` ) ,
1473
+ bFoo : file ( "B" , "index.ts" , `export function foo() { }` ) ,
1474
+ bBar : file ( "B" , "bar.ts" , `export function bar() { }` )
1475
+ } ) ) ;
1476
+ } ) ;
1477
+
1478
+ describe ( "when referencing file from subFolder" , ( ) => {
1479
+ verifySymlinkScenario ( ( ) => ( {
1480
+ bPackageJson : {
1481
+ path : `${ projectRoot } /packages/B/package.json` ,
1482
+ content : "{}"
1483
+ } ,
1484
+ aTest : file ( "A" , "test.ts" , `import { foo } from 'b/lib/foo';
1485
+ import { bar } from 'b/lib/bar/foo';
1486
+ foo();
1487
+ bar();` ) ,
1488
+ bFoo : file ( "B" , "foo.ts" , `export function foo() { }` ) ,
1489
+ bBar : file ( "B" , "bar/foo.ts" , `export function bar() { }` )
1490
+ } ) ) ;
1491
+ } ) ;
1467
1492
} ) ;
1468
1493
} ) ;
1469
1494
}
0 commit comments