Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #31191 from Microsoft/fileFromNodeModules
  Include only files that can be emitted into the source file directory check for composite projects
  • Loading branch information
sheetalkamat committed May 1, 2019
2 parents a86fa20 + a58fdf2 commit e3a91d8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/compiler/program.ts
Expand Up @@ -2768,10 +2768,8 @@ namespace ts {
if (options.composite) {
const rootPaths = rootNames.map(toPath);
for (const file of files) {
// Ignore declaration files
if (file.isDeclarationFile) continue;
// Ignore json file thats from project reference
if (isJsonSourceFile(file) && getResolvedProjectReferenceToRedirect(file.fileName)) continue;
// Ignore file that is not emitted
if (!sourceFileMayBeEmitted(file, options, isSourceFileFromExternalLibrary, getResolvedProjectReferenceToRedirect)) continue;
if (rootPaths.indexOf(file.path) === -1) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_in_project_file_list_Projects_must_list_all_files_or_use_an_include_pattern, file.fileName));
}
Expand Down
20 changes: 20 additions & 0 deletions tests/baselines/reference/compositeWithNodeModulesSourceFile.js
@@ -0,0 +1,20 @@
//// [tests/cases/compiler/compositeWithNodeModulesSourceFile.ts] ////

//// [index.ts]
export class c { }

//// [test.ts]
import myModule = require("myModule");
new myModule.c();



//// [test.js]
"use strict";
exports.__esModule = true;
var myModule = require("myModule");
new myModule.c();


//// [test.d.ts]
export {};
@@ -0,0 +1,14 @@
=== /foo/test.ts ===
import myModule = require("myModule");
>myModule : Symbol(myModule, Decl(test.ts, 0, 0))

new myModule.c();
>myModule.c : Symbol(myModule.c, Decl(index.ts, 0, 0))
>myModule : Symbol(myModule, Decl(test.ts, 0, 0))
>c : Symbol(myModule.c, Decl(index.ts, 0, 0))


=== /foo/node_modules/myModule/index.ts ===
export class c { }
>c : Symbol(c, Decl(index.ts, 0, 0))

15 changes: 15 additions & 0 deletions tests/baselines/reference/compositeWithNodeModulesSourceFile.types
@@ -0,0 +1,15 @@
=== /foo/test.ts ===
import myModule = require("myModule");
>myModule : typeof myModule

new myModule.c();
>new myModule.c() : myModule.c
>myModule.c : typeof myModule.c
>myModule : typeof myModule
>c : typeof myModule.c


=== /foo/node_modules/myModule/index.ts ===
export class c { }
>c : c

13 changes: 13 additions & 0 deletions tests/cases/compiler/compositeWithNodeModulesSourceFile.ts
@@ -0,0 +1,13 @@
// @filename: /foo/tsconfig.json
{
"compilerOptions": { "composite": true },
"exclude": [ "node_modules" ]
}

// @filename: /foo/node_modules/myModule/index.ts
export class c { }

// @filename: /foo/test.ts
import myModule = require("myModule");
new myModule.c();

0 comments on commit e3a91d8

Please sign in to comment.