Merge pull request #31191 from Microsoft/fileFromNodeModules

Include only files that can be emitted into the source file directory check for composite projects
This commit is contained in:
Sheetal Nandi
2019-05-01 15:09:32 -07:00
committed by GitHub
5 changed files with 64 additions and 4 deletions

View File

@@ -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));
}

View File

@@ -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 {};

View File

@@ -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))

View File

@@ -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

View File

@@ -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();