Added emitHost method to return source from node modules
This commit is contained in:
parent
de559fb3f4
commit
d8e3bd99e8
|
@ -1361,10 +1361,8 @@ namespace ts {
|
|||
getNewLine: () => host.getNewLine(),
|
||||
getSourceFile: program.getSourceFile,
|
||||
getSourceFileByPath: program.getSourceFileByPath,
|
||||
getSourceFiles: () => filter(program.getSourceFiles(),
|
||||
// Remove JavaScript files found by searching node_modules from the source files to emit
|
||||
sourceFile => !lookUp(jsFilesFoundSearchingNodeModules, sourceFile.path)
|
||||
),
|
||||
getSourceFiles: program.getSourceFiles,
|
||||
getFilesFromNodeModules: () => jsFilesFoundSearchingNodeModules,
|
||||
writeFile: writeFileCallback || (
|
||||
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
|
||||
isEmitBlocked,
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace ts {
|
|||
|
||||
export interface EmitHost extends ScriptReferenceHost {
|
||||
getSourceFiles(): SourceFile[];
|
||||
getFilesFromNodeModules(): Map<boolean>;
|
||||
|
||||
getCommonSourceDirectory(): string;
|
||||
getCanonicalFileName(fileName: string): string;
|
||||
|
@ -2274,9 +2275,10 @@ namespace ts {
|
|||
}
|
||||
else {
|
||||
const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile];
|
||||
const nodeModulesFiles = host.getFilesFromNodeModules();
|
||||
for (const sourceFile of sourceFiles) {
|
||||
// Don't emit if source file is a declaration file
|
||||
if (!isDeclarationFile(sourceFile)) {
|
||||
// Don't emit if source file is a declaration file, or was located under node_modules
|
||||
if (!isDeclarationFile(sourceFile) && !lookUp(nodeModulesFiles, sourceFile.path)) {
|
||||
onSingleFileEmit(host, sourceFile);
|
||||
}
|
||||
}
|
||||
|
@ -2308,11 +2310,14 @@ namespace ts {
|
|||
}
|
||||
|
||||
function onBundledEmit(host: EmitHost) {
|
||||
// Can emit only sources that are not declaration file and are either non module code or module with --module or --target es6 specified
|
||||
// Can emit only sources that are not declaration file and are either non module code or module with
|
||||
// --module or --target es6 specified. Files included by searching under node_modules are also not emitted.
|
||||
const nodeModulesFiles = host.getFilesFromNodeModules();
|
||||
const bundledSources = filter(host.getSourceFiles(),
|
||||
sourceFile => !isDeclarationFile(sourceFile) && // Not a declaration file
|
||||
(!isExternalModule(sourceFile) || // non module file
|
||||
!!getEmitModuleKind(options))); // module that can emit - note falsy value from getEmitModuleKind means the module kind that shouldn't be emitted
|
||||
sourceFile => !isDeclarationFile(sourceFile) &&
|
||||
!lookUp(nodeModulesFiles, sourceFile.path) &&
|
||||
(!isExternalModule(sourceFile) ||
|
||||
!!getEmitModuleKind(options)));
|
||||
if (bundledSources.length) {
|
||||
const jsFilePath = options.outFile || options.out;
|
||||
const emitFileNames: EmitFileNames = {
|
||||
|
|
Loading…
Reference in a new issue