forked from barbatus/meteor-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
99 lines (77 loc) · 2.56 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var ts = require("typescript");
var _ = require("underscore");
function presetCompilerOptions(customOptions) {
if (! customOptions) return;
var compilerOptions = customOptions;
// Declaration files are expected to
// be generated separately.
compilerOptions.declaration = false;
// Overrides watching,
// it is handled by Meteor itself.
compilerOptions.watch = false;
// We use source maps via Meteor file API,
// This class's API provides source maps
// separately but alongside compilation results.
// Hence, skip generating inline source maps.
compilerOptions.inlineSourceMap = false;
compilerOptions.inlineSources = false;
// Always emit.
compilerOptions.noEmit = false;
compilerOptions.noEmitOnError = false;
// Don't generate any files, hence,
// skip setting outDir and outFile.
compilerOptions.outDir = null;
compilerOptions.outFile = null;
// This is not need as well.
// API doesn't have paramless methods.
compilerOptions.rootDir = null;
compilerOptions.sourceRoot = null;
return compilerOptions;
}
exports.presetCompilerOptions = presetCompilerOptions;
// Default compiler options.
function getDefaultCompilerOptions(arch) {
var options = {
target: "es5",
module : "commonjs",
moduleResolution: "node",
sourceMap: true,
noResolve: false,
lib: ["es5"],
diagnostics: true,
noEmitHelpers: true,
// Always emit class metadata,
// especially useful for Angular2.
emitDecoratorMetadata: true,
// Support decorators by default.
experimentalDecorators: true,
// Don't impose `use strict`
noImplicitUseStrict: true,
baseUrl: ".",
rootDirs: ["."],
};
if (/^web/.test(arch)) {
options.lib.push("dom");
}
return options;
}
exports.getDefaultCompilerOptions = getDefaultCompilerOptions;
// Validate compiler options and convert them from
// user-friendly format to enum values used by TypeScript, e.g.:
// 'system' string converted to ts.ModuleKind.System value.
function convertCompilerOptionsOrThrow(options) {
if (! options) return null;
var result = ts.convertCompilerOptionsFromJson(options, "");
if (result.errors && result.errors.length) {
throw new Error(result.errors[0].messageText);
}
return result.options;
}
exports.convertCompilerOptionsOrThrow = convertCompilerOptionsOrThrow;
function validateTsConfig(configJson) {
var result = ts.parseJsonConfigFileContent(configJson, ts.sys, "");
if (result.errors && result.errors.length) {
throw new Error(result.errors[0].messageText);
}
}
exports.validateTsConfig = validateTsConfig;