Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have the typescript package perform as much processing of the configuration file as possible. #359

Merged
merged 2 commits into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions src/lib/converter/converter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ts from "typescript";
import * as _ts from "../ts-internal";
import * as Path from "path";
import * as _ from "lodash";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to note that this is also a part of #353.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wrote in the initial submission: "The first commit in this PR is fixing the same problem as in #353. I need it there, otherwise the code does not compile. I'll remove it once #353 is merged."


import {Application} from "../application";
import {ParameterType} from "../utils/options/declaration";
Expand Down Expand Up @@ -424,19 +425,19 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
program.getSourceFiles().forEach((sourceFile) => {
this.convertNode(context, sourceFile);
});

let diagnostics = program.getOptionsDiagnostics();
if (diagnostics.length) return diagnostics;

diagnostics = program.getSyntacticDiagnostics();
if (diagnostics.length) return diagnostics;

diagnostics = program.getGlobalDiagnostics();
if (diagnostics.length) return diagnostics;

diagnostics = program.getSemanticDiagnostics();
if (diagnostics.length) return diagnostics;

return [];
}

Expand Down
30 changes: 17 additions & 13 deletions src/lib/utils/options/readers/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export class TSConfigReader extends OptionsComponent
if (TSConfigReader.OPTIONS_KEY in event.data) {
this.load(event, Path.resolve(event.data[TSConfigReader.OPTIONS_KEY]));
} else if (this.application.isCLI) {
var file = Path.resolve('tsconfig.json');
if (FS.existsSync(file)) {
let file:string = ts.findConfigFile(".", ts.sys.fileExists);
// If file is undefined, we found no file to load.
if (file) {
this.load(event, file);
}
}
Expand All @@ -56,7 +57,7 @@ export class TSConfigReader extends OptionsComponent
return;
}

var data = ts.readConfigFile(fileName, (fileName) => ts.sys.readFile(fileName)).config;
let data = ts.readConfigFile(fileName, ts.sys.readFile).config;
if (data === undefined) {
event.addError('The tsconfig file %s does not contain valid JSON.', fileName);
return;
Expand All @@ -66,20 +67,23 @@ export class TSConfigReader extends OptionsComponent
return;
}

if ("files" in data && _.isArray(data.files)) {
event.inputFiles = data.files;
}
data = ts.parseJsonConfigFileContent(
data,
ts.sys,
Path.resolve(Path.dirname(fileName)),
{},
Path.resolve(fileName));

if ("compilerOptions" in data) {
var ignored = TypeScriptSource.IGNORED;
var compilerOptions = _.clone(data.compilerOptions);
for (var key of ignored) {
delete compilerOptions[key];
}
event.inputFiles = data.fileNames;

_.merge(event.data, compilerOptions);
const ignored = TypeScriptSource.IGNORED;
let compilerOptions = _.clone(data.raw.compilerOptions);
for (const key of ignored) {
delete compilerOptions[key];
}

_.merge(event.data, compilerOptions);

if ("typedocOptions" in data) {
_.merge(event.data, data.typedocOptions);
}
Expand Down