Skip to content

Commit e3a91d8

Browse files
authored
Merge pull request microsoft#31191 from Microsoft/fileFromNodeModules
Include only files that can be emitted into the source file directory check for composite projects
2 parents a86fa20 + a58fdf2 commit e3a91d8

File tree

5 files changed

+64
-4
lines changed

5 files changed

+64
-4
lines changed

src/compiler/program.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,10 +2768,8 @@ namespace ts {
27682768
if (options.composite) {
27692769
const rootPaths = rootNames.map(toPath);
27702770
for (const file of files) {
2771-
// Ignore declaration files
2772-
if (file.isDeclarationFile) continue;
2773-
// Ignore json file thats from project reference
2774-
if (isJsonSourceFile(file) && getResolvedProjectReferenceToRedirect(file.fileName)) continue;
2771+
// Ignore file that is not emitted
2772+
if (!sourceFileMayBeEmitted(file, options, isSourceFileFromExternalLibrary, getResolvedProjectReferenceToRedirect)) continue;
27752773
if (rootPaths.indexOf(file.path) === -1) {
27762774
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_in_project_file_list_Projects_must_list_all_files_or_use_an_include_pattern, file.fileName));
27772775
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/compiler/compositeWithNodeModulesSourceFile.ts] ////
2+
3+
//// [index.ts]
4+
export class c { }
5+
6+
//// [test.ts]
7+
import myModule = require("myModule");
8+
new myModule.c();
9+
10+
11+
12+
//// [test.js]
13+
"use strict";
14+
exports.__esModule = true;
15+
var myModule = require("myModule");
16+
new myModule.c();
17+
18+
19+
//// [test.d.ts]
20+
export {};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== /foo/test.ts ===
2+
import myModule = require("myModule");
3+
>myModule : Symbol(myModule, Decl(test.ts, 0, 0))
4+
5+
new myModule.c();
6+
>myModule.c : Symbol(myModule.c, Decl(index.ts, 0, 0))
7+
>myModule : Symbol(myModule, Decl(test.ts, 0, 0))
8+
>c : Symbol(myModule.c, Decl(index.ts, 0, 0))
9+
10+
11+
=== /foo/node_modules/myModule/index.ts ===
12+
export class c { }
13+
>c : Symbol(c, Decl(index.ts, 0, 0))
14+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== /foo/test.ts ===
2+
import myModule = require("myModule");
3+
>myModule : typeof myModule
4+
5+
new myModule.c();
6+
>new myModule.c() : myModule.c
7+
>myModule.c : typeof myModule.c
8+
>myModule : typeof myModule
9+
>c : typeof myModule.c
10+
11+
12+
=== /foo/node_modules/myModule/index.ts ===
13+
export class c { }
14+
>c : c
15+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @filename: /foo/tsconfig.json
2+
{
3+
"compilerOptions": { "composite": true },
4+
"exclude": [ "node_modules" ]
5+
}
6+
7+
// @filename: /foo/node_modules/myModule/index.ts
8+
export class c { }
9+
10+
// @filename: /foo/test.ts
11+
import myModule = require("myModule");
12+
new myModule.c();
13+

0 commit comments

Comments
 (0)