Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated services and harnesses and added a test
  • Loading branch information
rbuckton committed May 8, 2015
commit 57a81e6cf9ac136b85214a474d128066f02a06bc
49 changes: 39 additions & 10 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ module Utils {
export function getExecutionEnvironment() {
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
return ExecutionEnvironment.CScript;
} else if (typeof window !== "undefined") {
} else if (typeof window !== "undefined") {
return ExecutionEnvironment.Browser;
} else {
return ExecutionEnvironment.Node;
} else {
return ExecutionEnvironment.Node;
}
}

Expand Down Expand Up @@ -878,7 +878,8 @@ module Harness {
writeFile,
getCanonicalFileName,
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
getNewLine: () => newLine
getNewLine: () => newLine,
getPackagePath: getCurrentDirectory
};
}

Expand Down Expand Up @@ -1048,6 +1049,18 @@ module Harness {
case 'declaration':
options.declaration = !!setting.value;
break;

case 'packagename':
options.packageName = setting.value;
break;

case 'packagemain':
options.packageMain = setting.value;
break;

case 'packagedeclaration':
options.packageDeclaration = setting.value;
break;

case 'newline':
if (setting.value.toLowerCase() === 'crlf') {
Expand Down Expand Up @@ -1149,7 +1162,7 @@ module Harness {
options?: ts.CompilerOptions,
// Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
currentDirectory?: string) {
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length !== result.files.length) {
if (options.declaration && result.errors.length === 0 && (options.packageDeclaration ? result.declFilesCode.length !== 1 : result.declFilesCode.length !== result.files.length)) {
throw new Error('There were no errors and declFiles generated did not match number of js files generated');
}

Expand All @@ -1158,12 +1171,27 @@ module Harness {
var declInputFiles: { unitName: string; content: string }[] = [];
var declOtherFiles: { unitName: string; content: string }[] = [];
var declResult: Harness.Compiler.CompilerResult;

ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles));
ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));
if (options.packageDeclaration) {
let file = ts.forEach(result.declFilesCode, declFile => declFile.fileName === options.packageDeclaration ? declFile : undefined);
declInputFiles.push({ unitName: file.fileName, content: file.code });
ts.forEach(inputFiles, file => {
if (isDTS(file.unitName)) {
declInputFiles.push(file);
}
});
ts.forEach(otherFiles, file => {
if (isDTS(file.unitName)) {
declOtherFiles.push(file);
}
});
}
else {
ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles));
ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));
}

this.compileFiles(declInputFiles, declOtherFiles, function (compileResult) { declResult = compileResult; },
settingsCallback, options, currentDirectory);

return { declInputFiles, declOtherFiles, declResult };
}

Expand Down Expand Up @@ -1510,7 +1538,8 @@ module Harness {
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
"separatecompilation", "inlinesourcemap", "maproot", "sourceroot",
"inlinesources", "emitdecoratormetadata"];
"inlinesources", "emitdecoratormetadata", "packagemain", "packagename",
"packagedeclaration"];

function extractCompilerSettings(content: string): CompilerSetting[] {

Expand Down
3 changes: 2 additions & 1 deletion src/harness/projectsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ class ProjectRunner extends RunnerBase {
getCurrentDirectory,
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
getNewLine: () => ts.sys.newLine
getNewLine: () => ts.sys.newLine,
getPackagePath: getCurrentDirectory
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,7 @@ module ts {
useCaseSensitiveFileNames: () => false,
getCanonicalFileName: fileName => fileName,
getCurrentDirectory: () => "",
getPackagePath: () => "",
getNewLine: () => (sys && sys.newLine) || "\r\n"
};

Expand Down Expand Up @@ -2419,7 +2420,8 @@ module ts {
getNewLine: () => host.getNewLine ? host.getNewLine() : "\r\n",
getDefaultLibFileName: (options) => host.getDefaultLibFileName(options),
writeFile: (fileName, data, writeByteOrderMark) => { },
getCurrentDirectory: () => host.getCurrentDirectory()
getCurrentDirectory: () => host.getCurrentDirectory(),
getPackagePath: (emitHost?: EmitHost) => (emitHost && emitHost.getCommonSourceDirectory()) || host.getCurrentDirectory()
});

// Release any files we have acquired in the old program but are
Expand Down
13 changes: 13 additions & 0 deletions tests/cases/compiler/packageDeclarationEmit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @module: commonjs
// @target: es5
// @declaration: true
// @packageName: app
// @packageMain: index.ts
// @packageDeclaration: app.d.ts

// @filename: index.ts
export * from './ext';

// @filename: ext.ts
export function func(): void {
}