UNPKG

1.93 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2018 The Polymer Project Authors. All rights reserved. This
5 * code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt The complete set of authors may be
7 * found at http://polymer.github.io/AUTHORS.txt The complete set of
8 * contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code
9 * distributed by Google as part of the polymer project is also subject to an
10 * additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11 */
12Object.defineProperty(exports, "__esModule", { value: true });
13const ts = require("typescript");
14const compilerOptions = {
15 target: ts.ScriptTarget.ES2015,
16 module: ts.ModuleKind.ES2015,
17 moduleResolution: ts.ModuleResolutionKind.NodeJs,
18 strict: true,
19 noUnusedLocals: true,
20 noUnusedParameters: true,
21 declaration: true,
22 lib: [
23 'lib.dom.d.ts',
24 'lib.esnext.d.ts',
25 ],
26};
27const diagnosticsHost = {
28 getNewLine: () => '\n',
29 getCurrentDirectory: () => process.cwd(),
30 getCanonicalFileName: (fileName) => fileName,
31};
32/**
33 * Compile the given declaration file paths with TypeScript and return whether
34 * compilation succeeded or failed, and a "pretty" formatted error log string.
35 *
36 * Uses a TypeScript compiler configuration suitable for web development, and
37 * strict type checking.
38 */
39function verifyTypings(filePaths) {
40 const program = ts.createProgram(filePaths, compilerOptions);
41 const emitResult = program.emit();
42 const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
43 if (diagnostics.length > 0) {
44 return {
45 success: false,
46 errorLog: ts.formatDiagnosticsWithColorAndContext(diagnostics, diagnosticsHost)
47 };
48 }
49 return { success: true, errorLog: '' };
50}
51exports.verifyTypings = verifyTypings;
52//# sourceMappingURL=verify.js.map
\No newline at end of file